Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tobioyelekan committed Dec 15, 2024
1 parent c2a193a commit a4f2d6c
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class TopicActivityTest {
@Inject
lateinit var spotlightStateController: SpotlightStateController

private val internalProfileId = 1
private val profileId = ProfileId.newBuilder().setInternalId(1).build()

@Before
fun setUp() {
Expand All @@ -154,12 +154,13 @@ class TopicActivityTest {

@Test
fun testActivity_createIntent_verifyScreenNameInIntent() {
val profileId = ProfileId.newBuilder().setInternalId(1).build()
val currentScreenNameWithIntentOne = TopicActivity.createTopicActivityIntent(
context, 1, TEST_CLASSROOM_ID_1, FRACTIONS_TOPIC_ID
context, profileId, TEST_CLASSROOM_ID_1, FRACTIONS_TOPIC_ID
).extractCurrentAppScreenName()

val currentScreenNameWithIntentTwo = TopicActivity.createTopicPlayStoryActivityIntent(
context, 1, TEST_CLASSROOM_ID_1, FRACTIONS_TOPIC_ID, FRACTIONS_STORY_ID_0
context, profileId, TEST_CLASSROOM_ID_1, FRACTIONS_TOPIC_ID, FRACTIONS_STORY_ID_0
).extractCurrentAppScreenName()

assertThat(currentScreenNameWithIntentOne).isEqualTo(ScreenName.TOPIC_ACTIVITY)
Expand All @@ -170,7 +171,7 @@ class TopicActivityTest {
fun testTopicActivity_hasCorrectActivityLabel() {
TestPlatformParameterModule.forceEnableExtraTopicTabsUi(true)
launchTopicActivity(
internalProfileId, TEST_CLASSROOM_ID_1, FRACTIONS_TOPIC_ID
profileId, TEST_CLASSROOM_ID_1, FRACTIONS_TOPIC_ID
).use { scenario ->
lateinit var title: CharSequence
scenario.onActivity { activity -> title = activity.title }
Expand All @@ -185,7 +186,7 @@ class TopicActivityTest {
@RunOn(TestPlatform.ROBOLECTRIC) // TODO(#3858): Enable for Espresso.
fun testTopicActivity_startPracticeSession_questionActivityStartedWithProfileId() {
TestPlatformParameterModule.forceEnableExtraTopicTabsUi(true)
launchTopicActivity(internalProfileId, TEST_CLASSROOM_ID_1, FRACTIONS_TOPIC_ID).use {
launchTopicActivity(profileId, TEST_CLASSROOM_ID_1, FRACTIONS_TOPIC_ID).use {
// Open the practice tab and select a skill.
onView(withText("Practice")).perform(click())
testCoroutineDispatchers.runCurrent()
Expand All @@ -200,27 +201,25 @@ class TopicActivityTest {
testCoroutineDispatchers.runCurrent()

// Verify that the question activity is started with the correct profile ID.
val profileId = ProfileId.newBuilder().apply { internalId = internalProfileId }.build()
intended(hasComponent(QuestionPlayerActivity::class.java.name))
intended(hasProtoExtra(PROFILE_ID_INTENT_DECORATOR, profileId))
}
}

private fun launchTopicActivity(
internalProfileId: Int,
profileId: ProfileId,
classroomId: String,
topicId: String
): ActivityScenario<TopicActivity> {
val scenario = ActivityScenario.launch<TopicActivity>(
TopicActivity.createTopicActivityIntent(context, internalProfileId, classroomId, topicId)
TopicActivity.createTopicActivityIntent(context, profileId, classroomId, topicId)
)
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.topic_name_text_view)).check(matches(isDisplayed()))
return scenario
}

private fun markAllSpotlightsSeen() {
val profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
spotlightStateController.markSpotlightViewed(profileId, TOPIC_LESSON_TAB)
testCoroutineDispatchers.runCurrent()
spotlightStateController.markSpotlightViewed(profileId, TOPIC_REVISION_TAB)
Expand Down
Loading

0 comments on commit a4f2d6c

Please sign in to comment.