Modern Apps git

← Modern-Apps.git

youpipe: add tests for slice 3/3 (root M-Z, dialogs)

Commit
0582f9133e1eee024ffd929bbc4f6d32f1036710
Author
Vayun Mathur <[email protected]>
When
2026-11-06 18:47 UTC (29 days ago)
Parents
190cc96
Route/defaultBackStack contract (7 pure-JVM tests) plus the four
dialogs driven through the REAL composables against a real
YouPipeViewModel (12 Robolectric + Compose tests). No production change:
the cached-database registry is pre-seeded with an in-memory
SubscriptionDatabase so the SQLCipher/AndroidKeyStore path is never hit;
WorkManager is initialized manually (manifest disables auto-init).

Coverage (merged): slice 0% -> ~81% instructions (1306/1609);
dialogs 92-98% per file; Route data classes 100%; defaultBackStack 100%.

(cherry picked from commit b33071bf6c1a30bba20d6f909c649e0ff2a7dfe0)

Diff

youpipe/src/test/java/com/vayunmathur/youpipe/RootSlice3RouteTest.kt
diff --git a/youpipe/src/test/java/com/vayunmathur/youpipe/RootSlice3RouteTest.kt b/youpipe/src/test/java/com/vayunmathur/youpipe/RootSlice3RouteTest.ktnew file mode 100644index 0000000000..4ff089f953--- /dev/null+++ b/youpipe/src/test/java/com/vayunmathur/youpipe/RootSlice3RouteTest.kt@@ -0,0 +1,137 @@+package com.vayunmathur.youpipe++import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNotEquals+import kotlin.test.assertTrue+import kotlinx.serialization.Serializable++/**+ * Slice-3 tests for the youpipe root navigation model ([Route] variants and+ * [defaultBackStack] mapping). Pure Kotlin — no Android needed.+ *+ * MainActivity's intent-routing (`resolveInitialBackStack`) reads Intent extras+ * and DataStore and is covered on the emulator; the backstack mapping it+ * delegates to is fully exercised here.+ */+class RootSlice3RouteTest {++    @Test+    fun defaultBackStackHomeVariants() {+        assertEquals(listOf(Route.Main(0)), defaultBackStack(null))+        assertEquals(listOf(Route.Main(0)), defaultBackStack("home"))+        assertEquals(listOf(Route.Main(0)), defaultBackStack("unknown-key"))+        assertEquals(listOf(Route.Main(0)), defaultBackStack(""))+    }++    @Test+    fun defaultBackStackEachDestination() {+        assertEquals(listOf(Route.Main(1)), defaultBackStack("subscriptions"))+        assertEquals(+            listOf(Route.Main(1), Route.SubscriptionVideosPage(null)),+            defaultBackStack("all_subscriptions"),+        )+        assertEquals(listOf(Route.Main(2)), defaultBackStack("history"))+        // Legacy downloads key and saved key both open the Saved hub.+        assertEquals(listOf(Route.Main(3)), defaultBackStack("downloads"))+        assertEquals(listOf(Route.Main(3)), defaultBackStack("saved"))+        assertEquals(listOf(Route.Main(4)), defaultBackStack("settings"))+    }++    @Test+    fun defaultPageOptionsAreDistinctAndCoverHubs() {+        val keys = DEFAULT_PAGE_OPTIONS.map { it.first }+        assertEquals(keys.size, keys.distinct().size)+        assertTrue(keys.containsAll(listOf("home", "subscriptions", "history", "saved", "settings")))+        // Every option key maps to a non-empty backstack.+        for ((key, _) in DEFAULT_PAGE_OPTIONS) {+            assertTrue(defaultBackStack(key).isNotEmpty(), "backstack for $key")+        }+        // Labels are resource ids.+        for ((_, res) in DEFAULT_PAGE_OPTIONS) {+            assertTrue(res != 0)+        }+    }++    @Test+    fun routeVariantsCarryPayloads() {+        assertEquals(42L, Route.VideoPage(42L).videoID)+        assertEquals("UC123", Route.ChannelPage("UC123").channelID)+        assertEquals("music", Route.SubscriptionVideosPage("music").category)+        assertEquals(null, Route.SubscriptionVideosPage(null).category)+        assertEquals(7L, Route.PlaylistDetail(7L).playlistId)+        assertEquals(9L, Route.AddToPlaylist(9L).videoID)+        assertEquals(true, Route.AddToPlaylist(9L).includeWatchLater)+        assertEquals(11L, Route.AddToWatchLater(11L).videoID)+        assertEquals(0, Route.Main().initialTab)+        assertEquals(3, Route.Main(3).initialTab)+    }++    @Test+    fun defaultPageKeyConstants() {+        assertEquals("default_page", DEFAULT_PAGE_KEY)+        assertEquals("home", DEFAULT_PAGE_HOME)+        assertEquals("subscriptions", DEFAULT_PAGE_SUBSCRIPTIONS)+        assertEquals("all_subscriptions", DEFAULT_PAGE_ALL_SUBSCRIPTIONS)+        assertEquals("history", DEFAULT_PAGE_HISTORY)+        assertEquals("downloads", DEFAULT_PAGE_DOWNLOADS)+        assertEquals("saved", DEFAULT_PAGE_SAVED)+        assertEquals("settings", DEFAULT_PAGE_SETTINGS)+    }++    @Test+    fun allRouteVariantsAreSerializable() {+        // The back stack is persisted; every Route subtype must stay+        // @Serializable or restores silently drop entries.+        val variants: List<Route> = listOf(+            Route.Main(1),+            Route.VideoPage(9L),+            Route.ChannelPage("UC1"),+            Route.SubscriptionVideosPage("music"),+            Route.SubscriptionVideosPage(null),+            Route.CreateSubscriptionCategory(null),+            Route.CreateSubscriptionCategory("music"),+            Route.Downloads,+            Route.PlaylistDetail(3L),+            Route.CreatePlaylist,+            Route.AddToPlaylist(9L),+            Route.AddToPlaylist(9L, includeWatchLater = false),+            Route.AddToWatchLater(11L),+            Route.SettingsGeneral,+            Route.SettingsSponsorBlock,+            Route.SettingsRecommendations,+            Route.SettingsData,+            Route.ManageInterests,+        )+        assertEquals(18, variants.size)+        for (route in variants) {+            val annotation = route.javaClass.getAnnotation(Serializable::class.java)+            assertTrue(annotation != null, "${route.javaClass.simpleName} lost @Serializable")+        }+    }++    @Test+    fun routeEqualityCoversEveryField() {+        assertEquals(Route.Main(1), Route.Main(1))+        assertNotEquals(Route.Main(1), Route.Main(2))+        assertEquals(Route.VideoPage(9L), Route.VideoPage(9L))+        assertNotEquals(Route.VideoPage(9L), Route.VideoPage(10L))+        assertEquals(Route.ChannelPage("A"), Route.ChannelPage("A"))+        assertNotEquals(Route.ChannelPage("A"), Route.ChannelPage("B"))+        assertEquals(Route.SubscriptionVideosPage("m"), Route.SubscriptionVideosPage("m"))+        assertNotEquals(Route.SubscriptionVideosPage("m"), Route.SubscriptionVideosPage(null))+        assertEquals(Route.CreateSubscriptionCategory("m"), Route.CreateSubscriptionCategory("m"))+        assertNotEquals(+            Route.CreateSubscriptionCategory("m"),+            Route.CreateSubscriptionCategory(null),+        )+        assertEquals(Route.PlaylistDetail(3L), Route.PlaylistDetail(3L))+        assertEquals(Route.AddToPlaylist(9L), Route.AddToPlaylist(9L))+        assertNotEquals(Route.AddToPlaylist(9L), Route.AddToPlaylist(9L, includeWatchLater = false))+        assertEquals(Route.AddToWatchLater(11L), Route.AddToWatchLater(11L))+        // Singletons are identical by definition; distinct types never equal.+        assertTrue(Route.Downloads === Route.Downloads)+        assertTrue(Route.CreatePlaylist === Route.CreatePlaylist)+        assertNotEquals<Route>(Route.Downloads, Route.CreatePlaylist)+    }+}
youpipe/src/test/java/com/vayunmathur/youpipe/ui/dialogs/RootSlice3PlaylistDialogsTest.kt
diff --git a/youpipe/src/test/java/com/vayunmathur/youpipe/ui/dialogs/RootSlice3PlaylistDialogsTest.kt b/youpipe/src/test/java/com/vayunmathur/youpipe/ui/dialogs/RootSlice3PlaylistDialogsTest.ktnew file mode 100644index 0000000000..63d817b49e--- /dev/null+++ b/youpipe/src/test/java/com/vayunmathur/youpipe/ui/dialogs/RootSlice3PlaylistDialogsTest.kt@@ -0,0 +1,392 @@+package com.vayunmathur.youpipe.ui.dialogs++import android.app.Application+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.assertIsEnabled+import androidx.compose.ui.test.assertIsNotEnabled+import androidx.compose.ui.test.filterToOne+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onAllNodesWithText+import androidx.compose.ui.test.onChildren+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.onParent+import androidx.compose.ui.test.performClick+import androidx.compose.ui.test.performTextInput+import androidx.room3.Room+import androidx.test.core.app.ApplicationProvider+import androidx.work.Configuration+import androidx.work.WorkManager+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.youpipe.Route+import com.vayunmathur.youpipe.data.Playlist+import com.vayunmathur.youpipe.data.Subscription+import com.vayunmathur.youpipe.data.SubscriptionDatabase+import com.vayunmathur.youpipe.data.SubscriptionRepository+import com.vayunmathur.youpipe.util.YouPipeViewModel+import kotlin.test.AfterTest+import kotlin.test.BeforeTest+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.annotation.Config++/**+ * Slice-3 tests for the playlist dialogs ([CreatePlaylist] validation ++ * creation, [AddToPlaylist] membership staging, [AddToWatchLater] auto-add),+ * driven through the REAL composables against a real [YouPipeViewModel].+ *+ * The VM's repository is Room/SQLCipher-backed, but Room is bypassed cleanly:+ * [SubscriptionRepository] exposes its flows cold, and the cached database+ * registry (`com.vayunmathur.library.util.databases`, keyed by class) is+ * pre-seeded with an in-memory [SubscriptionDatabase] — the exact instance the+ * repository resolves on first access, so no production change and no+ * AndroidKeyStore is ever touched. WorkManager is initialized manually+ * (the manifest disables auto-init); the VM's periodic-enqueue calls then+ * no-op against the test driver.+ */+@RunWith(RobolectricTestRunner::class)+@Config(sdk = [34])+class RootSlice3PlaylistDialogsTest {++    @get:Rule+    val composeRule = createComposeRule()++    private lateinit var db: SubscriptionDatabase+    private lateinit var vm: YouPipeViewModel++    private val context get() = ApplicationProvider.getApplicationContext<android.content.Context>()+    private val app get() = context.applicationContext as Application++    companion object {+        private var sharedDb: SubscriptionDatabase? = null++        private fun sharedDb(context: android.content.Context): SubscriptionDatabase {+            sharedDb?.let { return it }+            com.vayunmathur.library.util.databases[SubscriptionDatabase::class]?.let {+                @Suppress("UNCHECKED_CAST")+                sharedDb = it as SubscriptionDatabase+                return it as SubscriptionDatabase+            }+            return Room.inMemoryDatabaseBuilder(context, SubscriptionDatabase::class.java)+                .allowMainThreadQueries()+                .build().also {+                    com.vayunmathur.library.util.databases[SubscriptionDatabase::class] = it+                    sharedDb = it+                }+        }+    }++    @BeforeTest+    fun open() {+        try {+            WorkManager.initialize(context, Configuration.Builder().build())+        } catch (_: IllegalStateException) {+            // One init per Robolectric sandbox: earlier tests in this class+            // already initialized it; the instance survives across tests.+        }+        db = sharedDb(context)+        vm = YouPipeViewModel(app, SubscriptionRepository.get(context))+    }++    @AfterTest+    fun close() {+        // Keep ONE database per test class: closeCachedDatabase() + db.close()+        // races the next test's in-flight cleanup coroutines (the VM init+        // launches IO cleanup on a shared scope), so instead wipe rows and+        // reuse the same instance across tests. Blocking reads: runTest's+        // scheduler would freeze concurrent collectors.+        kotlinx.coroutines.runBlocking {+            db.subscriptionDao().clearAll()+            // Wipe category rows (no clearAll on the DAO; delete per name).+            // The VM's subscriptionCategories flow always holds the latest+            // emission — read it off the current VM instead of collecting.+            for (name in vm.subscriptionCategories.value.map { it.category }.distinct()) {+                db.subscriptionCategoryDao().deleteCategory(name)+            }+            for (playlist in db.playlistDao().getAll()) {+                for (item in db.playlistItemDao().getForPlaylist(playlist.id)) {+                    db.playlistItemDao().delete(item)+                }+                db.playlistDao().delete(playlist)+            }+        }+    }++    // ---------- CreatePlaylist ----------++    @Test+    fun createPlaylistStartsDisabledThenValidates() {+        val backStack = NavBackStack(arrayOf<Route>(Route.Main(0), Route.CreatePlaylist))+        composeRule.setContent { CreatePlaylist(backStack, vm) }+        val createLabel = context.getString(com.vayunmathur.library.ui.R.string.create)+        composeRule.onNodeWithText(+            context.getString(com.vayunmathur.youpipe.R.string.title_create_playlist),+        ).assertIsDisplayed()+        composeRule.onNodeWithText(createLabel).assertIsNotEnabled()+    }++    @Test+    fun createPlaylistTypingEnablesAndCreates() {+        val backStack = NavBackStack(arrayOf<Route>(Route.Main(0), Route.CreatePlaylist))+        composeRule.setContent { CreatePlaylist(backStack, vm) }+        val createLabel = context.getString(com.vayunmathur.library.ui.R.string.create)+        composeRule.onNodeWithText(+            context.getString(com.vayunmathur.youpipe.R.string.label_playlist_name),+        ).performTextInput("My Mix")+        composeRule.waitForIdle()+        composeRule.onNodeWithText(createLabel).assertIsEnabled()+        composeRule.onNodeWithText(createLabel).performClick()+        composeRule.waitForIdle()+        composeRule.waitUntil(timeoutMillis = 10_000) { backStack.backStack.size == 1 }+        assertEquals(1, backStack.backStack.size)+    }++    @Test+    fun createPlaylistDuplicateNameStaysDisabled() {+        kotlinx.coroutines.runBlocking {+            db.playlistDao().upsert(Playlist(name = "Existing", position = 1.0))+        }+        val backStack = NavBackStack(arrayOf<Route>(Route.Main(0), Route.CreatePlaylist))+        composeRule.setContent { CreatePlaylist(backStack, vm) }+        val createLabel = context.getString(com.vayunmathur.library.ui.R.string.create)+        // Wait for the seeded playlist to reach the dialog through the VM flows.+        composeRule.waitUntil(timeoutMillis = 10_000) {+            vm.playlists.value.any { it.name == "Existing" }+        }+        composeRule.onNodeWithText(+            context.getString(com.vayunmathur.youpipe.R.string.label_playlist_name),+        ).performTextInput("Existing")+        composeRule.waitForIdle()+        composeRule.onNodeWithText(createLabel).assertIsNotEnabled()+    }++    @Test+    fun createPlaylistPersistsThroughOps() {+        val backStack = NavBackStack(arrayOf<Route>(Route.Main(0), Route.CreatePlaylist))+        composeRule.setContent { CreatePlaylist(backStack, vm) }+        composeRule.onNodeWithText(+            context.getString(com.vayunmathur.youpipe.R.string.label_playlist_name),+        ).performTextInput("Persisted")+        composeRule.waitForIdle()+        composeRule.onNodeWithText(+            context.getString(com.vayunmathur.library.ui.R.string.create),+        ).performClick()+        // The dialog pops synchronously; the IO write lands shortly after.+        // Poll the DAO with blocking reads on the test thread (never the VM+        // flow under runTest: its scheduler would freeze the collector).+        composeRule.waitUntil(timeoutMillis = 10_000) { backStack.backStack.size == 1 }+        var found = false+        val deadline = System.currentTimeMillis() + 10_000+        while (!found && System.currentTimeMillis() < deadline) {+            composeRule.waitForIdle()+            found = kotlinx.coroutines.runBlocking { db.playlistDao().getAll() }+                .any { it.name == "Persisted" }+        }+        assertTrue(found, "Persisted playlist missing from DAO")+    }++    // ---------- AddToPlaylist ----------++    @Test+    fun addToPlaylistShowsTitleWhenVideoMissing() {+        val backStack = NavBackStack(arrayOf<Route>(Route.Main(0), Route.AddToPlaylist(7L)))+        composeRule.setContent { AddToPlaylist(backStack, vm, videoID = 7L) }+        composeRule.onNodeWithText(+            context.getString(com.vayunmathur.youpipe.R.string.add_to_playlist),+        ).assertIsDisplayed()+    }++    @Test+    fun addToPlaylistConfirmsMembershipChange() {+        seedVideoState(videoID = 11L)+        kotlinx.coroutines.runBlocking {+            db.playlistDao().upsert(Playlist(name = "Rock", position = 1.0))+        }+        val backStack = NavBackStack(arrayOf<Route>(Route.Main(0), Route.AddToPlaylist(11L)))+        composeRule.setContent { AddToPlaylist(backStack, vm, videoID = 11L) }+        // The staged dialog lists the playlist with an unchecked box; checking it+        // and confirming persists the membership row and pops the dialog.+        composeRule.waitUntil(timeoutMillis = 10_000) {+            composeRule.onAllNodesWithText("Rock").fetchSemanticsNodes().isNotEmpty()+        }+        composeRule.onNodeWithText("Rock").performClick()+        composeRule.onNodeWithText(context.getString(android.R.string.ok)).performClick()+        composeRule.waitUntil(timeoutMillis = 10_000) { backStack.backStack.size == 1 }+        assertEquals(1, backStack.backStack.size)+    }++    // ---------- AddToWatchLater ----------++    @Test+    fun addToWatchLaterShowsProgressThenAddsAndPops() {+        seedVideoState(videoID = 21L)+        // The mandatory Watch-later row is seeded by the VM init; wait for the+        // DAO row directly (plain thread, no runTest scheduler freeze).+        var watchLaterId = -1L+        val seedDeadline = System.currentTimeMillis() + 10_000+        while (watchLaterId < 0 && System.currentTimeMillis() < seedDeadline) {+            composeRule.waitForIdle()+            watchLaterId = kotlinx.coroutines.runBlocking { db.playlistDao().getAll() }+                .firstOrNull { it.mandatory }?.id ?: -1L+        }+        assertTrue(watchLaterId >= 0, "Watch-later seed row never landed")+        val backStack = NavBackStack(arrayOf<Route>(Route.Main(0), Route.AddToWatchLater(21L)))+        composeRule.setContent { AddToWatchLater(backStack, vm, videoID = 21L) }+        composeRule.onNodeWithText(+            context.getString(com.vayunmathur.youpipe.R.string.adding_to_watch_later),+        ).assertIsDisplayed()+        composeRule.waitUntil(timeoutMillis = 10_000) { backStack.backStack.size == 1 }+        var added = false+        val deadline = System.currentTimeMillis() + 10_000+        while (!added && System.currentTimeMillis() < deadline) {+            composeRule.waitForIdle()+            added = kotlinx.coroutines.runBlocking {+                db.playlistItemDao().getForPlaylist(watchLaterId)+            }.any { it.videoItem.videoID == 21L }+        }+        assertTrue(added, "video 21 missing from Watch later")+    }++    @Test+    fun addToWatchLaterPopsOnVideoError() {+        vm.videoStateMutable.value = YouPipeViewModel.VideoState(error = true)+        val backStack = NavBackStack(arrayOf<Route>(Route.Main(0), Route.AddToWatchLater(22L)))+        composeRule.setContent { AddToWatchLater(backStack, vm, videoID = 22L) }+        composeRule.waitUntil(timeoutMillis = 10_000) { backStack.backStack.size == 1 }+        assertEquals(1, backStack.backStack.size)+    }++    // ---------- CreateSubscriptionCategory ----------++    @Test+    fun createCategoryShowsTitleAndDisablesCreate() {+        val backStack = NavBackStack(arrayOf<Route>(Route.Main(0), Route.CreateSubscriptionCategory(null)))+        composeRule.setContent { CreateSubscriptionCategory(backStack, vm, null) }+        composeRule.onNodeWithText(+            context.getString(com.vayunmathur.youpipe.R.string.title_create_subscription_category),+        ).assertIsDisplayed()+        composeRule.onNodeWithText(+            context.getString(com.vayunmathur.library.ui.R.string.create),+        ).assertIsNotEnabled()+    }++    @Test+    fun createCategoryTypingNameAndSelectingEnables() {+        // Seed on a plain thread: runTest's scheduler would freeze the+        // compose collector while waiting for the row to flow through.+        kotlinx.coroutines.runBlocking {+            db.subscriptionDao().upsert(+                Subscription(name = "Chan", channelID = "UC1", avatarURL = "https://x/y.jpg"),+            )+        }+        val backStack = NavBackStack(arrayOf<Route>(Route.Main(0), Route.CreateSubscriptionCategory(null)))+        composeRule.setContent { CreateSubscriptionCategory(backStack, vm, null) }+        composeRule.waitUntil(timeoutMillis = 10_000) {+            composeRule.onAllNodesWithText("Chan").fetchSemanticsNodes().isNotEmpty()+        }+        composeRule.onNodeWithText(+            context.getString(com.vayunmathur.youpipe.R.string.label_category_name),+        ).performTextInput("Music")+        composeRule.waitForIdle()+        toggleRowCheckbox("Chan")+        composeRule.waitForIdle()+        composeRule.onNodeWithText(+            context.getString(com.vayunmathur.library.ui.R.string.create),+        ).assertIsEnabled()+    }++    @Test+    fun updateCategoryShowsUpdateTitleAndSaves() {+        // Seed a subscription already assigned to "Music" via the real+        // replaceCategory path, then open the dialog in update mode.+        val subId = kotlinx.coroutines.runBlocking {+            db.subscriptionDao().upsert(+                Subscription(name = "Chan", channelID = "UC1", avatarURL = "https://x/y.jpg"),+            )+        }+        kotlinx.coroutines.runBlocking {+            db.subscriptionCategoryDao().replaceCategory(null, "Music", listOf(subId))+        }+        val backStack = NavBackStack(arrayOf<Route>(Route.Main(0), Route.CreateSubscriptionCategory("Music")))+        composeRule.setContent { CreateSubscriptionCategory(backStack, vm, "Music") }+        // Update title (not the create title) shows with the id prefilled.+        composeRule.onNodeWithText(+            context.getString(com.vayunmathur.youpipe.R.string.title_update_subscription_category),+        ).assertIsDisplayed()+        composeRule.waitUntil(timeoutMillis = 10_000) {+            composeRule.onAllNodesWithText("Chan").fetchSemanticsNodes().isNotEmpty()+        }+        // The pre-existing membership keeps Update enabled; confirming writes+        // through replaceCategory and pops the dialog.+        composeRule.waitForIdle()+        val updateLabel = context.getString(com.vayunmathur.youpipe.R.string.action_update)+        composeRule.onNodeWithText(updateLabel).assertIsEnabled()+        composeRule.onNodeWithText(updateLabel).performClick()+        composeRule.waitUntil(timeoutMillis = 10_000) { backStack.backStack.size == 1 }+        assertEquals(1, backStack.backStack.size)+    }++    @Test+    fun createCategoryDuplicateNameStaysDisabled() {+        val subId = kotlinx.coroutines.runBlocking {+            db.subscriptionDao().upsert(+                Subscription(name = "Chan", channelID = "UC1", avatarURL = "https://x/y.jpg"),+            )+        }+        kotlinx.coroutines.runBlocking {+            db.subscriptionCategoryDao().replaceCategory(null, "Music", listOf(subId))+        }+        // New-category mode: typing an already-used name keeps Create disabled+        // even with a subscription selected.+        val backStack = NavBackStack(arrayOf<Route>(Route.Main(0), Route.CreateSubscriptionCategory(null)))+        composeRule.setContent { CreateSubscriptionCategory(backStack, vm, null) }+        composeRule.waitUntil(timeoutMillis = 10_000) {+            composeRule.onAllNodesWithText("Chan").fetchSemanticsNodes().isNotEmpty()+        }+        composeRule.onNodeWithText(+            context.getString(com.vayunmathur.youpipe.R.string.label_category_name),+        ).performTextInput("Music")+        composeRule.waitForIdle()+        toggleRowCheckbox("Chan")+        composeRule.waitForIdle()+        composeRule.onNodeWithText(+            context.getString(com.vayunmathur.library.ui.R.string.create),+        ).assertIsNotEnabled()+    }++    // ---------- helpers ----------++    /** Clicks the checkbox inside the subscription row showing [name]. */+    private fun toggleRowCheckbox(name: String) {+        // The ListItem row itself has no click handler — only the M3 Checkbox+        // does — so click the checkbox node: a sibling of the name text+        // inside the same row.+        composeRule.onNodeWithText(name, useUnmergedTree = true)+            .onParent()+            .onChildren()+            .filterToOne(+                androidx.compose.ui.test.SemanticsMatcher.keyIsDefined(+                    androidx.compose.ui.semantics.SemanticsActions.OnClick,+                ),+            ).performClick()+    }++    private fun seedVideoState(videoID: Long) {+        vm.videoStateMutable.value = YouPipeViewModel.VideoState(+            data = com.vayunmathur.youpipe.ui.VideoData(+                title = "Title $videoID",+                views = 100L,+                duration = 60L,+                uploadDate = kotlin.time.Instant.fromEpochSeconds(1_700_000_000L),+                thumbnailURL = "https://x/t.jpg",+                author = "Author",+                authorURL = "https://x/c",+                authorThumbnail = "https://x/a.jpg",+                description = "desc",+            ),+        )+    }+}