Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"data":[{"id":1000,"name":"Chateaubriand","quantity":2,"shelf_id":100,"is_mandatory":false}]}
12 changes: 8 additions & 4 deletions app/src/androidTest/java/dev/scuttle/inventory/FlowTestBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,17 @@ abstract class FlowTestBase {
.trim()

/**
* Open a product row by tapping its NAME area (left side), not the node
* center: performClick's center tap lands on the quantity stepper cluster —
* a DISABLED "−" (qty 0) silently swallows the click and the card's
* Open a product row by tapping its NAME area, not the node center:
* performClick's center tap lands on the quantity stepper cluster — a
* DISABLED "−" (qty 0) silently swallows the click and the card's
* navigation onClick never fires. Humans naturally tap the name, which is
* why manual testing never reproduced it (found via the 06a989b layout
* shift; nightly-emulator + phone both failed the same way).
*
* The name is the card's top line since #31 (it used to be its left column),
* so aim high rather than left — the stepper now owns the lower half at
* every horizontal offset.
*/
protected fun androidx.compose.ui.test.SemanticsNodeInteraction.clickNameArea() =
performTouchInput { click(percentOffset(0.15f, 0.5f)) }
performTouchInput { click(percentOffset(0.15f, 0.2f)) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
@file:OptIn(androidx.compose.ui.test.ExperimentalTestApi::class)

package dev.scuttle.inventory.flow

import androidx.compose.ui.semantics.SemanticsActions
import androidx.compose.ui.test.filterToOne
import androidx.compose.ui.test.getUnclippedBoundsInRoot
import androidx.compose.ui.test.hasClickAction
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.waitUntilAtLeastOneExists
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.unit.width
import dagger.hilt.android.testing.HiltAndroidTest
import dev.scuttle.inventory.FlowTestBase
import dev.scuttle.inventory.ui.dashboard.DASHBOARD_TITLE_TEST_TAG
import org.junit.Test

/**
* Regression cover for #31: the product name shared one Row with the quantity stepper and the
* move button, so it only ever got the width those controls left over — a few characters wide,
* and narrower still in Dutch, where "Verplaatsen" is 7 characters longer than "Move". The name
* must own the card's full width, independent of how wide the action controls happen to be in
* the current locale.
*/
@HiltAndroidTest
class ProductNameLayoutFlowTest : FlowTestBase() {
private fun loginAndNavigateToShelf() {
mockServer.enqueue(fixture("auth_login.json"))
mockServer.route("/households", fixture("households_one.json"))
mockServer.route("/households/1/locations", fixture("locations_one.json"))
mockServer.route("/households/1/locations/10/shelves", fixture("shelves_one.json"))
mockServer.route("/households/1/shelves/100/products", fixture("products_long_name.json"))

composeRule.apply {
onNodeWithText("Email").performTextInput("test@example.com")
onNodeWithText("Password").performTextInput("password123")
onAllNodesWithText("Sign in").filterToOne(hasClickAction()).performClick()

waitUntilAtLeastOneExists(hasTestTag(DASHBOARD_TITLE_TEST_TAG), timeoutMillis = 8_000)

onNodeWithTag("bottom-nav-home").performClick()
waitUntilAtLeastOneExists(hasTestTag("home-location-Fridge"), timeoutMillis = 8_000)

mockServer.route("/households/1/locations/10/shelves", fixture("shelves_one.json"))
mockServer.route("/households/1/shelves/100/products", fixture("products_long_name.json"))
onNodeWithTag("home-location-Fridge").performClick()
waitUntilAtLeastOneExists(hasTestTag("product-1000"), timeoutMillis = 8_000)
}
}

/**
* The structural invariant: the name is laid out against the card's width, not against
* whatever the stepper and move button leave behind. Locale- and font-scale-independent,
* which is the point — the Dutch build broke precisely because the old layout was neither.
*/
@Test
fun product_name_gets_the_full_card_width() {
loginAndNavigateToShelf()

// Unmerged tree throughout: the card is clickable, so it merges its descendants'
// semantics — onNodeWithText would otherwise match the card itself and measure it
// against its own width, which passes no matter how squashed the name is.
val cardWidth = composeRule.onNodeWithTag("product-1000").getUnclippedBoundsInRoot().width
val nameWidth =
composeRule
.onNodeWithText("Chateaubriand", useUnmergedTree = true)
.getUnclippedBoundsInRoot()
.width

assert(nameWidth >= cardWidth * 0.8f) {
"Product name got $nameWidth of a $cardWidth card — it is still competing with the " +
"action controls for horizontal space (#31)"
}
}

/** What the reporter actually asked for: a normal product name reads on one line. */
@Test
fun product_name_renders_on_a_single_unellipsized_line() {
loginAndNavigateToShelf()

val layouts = mutableListOf<TextLayoutResult>()
composeRule
.onNodeWithText("Chateaubriand", useUnmergedTree = true)
.fetchSemanticsNode()
.config[SemanticsActions.GetTextLayoutResult]
.action
?.invoke(layouts)
val layout = layouts.first()

assert(layout.lineCount == 1) { "Name wrapped onto ${layout.lineCount} lines (#31)" }
assert(!layout.hasVisualOverflow) { "Name was truncated/ellipsized (#31)" }
}
}
142 changes: 78 additions & 64 deletions app/src/main/java/dev/scuttle/inventory/ui/products/ProductsPane.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
Expand Down Expand Up @@ -58,7 +60,7 @@ import dev.scuttle.inventory.ui.common.SnackbarErrorEffect
import dev.scuttle.inventory.ui.common.SortMenu
import dev.scuttle.inventory.ui.theme.FrostCard

@OptIn(ExperimentalMaterial3Api::class)
@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class)
@Composable
fun ProductsPane(
householdId: Long,
Expand Down Expand Up @@ -209,7 +211,12 @@ fun ProductsPane(
onClick = { onOpenProduct(product) },
modifier = Modifier.fillMaxWidth().testTag("product-${product.id}"),
) {
Row(
// Name on its own line, controls beneath it. Sharing one line with the
// stepper and the move button left the name only the width those
// controls didn't want — a quarter of the card, and less still in
// locales where "Move" is a longer word ("Verplaatsen"), which squashed
// names down to two or three characters (#31).
Column(
modifier =
Modifier
.fillMaxWidth()
Expand All @@ -220,80 +227,87 @@ fun ProductsPane(
Color.Transparent
},
).padding(horizontal = 16.dp, vertical = 8.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(4.dp),
) {
Column(modifier = Modifier.weight(1f)) {
// Long names wrap to at most two lines and then
// ellipsize — never the one-char-per-line squash
// reported on narrow devices. Full name lives on
// the detail screen, one tap away.
Text(
text = product.name,
style = MaterialTheme.typography.bodyLarge,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.fillMaxWidth(),
)
if (!product.code.isNullOrBlank()) {
Text(
text = product.name,
style = MaterialTheme.typography.bodyLarge,
maxLines = 2,
text = product.code,
style = MaterialTheme.typography.labelSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
if (!product.code.isNullOrBlank()) {
Text(
text = product.code,
style = MaterialTheme.typography.labelSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
if (product.is_mandatory == true) {
}
if (product.is_mandatory == true) {
Text(
text = stringResource(R.string.products_pane_mandatory_label),
style = MaterialTheme.typography.labelSmall,
color =
if (isMandatoryWarning) {
MaterialTheme.colorScheme.error
} else {
MaterialTheme.colorScheme.primary
},
)
}
// FlowRow, not Row: at large font scales the move button drops to
// its own line instead of being clipped off the card's edge.
FlowRow(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalArrangement = Arrangement.spacedBy(4.dp),
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
OutlinedButton(
onClick = { viewModel.decrement(product.id) },
enabled = !state.loading && product.quantity > 0,
modifier =
Modifier.semantics {
contentDescription = decreaseDesc
},
) {
Text("−")
}
Text(
text = stringResource(R.string.products_pane_mandatory_label),
style = MaterialTheme.typography.labelSmall,
text = product.quantity.toString(),
color =
if (isMandatoryWarning) {
MaterialTheme.colorScheme.error
} else {
MaterialTheme.colorScheme.primary
MaterialTheme.colorScheme.onSurface
},
)
OutlinedButton(
onClick = { viewModel.increment(product.id) },
enabled = !state.loading,
modifier =
Modifier.semantics {
contentDescription = increaseDesc
},
) {
Text("+")
}
}
TextButton(
onClick = { viewModel.startMove(product.id) },
enabled = !state.loading,
modifier =
Modifier.semantics {
contentDescription = moveDesc
},
) {
Text(stringResource(R.string.products_pane_move_button))
}
}
OutlinedButton(
onClick = { viewModel.decrement(product.id) },
enabled = !state.loading && product.quantity > 0,
modifier =
Modifier.semantics {
contentDescription = decreaseDesc
},
) {
Text("−")
}
Text(
text = product.quantity.toString(),
color =
if (isMandatoryWarning) {
MaterialTheme.colorScheme.error
} else {
MaterialTheme.colorScheme.onSurface
},
)
OutlinedButton(
onClick = { viewModel.increment(product.id) },
enabled = !state.loading,
modifier =
Modifier.semantics {
contentDescription = increaseDesc
},
) {
Text("+")
}
TextButton(
onClick = { viewModel.startMove(product.id) },
enabled = !state.loading,
modifier =
Modifier.semantics {
contentDescription = moveDesc
},
) {
Text(stringResource(R.string.products_pane_move_button))
}
}
}
Expand Down