Skip to content

Commit

Permalink
Add UI tests for coming soon topic list
Browse files Browse the repository at this point in the history
  • Loading branch information
theMr17 committed Jul 11, 2024
1 parent 611dff2 commit e3727f6
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource
Expand All @@ -35,6 +36,12 @@ import org.oppia.android.app.home.promotedlist.ComingSoonTopicListViewModel
import org.oppia.android.app.home.promotedlist.ComingSoonTopicsViewModel
import org.oppia.android.util.locale.OppiaLocale

/** Test tag for the header of the promoted story list. */
const val COMING_SOON_TOPIC_LIST_HEADER_TEST_TAG = "TEST_TAG.coming_soon_topic_list_header"

/** Test tag for the promoted story list. */
const val COMING_SOON_TOPIC_LIST_TEST_TAG = "TEST_TAG.coming_soon_topic_list"

/** Displays a list of coming soon topics. */
@Composable
fun ComingSoonTopicList(
Expand All @@ -47,17 +54,20 @@ fun ComingSoonTopicList(
fontFamily = FontFamily.SansSerif,
fontWeight = FontWeight.Medium,
fontSize = dimensionResource(id = R.dimen.coming_soon_topic_list_header_text_size).value.sp,
modifier = Modifier.padding(
start = dimensionResource(id = R.dimen.coming_soon_topic_list_layout_margin_start),
top = dimensionResource(id = R.dimen.coming_soon_topic_list_layout_margin_top),
end = dimensionResource(id = R.dimen.coming_soon_topic_list_layout_margin_end),
),
modifier = Modifier
.padding(
start = dimensionResource(id = R.dimen.coming_soon_topic_list_layout_margin_start),
top = dimensionResource(id = R.dimen.coming_soon_topic_list_layout_margin_top),
end = dimensionResource(id = R.dimen.coming_soon_topic_list_layout_margin_end),
)
.testTag(COMING_SOON_TOPIC_LIST_HEADER_TEST_TAG),
)
LazyRow(
modifier = Modifier
.padding(
top = dimensionResource(id = R.dimen.coming_soon_topic_list_padding)
),
)
.testTag(COMING_SOON_TOPIC_LIST_TEST_TAG),
contentPadding = PaddingValues(
start = dimensionResource(id = R.dimen.coming_soon_topic_list_layout_margin_start),
end = dimensionResource(id = R.dimen.home_padding_end),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import org.oppia.android.app.application.ApplicationStartupListenerModule
import org.oppia.android.app.application.testing.TestingBuildFlavorModule
import org.oppia.android.app.classroom.classroomlist.CLASSROOM_HEADER_TEST_TAG
import org.oppia.android.app.classroom.classroomlist.CLASSROOM_LIST_TEST_TAG
import org.oppia.android.app.classroom.promotedlist.COMING_SOON_TOPIC_LIST_HEADER_TEST_TAG
import org.oppia.android.app.classroom.promotedlist.COMING_SOON_TOPIC_LIST_TEST_TAG
import org.oppia.android.app.classroom.promotedlist.PROMOTED_STORY_LIST_HEADER_TEST_TAG
import org.oppia.android.app.classroom.promotedlist.PROMOTED_STORY_LIST_TEST_TAG
import org.oppia.android.app.classroom.topiclist.ALL_TOPICS_HEADER_TEST_TAG
Expand Down Expand Up @@ -624,6 +626,90 @@ class ClassroomListFragmentTest {
}
}

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

composeRule.onNodeWithTag(COMING_SOON_TOPIC_LIST_HEADER_TEST_TAG)
.assertTextContains(context.getString(R.string.coming_soon))
.assertIsDisplayed()

composeRule.onNodeWithTag(COMING_SOON_TOPIC_LIST_TEST_TAG)
.onChildAt(0)
.onChildAt(1)
.assertTextContains("Third Test Topic")
.assertIsDisplayed()
}

@Test
fun testFragment_markFullProgressForSecondTestTopic_displaysComingSoonTopicsText() {
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))
.assertIsDisplayed()

composeRule.onNodeWithTag(COMING_SOON_TOPIC_LIST_TEST_TAG)
.onChildAt(0)
.onChildAt(1)
.assertTextContains("Third Test Topic")
.assertIsDisplayed()
}

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

composeRule.onNodeWithTag(COMING_SOON_TOPIC_LIST_HEADER_TEST_TAG)
.assertTextContains(context.getString(R.string.coming_soon))
.assertIsDisplayed()

composeRule.onNodeWithTag(COMING_SOON_TOPIC_LIST_TEST_TAG)
.onChildAt(0)
.onChildAt(1)
.assertTextContains("Third Test Topic")
.assertIsDisplayed()
}

@Test
fun testFragment_clickPromotedStory_opensTopicActivity() {
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS)
Expand Down

0 comments on commit e3727f6

Please sign in to comment.