-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix: Flasky-tests #20413 #20414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: Flasky-tests #20413 #20414
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,7 +97,12 @@ class DeckPickerTest : RobolectricTest() { | |
| // but Android lifecycle callback (onCreate) have not yet executed. | ||
| DeckPicker() | ||
|
|
||
| assertDoesNotThrow { ChangeManager.notifySubscribers(opChanges { studyQueues = true }, null) } | ||
| assertDoesNotThrow { | ||
| ChangeManager.notifySubscribers( | ||
| opChanges { studyQueues = true }, | ||
| null, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -143,7 +148,8 @@ class DeckPickerTest : RobolectricTest() { | |
| whenever(editor.remove(DeckPickerViewModel.UPGRADE_VERSION_KEY)).thenReturn(updated) | ||
| ActivityScenario.launch(DeckPicker::class.java).use { scenario -> | ||
| scenario.onActivity { deckPicker: DeckPicker -> | ||
| val previousVersion = deckPicker.viewModel.getPreviousVersion(preferences, newVersion) | ||
| val previousVersion = | ||
| deckPicker.viewModel.getPreviousVersion(preferences, newVersion) | ||
| assertEquals(40, previousVersion) | ||
| } | ||
| } | ||
|
|
@@ -167,7 +173,8 @@ class DeckPickerTest : RobolectricTest() { | |
| whenever(editor.remove(DeckPickerViewModel.UPGRADE_VERSION_KEY)).thenReturn(updated) | ||
| ActivityScenario.launch(DeckPicker::class.java).use { scenario -> | ||
| scenario.onActivity { deckPicker: DeckPicker -> | ||
| val previousVersion = deckPicker.viewModel.getPreviousVersion(preferences, newVersion) | ||
| val previousVersion = | ||
| deckPicker.viewModel.getPreviousVersion(preferences, newVersion) | ||
| assertEquals(prevVersion.toLong(), previousVersion) | ||
| } | ||
| } | ||
|
|
@@ -186,7 +193,8 @@ class DeckPickerTest : RobolectricTest() { | |
| whenever(preferences.edit()).thenReturn(editor) | ||
| ActivityScenario.launch(DeckPicker::class.java).use { scenario -> | ||
| scenario.onActivity { deckPicker: DeckPicker -> | ||
| val previousVersion = deckPicker.viewModel.getPreviousVersion(preferences, newVersion) | ||
| val previousVersion = | ||
| deckPicker.viewModel.getPreviousVersion(preferences, newVersion) | ||
| assertEquals(prevVersion, previousVersion) | ||
| } | ||
| } | ||
|
|
@@ -377,15 +385,24 @@ class DeckPickerTest : RobolectricTest() { | |
| deckPicker { | ||
| val didA = addDeck("Deck 1") | ||
|
|
||
| supportFragmentManager.selectContextMenuOption(DeckPickerContextMenuOption.RENAME_DECK, didA) | ||
| supportFragmentManager.selectContextMenuOption( | ||
| DeckPickerContextMenuOption.RENAME_DECK, | ||
| didA, | ||
| ) | ||
| assertDialogTitleEquals("Rename deck") | ||
| dismissAllDialogFragments() | ||
|
|
||
| supportFragmentManager.selectContextMenuOption(DeckPickerContextMenuOption.CREATE_SUBDECK, didA) | ||
| supportFragmentManager.selectContextMenuOption( | ||
| DeckPickerContextMenuOption.CREATE_SUBDECK, | ||
| didA, | ||
| ) | ||
| assertDialogTitleEquals("Create subdeck") | ||
| dismissAllDialogFragments() | ||
|
|
||
| supportFragmentManager.selectContextMenuOption(DeckPickerContextMenuOption.CUSTOM_STUDY, didA) | ||
| supportFragmentManager.selectContextMenuOption( | ||
| DeckPickerContextMenuOption.CUSTOM_STUDY, | ||
| didA, | ||
| ) | ||
| assertDialogTitleEquals("Custom study") | ||
| dismissAllDialogFragments() | ||
|
|
||
|
|
@@ -432,48 +449,80 @@ class DeckPickerTest : RobolectricTest() { | |
| val didA = addDeck("Deck 1") | ||
| val didDynamicA = addDynamicDeck("Deck Dynamic 1") | ||
|
|
||
| val noteEditor = selectContextMenuOptionForActivity(DeckPickerContextMenuOption.ADD_CARD, didA) | ||
| val noteEditor = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert all these spacing changes, they make it difficult to understand the change |
||
| selectContextMenuOptionForActivity(DeckPickerContextMenuOption.ADD_CARD, didA) | ||
| assertEquals("com.ichi2.anki.NoteEditorActivity", noteEditor.component!!.className) | ||
| onBackPressedDispatcher.onBackPressed() | ||
|
|
||
| val browser = selectContextMenuOptionForActivity(DeckPickerContextMenuOption.BROWSE_CARDS, didA) | ||
| val browser = | ||
| selectContextMenuOptionForActivity(DeckPickerContextMenuOption.BROWSE_CARDS, didA) | ||
| assertEquals("com.ichi2.anki.CardBrowser", browser.component!!.className) | ||
| onBackPressedDispatcher.onBackPressed() | ||
|
|
||
| // select deck options for a normal deck | ||
| val deckOptionsNormal = selectContextMenuOptionForActivity(DeckPickerContextMenuOption.DECK_OPTIONS, didA) | ||
| assertEquals("com.ichi2.anki.SingleFragmentActivity", deckOptionsNormal.component!!.className) | ||
| val deckOptionsNormal = | ||
| selectContextMenuOptionForActivity(DeckPickerContextMenuOption.DECK_OPTIONS, didA) | ||
| assertEquals( | ||
| "com.ichi2.anki.SingleFragmentActivity", | ||
| deckOptionsNormal.component!!.className, | ||
| ) | ||
| onBackPressedDispatcher.onBackPressed() | ||
|
|
||
| // select deck options for a dynamic deck | ||
| val deckOptionsDynamic = selectContextMenuOptionForActivity(DeckPickerContextMenuOption.DECK_OPTIONS, didDynamicA) | ||
| assertEquals("com.ichi2.anki.FilteredDeckOptions", deckOptionsDynamic.component!!.className) | ||
| val deckOptionsDynamic = | ||
| selectContextMenuOptionForActivity( | ||
| DeckPickerContextMenuOption.DECK_OPTIONS, | ||
| didDynamicA, | ||
| ) | ||
| assertEquals( | ||
| "com.ichi2.anki.FilteredDeckOptions", | ||
| deckOptionsDynamic.component!!.className, | ||
| ) | ||
| onBackPressedDispatcher.onBackPressed() | ||
|
|
||
| Prefs.newReviewRemindersEnabled = true | ||
| val scheduleReminders = selectContextMenuOptionForActivity(DeckPickerContextMenuOption.SCHEDULE_REMINDERS, didA) | ||
| assertEquals("com.ichi2.anki.SingleFragmentActivity", scheduleReminders.component!!.className) | ||
| val scheduleReminders = | ||
| selectContextMenuOptionForActivity( | ||
| DeckPickerContextMenuOption.SCHEDULE_REMINDERS, | ||
| didA, | ||
| ) | ||
| assertEquals( | ||
| "com.ichi2.anki.SingleFragmentActivity", | ||
| scheduleReminders.component!!.className, | ||
| ) | ||
| onBackPressedDispatcher.onBackPressed() | ||
| } | ||
|
|
||
| @Test | ||
| fun `ContextMenu deletes deck when selecting DELETE_DECK`() = | ||
| deckPicker { | ||
| val didA = addDeck("Deck 1") | ||
| supportFragmentManager.selectContextMenuOption(DeckPickerContextMenuOption.DELETE_DECK, didA) | ||
| assertThat(getColUnsafe.decks.allNamesAndIds().map { it.id }, not(containsInAnyOrder(didA))) | ||
| supportFragmentManager.selectContextMenuOption( | ||
| DeckPickerContextMenuOption.DELETE_DECK, | ||
| didA, | ||
| ) | ||
| assertThat( | ||
| getColUnsafe.decks.allNamesAndIds().map { it.id }, | ||
| not(containsInAnyOrder(didA)), | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `ContextMenu creates deck shortcut when selecting CREATE_SHORTCUT`() = | ||
| deckPicker { | ||
| val didA = addDeck("Deck 1") | ||
| supportFragmentManager.selectContextMenuOption(DeckPickerContextMenuOption.CREATE_SHORTCUT, didA) | ||
| supportFragmentManager.selectContextMenuOption( | ||
| DeckPickerContextMenuOption.CREATE_SHORTCUT, | ||
| didA, | ||
| ) | ||
| // Wait for the shortcut creation to complete | ||
| ShadowLooper.runUiThreadTasksIncludingDelayedTasks() | ||
| assertEquals( | ||
| "Deck 1", | ||
| ShortcutManagerCompat.getShortcuts(this, ShortcutManagerCompat.FLAG_MATCH_PINNED).first().shortLabel, | ||
| ShortcutManagerCompat | ||
| .getShortcuts(this, ShortcutManagerCompat.FLAG_MATCH_PINNED) | ||
| .first() | ||
| .shortLabel, | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -493,7 +542,10 @@ class DeckPickerTest : RobolectricTest() { | |
| advanceRobolectricLooper() | ||
| assertEquals(1, visibleDeckCount) | ||
| assertTrue(getColUnsafe.sched.haveBuried(), "Deck should have buried cards") | ||
| supportFragmentManager.selectContextMenuOption(DeckPickerContextMenuOption.UNBURY, deckId) | ||
| supportFragmentManager.selectContextMenuOption( | ||
| DeckPickerContextMenuOption.UNBURY, | ||
| deckId, | ||
| ) | ||
| kotlin.test.assertFalse(getColUnsafe.sched.haveBuried()) | ||
| } | ||
|
|
||
|
|
@@ -508,14 +560,21 @@ class DeckPickerTest : RobolectricTest() { | |
| getColUnsafe.sched.rebuildFilteredDeck(deckId) | ||
| assertTrue(allCardsInSameDeck(cardIds, deckId)) | ||
| updateDeckList() | ||
| advanceRobolectricLooper() | ||
| assertEquals(1, visibleDeckCount) | ||
|
|
||
| supportFragmentManager.selectContextMenuOption(DeckPickerContextMenuOption.CUSTOM_STUDY_EMPTY, deckId) // Empty | ||
| supportFragmentManager.selectContextMenuOption( | ||
| DeckPickerContextMenuOption.CUSTOM_STUDY_EMPTY, | ||
| deckId, | ||
| ) // Empty | ||
|
|
||
| assertTrue(allCardsInSameDeck(cardIds, 1)) | ||
|
|
||
| supportFragmentManager.selectContextMenuOption(DeckPickerContextMenuOption.CUSTOM_STUDY_REBUILD, deckId) // Rebuild | ||
|
|
||
| supportFragmentManager.selectContextMenuOption( | ||
| DeckPickerContextMenuOption.CUSTOM_STUDY_REBUILD, | ||
| deckId, | ||
| ) // Rebuild | ||
| advanceRobolectricLooper() | ||
| assertTrue(allCardsInSameDeck(cardIds, deckId)) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,7 @@ import org.junit.Ignore | |
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.Shadows | ||
| import org.robolectric.shadows.ShadowLooper.runUiThreadTasksIncludingDelayedTasks | ||
| import timber.log.Timber | ||
| import kotlin.test.junit5.JUnit5Asserter.assertNotNull | ||
|
|
||
|
|
@@ -246,31 +247,27 @@ class ReviewerTest : RobolectricTest() { | |
| addBasicNote("2", "bar").firstCard(), | ||
| addBasicNote("3", "bar").firstCard(), | ||
| ) | ||
| advanceRobolectricLooper() | ||
|
|
||
| val reviewer = startReviewer() | ||
|
|
||
| advanceRobolectricLooper() | ||
|
|
||
| equalFirstField(cards[0], reviewer.currentCard!!) | ||
| reviewer.answerCard(Rating.AGAIN) | ||
| advanceRobolectricLooper() | ||
| runUiThreadTasksIncludingDelayedTasks() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These appear to be equivalent fun advanceRobolectricLooper() {
Shadows.shadowOf(Looper.getMainLooper()).runToEndOfTasks()
} public static void runUiThreadTasksIncludingDelayedTasks() {
getShadowMainLooper().runToEndOfTasks();
} |
||
|
|
||
| equalFirstField(cards[1], reviewer.currentCard!!) | ||
| reviewer.answerCard(Rating.AGAIN) | ||
| advanceRobolectricLooper() | ||
| runUiThreadTasksIncludingDelayedTasks() | ||
|
|
||
| undo(reviewer) | ||
| advanceRobolectricLooper() | ||
|
|
||
| equalFirstField(cards[1], reviewer.currentCard!!) | ||
| reviewer.answerCard(Rating.GOOD) | ||
| advanceRobolectricLooper() | ||
| runUiThreadTasksIncludingDelayedTasks() | ||
|
|
||
| equalFirstField(cards[2], reviewer.currentCard!!) | ||
| time.addM(2) | ||
| reviewer.answerCard(Rating.GOOD) | ||
| advanceRobolectricLooper() | ||
| runUiThreadTasksIncludingDelayedTasks() | ||
|
|
||
| equalFirstField( | ||
| cards[0], | ||
| reviewer.currentCard!!, | ||
|
|
@@ -359,14 +356,17 @@ class ReviewerTest : RobolectricTest() { | |
| val nonDefaultDeck = addDeck("Hello") | ||
| assertThat("first card is shown", this.cardContent, containsString("One")) | ||
| flipOrAnswerCard(Rating.GOOD) | ||
| advanceRobolectricLooper() | ||
| // answer good, 'Rating.GOOD' should now be < 10m | ||
| assertThat("initial time is 10m", this.getCardDataForJsApi().nextTime3, equalTo("<\u206810\u2069m")) | ||
| flipOrAnswerCard(Rating.GOOD) | ||
| advanceRobolectricLooper() | ||
| assertThat("next card is shown", this.cardContent, containsString("Two")) | ||
|
|
||
| undoableOp { col.setDeck(listOf(currentCard!!.id), nonDefaultDeck) } | ||
|
|
||
| advanceRobolectricLooper() | ||
| flipOrAnswerCard(Rating.GOOD) | ||
| advanceRobolectricLooper() | ||
| assertThat("buttons should be updated", this.getCardDataForJsApi().nextTime3, equalTo("\u20681\u2069d")) | ||
| assertThat("content should be updated", this.cardContent, containsString("One")) | ||
| } | ||
|
|
@@ -403,6 +403,7 @@ class ReviewerTest : RobolectricTest() { | |
|
|
||
| private fun undo(reviewer: Reviewer) { | ||
| reviewer.undo() | ||
| runUiThreadTasksIncludingDelayedTasks() | ||
| } | ||
|
|
||
| @Suppress("SameParameterValue") | ||
|
|
@@ -439,14 +440,14 @@ class ReviewerTest : RobolectricTest() { | |
|
|
||
| r.answerCard(Rating.GOOD) | ||
|
|
||
| advanceRobolectricLooper() | ||
| runUiThreadTasksIncludingDelayedTasks() | ||
| } | ||
|
|
||
| private fun assertCurrentOrdIs( | ||
| r: Reviewer, | ||
| i: Int, | ||
| ) { | ||
| advanceRobolectricLooper() | ||
| runUiThreadTasksIncludingDelayedTasks() | ||
| val ord = r.currentCard!!.ord | ||
|
|
||
| assertThat("Unexpected card ord", ord + 1, equalTo(i)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,10 +59,10 @@ class PrefsSearchBarTest : RobolectricTest() { | |
|
|
||
| // Join both lists | ||
| val allResIds = | ||
| filesResIds | ||
| .plus(prefItemsResIds) | ||
| .distinct() as List<Int> | ||
|
|
||
| (filesResIds + prefItemsResIds) | ||
| .filterIsInstance<Int>() | ||
| .filter { it != 0 } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is there sometimes a resource of 0? It's best to figure this out, rather than ignore something in the test which we don't understand. Is this I think the best option would be to add a log of the count + names of all selected resource IDs, then we know if it's extra or missing. |
||
| .distinct() | ||
| // Check if all indexed XML resIDs lead to the correct fragments on getFragmentFromXmlRes | ||
| for (resId in allResIds) { | ||
| val fragment = getFragmentFromXmlRes(resId) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ import org.junit.Before | |
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import java.util.Calendar | ||
| import java.util.TimeZone | ||
| import kotlin.time.Duration.Companion.minutes | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
|
|
@@ -60,6 +61,7 @@ class AlarmManagerServiceTest : RobolectricTest() { | |
| @Before | ||
| override fun setUp() { | ||
| super.setUp() | ||
| TimeZone.setDefault(TimeZone.getTimeZone("UTC")) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't this fail at the same time in UTC? |
||
| context = mockk(relaxed = true) | ||
| alarmManager = mockk(relaxed = true) | ||
| notificationManager = mockk(relaxed = true) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a no-op