Fix test: Add unit test for collapsed decks in disableDeckAndChildrenShortcuts#20364
Fix test: Add unit test for collapsed decks in disableDeckAndChildrenShortcuts#20364DoomsCoder wants to merge 1 commit intoankidroid:mainfrom
Conversation
There was a problem hiding this comment.
Thank you for contributing.
The proposed code works but it's way to complicated for what is trying to achieve.
I left a patch below with a much simpler implementation to use:
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/deckpicker/DeckPickerViewModelTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/deckpicker/DeckPickerViewModelTest.kt
index ae5f0ee83b..24bd2bfca6 100644
--- a/AnkiDroid/src/test/java/com/ichi2/anki/deckpicker/DeckPickerViewModelTest.kt
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/deckpicker/DeckPickerViewModelTest.kt
@@ -35,6 +35,7 @@ import org.hamcrest.Matchers.equalTo
import org.junit.Test
import org.junit.runner.RunWith
import timber.log.Timber
+import kotlin.test.assertEquals
/** Test of [DeckPickerViewModel] */
@RunWith(AndroidJUnit4::class)
@@ -147,6 +148,29 @@ class DeckPickerViewModelTest : RobolectricTest() {
}
}
+ @Test
+ fun `ensure collapsed decks are also deleted when disabling shortcuts`() =
+ runTest {
+ val deckIdA = addDeck("A")
+ val subDeckIdA1 = addDeck("A::A1")
+ val subDeckIdA2 = addDeck("A::A2")
+ // add other decks as well as control
+ addDeck("B")
+ addDeck("B:B1")
+ viewModel.flowOfDisableShortcuts.test {
+ viewModel.reloadDeckCounts().join()
+ viewModel.disableDeckAndChildrenShortcuts(deckIdA)
+ val actual = awaitItem()
+ assertEquals(
+ listOf(
+ deckIdA.toString(),
+ subDeckIdA1.toString(),
+ subDeckIdA2.toString(),
+ ), actual
+ )
+ }
+ }
+
/**
* Creates a note with 3 cards, all empty
*Also consider squashing into a single commit.
|
Hi @lukstbit I will update my PR with your suggested approach and also squash commits. Thanks again for the guidance! |
189b422 to
ba13849
Compare
|
Thanks again for the guidance. I have updated the test based on your suggestion and squashed the commits into single commit. The PR should now be ready for review. |
…ortcuts Simplified test implementation based on reviewer suggestion.
ba2f90c to
65a826a
Compare
Purpose / Description
Adds a missing regression unit test for the disableDeckAndChildrenShortcuts flow in DeckPickerViewModel.
When a parent deck is collapsed, disabling shortcuts should also include all of its child decks. This test ensures that the emitted shortcut disable list correctly contains the parent deck and all descendant deck Ids.
This prevent a future regression where hidden child decks could be missed during this process.
Fixes
@NeedsTest) #13283Approach
The test verifies that:
1.Parent deck Id
2. All child deck Ids
A custom MainCoroutinesRule was added to control coroutine execution and ensure deterministic test behavior.
How Has This Been Tested?
Test Type:
Unit test(/test, not /androidTest)
Steps to Reproduce:
viewmodel.reloadDeckCounts().join()viemodel.disableDeckAndChildrenShortcuts(parentId)4.Collect from:
flowOfDisableShortcuts5.Assert emitted IDs match expected deck hierarchy.
Learning (optional, can help others)
Key learnings while implementing this test:
Checklist