Repository navigation
Add optional card list slots and tablet columns #2905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1dd59e8
Add optional card list slots and tablet columns
melwaraki cd0632b
Capture adaptive card list tests at tablet width
melwaraki 3e6fd9a
Use Compose node member assertions without extension imports
melwaraki 0e038c1
Cover two-column card lists at 200 percent text scale
melwaraki 7f81d19
Updated snapshots
skyscanner-backpack-bot[bot] 198ef40
Use tablet util that already exists
Caoilinn 71c021c
Remove unnecessary overloads
Caoilinn 6d0b511
Header and empty content are animated & updated test + screenshots
Caoilinn 55281a6
Updated snapshots
skyscanner-backpack-bot[bot] f7b29e5
Name change
Caoilinn 120866f
Rename to useTwoColumnsWhenWide, keep card state across column change…
melwaraki c8a03d9
Simplify StackCards
Caoilinn 964e588
Merge branch 'main' into codex/card-list-slots-tablet
Caoilinn 4aa1d5e
Updated snapshots
skyscanner-backpack-bot[bot] 4157347
Revert
Caoilinn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
|
Caoilinn marked this conversation as resolved.
Resolved
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file added
BIN
+8.16 KB
...pkStackCardListAdaptiveTest_columnsAdaptWhenWindowCrossesTabletWidth.Column.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.16 KB
...ackCardListAdaptiveTest_columnsAdaptWhenWindowCrossesTabletWidth.LazyColumn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.2 KB
...t.stack.BpkStackCardListAdaptiveTest_controlsContentSpansBothColumns.Column.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.2 KB
...ack.BpkStackCardListAdaptiveTest_controlsContentSpansBothColumns.LazyColumn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.71 KB
...stack.BpkStackCardListAdaptiveTest_emptyListShowsOnlyControlsContent.Column.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.6 KB
...k.BpkStackCardListAdaptiveTest_emptyListShowsOnlyControlsContent.LazyColumn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.3 KB
...st.stack.BpkStackCardListAdaptiveTest_emptyListShowsOnlyEmptyContent.Column.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.3 KB
...tack.BpkStackCardListAdaptiveTest_emptyListShowsOnlyEmptyContent.LazyColumn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.22 KB
...ack.BpkStackCardListAdaptiveTest_expansionSurvivesEmptyListAndResize.Column.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.22 KB
...BpkStackCardListAdaptiveTest_expansionSurvivesEmptyListAndResize.LazyColumn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.4 KB
...ck.BpkStackCardListAdaptiveTest_largeFontKeepsContentVisibleOnTablet.Column.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.4 KB
...pkStackCardListAdaptiveTest_largeFontKeepsContentVisibleOnTablet.LazyColumn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.81 KB
...tack.BpkStackCardListAdaptiveTest_singleCardKeepsColumnWidthOnTablet.Column.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.81 KB
....BpkStackCardListAdaptiveTest_singleCardKeepsColumnWidthOnTablet.LazyColumn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.47 KB
...tack.BpkStackCardListAdaptiveTest_staysSingleColumnOnTabletByDefault.Column.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.47 KB
....BpkStackCardListAdaptiveTest_staysSingleColumnOnTabletByDefault.LazyColumn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.3 KB
....cardlist.stack.BpkStackCardListTest_columnStackWithControlsAndEmptyContent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+87.9 KB
...mpose.cardlist.stack.BpkStackCardListTest_columnStackWithTwoColumnsOnTablet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+87.9 KB
...e.cardlist.stack.BpkStackCardListTest_lazyColumnStackWithTwoColumnsOnTablet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.3 KB
....cardlist.stack.BpkStackCardListTest_columnStackWithControlsAndEmptyContent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+88.5 KB
...mpose.cardlist.stack.BpkStackCardListTest_columnStackWithTwoColumnsOnTablet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+88.5 KB
...e.cardlist.stack.BpkStackCardListTest_lazyColumnStackWithTwoColumnsOnTablet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.4 KB
....cardlist.stack.BpkStackCardListTest_columnStackWithControlsAndEmptyContent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+87.8 KB
...mpose.cardlist.stack.BpkStackCardListTest_columnStackWithTwoColumnsOnTablet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+87.8 KB
...e.cardlist.stack.BpkStackCardListTest_lazyColumnStackWithTwoColumnsOnTablet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
253 changes: 253 additions & 0 deletions
253
.../test/java/net/skyscanner/backpack/compose/cardlist/stack/BpkStackCardListAdaptiveTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,253 @@ | ||
| /** | ||
| * Backpack for Android - Skyscanner's Design System | ||
| * | ||
| * Copyright 2018 - 2026 Skyscanner Ltd | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package net.skyscanner.backpack.compose.cardlist.stack | ||
|
|
||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.height | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.CompositionLocalProvider | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.platform.LocalDensity | ||
| import androidx.compose.ui.platform.LocalWindowInfo | ||
| import androidx.compose.ui.platform.WindowInfo | ||
| import androidx.compose.ui.platform.testTag | ||
| import androidx.compose.ui.test.assertIsDisplayed | ||
| import androidx.compose.ui.test.junit4.ComposeTestRule | ||
| import androidx.compose.ui.test.onNodeWithTag | ||
| import androidx.compose.ui.test.onNodeWithText | ||
| import androidx.compose.ui.test.performClick | ||
| import androidx.compose.ui.unit.Density | ||
| import androidx.compose.ui.unit.IntSize | ||
| import androidx.compose.ui.unit.dp | ||
| import net.skyscanner.backpack.BpkTestVariant | ||
| import net.skyscanner.backpack.Variants | ||
| import net.skyscanner.backpack.compose.BpkSnapshotTest | ||
| import net.skyscanner.backpack.compose.button.BpkButton | ||
| import net.skyscanner.backpack.compose.text.BpkText | ||
| import net.skyscanner.backpack.compose.utils.TABLET_WIDTH | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.ParameterizedRobolectricTestRunner | ||
| import org.robolectric.annotation.Config | ||
|
|
||
| @RunWith(ParameterizedRobolectricTestRunner::class) | ||
| @Config(qualifiers = "w700dp-h1000dp-mdpi", sdk = [35]) | ||
| class BpkStackCardListAdaptiveTest( | ||
| private val stackType: StackType, | ||
| ) : BpkSnapshotTest(listOf(stackType)) { | ||
|
|
||
| @Test | ||
| @Variants(BpkTestVariant.Default) | ||
| fun columnsAdaptWhenWindowCrossesTabletWidth() { | ||
| val windowWidth = mutableStateOf(TABLET_WIDTH) | ||
| snap( | ||
| width = 650.dp, | ||
| assertion = { | ||
| assertSingleColumn() | ||
|
|
||
| runOnIdle { windowWidth.value = TABLET_WINDOW_WIDTH } | ||
| waitForIdle() | ||
| assertTwoColumns() | ||
|
|
||
| runOnIdle { windowWidth.value = TABLET_WIDTH } | ||
| waitForIdle() | ||
| assertSingleColumn() | ||
| }, | ||
| ) { WindowWidth(windowWidth.value) { ListFixture() } } | ||
| } | ||
|
|
||
| @Test | ||
| @Variants(BpkTestVariant.Default) | ||
| fun staysSingleColumnOnTabletByDefault() = snap( | ||
| width = 650.dp, | ||
| assertion = { assertSingleColumn() }, | ||
| ) { | ||
| WindowWidth(TABLET_WINDOW_WIDTH) { | ||
| BpkStackCardList( | ||
| title = "Destinations", | ||
| totalCount = 3, | ||
| isInScrollableContainer = stackType.isInScrollableContainer, | ||
| ) { Card(it) } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| @Variants(BpkTestVariant.Default) | ||
| fun expansionSurvivesEmptyListAndResize() { | ||
| val count = mutableStateOf(3) | ||
| val windowWidth = mutableStateOf(TABLET_WIDTH) | ||
| snap( | ||
| width = 650.dp, | ||
| assertion = { | ||
| onNodeWithTag("card-2").assertDoesNotExist() | ||
| onNodeWithText("More").performClick() | ||
| onNodeWithTag("card-2").assertExists() | ||
|
|
||
| runOnIdle { | ||
| count.value = 0 | ||
| windowWidth.value = TABLET_WINDOW_WIDTH | ||
| } | ||
| onNodeWithTag("controls").assertIsDisplayed() | ||
| onNodeWithText("Find a destination").assertIsDisplayed() | ||
| onNodeWithTag("card-0").assertDoesNotExist() | ||
| onNodeWithText("Less").assertDoesNotExist() | ||
|
|
||
| runOnIdle { count.value = 3 } | ||
| onNodeWithTag("card-2").assertExists() | ||
| onNodeWithText("Find a destination").assertDoesNotExist() | ||
| onNodeWithText("Less").performClick() | ||
| onNodeWithTag("card-2").assertDoesNotExist() | ||
| }, | ||
| ) { | ||
| WindowWidth(windowWidth.value) { ListFixture(count = count.value, expandable = true) } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| @Variants(BpkTestVariant.Default) | ||
| fun emptyListShowsOnlyControlsContent() = snap( | ||
| assertion = { | ||
| onNodeWithTag("controls").assertIsDisplayed() | ||
| onNodeWithText("Find a destination").assertDoesNotExist() | ||
| onNodeWithTag("card-0").assertDoesNotExist() | ||
| }, | ||
| ) { ListFixture(count = 0, empty = false) } | ||
|
|
||
| @Test | ||
| @Variants(BpkTestVariant.Default) | ||
| fun emptyListShowsOnlyEmptyContent() = snap( | ||
| assertion = { | ||
| onNodeWithText("Find a destination").assertIsDisplayed() | ||
| onNodeWithTag("controls").assertDoesNotExist() | ||
| onNodeWithTag("card-0").assertDoesNotExist() | ||
| }, | ||
| ) { ListFixture(count = 0, controls = false) } | ||
|
|
||
| @Test | ||
| @Variants(BpkTestVariant.Default) | ||
| fun controlsContentSpansBothColumns() = snap( | ||
| width = 650.dp, | ||
| assertion = { | ||
| val first = boundsOf("card-0") | ||
| val second = boundsOf("card-1") | ||
| val controls = boundsOf("controls") | ||
| assertTrue(controls.width > first.width + second.width) | ||
| assertTrue(controls.bottom <= first.top) | ||
| }, | ||
| ) { WindowWidth(TABLET_WINDOW_WIDTH) { ListFixture() } } | ||
|
|
||
| @Test | ||
| @Variants(BpkTestVariant.Default) | ||
| fun singleCardKeepsColumnWidthOnTablet() = snap( | ||
| width = 650.dp, | ||
| assertion = { | ||
| assertTrue(boundsOf("card-0").width < boundsOf("controls").width / 2) | ||
| onNodeWithTag("card-1").assertDoesNotExist() | ||
| }, | ||
| ) { WindowWidth(TABLET_WINDOW_WIDTH) { ListFixture(count = 1) } } | ||
|
|
||
| @Test | ||
| @Variants(BpkTestVariant.Default) | ||
| fun largeFontKeepsContentVisibleOnTablet() = snap( | ||
| width = 650.dp, | ||
| assertion = { | ||
| assertTwoColumns() | ||
| onNodeWithText("Filter destinations").assertIsDisplayed() | ||
| onNodeWithText("Card 0").assertIsDisplayed() | ||
| onNodeWithText("Card 1").assertIsDisplayed() | ||
| onNodeWithText("Card 2").assertIsDisplayed() | ||
| }, | ||
| ) { | ||
| CompositionLocalProvider(LocalDensity provides Density(LocalDensity.current.density, fontScale = 2f)) { | ||
| WindowWidth(TABLET_WINDOW_WIDTH) { ListFixture() } | ||
| } | ||
| } | ||
|
|
||
| private fun ComposeTestRule.boundsOf(tag: String) = onNodeWithTag(tag).fetchSemanticsNode().boundsInRoot | ||
|
|
||
| private fun ComposeTestRule.assertSingleColumn() { | ||
| assertTrue(boundsOf("card-1").top > boundsOf("card-0").top) | ||
| } | ||
|
|
||
| private fun ComposeTestRule.assertTwoColumns() { | ||
| val first = boundsOf("card-0") | ||
| val second = boundsOf("card-1") | ||
| val last = boundsOf("card-2") | ||
| assertEquals(first.top, second.top, 1f) | ||
| assertEquals(first.width, second.width, 1f) | ||
| assertEquals(first.width, last.width, 1f) | ||
| assertTrue(last.top > first.top) | ||
| } | ||
|
|
||
| @Composable | ||
| private fun ListFixture( | ||
| count: Int = 3, | ||
| expandable: Boolean = false, | ||
| controls: Boolean = true, | ||
| empty: Boolean = true, | ||
| ) { | ||
| BpkStackCardList( | ||
| title = "Destinations", | ||
| totalCount = count, | ||
| isInScrollableContainer = stackType.isInScrollableContainer, | ||
| useTwoColumnsOnTablet = true, | ||
| accessoryStyle = if (expandable && count > 2) { | ||
| BpkStackCardAccessoryStyle.Expand(collapsedCount = 2, expandText = "More", collapsedText = "Less") | ||
| } else null, | ||
| controlsContent = if (controls) { | ||
| { Box(Modifier.fillMaxWidth().testTag("controls")) { BpkText("Filter destinations") } } | ||
| } else null, | ||
| emptyContent = if (empty) { | ||
| { BpkButton(text = "Find a destination", onClick = {}) } | ||
| } else null, | ||
| ) { Card(it) } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun Card(index: Int) { | ||
| Box(Modifier.fillMaxWidth().height(48.dp).testTag("card-$index")) { BpkText("Card $index") } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun WindowWidth(widthDp: Int, content: @Composable () -> Unit) { | ||
| val original = LocalWindowInfo.current | ||
| val widthPx = with(LocalDensity.current) { widthDp.dp.roundToPx() } | ||
| val window = object : WindowInfo by original { | ||
| override val containerSize = IntSize(widthPx, original.containerSize.height) | ||
| } | ||
| CompositionLocalProvider(LocalWindowInfo provides window, content = content) | ||
| } | ||
|
|
||
| enum class StackType(val isInScrollableContainer: Boolean) { | ||
| Column(isInScrollableContainer = true), | ||
| LazyColumn(isInScrollableContainer = false), | ||
| } | ||
|
|
||
| companion object { | ||
| @JvmStatic | ||
| @ParameterizedRobolectricTestRunner.Parameters(name = "{0}") | ||
| fun stackTypes(): List<StackType> = StackType.entries | ||
| } | ||
| } | ||
|
|
||
| private const val TABLET_WINDOW_WIDTH = TABLET_WIDTH + 1 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.