package com.cottondb.music import android.app.Application import androidx.compose.foundation.layout.size import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.Modifier import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.longClick import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performTouchInput import androidx.compose.ui.unit.dp import com.cottondb.music.faces.FaceTrackPlay import com.cottondb.music.faces.SingleFace import com.cottondb.music.faces.SleeveFace import com.cottondb.music.faces.TrackPlay import com.cottondb.shell.LocalCardHold import com.cottondb.shell.LocalMaterials import com.cottondb.shell.Materials import androidx.compose.ui.platform.LocalContext import com.cottondb.specimen.card 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 /** * 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) } }