Skip to content

Commit

Permalink
Re-enable DeckPickerTest
Browse files Browse the repository at this point in the history
The FAB was failing. This bypass the FAB.
  • Loading branch information
Arthur-Milchior authored and mikehardy committed Dec 2, 2024
1 parent 2367677 commit 37f12c5
Showing 1 changed file with 3 additions and 43 deletions.
46 changes: 3 additions & 43 deletions AnkiDroid/src/androidTest/java/com/ichi2/anki/DeckPickerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,24 @@
package com.ichi2.anki

import android.annotation.SuppressLint
import androidx.test.espresso.Espresso.closeSoftKeyboard
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.typeText
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.ViewMatchers.assertThat
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import com.ichi2.anki.TestUtils.activityInstance
import com.ichi2.anki.TestUtils.isTablet
import com.ichi2.anki.TestUtils.wasBuiltOnCI
import com.ichi2.anki.tests.InstrumentedTest
import com.ichi2.anki.testutil.GrantStoragePermission.storagePermission
import com.ichi2.anki.testutil.createDeckWithUniqueName
import com.ichi2.anki.testutil.disableIntroductionSlide
import com.ichi2.anki.testutil.discardPreliminaryViews
import com.ichi2.anki.testutil.grantPermissions
import com.ichi2.anki.testutil.notificationPermission
import com.ichi2.anki.testutil.tapOnCountLayouts
import org.hamcrest.Matchers.instanceOf
import org.junit.Assume.assumeFalse
import org.junit.Assume.assumeTrue
import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test

Expand All @@ -59,22 +49,21 @@ class DeckPickerTest : InstrumentedTest() {

@Before
fun before() {
addNoteUsingBasicModel()
disableIntroductionSlide()
discardPreliminaryViews()
}

@Ignore("This test appears to be flaky everywhere")
@Test
fun checkIfClickOnCountsLayoutOpensStudyOptionsOnMobile() {
// Run the test only on emulator.
assumeTrue(isEmulator())
assumeFalse("Test flaky in CI - #9282, skipping", wasBuiltOnCI())

// For mobile. If it is not a mobile, then test will be ignored.
assumeTrue(!isTablet)
val deckName = createDeckWithCard()

// Go to RecyclerView item having "Test Deck" and click on the counts layout
tapOnCountLayouts(deckName)
tapOnCountLayouts("Default")

// Check if currently open Activity is StudyOptionsActivity
assertThat(
Expand All @@ -87,41 +76,12 @@ class DeckPickerTest : InstrumentedTest() {
fun checkIfStudyOptionsIsDisplayedOnTablet() {
// Run the test only on emulator.
assumeTrue(isEmulator())
assumeFalse("Test flaky in CI - #9282, skipping", wasBuiltOnCI())

// For tablet. If it is not a tablet, then test will be ignored.
assumeTrue(isTablet)
discardPreliminaryViews()
createDeckWithCard()

// Check if currently open Fragment is StudyOptionsFragment
onView(withId(R.id.studyoptions_fragment))
.check(ViewAssertions.matches(isDisplayed()))
}

private fun createDeckWithCard(): String {
// Create a new deck
val deckName = createDeckWithUniqueName()

// The deck is currently empty, so if we tap on it, it becomes the selected deck but doesn't enter
tapOnCountLayouts(deckName)

// Create a card belonging to the new deck, using Basic type (guaranteed to exist)
onView(withId(R.id.fab_main)).perform(click())
onView(withId(R.id.fab_main)).perform(click())

// Close the keyboard, it auto-focuses and obscures enough of the screen
// on some devices that espresso complains about global visibility being <90%
closeSoftKeyboard()
onView(withId(R.id.note_type_spinner)).perform(click())
onView(withText("Basic")).perform(click())
onView(withContentDescription("Front"))
.perform(typeText("SampleText"))
onView(withId(R.id.action_save)).perform(click())
closeSoftKeyboard()

// Go back to Deck Picker
pressBack()
return deckName
}
}

0 comments on commit 37f12c5

Please sign in to comment.