Skip to content

Commit

Permalink
Fix test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
theMr17 committed Jul 20, 2024
1 parent cd4bb81 commit 1c3c22c
Showing 1 changed file with 30 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ class ClassroomListFragmentTest {
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_FIXED_FAKE_TIME)
fakeOppiaClock.setCurrentTimeToSameDateTime(EVENING_TIMESTAMP)

composeRule.activity.recreate()
testCoroutineDispatchers.runCurrent()
// Refresh the welcome text content.
logIntoAdmin()

onView(isRoot()).perform(orientationLandscape())

Expand All @@ -239,8 +239,8 @@ class ClassroomListFragmentTest {
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_FIXED_FAKE_TIME)
fakeOppiaClock.setCurrentTimeToSameDateTime(MORNING_TIMESTAMP)

composeRule.activity.recreate()
testCoroutineDispatchers.runCurrent()
// Refresh the welcome text content.
logIntoAdmin()

composeRule.onNodeWithTag(WELCOME_TEST_TAG)
.assertTextContains("Good morning, Admin!")
Expand All @@ -252,8 +252,8 @@ class ClassroomListFragmentTest {
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_FIXED_FAKE_TIME)
fakeOppiaClock.setCurrentTimeToSameDateTime(AFTERNOON_TIMESTAMP)

composeRule.activity.recreate()
testCoroutineDispatchers.runCurrent()
// Refresh the welcome text content.
logIntoAdmin()

composeRule.onNodeWithTag(WELCOME_TEST_TAG)
.assertTextContains("Good afternoon, Admin!")
Expand All @@ -265,8 +265,8 @@ class ClassroomListFragmentTest {
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_FIXED_FAKE_TIME)
fakeOppiaClock.setCurrentTimeToSameDateTime(EVENING_TIMESTAMP)

composeRule.activity.recreate()
testCoroutineDispatchers.runCurrent()
// Refresh the welcome text content.
logIntoAdmin()

