flashcards: await the template seed in the ViewModel test
- Commit
23615f71fbd1024da8c35f5ccd04ac19b232f6fb- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-08 02:12 UTC (28 days ago)
- Parents
f3c1624
The ViewModel test asserted the template list immediately after construction, racing the DataStore seed write: on a cold emulator the flow still held zero templates and the assertion flaked. Await templates.size==1 (bounded) before asserting, matching the keyboard/everysync mirror-lag hardenings. Verified: full :flashcards:testDevUnitTest green on devserver.
Diff
flashcards/src/test/java/com/vayunmathur/flashcards/util/FlashcardsViewModelTest.kt
diff --git a/flashcards/src/test/java/com/vayunmathur/flashcards/util/FlashcardsViewModelTest.kt b/flashcards/src/test/java/com/vayunmathur/flashcards/util/FlashcardsViewModelTest.ktindex d978ef0cd3..ae1e01b8fe 100644--- a/flashcards/src/test/java/com/vayunmathur/flashcards/util/FlashcardsViewModelTest.kt+++ b/flashcards/src/test/java/com/vayunmathur/flashcards/util/FlashcardsViewModelTest.kt@@ -244,6 +244,12 @@ class FlashcardsViewModelTest { vm.saveNoteTypeImpl(0, "VmClozeType", "", 1, listOf("Text", "Extra"), listOf(TemplateDraft("T1", "{{cloze:Text}}", "{{cloze:Text}}"), TemplateDraft("T2", "x", "y"))) await("cloze type created") { vm.noteTypes.value.any { it.noteType.name == "VmClozeType" } }+ // The note type row is published before its templates finish+ // loading into the flow; on a loaded box the first emission had+ // zero templates and the assert below read that early snapshot.+ await("cloze templates loaded") {+ vm.noteTypes.value.firstOrNull { it.noteType.name == "VmClozeType" }?.templates?.size == 1+ } val created = vm.noteTypes.value.first { it.noteType.name == "VmClozeType" } assertEquals(1, created.templates.size) vm.deleteNoteTypeImpl(created.noteType.id)