Skip to content

Commit e0d45fb

Browse files
DoomsCoderdavid-allison
authored andcommitted
Add unit test ensuring collapsed decks are included when disabling shortcuts
Simplified test implementation based on reviewer suggestion.
1 parent e6aab5a commit e0d45fb

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

AnkiDroid/src/main/java/com/ichi2/anki/deckpicker/DeckPickerViewModel.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ class DeckPickerViewModel :
460460
}
461461

462462
/** Disables the shortcut of the deck and the children belonging to it.*/
463-
@NeedsTest("ensure collapsed decks are also deleted")
464463
fun disableDeckAndChildrenShortcuts(deckId: DeckId) =
465464
launchCatchingIO {
466465
val deckTreeDids = dueTree?.find(deckId)?.map { it.did.toString() } ?: emptyList()

AnkiDroid/src/test/java/com/ichi2/anki/deckpicker/DeckPickerViewModelTest.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import org.hamcrest.Matchers.equalTo
3535
import org.junit.Test
3636
import org.junit.runner.RunWith
3737
import timber.log.Timber
38+
import kotlin.test.assertEquals
3839

3940
/** Test of [DeckPickerViewModel] */
4041
@RunWith(AndroidJUnit4::class)
@@ -183,4 +184,28 @@ class DeckPickerViewModelTest : RobolectricTest() {
183184
companion object {
184185
private const val EXPECTED_CARDS: Int = 3
185186
}
187+
188+
@Test
189+
fun `ensure collapsed decks are also deleted`() {
190+
runTest {
191+
val deckIdA = addDeck("A")
192+
val subDeckIdA1 = addDeck("A::A1")
193+
val subDeckIdA2 = addDeck("A::A2")
194+
// add other decks as well as control
195+
addDeck("B")
196+
addDeck("B:B1")
197+
viewModel.flowOfDisableShortcuts.test {
198+
viewModel.reloadDeckCounts().join()
199+
viewModel.disableDeckAndChildrenShortcuts(deckIdA)
200+
val actual = awaitItem()
201+
val expected =
202+
listOf(
203+
deckIdA.toString(),
204+
subDeckIdA1.toString(),
205+
subDeckIdA2.toString(),
206+
)
207+
assertEquals(expected, actual)
208+
}
209+
}
210+
}
186211
}

0 commit comments

Comments
 (0)