Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate getTopicList() to DataProvider #2253

Merged
merged 5 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Configurations for arguments that should automatically be added to Bazel commands.
build --android_databinding_use_v3_4_args \
--experimental_android_databinding_v2 \
--java_header_compilation=false \
--noincremental_dexing \
--define=android_standalone_dexing_tool=d8_compat_dx

# Show all test output by default (for better debugging).
test --test_output=all
6 changes: 3 additions & 3 deletions app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -1048,9 +1048,9 @@ app_test(

# TODO(#973): Fix app module tests for Robolectric.
app_test(
name = "NavigationDrawerTestActivityTest",
srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerTestActivityTest.kt")],
test_class = "org.oppia.android.app.testing.NavigationDrawerTestActivityTest",
name = "NavigationDrawerActivityTest",
srcs = [test_with_resources("src/sharedTest/java/org/oppia/android/app/testing/NavigationDrawerActivityTest.kt")],
test_class = "org.oppia.android.app.testing.NavigationDrawerActivityTest",
deps = TEST_DEPS,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class HomeFragmentPresenter @Inject constructor(
}

private val topicListSummaryResultLiveData: LiveData<AsyncResult<TopicList>> by lazy {
topicListController.getTopicList()
topicListController.getTopicList().toLiveData()
}

private fun subscribeToTopicList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.oppia.android.app.walkthrough.topiclist.topiclistviewmodel.Walkthroug
import org.oppia.android.app.walkthrough.topiclist.topiclistviewmodel.WalkthroughTopicSummaryViewModel
import org.oppia.android.domain.topic.TopicListController
import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import org.oppia.android.util.logging.ConsoleLogger
import javax.inject.Inject

Expand All @@ -24,7 +25,7 @@ class WalkthroughTopicViewModel @Inject constructor(
}

private val topicListSummaryResultLiveData: LiveData<AsyncResult<TopicList>> by lazy {
topicListController.getTopicList()
topicListController.getTopicList().toLiveData()
}

private val topicListSummaryLiveData: LiveData<TopicList> by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ class HomeActivityTest {
@Test
fun testHomeActivity_recyclerViewIndex1_displaysRecentlyPlayedStoriesText() {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.home_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(1)
)
Expand All @@ -260,6 +261,7 @@ class HomeActivityTest {
@Test
fun testHomeActivity_recyclerViewIndex1_displaysViewAllText() {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.home_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(1)
)
Expand All @@ -274,6 +276,7 @@ class HomeActivityTest {
@Test
fun testHomeActivity_recyclerViewIndex1_clickViewAll_opensRecentlyPlayedActivity() {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.home_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(1)
)
Expand Down Expand Up @@ -372,6 +375,7 @@ class HomeActivityTest {
@Test
fun testHomeActivity_recyclerViewIndex3_topicSummary_topicNameIsCorrect() {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.home_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(3)
)
Expand All @@ -386,6 +390,7 @@ class HomeActivityTest {
@Test
fun testHomeActivity_recyclerViewIndex3_topicSummary_lessonCountIsCorrect() {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.home_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(3)
)
Expand All @@ -405,6 +410,7 @@ class HomeActivityTest {
@Test
fun testHomeActivity_recyclerViewIndex4_topicSummary_topicNameIsCorrect() {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.home_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(4)
)
Expand All @@ -419,6 +425,7 @@ class HomeActivityTest {
@Test
fun testHomeActivity_recyclerViewIndex4_topicSummary_lessonCountIsCorrect() {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.home_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(4)
)
Expand All @@ -438,6 +445,7 @@ class HomeActivityTest {
@Test
fun testHomeActivity_recyclerViewIndex4_topicSummary_configurationChange_lessonCountIsCorrect() {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
onView(isRoot()).perform(orientationLandscape())
onView(withId(R.id.home_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(4)
Expand All @@ -458,6 +466,7 @@ class HomeActivityTest {
@Test
fun testHomeActivity_recyclerViewIndex3_clickTopicSummary_opensTopicActivity() {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.home_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(3)
)
Expand All @@ -470,6 +479,7 @@ class HomeActivityTest {
@Test
fun testHomeActivity_onBackPressed_showsExitToProfileChooserDialog() {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
pressBack()
onView(withText(R.string.home_activity_back_dialog_message))
.inRoot(isDialog())
Expand All @@ -480,6 +490,7 @@ class HomeActivityTest {
@Test
fun testHomeActivity_onBackPressed_orientationChange_showsExitToProfileChooserDialog() {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
pressBack()
onView(isRoot()).perform(orientationLandscape())
onView(withText(R.string.home_activity_back_dialog_message))
Expand All @@ -491,6 +502,7 @@ class HomeActivityTest {
@Test
fun testHomeActivity_onBackPressed_clickExit_checkOpensProfileActivity() {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
pressBack()
onView(withText(R.string.home_activity_back_dialog_exit))
.inRoot(isDialog())
Expand All @@ -502,6 +514,7 @@ class HomeActivityTest {
@Test
fun testHomeActivity_checkSpanForItem0_spanSizeIsTwoOrThree() {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
if (context.resources.getBoolean(R.bool.isTablet)) {
onView(withId(R.id.home_recycler_view)).check(hasGridItemCount(3, 0))
} else {
Expand All @@ -513,13 +526,15 @@ class HomeActivityTest {
@Test
fun testHomeActivity_checkSpanForItem4_spanSizeIsOne() {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.home_recycler_view)).check(hasGridItemCount(1, 4))
}
}

@Test
fun testHomeActivity_configurationChange_checkSpanForItem4_spanSizeIsOne() {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
onView(isRoot()).perform(orientationLandscape())
onView(withId(R.id.home_recycler_view)).check(hasGridItemCount(1, 4))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ class WalkthroughFinalFragmentTest {
@Test
fun testWalkthroughWelcomeFragment_recyclerViewIndex1_topicSelected_topicTitleIsCorrect() {
launch<WalkthroughActivity>(createWalkthroughActivityIntent(0)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.walkthrough_welcome_next_button))
.perform(scrollTo(), click())
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.walkthrough_topic_recycler_view))
.perform(scrollToPosition<RecyclerView.ViewHolder>(1))
onView(
Expand All @@ -131,8 +133,10 @@ class WalkthroughFinalFragmentTest {
@Test
fun testWalkthroughWelcomeFragment_recyclerViewIndex2_topicSelected_topicTitleIsCorrect() {
launch<WalkthroughActivity>(createWalkthroughActivityIntent(0)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.walkthrough_welcome_next_button))
.perform(scrollTo(), click())
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.walkthrough_topic_recycler_view))
.perform(scrollToPosition<RecyclerView.ViewHolder>(1))
onView(
Expand All @@ -154,8 +158,10 @@ class WalkthroughFinalFragmentTest {
@Test
fun testWalkthroughWelcomeFragment_recyclerViewIndex2_topicSelected_configurationChanged_topicTitleIsCorrect() { // ktlint-disable max-line-length
launch<WalkthroughActivity>(createWalkthroughActivityIntent(0)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.walkthrough_welcome_next_button))
.perform(scrollTo(), click())
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.walkthrough_topic_recycler_view))
.perform(scrollToPosition<RecyclerView.ViewHolder>(1))
onView(
Expand Down Expand Up @@ -184,8 +190,10 @@ class WalkthroughFinalFragmentTest {
@Test
fun testWalkthroughWelcomeFragment_recyclerViewIndex1_topicSelected_yesNoButton_isDisplayedCorrectly() { // ktlint-disable max-line-length
launch<WalkthroughActivity>(createWalkthroughActivityIntent(0)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.walkthrough_welcome_next_button))
.perform(scrollTo(), click())
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.walkthrough_topic_recycler_view))
.perform(scrollToPosition<RecyclerView.ViewHolder>(1))
onView(
Expand All @@ -205,8 +213,10 @@ class WalkthroughFinalFragmentTest {
@Test
fun testWalkthroughWelcomeFragment_recyclerViewIndex1_topicSelected_clickNoButton_worksCorrectly() { // ktlint-disable max-line-length
launch<WalkthroughActivity>(createWalkthroughActivityIntent(0)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.walkthrough_welcome_next_button))
.perform(scrollTo(), click())
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.walkthrough_topic_recycler_view))
.perform(scrollToPosition<RecyclerView.ViewHolder>(1))
onView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ class WalkthroughTopicListFragmentTest {
@Test
fun testWalkthroughWelcomeFragment_recyclerViewIndex0_topicHeader_topicHeaderIsCorrect() {
launch<WalkthroughActivity>(createWalkthroughActivityIntent(0)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.walkthrough_welcome_next_button)).perform(scrollTo(), click())
testCoroutineDispatchers.runCurrent()
onView(
atPositionOnView(
R.id.walkthrough_topic_recycler_view,
Expand All @@ -124,7 +126,9 @@ class WalkthroughTopicListFragmentTest {
@Test
fun testWalkthroughWelcomeFragment_recyclerViewIndex1_topicCard_topicNameIsCorrect() {
launch<WalkthroughActivity>(createWalkthroughActivityIntent(0)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.walkthrough_welcome_next_button)).perform(scrollTo(), click())
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.walkthrough_topic_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(
1
Expand All @@ -148,7 +152,9 @@ class WalkthroughTopicListFragmentTest {
@Test
fun testWalkthroughWelcomeFragment_recyclerViewIndex1_topicCard_configurationChanged_topicNameIsCorrect() { // ktlint-disable max-line-length
launch<WalkthroughActivity>(createWalkthroughActivityIntent(0)).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.walkthrough_welcome_next_button)).perform(scrollTo(), click())
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.walkthrough_topic_recycler_view)).perform(
scrollToPosition<RecyclerView.ViewHolder>(
1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.oppia.android.domain.topic

import android.graphics.Color
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import org.json.JSONObject
import org.oppia.android.app.model.ChapterPlayState
import org.oppia.android.app.model.ChapterProgress
Expand All @@ -19,6 +17,7 @@ import org.oppia.android.app.model.TopicSummary
import org.oppia.android.domain.util.JsonAssetRetriever
import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProvider
import org.oppia.android.util.data.DataProviders
import org.oppia.android.util.data.DataProviders.Companion.transformAsync
import java.util.Date
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -67,6 +66,7 @@ val EXPLORATION_THUMBNAILS = mapOf(
TEST_EXPLORATION_ID_6 to createChapterThumbnail0()
)

private const val GET_TOPIC_LIST_PROVIDER_ID = "get_topic_list_provider_id"
private const val GET_ONGOING_STORY_LIST_PROVIDER_ID =
"get_ongoing_story_list_provider_id"

Expand All @@ -77,14 +77,18 @@ private val EVICTION_TIME_MILLIS = TimeUnit.DAYS.toMillis(1)
class TopicListController @Inject constructor(
private val jsonAssetRetriever: JsonAssetRetriever,
private val topicController: TopicController,
private val storyProgressController: StoryProgressController
private val storyProgressController: StoryProgressController,
private val dataProviders: DataProviders
) {
/**
* Returns the list of [TopicSummary]s currently tracked by the app, possibly up to
* [EVICTION_TIME_MILLIS] old.
*/
fun getTopicList(): LiveData<AsyncResult<TopicList>> {
return MutableLiveData(AsyncResult.success(createTopicList()))
fun getTopicList(): DataProvider<TopicList> {
return dataProviders.createInMemoryDataProvider(
GET_TOPIC_LIST_PROVIDER_ID,
this::createTopicList
)
}

/**
Expand Down
Loading