Cotton code
68 lines · 2.9 KB · KotlinRaw
package com.cottondb.musicimport android.app.Applicationimport androidx.compose.foundation.layout.sizeimport androidx.compose.runtime.CompositionLocalProviderimport androidx.compose.ui.Modifierimport androidx.compose.ui.test.junit4.createComposeRuleimport androidx.compose.ui.test.longClickimport androidx.compose.ui.test.onNodeWithTagimport androidx.compose.ui.test.performTouchInputimport androidx.compose.ui.unit.dpimport com.cottondb.music.faces.FaceTrackPlayimport com.cottondb.music.faces.SingleFaceimport com.cottondb.music.faces.SleeveFaceimport com.cottondb.music.faces.TrackPlayimport com.cottondb.shell.LocalCardHoldimport com.cottondb.shell.LocalMaterialsimport com.cottondb.shell.Materialsimport androidx.compose.ui.platform.LocalContextimport com.cottondb.specimen.cardimport org.junit.Assert.assertEqualsimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Config/** * On the emulator a hold on a single's record played the song, and a hold on an album's sleeve turned it over: their * own taps took the hold, so the card's acts (Play next, Add to queue, Play shuffled) never fanned there, only beside * them. A hold on either part is now the card's. */@RunWith(RobolectricTestRunner::class)@Config(sdk = [35], application = Application::class)class FaceHoldTest {    @get:Rule val compose = createComposeRule()    private val s = PlayerSpecimens    @Test fun a_hold_on_a_singles_record_holds_the_card_and_does_not_play() {        var held = 0        var played = 0        compose.setContent {            CompositionLocalProvider(LocalCardHold provides { held++ }, LocalMaterials provides Materials(LocalContext.current)) {                androidx.compose.foundation.layout.Box(Modifier.size(360.dp, 450.dp)) {                    SingleFace(card(s.harbour("song.single")), s.lines, null, FaceTrackPlay(TrackPlay.still, { played++ }, {}))                }            }        }        compose.onNodeWithTag("single-record").performTouchInput { longClick() }        compose.waitForIdle()        assertEquals("the hold did not hold the card", 1, held)        assertEquals("the hold played the song", 0, played)    }    @Test fun a_hold_on_an_albums_sleeve_holds_the_card() {        var held = 0        compose.setContent {            CompositionLocalProvider(LocalCardHold provides { held++ }, LocalMaterials provides Materials(LocalContext.current)) {                androidx.compose.foundation.layout.Box(Modifier.size(360.dp, 450.dp)) {                    SleeveFace(card("""{"id":"a1","face":"album.sleeve","slots":{"title":"Night Ferry","subtitle":"The Low Tide"}}"""), s.lines, null, FaceTrackPlay.still)                }            }        }        compose.onNodeWithTag("album-sleeve").performTouchInput { longClick() }        compose.waitForIdle()        assertEquals(1, held)    }}