feat(proposals): a chip row over the list, and four ways of being empty

Five chips under the app bar, each carrying its count, scrolling sideways. The
row is 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. It scrolls rather than
wraps for the same reason from the other side: five counted chips do not fit
the sixty characters `readableContent` holds the column to at the largest text
size a reader can ask for, and a row reflowing to a second line moves the list
under the thumb about to tap it.

Unfiltered, the two sections stay. Filtered, they go: "waiting for you" against
"everything else" is a distinction the reader has already made by tapping, and
heading a single-state list with it would answer a question nobody asked.

A room with nothing in it gets no chips at all. Five chips reading 0 over an
empty screen would be five ways of saying what the empty state says once.

The screen also picks up the state widgets it never had -- `LoadingDataIndicator`,
`ErrorState` with an explicit `onRetry = null` because a room missing from this
device will not appear by looking again, and `EmptyState` with a message per
filter. That last one is the point: one shared default 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 -- it keeps the queue's own icon and reads as finished.

`initialFilter` reaches the screen and is applied in the view model's `init`,
so a `Loaded` handed in for a preview cannot open with its chips saying one
thing and its rows showing another. Nothing passes it yet.

Fourteen screen tests, and the audit's budgets all still met: 0 hardcoded
colours, 0 dp literals in spacing positions, 0 title-case strings, both floors
held. 1329 jvm tests pass; the Android target compiles.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5 committed 2026-10-08 11:53:45 -05:00
1 parent f42f4913c4
commit ef2b461c5c
4 files changed
+531 -75

No files matched your search

@@ -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."
-->
<string name="abandoned">Abandoned</string>
<string name="filter_all">All</string>
<string name="app_name">Curare</string>
<string name="add_a_dialect_the_group_can_translate_into">Add a dialect the group can translate into</string>
<string name="add_artifact_to_library">Add artifact to library</string>
@@ -108,6 +110,7 @@
<string name="i_have_saved_my_recovery_phrase_somewhere">I have saved my recovery phrase somewhere safe.</string>
<string name="i_understand_that_if_i_lose_this_phone_and">I understand that if I lose this phone and my recovery phrase, I lose this profile and the funds in its wallet.</string>
<string name="if_you_are_new_to_torch_or_just_want_to">If you are new to Curare or just want to create a fresh profile</string>
<string name="in_progress">In progress</string>
<string name="initial_version_label">Initial version label</string>
<string name="input_npub_or_nip05">Input npub... or nip05</string>
<string name="introduce_yourself">Introduce yourself</string>
@@ -151,6 +154,7 @@
<string name="name_eg_alan_turing">Name (eg. Alan Turing)</string>
<string name="name_eg_group_discussions">Name (eg. Group Discussions)</string>
<string name="name_of_artifact">Name of artifact</string>
<string name="needs_you">Needs you</string>
<string name="network_relays">Network relays</string>
<string name="no_wallet_is_open_on_this_device_so_there">No wallet is open on this device, so there is no phrase to show.</string>
<string name="not_backed_up_yet">Not backed up yet</string>
@@ -167,9 +171,12 @@
<string name="no_one_selected_yet">No one selected yet</string>
<string name="no_one_to_add_yet">No one to add yet.</string>
<string name="no_projects_exists_in_this_group">No projects exists in this group.</string>
<string name="no_proposal_has_been_abandoned">No proposal has been abandoned.</string>
<string name="no_proposal_is_in_progress">No proposal is in progress.</string>
<string name="no_translations_yet">No translations yet.</string>
<string name="no_versions">No versions.</string>
<string name="not_now">Not now</string>
<string name="nothing_is_waiting_for_your_signature">Nothing is waiting for your signature.</string>
<string name="nothing_was_created_and_no_key_exists_it_is">Nothing was created and no key exists. It is safe to run it again.</string>
<string name="open_chat">Open chat</string>
<string name="original">Original</string>
@@ -221,6 +228,7 @@
<string name="send_message">Send message</string>
<string name="share_profile">Share profile</string>
<string name="shared_key">Shared key</string>
<string name="signed">Signed</string>
<string name="signing_key">Signing key</string>
<string name="the_key_this_room_signs_as">The key this room signs as, and the ceremony it came from.</string>
<string name="what_the_group_signed">What the group signed</string>
@@ -265,6 +273,7 @@
<string name="this_decides_who_can_change_the_group_later">This decides who can change the group later. You can't switch afterwards.</string>
<string name="this_group_has_no_shared_key_so_it_cannot">This group has no shared key, so it cannot sign them in.</string>
<string name="this_group_has_not_been_asked_to_sign">This group has not been asked to sign anything yet.</string>
<string name="this_group_has_not_signed_anything_yet">This group has not signed anything yet.</string>
<string name="this_is_fixed_once_the_ceremony_runs">This is fixed once the ceremony runs. Changing it later means generating a new key.</string>
<string name="this_is_the_last_thing_the_ceremony_needs">This is the last thing the ceremony needs from you.</string>
<string name="this_will_be_shown_when_people_open_the_chat">This will be shown when people open the chat for more details.</string>
@@ -334,6 +343,7 @@
<string name="event_s_still_unreadable">%1$s event(s) still unreadable%2$s</string>
<string name="events_signed_together">%1$s events, signed together</string>
<string name="everyone_has_to_be_online_at_the_same_time">Everyone has to be online at the same time — the ceremony can only finish once all %1$s of you have taken part.</string>
<string name="filter_and_count">%1$s · %2$s</string>
<string name="functionality_coming_soon_2">"%1$s" functionality coming soon</string>
<string name="how_should_be_run">How should %1$s be run?</string>
<string name="invite_2">Invite %1$s</string>
@@ -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<ProposalState, Int>,
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.
*
@@ -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.
*
@@ -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.Proposal>) =
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()
}
}