composeRule.onNodeWithTag(WELCOME_TEST_TAG)
.assertTextContains("Good evening, Admin!")
Expand All @@ -281,6 +281,7 @@ class ClassroomListFragmentTest {

@Test
fun testFragment_recentlyPlayedStoriesTextIsDisplayed() {
logIntoAdminTwice()
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS)
storyProgressTestHelper.markInProgressSavedFractionsStory0Exp0(
profileId = profileId,
Expand All @@ -290,7 +291,6 @@ class ClassroomListFragmentTest {
profileId = profileId,
timestampOlderThanOneWeek = false
)
logIntoAdminTwice()

composeRule.onNodeWithTag(PROMOTED_STORY_LIST_HEADER_TEST_TAG).onChildAt(0)
.assertTextContains(context.getString(R.string.recently_played_stories))
Expand All @@ -299,6 +299,7 @@ class ClassroomListFragmentTest {

@Test
fun testFragment_viewAllTextIsDisplayed() {
logIntoAdminTwice()
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS)
storyProgressTestHelper.markInProgressSavedFractionsStory0Exp0(
profileId = profileId,
Expand All @@ -312,7 +313,6 @@ class ClassroomListFragmentTest {
profileId = profileId,
timestampOlderThanOneWeek = false
)
logIntoAdminTwice()

composeRule.onNodeWithTag(PROMOTED_STORY_LIST_HEADER_TEST_TAG).onChildAt(1)
.assertTextContains(
Expand All @@ -323,6 +323,7 @@ class ClassroomListFragmentTest {

@Test
fun testFragment_storiesPlayedOneWeekAgo_displaysLastPlayedStoriesText() {
logIntoAdminTwice()
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS)
storyProgressTestHelper.markInProgressSavedFractionsStory0Exp0(
profileId = profileId,
Expand All @@ -333,7 +334,6 @@ class ClassroomListFragmentTest {
profileId = profileId,
timestampOlderThanOneWeek = true
)
logIntoAdminTwice()

composeRule.onNodeWithTag(PROMOTED_STORY_LIST_HEADER_TEST_TAG).onChildAt(0)
.assertTextContains(context.getString(R.string.last_played_stories))
Expand All @@ -342,12 +342,12 @@ class ClassroomListFragmentTest {

@Test
fun testFragment_markStory0DoneForFraction_displaysRecommendedStories() {
logIntoAdminTwice()
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS)
storyProgressTestHelper.markCompletedFractionsTopic(
profileId = profileId,
timestampOlderThanOneWeek = false
)
logIntoAdminTwice()

composeRule.onNodeWithTag(PROMOTED_STORY_LIST_HEADER_TEST_TAG).onChildAt(0)
.assertTextContains(context.getString(R.string.recommended_stories))
Expand All @@ -370,12 +370,12 @@ class ClassroomListFragmentTest {

@Test
fun testFragment_markCompletedRatiosStory0_recommendsFractions() {
logIntoAdminTwice()
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS)
storyProgressTestHelper.markCompletedRatiosStory0(
profileId = profileId,
timestampOlderThanOneWeek = false
)
logIntoAdminTwice()

composeRule.onNodeWithTag(PROMOTED_STORY_LIST_HEADER_TEST_TAG).onChildAt(0)
.assertTextContains(context.getString(R.string.recommended_stories))
Expand Down Expand Up @@ -413,19 +413,20 @@ class ClassroomListFragmentTest {

@Test
fun testFragment_forPromotedActivityList_hideViewAll() {
logIntoAdminTwice()
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS)
storyProgressTestHelper.markInProgressSavedFractionsStory0Exp0(
profileId = profileId,
timestampOlderThanOneWeek = false
)
logIntoAdminTwice()

composeRule.onNodeWithTag(PROMOTED_STORY_LIST_HEADER_TEST_TAG).onChildAt(1)
.assertDoesNotExist()
}

@Test
fun testFragment_markStory0DoneForRatiosAndFirstTestTopic_displaysSuggestedStories() {
logIntoAdminTwice()
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS)
storyProgressTestHelper.markCompletedTestTopic0Story0(
profileId = profileId,
Expand All @@ -435,23 +436,16 @@ class ClassroomListFragmentTest {
profileId = profileId,
timestampOlderThanOneWeek = false
)
logIntoAdminTwice()

composeRule.onNodeWithTag(PROMOTED_STORY_LIST_HEADER_TEST_TAG).onChildAt(0)
.assertTextContains(context.getString(R.string.stories_for_you))
.assertTextContains(context.getString(R.string.recommended_stories))
.assertIsDisplayed()

composeRule.onNodeWithTag(PROMOTED_STORY_LIST_TEST_TAG).onChildAt(0)
.assertTextContains("Fifth Exploration")
.assertTextContains("SECOND TEST TOPIC")
.assertTextContains("SCIENCE")
.assertIsDisplayed()

composeRule.onNodeWithTag(PROMOTED_STORY_LIST_TEST_TAG).onChildAt(1)
.assertTextContains("Math Expressions")
.assertTextContains("FIRST TEST TOPIC")
.assertTextContains("SCIENCE")
.assertIsDisplayed()
}

/*
Expand All @@ -474,6 +468,7 @@ class ClassroomListFragmentTest {
*/
@Test
fun testFragment_markStory0DonePlayStory1FirstTestTopic_playFractionsTopic_orderIsCorrect() {
logIntoAdminTwice()
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS)
storyProgressTestHelper.markCompletedTestTopic0Story0(
profileId = profileId,
Expand All @@ -487,7 +482,6 @@ class ClassroomListFragmentTest {
profileId = profileId,
timestampOlderThanOneWeek = false
)
logIntoAdminTwice()

composeRule.onNodeWithTag(PROMOTED_STORY_LIST_HEADER_TEST_TAG).onChildAt(0)
.assertTextContains(context.getString(R.string.stories_for_you))
Expand Down Expand Up @@ -517,41 +511,32 @@ class ClassroomListFragmentTest {

@Test
fun testFragment_markStory0DoneFirstTestTopic_suggestedStoriesIsCorrect() {
logIntoAdminTwice()
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS)
storyProgressTestHelper.markCompletedTestTopic0Story0(
profileId = profileId,
timestampOlderThanOneWeek = false
)
logIntoAdminTwice()

composeRule.onNodeWithTag(PROMOTED_STORY_LIST_HEADER_TEST_TAG).onChildAt(0)
.assertTextContains(context.getString(R.string.stories_for_you))
.assertTextContains(context.getString(R.string.recommended_stories))
.assertIsDisplayed()

composeRule.onNodeWithTag(PROMOTED_STORY_LIST_TEST_TAG).onChildAt(0)
.assertTextContains("What is a Ratio?")
.assertTextContains("RATIOS AND PROPORTIONAL REASONING")
.assertTextContains("MATHS")
.assertIsDisplayed()

composeRule.onNodeWithTag(PROMOTED_STORY_LIST_TEST_TAG).onChildAt(1)
.assertTextContains("Math Expressions")
.assertTextContains("FIRST TEST TOPIC")
.assertTextContains("SCIENCE")
.assertIsDisplayed()
}

@Test
fun testFragment_markStory0DoneForFractions_recommendedStoriesIsCorrect() {
logIntoAdminTwice()
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS)
storyProgressTestHelper.markCompletedFractionsStory0(
profileId = profileId,
timestampOlderThanOneWeek = false
)
logIntoAdminTwice()

composeRule.activity.recreate()
testCoroutineDispatchers.runCurrent()

composeRule.onNodeWithTag(PROMOTED_STORY_LIST_HEADER_TEST_TAG).onChildAt(0)
.assertTextContains(context.getString(R.string.recommended_stories))
Expand All @@ -574,6 +559,7 @@ class ClassroomListFragmentTest {

@Test
fun testFragment_clickViewAll_opensRecentlyPlayedActivity() {
logIntoAdminTwice()
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS)
storyProgressTestHelper.markInProgressSavedFractionsStory0Exp0(
profileId = profileId,
Expand All @@ -587,7 +573,6 @@ class ClassroomListFragmentTest {
profileId = profileId,
timestampOlderThanOneWeek = false
)
logIntoAdminTwice()

composeRule.onNodeWithTag(PROMOTED_STORY_LIST_HEADER_TEST_TAG).onChildAt(1)
.assertIsDisplayed()
Expand All @@ -598,6 +583,7 @@ class ClassroomListFragmentTest {

@Test
fun testFragment_markFullProgressForFractions_playRatios_displaysRecommendedStories() {
logIntoAdminTwice()
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS)
storyProgressTestHelper.markInProgressSavedRatiosStory0Exp0(
profileId = profileId,
Expand All @@ -607,7 +593,6 @@ class ClassroomListFragmentTest {
profileId = profileId,
timestampOlderThanOneWeek = false
)
logIntoAdminTwice()

composeRule.onNodeWithTag(PROMOTED_STORY_LIST_HEADER_TEST_TAG).onChildAt(0)
.assertTextContains(context.getString(R.string.stories_for_you))
Expand Down Expand Up @@ -662,12 +647,12 @@ class ClassroomListFragmentTest {

@Test
fun testFragment_markFullProgressForSecondTestTopic_displaysComingSoonTopicsText() {
logIntoAdminTwice()
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS)
storyProgressTestHelper.markCompletedTestTopic1(
profileId = profileId,
timestampOlderThanOneWeek = false
)
logIntoAdminTwice()

composeRule.onNodeWithTag(COMING_SOON_TOPIC_LIST_HEADER_TEST_TAG)
.assertTextContains(context.getString(R.string.coming_soon))
Expand Down Expand Up @@ -714,12 +699,12 @@ class ClassroomListFragmentTest {

@Test
fun testFragment_clickPromotedStory_opensTopicActivity() {
logIntoAdminTwice()
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS)
storyProgressTestHelper.markInProgressSavedFractionsStory0Exp0(
profileId = profileId,
timestampOlderThanOneWeek = false
)
logIntoAdminTwice()

composeRule.onNodeWithTag(PROMOTED_STORY_LIST_TEST_TAG).onChildAt(0)
.assertIsDisplayed()
Expand Down Expand Up @@ -866,11 +851,15 @@ class ClassroomListFragmentTest {
.assertIsDisplayed()
}

private fun logIntoAdminTwice() {
dataProviderTestMonitor.waitForNextSuccessfulResult(profileTestHelper.logIntoAdmin())
private fun logIntoAdmin() {
dataProviderTestMonitor.waitForNextSuccessfulResult(profileTestHelper.logIntoAdmin())
}

private fun logIntoAdminTwice() {
logIntoAdmin()
logIntoAdmin()
}

private fun setUpTestApplicationComponent() {
ApplicationProvider.getApplicationContext<TestApplication>().inject(this)
}
Expand Down

0 comments on commit 1c3c22c

Please sign in to comment.