diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml
index 7232b68b..e4a9cdc4 100644
--- a/composeApp/src/commonMain/composeResources/values/strings.xml
+++ b/composeApp/src/commonMain/composeResources/values/strings.xml
@@ -20,6 +20,8 @@
an em dash or a comma. The compose resources plugin reports that only as
"XML file ... is not valid. Check the file content."
-->
+ Abandoned
+ All
Curare
Add a dialect the group can translate into
Add artifact to library
@@ -108,6 +110,7 @@
I have saved my recovery phrase somewhere safe.
I understand that if I lose this phone and my recovery phrase, I lose this profile and the funds in its wallet.
If you are new to Curare or just want to create a fresh profile
+ In progress
Initial version label
Input npub... or nip05
Introduce yourself
@@ -151,6 +154,7 @@
Name (eg. Alan Turing)
Name (eg. Group Discussions)
Name of artifact
+ Needs you
Network relays
No wallet is open on this device, so there is no phrase to show.
Not backed up yet
@@ -167,9 +171,12 @@
No one selected yet
No one to add yet.
No projects exists in this group.
+ No proposal has been abandoned.
+ No proposal is in progress.
No translations yet.
No versions.
Not now
+ Nothing is waiting for your signature.
Nothing was created and no key exists. It is safe to run it again.
Open chat
Original
@@ -221,6 +228,7 @@
Send message
Share profile
Shared key
+ Signed
Signing key
The key this room signs as, and the ceremony it came from.
What the group signed
@@ -265,6 +273,7 @@
This decides who can change the group later. You can't switch afterwards.
This group has no shared key, so it cannot sign them in.
This group has not been asked to sign anything yet.
+ This group has not signed anything yet.
This is fixed once the ceremony runs. Changing it later means generating a new key.
This is the last thing the ceremony needs from you.
This will be shown when people open the chat for more details.
@@ -334,6 +343,7 @@
%1$s event(s) still unreadable%2$s
%1$s events, signed together
Everyone has to be online at the same time — the ceremony can only finish once all %1$s of you have taken part.
+ %1$s · %2$s
"%1$s" functionality coming soon
How should %1$s be run?
Invite %1$s
diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/ProposalListScreen.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/ProposalListScreen.kt
index a16fdce1..72611630 100644
--- a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/ProposalListScreen.kt
+++ b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/composable/ProposalListScreen.kt
@@ -1,25 +1,26 @@
package to.curare.compose.ui.composable
+import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
-import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
+import androidx.compose.foundation.rememberScrollState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material.icons.filled.ChevronRight
import androidx.compose.material.icons.filled.Draw
import androidx.compose.material.icons.filled.ErrorOutline
import androidx.compose.material.icons.filled.HourglassEmpty
+import androidx.compose.material.icons.filled.Inbox
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
-import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.FilterChip
import androidx.compose.material3.Icon
import androidx.compose.material3.ListItem
import androidx.compose.material3.ListItemDefaults
@@ -33,7 +34,6 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
@@ -51,19 +51,34 @@ import to.curare.compose.ui.composable.navigation.routes.FrostSigningRoute
import to.curare.compose.ui.composable.navigation.routes.Route
import to.curare.compose.ui.theme.CurareTheme
import to.curare.compose.ui.view.model.ProposalListViewModel
+import to.curare.compose.ui.view.state.ProposalFilter
import to.curare.compose.ui.view.state.ProposalListUIState
import to.curare.compose.ui.view.state.ProposalState
import to.curare.compose.ui.theme.spacing
import curare.composeapp.generated.resources.Res
import org.jetbrains.compose.resources.stringResource
+import curare.composeapp.generated.resources.abandoned
import curare.composeapp.generated.resources.everything_else
+import curare.composeapp.generated.resources.filter_all
+import curare.composeapp.generated.resources.filter_and_count
+import curare.composeapp.generated.resources.in_progress
+import curare.composeapp.generated.resources.needs_you
+import curare.composeapp.generated.resources.no_proposal_has_been_abandoned
+import curare.composeapp.generated.resources.no_proposal_is_in_progress
+import curare.composeapp.generated.resources.nothing_is_waiting_for_your_signature
+import curare.composeapp.generated.resources.signed
+import curare.composeapp.generated.resources.this_group_has_not_signed_anything_yet
import curare.composeapp.generated.resources.proposals
import curare.composeapp.generated.resources.review
import curare.composeapp.generated.resources.this_group_has_not_been_asked_to_sign
import curare.composeapp.generated.resources.waiting_for_you
import curare.composeapp.generated.resources.of_them_could_not_be_read
import androidx.compose.material3.SnackbarHost
+import to.curare.compose.ui.composable.widgets.EmptyState
+import to.curare.compose.ui.composable.widgets.ErrorState
+import to.curare.compose.ui.composable.widgets.LoadingDataIndicator
import to.curare.compose.ui.composable.widgets.LocalSnackbarHostState
+import to.curare.compose.ui.composable.widgets.ScreenStateTransition
import to.curare.compose.ui.composable.widgets.NavigateBackButton
import to.curare.compose.ui.theme.readableContent
import to.curare.compose.ui.theme.ConformancePreviews
@@ -93,13 +108,15 @@ fun ProposalListScreen(
frostSigningRepository: FrostSigningRepository,
onNavigateBack: () -> Unit,
onNavigateToRoute: (Route) -> Unit,
+ initialFilter: ProposalFilter = ProposalFilter.ALL,
) {
val proposalListViewModel: ProposalListViewModel = viewModel(
factory = ProposalListViewModel.factory(
chatRoomId = chatRoomId,
initialProposalListUIState = initialProposalListUIState,
chatRepository = chatRepository,
- frostSigningRepository = frostSigningRepository
+ frostSigningRepository = frostSigningRepository,
+ initialFilter = initialFilter
)
)
@@ -124,84 +141,55 @@ fun ProposalListScreen(
)
}
) { padding ->
- when (val state = proposalListViewModel.proposalListUIState) {
- is ProposalListUIState.Loading -> Column(
- modifier = Modifier.fillMaxWidth().padding(padding).readableContent().padding(MaterialTheme.spacing.space250),
- horizontalAlignment = Alignment.CenterHorizontally
- ) {
- Spacer(modifier = Modifier.height(MaterialTheme.spacing.space600))
- CircularProgressIndicator()
- }
+ ScreenStateTransition(proposalListViewModel.proposalListUIState) { uiState ->
+ when (val state = uiState) {
+ is ProposalListUIState.Loading -> LoadingDataIndicator(
+ modifier = Modifier.fillMaxSize().padding(padding).readableContent()
+ )
- is ProposalListUIState.Error -> Column(
- modifier = Modifier.fillMaxWidth().padding(padding).readableContent().padding(MaterialTheme.spacing.space250),
- horizontalAlignment = Alignment.CenterHorizontally
- ) {
- Spacer(modifier = Modifier.height(MaterialTheme.spacing.space600))
- Text(text = state.message, textAlign = TextAlign.Center)
- }
+ is ProposalListUIState.Error -> ErrorState(
+ message = state.message,
+ // Nothing to retry: the room either exists on this device or
+ // it does not, and looking again will not change that.
+ onRetry = null,
+ modifier = Modifier.fillMaxSize().padding(padding).readableContent()
+ )
- is ProposalListUIState.Loaded -> {
- val open: (ProposalListUIState.Proposal) -> Unit = { proposal ->
- onNavigateToRoute.invoke(
- FrostSigningRoute(
- activeUserPublicKey = activeUserPublicKey,
- chatRoomId = chatRoomId,
- sessionId = proposal.session.id
+ is ProposalListUIState.Loaded -> {
+ val open: (ProposalListUIState.Proposal) -> Unit = { proposal ->
+ onNavigateToRoute.invoke(
+ FrostSigningRoute(
+ activeUserPublicKey = activeUserPublicKey,
+ chatRoomId = chatRoomId,
+ sessionId = proposal.session.id
+ )
)
- )
- }
-
- LazyColumn(
- modifier = Modifier.padding(padding).readableContent().fillMaxSize().padding(MaterialTheme.spacing.space250),
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space125)
- ) {
- if (state.proposals.isEmpty()) {
- item {
- Text(
- modifier = Modifier.fillMaxWidth().padding(top = MaterialTheme.spacing.space600),
- text = stringResource(Res.string.this_group_has_not_been_asked_to_sign),
- textAlign = TextAlign.Center
- )
- }
}
- if (state.waitingForYou.isNotEmpty()) {
- item {
- Text(
- text = stringResource(Res.string.waiting_for_you),
- style = MaterialTheme.typography.labelMedium,
- color = MaterialTheme.colorScheme.primary
+ Column(
+ modifier = Modifier.fillMaxSize().padding(padding).readableContent()
+ ) {
+ // Outside the list rather than its first item, because a
+ // control that scrolls away is a control the reader has to
+ // scroll back for -- and the list it filters is as long as
+ // the group's whole signing history.
+ //
+ // A room with nothing in it has nothing to filter, and five
+ // chips reading 0 over an empty screen would be five ways of
+ // saying what the empty state says once.
+ if (state.proposals.isNotEmpty()) {
+ ProposalFilterRow(
+ selected = state.filter,
+ counts = state.counts,
+ onSelect = proposalListViewModel::select
)
}
- items(
- items = state.waitingForYou,
- key = { it.session.id }
- ) { proposal ->
- ProposalCard(proposal = proposal, onClick = { open(proposal) })
- }
- }
-
- if (state.rest.isNotEmpty()) {
- // Headed only when there is a section above to tell it
- // apart from; on its own it is the whole screen, which
- // the title already says.
- if (state.waitingForYou.isNotEmpty()) {
- item {
- Text(
- text = stringResource(Res.string.everything_else),
- style = MaterialTheme.typography.labelMedium
- )
- }
- }
-
- items(
- items = state.rest,
- key = { it.session.id }
- ) { proposal ->
- ProposalCard(proposal = proposal, onClick = { open(proposal) })
- }
+ ProposalList(
+ state = state,
+ onOpen = open,
+ modifier = Modifier.weight(1f)
+ )
}
}
}
@@ -209,6 +197,164 @@ fun ProposalListScreen(
}
}
+/**
+ * The rows the current filter asks for.
+ *
+ * Two layouts behind one list, and which one is drawn is the filter's doing.
+ * Unfiltered, the sections stay: what is waiting on the reader is a different
+ * kind of thing to read from what the group has done, and burying the first in
+ * the second is what this screen was written to stop. Filtered, the sections go
+ * -- "waiting for you" against "everything else" is a distinction the reader has
+ * already made by tapping a chip, and heading a single-state list with it would
+ * be answering a question nobody asked.
+ */
+@Composable
+private fun ProposalList(
+ state: ProposalListUIState.Loaded,
+ onOpen: (ProposalListUIState.Proposal) -> Unit,
+ modifier: Modifier = Modifier,
+) {
+ // Said rather than defaulted, because five different absences used to say one
+ // thing here. A filter with nothing in it is not the same fact as a group that
+ // has never been asked to sign, and the queue running dry is not an absence at
+ // all -- it is the reader having finished.
+ if (state.visible.isEmpty()) {
+ EmptyState(
+ message = when (state.filter) {
+ ProposalFilter.ALL -> stringResource(Res.string.this_group_has_not_been_asked_to_sign)
+ ProposalFilter.NEEDS_YOU -> stringResource(Res.string.nothing_is_waiting_for_your_signature)
+ ProposalFilter.IN_PROGRESS -> stringResource(Res.string.no_proposal_is_in_progress)
+ ProposalFilter.SIGNED -> stringResource(Res.string.this_group_has_not_signed_anything_yet)
+ ProposalFilter.ABANDONED -> stringResource(Res.string.no_proposal_has_been_abandoned)
+ },
+ icon = when (state.filter) {
+ // The queue emptying is the end of the work, not a blank screen,
+ // so it keeps the icon the rows it replaced were carrying.
+ ProposalFilter.NEEDS_YOU -> Icons.Default.Draw
+ else -> Icons.Default.Inbox
+ },
+ modifier = modifier.fillMaxSize()
+ )
+
+ return
+ }
+
+ LazyColumn(
+ modifier = modifier.fillMaxSize().padding(MaterialTheme.spacing.containerPadding),
+ verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.relatedGap)
+ ) {
+ if (state.filter != ProposalFilter.ALL) {
+ items(items = state.visible, key = { it.session.id }) { proposal ->
+ ProposalCard(proposal = proposal, onClick = { onOpen(proposal) })
+ }
+
+ return@LazyColumn
+ }
+
+ if (state.waitingForYou.isNotEmpty()) {
+ item {
+ Text(
+ text = stringResource(Res.string.waiting_for_you),
+ style = MaterialTheme.typography.labelMedium,
+ color = MaterialTheme.colorScheme.primary
+ )
+ }
+
+ items(
+ items = state.waitingForYou,
+ key = { it.session.id }
+ ) { proposal ->
+ ProposalCard(proposal = proposal, onClick = { onOpen(proposal) })
+ }
+ }
+
+ if (state.rest.isNotEmpty()) {
+ // Headed only when there is a section above to tell it
+ // apart from; on its own it is the whole screen, which
+ // the title already says.
+ if (state.waitingForYou.isNotEmpty()) {
+ item {
+ Text(
+ text = stringResource(Res.string.everything_else),
+ style = MaterialTheme.typography.labelMedium
+ )
+ }
+ }
+
+ items(
+ items = state.rest,
+ key = { it.session.id }
+ ) { proposal ->
+ ProposalCard(proposal = proposal, onClick = { onOpen(proposal) })
+ }
+ }
+ }
+}
+
+/**
+ * One chip per state, and one for all of them.
+ *
+ * Scrolls sideways rather than wrapping. Five chips carrying counts will not fit
+ * 360dp at the largest text size the reader can ask for, and a row that reflows
+ * to a second line moves the list under the thumb that was about to tap it. The
+ * first chip is [ProposalFilter.NEEDS_YOU]'s neighbour on purpose: the reason to
+ * arrive here with a filter in mind is almost always that one.
+ *
+ * Every chip is present even at zero, which is the same reasoning from the other
+ * side -- chips that come and go as sessions advance move the row, and sessions
+ * advance while this screen is open.
+ */
+@Composable
+private fun ProposalFilterRow(
+ selected: ProposalFilter,
+ counts: Map,
+ onSelect: (ProposalFilter) -> Unit,
+) {
+ Row(
+ modifier = Modifier
+ .fillMaxWidth()
+ .horizontalScroll(rememberScrollState())
+ .padding(
+ horizontal = MaterialTheme.spacing.containerPadding,
+ vertical = MaterialTheme.spacing.compactPadding
+ ),
+ horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap)
+ ) {
+ for (filter in ProposalFilter.entries) {
+ val label = labelOf(filter)
+
+ FilterChip(
+ selected = filter == selected,
+ onClick = { onSelect(filter) },
+ label = {
+ Text(
+ text = when (val state = filter.state) {
+ // "All" carries no number: it is every chip's counts
+ // added up, which the chips beside it already say.
+ null -> label
+ else -> stringResource(
+ Res.string.filter_and_count,
+ label,
+ counts[state] ?: 0
+ )
+ }
+ )
+ }
+ )
+ }
+ }
+}
+
+/** What a chip calls its state, in sentence case because M3 says so. */
+@Composable
+private fun labelOf(filter: ProposalFilter): String = when (filter) {
+ ProposalFilter.ALL -> stringResource(Res.string.filter_all)
+ ProposalFilter.NEEDS_YOU -> stringResource(Res.string.needs_you)
+ ProposalFilter.IN_PROGRESS -> stringResource(Res.string.in_progress)
+ ProposalFilter.SIGNED -> stringResource(Res.string.signed)
+ ProposalFilter.ABANDONED -> stringResource(Res.string.abandoned)
+}
+
/**
* One proposal, named after the first thing it signs.
*
diff --git a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/model/ProposalListViewModel.kt b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/model/ProposalListViewModel.kt
index b07daa6c..5c740e82 100644
--- a/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/model/ProposalListViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/to/curare/compose/ui/view/model/ProposalListViewModel.kt
@@ -59,6 +59,14 @@ class ProposalListViewModel(
private val logger = Logger.withTag(TAG)
+ init {
+ // A `Loaded` handed straight in -- a preview, a screen test -- carries a
+ // filter of its own, and [initialFilter] is the caller's. The caller's
+ // wins, so no screen can open with its chips saying one thing and its
+ // rows showing another.
+ select(initialFilter)
+ }
+
/**
* Loads the room, then watches its proposals for as long as the screen lives.
*
diff --git a/composeApp/src/jvmTest/kotlin/to/curare/compose/ui/composable/ProposalListScreenJvmTest.kt b/composeApp/src/jvmTest/kotlin/to/curare/compose/ui/composable/ProposalListScreenJvmTest.kt
new file mode 100644
index 00000000..b4239dac
--- /dev/null
+++ b/composeApp/src/jvmTest/kotlin/to/curare/compose/ui/composable/ProposalListScreenJvmTest.kt
@@ -0,0 +1,292 @@
+package to.curare.compose.ui.composable
+
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.test.ComposeUiTest
+import androidx.compose.ui.test.ExperimentalTestApi
+import androidx.compose.ui.test.assertCountEquals
+import androidx.compose.ui.test.assertIsDisplayed
+import androidx.compose.ui.test.getBoundsInRoot
+import androidx.compose.ui.test.onAllNodesWithText
+import androidx.compose.ui.test.onNodeWithContentDescription
+import androidx.compose.ui.test.onNodeWithText
+import androidx.compose.ui.test.performClick
+import androidx.compose.ui.test.performScrollTo
+import androidx.compose.ui.test.runDesktopComposeUiTest
+import to.curare.compose.database.model.FrostSigningSession
+import to.curare.compose.database.model.types.FrostSigningStage
+import to.curare.compose.repository.ChatRepository
+import to.curare.compose.repository.FrostSigningRepository
+import to.curare.compose.text.ProposedEvent
+import to.curare.compose.ui.composable.GroupSignedWorkFixtures.activeUserPublicKey
+import to.curare.compose.ui.composable.GroupSignedWorkFixtures.chatRoomId
+import to.curare.compose.ui.composable.navigation.routes.Route
+import to.curare.compose.ui.composable.widgets.ProvideSnackbarHost
+import to.curare.compose.ui.theme.CurareTheme
+import to.curare.compose.ui.view.state.ProposalFilter
+import to.curare.compose.ui.view.state.ProposalListUIState
+import kotlin.test.Test
+import kotlin.test.assertTrue
+import kotlin.time.Clock
+
+/**
+ * The chip row over the proposal list: what it offers, what it counts, and what
+ * tapping one does to the rows beneath it.
+ *
+ * **Every state is offered, with its own number.** A chip is present at zero
+ * too, which is the decision worth testing rather than the obvious one: the
+ * alternative is a row that gains and loses chips as sessions advance, and
+ * sessions advance while this screen is open -- somebody else signing is exactly
+ * when a member comes to look at it.
+ *
+ * **A filter flattens the screen.** Unfiltered, the two sections stay, because
+ * what is waiting on the reader reads differently from what the group has done.
+ * Filtered, the headings go: the reader has already said which they want by
+ * tapping, and heading a single-state list with "waiting for you" would answer a
+ * question nobody asked.
+ *
+ * **An empty filter says which emptiness it is.** One shared "nothing found" is
+ * how five different absences here came to say one thing. A group never asked to
+ * sign and a queue the reader has worked through are not the same fact, and the
+ * second is not an absence at all.
+ */
+@OptIn(ExperimentalTestApi::class)
+class ProposalListScreenJvmTest {
+ private val session = FrostSigningSession(
+ id = "needs",
+ chatRoomId = chatRoomId,
+ coordinatorPublicKey = "c".repeat(64),
+ userPublicKey = activeUserPublicKey,
+ dkgSessionId = "ceremony",
+ threshold = 2,
+ participantCount = 3,
+ signerId = 2,
+ )
+
+ private fun proposal(
+ id: String,
+ label: String,
+ detail: String,
+ stage: FrostSigningStage = FrostSigningStage.COLLECTING_NONCES,
+ awaitsYou: Boolean = false,
+ approved: Boolean = false,
+ ) = ProposalListUIState.Proposal(
+ session = session.copy(
+ id = id,
+ stage = stage,
+ signApprovedAt = Clock.System.now().takeIf { approved },
+ ),
+ proposerName = "Ada",
+ signs = listOf(ProposedEvent.Summary(label, detail)),
+ awaitsYou = awaitsYou,
+ )
+
+ private val needsYou = proposal("needs", "New chapter", "Genesis 1", awaitsYou = true)
+ private val alsoNeedsYou = proposal("also", "New chapter", "Genesis 2", awaitsYou = true)
+ private val open = proposal("open", "New translation", "isiZulu", approved = true)
+ private val signed = proposal("signed", "New post", "A note", stage = FrostSigningStage.COMPLETE)
+
+ private val mixed = listOf(needsYou, alsoNeedsYou, open, signed)
+
+ /**
+ * Scrolls a chip into view and returns it.
+ *
+ * The row scrolls sideways by design -- five counted chips do not fit the
+ * sixty characters `readableContent` holds the column to -- so reaching the
+ * last one is what the reader does as well.
+ */
+ private fun ComposeUiTest.chip(label: String) =
+ onNodeWithText(label).performScrollTo().assertIsDisplayed()
+
+ @Test
+ fun `every state is offered with its own count, zero included`() = render(loaded(mixed)) {
+ // Two in the queue, one in progress, one signed -- and nothing abandoned,
+ // which still gets a chip rather than vanishing.
+ chip("All")
+ chip("Needs you · 2")
+ chip("In progress · 1")
+ chip("Signed · 1")
+ chip("Abandoned · 0")
+ }
+
+ @Test
+ fun `the chips are offered above the rows, in the order the states run`() =
+ render(loaded(mixed)) {
+ val chips = listOf("All", "Needs you · 2", "In progress · 1", "Signed · 1", "Abandoned · 0")
+ .map { onNodeWithText(it).getBoundsInRoot().left }
+
+ assertTrue(
+ chips.zipWithNext().all { (left, right) -> left < right },
+ "the chips were drawn out of order: $chips"
+ )
+
+ val chipBottom = onNodeWithText("All").getBoundsInRoot().bottom
+ val firstRow = onNodeWithText("Genesis 1").getBoundsInRoot().top
+ assertTrue(chipBottom <= firstRow, "the chips were drawn over the rows")
+ }
+
+ @Test
+ fun `unfiltered, the sections stay and every proposal is drawn`() = render(loaded(mixed)) {
+ onNodeWithText("Waiting for you").assertIsDisplayed()
+ onNodeWithText("Everything else").assertIsDisplayed()
+
+ onNodeWithText("Genesis 1").assertIsDisplayed()
+ onNodeWithText("Genesis 2").assertIsDisplayed()
+ onNodeWithText("isiZulu").assertIsDisplayed()
+ onNodeWithText("A note").assertIsDisplayed()
+ }
+
+ @Test
+ fun `tapping a chip narrows the rows to its state`() = render(loaded(mixed)) {
+ chip("Signed · 1").performClick()
+
+ onNodeWithText("A note").assertIsDisplayed()
+ onAllNodesWithText("Genesis 1").assertCountEquals(0)
+ onAllNodesWithText("Genesis 2").assertCountEquals(0)
+ onAllNodesWithText("isiZulu").assertCountEquals(0)
+ }
+
+ @Test
+ fun `a filtered list drops the section headings`() = render(loaded(mixed)) {
+ chip("Needs you · 2").performClick()
+
+ onNodeWithText("Genesis 1").assertIsDisplayed()
+ onNodeWithText("Genesis 2").assertIsDisplayed()
+ onAllNodesWithText("Waiting for you").assertCountEquals(0)
+ onAllNodesWithText("Everything else").assertCountEquals(0)
+ }
+
+ @Test
+ fun `going back to all restores the sections and the rest of the rows`() =
+ render(loaded(mixed)) {
+ chip("Signed · 1").performClick()
+ onAllNodesWithText("Genesis 1").assertCountEquals(0)
+
+ chip("All").performClick()
+
+ onNodeWithText("Waiting for you").assertIsDisplayed()
+ onNodeWithText("Genesis 1").assertIsDisplayed()
+ onNodeWithText("A note").assertIsDisplayed()
+ }
+
+ /** The counts are the room's, so narrowing the rows must not narrow them. */
+ @Test
+ fun `the counts stay put when the filter moves`() = render(loaded(mixed)) {
+ chip("Signed · 1").performClick()
+
+ chip("Needs you · 2")
+ chip("In progress · 1")
+ chip("Abandoned · 0")
+ }
+
+ @Test
+ fun `a filter with nothing in it says which emptiness it is`() = render(loaded(mixed)) {
+ chip("Abandoned · 0").performClick()
+
+ onNodeWithText("No proposal has been abandoned.").assertIsDisplayed()
+ // Not the whole-screen message, which would be a different and false claim.
+ onAllNodesWithText("This group has not been asked to sign anything yet.")
+ .assertCountEquals(0)
+ }
+
+ /**
+ * The queue running dry is the end of the reader's work, not a blank screen,
+ * and the chips behind it still say where everything went.
+ */
+ @Test
+ fun `a worked-through queue reads as finished rather than as missing`() =
+ render(loaded(listOf(open, signed))) {
+ chip("Needs you · 0").performClick()
+
+ onNodeWithText("Nothing is waiting for your signature.").assertIsDisplayed()
+ chip("In progress · 1")
+ chip("Signed · 1")
+ }
+
+ @Test
+ fun `each filter has its own words for being empty`() {
+ render(loaded(listOf(needsYou))) {
+ chip("In progress · 0").performClick()
+ onNodeWithText("No proposal is in progress.").assertIsDisplayed()
+ }
+
+ render(loaded(listOf(needsYou))) {
+ chip("Signed · 0").performClick()
+ onNodeWithText("This group has not signed anything yet.").assertIsDisplayed()
+ }
+ }
+
+ /**
+ * A room with nothing in it has nothing to filter, and five chips reading 0
+ * would be five ways of saying what the empty state says once.
+ */
+ @Test
+ fun `an untouched room offers no chips at all, only the reason`() = render(loaded(emptyList())) {
+ onNodeWithText("This group has not been asked to sign anything yet.").assertIsDisplayed()
+
+ onAllNodesWithText("All").assertCountEquals(0)
+ onAllNodesWithText("Needs you · 0").assertCountEquals(0)
+ onAllNodesWithText("Abandoned · 0").assertCountEquals(0)
+ }
+
+ @Test
+ fun `an initial filter is the one selected when the screen opens`() =
+ render(loaded(mixed), initialFilter = ProposalFilter.NEEDS_YOU) {
+ onNodeWithText("Genesis 1").assertIsDisplayed()
+ onNodeWithText("Genesis 2").assertIsDisplayed()
+ onAllNodesWithText("A note").assertCountEquals(0)
+ onAllNodesWithText("Waiting for you").assertCountEquals(0)
+ }
+
+ @Test
+ fun `a pushed screen keeps its way back, chips or no chips`() {
+ render(loaded(mixed)) { onNodeWithContentDescription("Back").assertIsDisplayed() }
+ render(loaded(emptyList())) { onNodeWithContentDescription("Back").assertIsDisplayed() }
+ }
+
+ @Test
+ fun `the room that could not be found says so, with nothing to filter`() {
+ render(ProposalListUIState.Error("Couldn't find the group")) {
+ onNodeWithText("Couldn't find the group").assertIsDisplayed()
+ onAllNodesWithText("All").assertCountEquals(0)
+ // Nothing to retry, so nothing offering to.
+ onAllNodesWithText("Try again").assertCountEquals(0)
+ }
+ }
+
+ private fun loaded(proposals: List) =
+ ProposalListUIState.Loaded(
+ localChatRoom = GroupSignedWorkFixtures.localChatRoom(),
+ proposals = proposals,
+ )
+
+ private fun render(
+ uiState: ProposalListUIState,
+ onNavigateToRoute: (Route) -> Unit = {},
+ initialFilter: ProposalFilter = ProposalFilter.ALL,
+ assertions: ComposeUiTest.() -> Unit
+ ) = runDesktopComposeUiTest(width = 500, height = 1600) {
+ setContent {
+ CurareTheme {
+ ProvideSnackbarHost {
+ Box(modifier = Modifier.fillMaxSize()) {
+ ProposalListScreen(
+ activeUserPublicKey = activeUserPublicKey,
+ chatRoomId = chatRoomId,
+ initialProposalListUIState = uiState,
+ chatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY,
+ frostSigningRepository =
+ FrostSigningRepository.NO_OP_FROST_SIGNING_REPOSITORY,
+ onNavigateBack = {},
+ onNavigateToRoute = onNavigateToRoute,
+ initialFilter = initialFilter,
+ )
+ }
+ }
+ }
+ }
+
+ assertions()
+ }
+}