package com.cottondb.story import android.app.Application import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.rememberScrollState import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.test.getBoundsInRoot import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.unit.dp import com.cottondb.story.ink.bleed import org.junit.Assert.assertEquals import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config /** * The home's cast runs to the screen's edges as ink.html draws it (`.cast { margin: 0 -20px; padding: 0 20px }`): on the * emulator the faces were cut at the 20 dp side margin instead. Here ten invented faces in the home's list. */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], qualifiers = "w400dp-h700dp-mdpi", application = Application::class) class StoryCastRowTest { @get:Rule val compose = createComposeRule() @Test fun the_cast_reaches_both_edges_and_starts_at_the_margin() { compose.setContent { LazyColumn(Modifier.fillMaxSize(), contentPadding = PaddingValues(horizontal = 20.dp)) { item { Row( Modifier.fillMaxWidth().bleed(20.dp).horizontalScroll(rememberScrollState()).padding(horizontal = 20.dp).testTag("cast"), horizontalArrangement = Arrangement.spacedBy(16.dp), ) { (1..10).forEach { Box(Modifier.size(70.dp).testTag("face-$it")) } } } } } val cast = compose.onNodeWithTag("cast").getBoundsInRoot() assertEquals(0.dp, cast.left) assertEquals(400.dp, cast.right) assertEquals(20.dp, compose.onNodeWithTag("face-1").getBoundsInRoot().left) } }