-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* All xml files for topic-train except layout folder * Skill item related files * TopicTrainFragment implementation * Topic Train Test Case * Domain layer code integration * Start button activated * Start button activated * Separate ViewModel for item * Managing configuration changes * Checkbox state save * Nit changes * Fixing HomeActivityController * Managing configuration change in checkboxes * Proper route to QuestionPlayer * QuestionPlayerActivity test case * Nit changes * More test cases * Nit changes * EOF added * Test nit changes * Test case updated * Updated RecyclerViewMatcher * Nit change * Test added * Nit changes * Nit changes * Test cases * Test case updated
- Loading branch information
Showing
6 changed files
with
272 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
app/src/sharedTest/java/org/oppia/app/recyclerview/RecyclerViewMatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.oppia.app.recyclerview | ||
|
||
import android.content.res.Resources | ||
import android.view.View | ||
import androidx.recyclerview.widget.RecyclerView | ||
import org.hamcrest.Description | ||
import org.hamcrest.Matcher | ||
import org.hamcrest.TypeSafeMatcher | ||
|
||
// Reference Link: https://github.com/dannyroa/espresso-samples/blob/master/RecyclerView/app/src/androidTest/java/com/dannyroa/espresso_samples/recyclerview/RecyclerViewMatcher.java | ||
class RecyclerViewMatcher { | ||
companion object { | ||
/** | ||
* This function returns a Matcher for an item inside RecyclerView from a specified position. | ||
*/ | ||
fun atPosition(recyclerViewId: Int, position: Int): Matcher<View> { | ||
return atPositionOnView(recyclerViewId, position, -1) | ||
} | ||
|
||
/** | ||
* This function returns a Matcher for a specific view within the item inside RecyclerView from a specified position. | ||
*/ | ||
fun atPositionOnView(recyclerViewId: Int, position: Int, targetViewId: Int): Matcher<View> { | ||
return object : TypeSafeMatcher<View>() { | ||
var resources: Resources? = null | ||
var childView: View? = null | ||
|
||
override fun describeTo(description: Description) { | ||
var idDescription = Integer.toString(recyclerViewId) | ||
if (this.resources != null) { | ||
idDescription = try { | ||
this.resources!!.getResourceName(recyclerViewId) | ||
} catch (var4: Resources.NotFoundException) { | ||
String.format( | ||
"%s (resource name not found)", | ||
recyclerViewId | ||
) | ||
} | ||
} | ||
description.appendText("with id: $idDescription") | ||
} | ||
|
||
public override fun matchesSafely(view: View): Boolean { | ||
this.resources = view.resources | ||
if (childView == null) { | ||
val recyclerView = view.rootView.findViewById<View>(recyclerViewId) as RecyclerView | ||
if (recyclerView.id == recyclerViewId) { | ||
childView = recyclerView.findViewHolderForAdapterPosition(position)!!.itemView | ||
} else { | ||
return false | ||
} | ||
} | ||
return if (targetViewId == -1) { | ||
view === childView | ||
} else { | ||
val targetView = childView!!.findViewById<View>(targetViewId) | ||
view === targetView | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/src/sharedTest/java/org/oppia/app/topic/questionplayer/QuestionPlayerActivityTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.oppia.app.topic.questionplayer | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import androidx.test.core.app.ActivityScenario | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import androidx.test.espresso.matcher.ViewMatchers.withText | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import dagger.BindsInstance | ||
import dagger.Component | ||
import dagger.Module | ||
import dagger.Provides | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.oppia.app.R | ||
import org.oppia.util.threading.BackgroundDispatcher | ||
import org.oppia.util.threading.BlockingDispatcher | ||
import javax.inject.Singleton | ||
|
||
/** Tests for [QuestionPlayerActivity]. */ | ||
@RunWith(AndroidJUnit4::class) | ||
class QuestionPlayerActivityTest { | ||
|
||
@Test | ||
fun testQuestionPlayerActivity_loadQuestionPlayerFragment_hasDummyString() { | ||
ActivityScenario.launch(QuestionPlayerActivity::class.java).use { | ||
onView(withId(R.id.dummy_text_view)).check(matches(withText("This is dummy TextView for testing"))) | ||
} | ||
} | ||
|
||
@Module | ||
class TestModule { | ||
@Provides | ||
@Singleton | ||
fun provideContext(application: Application): Context { | ||
return application | ||
} | ||
|
||
// TODO(#89): Introduce a proper IdlingResource for background dispatchers to ensure they all complete before | ||
// proceeding in an Espresso test. This solution should also be interoperative with Robolectric contexts by using a | ||
// test coroutine dispatcher. | ||
|
||
@Singleton | ||
@Provides | ||
@BackgroundDispatcher | ||
fun provideBackgroundDispatcher(@BlockingDispatcher blockingDispatcher: CoroutineDispatcher): CoroutineDispatcher { | ||
return blockingDispatcher | ||
} | ||
} | ||
|
||
@Singleton | ||
@Component(modules = [TestModule::class]) | ||
interface TestApplicationComponent { | ||
@Component.Builder | ||
interface Builder { | ||
@BindsInstance | ||
fun setApplication(application: Application): Builder | ||
|
||
fun build(): TestApplicationComponent | ||
} | ||
} | ||
} |
Oops, something went wrong.