Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import org.mockito.ArgumentCaptor
import org.mockito.ArgumentMatchers.anyBoolean
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.anyString
import org.mockito.ArgumentMatchers.eq
import org.mockito.Captor
import org.mockito.Mock
import org.mockito.Mockito.atLeastOnce
Expand Down Expand Up @@ -165,6 +166,7 @@ class StoryFragmentTest {
@field:[Rule JvmField] val mockitoRule: MockitoRule = MockitoJUnit.rule()

@Mock lateinit var mockRouteToExplorationListener: RouteToExplorationListener
@Mock lateinit var mockRouteToResumeLessonListener: RouteToResumeLessonListener
@Captor lateinit var listCaptor: ArgumentCaptor<List<ImageTransformation>>

@Inject lateinit var profileTestHelper: ProfileTestHelper
Expand Down Expand Up @@ -905,6 +907,95 @@ class StoryFragmentTest {
}
}

@Test // TODO(#3245): Error -> URLSpan should be used in place of ClickableSpan
@DisableAccessibilityChecks
fun testStoryFragment_notStartedChapter_clickChapter_routesToExploration() {
runWithLaunchedActivityAndAddedFragment(
internalProfileId,
TEST_CLASSROOM_ID_1,
FRACTIONS_TOPIC_ID,
FRACTIONS_STORY_ID_0
) {
onView(allOf(withId(R.id.story_chapter_list))).perform(
scrollToPosition<RecyclerView.ViewHolder>(1)
)
onView(
atPositionOnView(
recyclerViewId = R.id.story_chapter_list,
position = 1,
targetViewId = R.id.story_chapter_card
)
).perform(click())
testCoroutineDispatchers.runCurrent()

verify(mockRouteToExplorationListener)
.routeToExploration(
anyOrNull(), anyString(), anyString(), anyString(), anyString(), anyOrNull(), anyBoolean()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since a not started chapter always starts with checkpointing enabled please use eq(true) here instead of anyBoolean().

)
}
}
Comment on lines +934 to +936

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ktlint would fail here. Did you test this locally? The closing parenthesis should be indented by 8 spaces, not 6. I think this indentation issue appears in multiple plaves, so please fix all of them and push the code only once ktlint passes locally.


@Test // TODO(#3245): Error -> URLSpan should be used in place of ClickableSpan
@DisableAccessibilityChecks
fun testStoryFragment_completedChapter_clickChapter_routesToExplorationAsReplay() {
setStoryPartialProgressForFractions()
runWithLaunchedActivityAndAddedFragment(
internalProfileId,
TEST_CLASSROOM_ID_1,
FRACTIONS_TOPIC_ID,
FRACTIONS_STORY_ID_0
) {
onView(allOf(withId(R.id.story_chapter_list))).perform(
scrollToPosition<RecyclerView.ViewHolder>(1)
)
onView(
atPositionOnView(
recyclerViewId = R.id.story_chapter_list,
position = 1,
targetViewId = R.id.story_chapter_card
)
).perform(click())
testCoroutineDispatchers.runCurrent()

verify(mockRouteToExplorationListener)
.routeToExploration(
anyOrNull(), anyString(), anyString(), anyString(), anyString(), anyOrNull(), eq(false)
)
}
}

@Test // TODO(#3245): Error -> URLSpan should be used in place of ClickableSpan
@DisableAccessibilityChecks
fun testStoryFragment_inProgressSavedChapter_clickChapter_routesToResumeLesson() {
storyProgressTestHelper.markInProgressSavedFractionsStory0Exp0(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only marks the chapter as IN_PROGRESS_SAVED, but it never saves an actual checkpoint. Checkpoint retrieval then fails, so the presenter falls back to routeToExploration and the resume mock is never called. Found out this from your failing CI. Again PTAL at how RecentlyPlayedFragmentTest handles this. I think no BUILD changes are needed, and the fake clock is already set up correctly in setUp() so this should be an easy fix.

profileId,
timestampOlderThanOneWeek = false
)
runWithLaunchedActivityAndAddedFragment(
internalProfileId,
TEST_CLASSROOM_ID_1,
FRACTIONS_TOPIC_ID,
FRACTIONS_STORY_ID_0
) {
onView(allOf(withId(R.id.story_chapter_list))).perform(
scrollToPosition<RecyclerView.ViewHolder>(1)
)
onView(
atPositionOnView(
recyclerViewId = R.id.story_chapter_list,
position = 1,
targetViewId = R.id.story_chapter_card
)
).perform(click())
testCoroutineDispatchers.runCurrent()

verify(mockRouteToResumeLessonListener)
.routeToResumeLesson(
anyOrNull(), anyString(), anyString(), anyString(), anyString(), anyOrNull(), anyOrNull()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since resume routing is the new coverage this issue asked for consider capturing the arguments and asserting the checkpoint. Take a look what RecentlyPlayedFragmentTest does you will get the idea what I am talking about.

)
}
}

@Config(qualifiers = "+sw600dp")
@Test // TODO(#4212): Error -> No views in hierarchy found matching
fun testStoryFragment_completedChapter_checkProgressDrawableIsCorrect() {
Expand Down Expand Up @@ -1124,6 +1215,7 @@ class StoryFragmentTest {
ActivityScenario.launch<StoryFragmentTestActivity>(intent).use { scenario ->
scenario.onActivity { activity ->
activity.mockRouteToExplorationListener = mockRouteToExplorationListener
activity.mockRouteToResumeLessonListener = mockRouteToResumeLessonListener
activity.setContentView(R.layout.test_activity)
activity.supportFragmentManager.beginTransaction()
.add(R.id.test_fragment_placeholder, fragment)
Expand All @@ -1137,6 +1229,7 @@ class StoryFragmentTest {
class StoryFragmentTestActivity :
TestActivity(), RouteToExplorationListener, RouteToResumeLessonListener {
lateinit var mockRouteToExplorationListener: RouteToExplorationListener
lateinit var mockRouteToResumeLessonListener: RouteToResumeLessonListener

override fun routeToExploration(
profileId: LegacyProfileId,
Expand Down Expand Up @@ -1167,6 +1260,15 @@ class StoryFragmentTest {
parentScreen: ExplorationActivityParams.ParentScreen,
explorationCheckpoint: ExplorationCheckpoint
) {
mockRouteToResumeLessonListener.routeToResumeLesson(
profileId,
classroomId,
topicId,
storyId,
explorationId,
parentScreen,
explorationCheckpoint
)
}
}

Expand Down
Loading