From 29d648a4e6acbcda08e82dd8d735846363c24656 Mon Sep 17 00:00:00 2001 From: S Plotnikov Date: Sun, 12 Jul 2026 19:41:03 +0200 Subject: [PATCH] Give the product name its own line in the shelf list (#31) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The name shared one Row with the quantity stepper and the move button, so it was only ever allotted the width those controls left behind — 103dp of a 452dp card on a Pixel 7 Pro. In Dutch it was worse still: "Verplaatsen" is seven characters longer than "Move", squashing names down to two or three characters. maxLines=2 + ellipsis had hidden the one-char-per-line squash without giving the name any width back. Stack the card instead: name on its own full-width line, stepper and move button beneath it. The name's width no longer depends on how long the current locale's move label happens to be. The action row is a FlowRow so the move button wraps rather than clipping at large font scales. Also retarget FlowTestBase.clickNameArea at the card's top: the name moved from the left column to the top line, so a 50%-height tap now lands on the stepper — the disabled-"−"-swallows-the-click trap that helper exists for. --- .../assets/fixtures/products_long_name.json | 1 + .../dev/scuttle/inventory/FlowTestBase.kt | 12 +- .../flow/ProductNameLayoutFlowTest.kt | 98 ++++++++++++ .../inventory/ui/products/ProductsPane.kt | 142 ++++++++++-------- 4 files changed, 185 insertions(+), 68 deletions(-) create mode 100644 app/src/androidTest/assets/fixtures/products_long_name.json create mode 100644 app/src/androidTest/java/dev/scuttle/inventory/flow/ProductNameLayoutFlowTest.kt diff --git a/app/src/androidTest/assets/fixtures/products_long_name.json b/app/src/androidTest/assets/fixtures/products_long_name.json new file mode 100644 index 0000000..588d389 --- /dev/null +++ b/app/src/androidTest/assets/fixtures/products_long_name.json @@ -0,0 +1 @@ +{"data":[{"id":1000,"name":"Chateaubriand","quantity":2,"shelf_id":100,"is_mandatory":false}]} diff --git a/app/src/androidTest/java/dev/scuttle/inventory/FlowTestBase.kt b/app/src/androidTest/java/dev/scuttle/inventory/FlowTestBase.kt index 98b6cce..9bedd66 100644 --- a/app/src/androidTest/java/dev/scuttle/inventory/FlowTestBase.kt +++ b/app/src/androidTest/java/dev/scuttle/inventory/FlowTestBase.kt @@ -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)) } } diff --git a/app/src/androidTest/java/dev/scuttle/inventory/flow/ProductNameLayoutFlowTest.kt b/app/src/androidTest/java/dev/scuttle/inventory/flow/ProductNameLayoutFlowTest.kt new file mode 100644 index 0000000..dd975f6 --- /dev/null +++ b/app/src/androidTest/java/dev/scuttle/inventory/flow/ProductNameLayoutFlowTest.kt @@ -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() + 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)" } + } +} diff --git a/app/src/main/java/dev/scuttle/inventory/ui/products/ProductsPane.kt b/app/src/main/java/dev/scuttle/inventory/ui/products/ProductsPane.kt index 52e7438..3d26e18 100644 --- a/app/src/main/java/dev/scuttle/inventory/ui/products/ProductsPane.kt +++ b/app/src/main/java/dev/scuttle/inventory/ui/products/ProductsPane.kt @@ -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 @@ -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, @@ -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() @@ -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)) } } }