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

Fix #2633: Add label for FAQList screen #2750

Merged
merged 7 commits into from
Feb 25, 2021
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
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
android:theme="@style/OppiaThemeWithoutActionBar" />
<activity
android:name=".app.help.faq.FAQListActivity"
android:theme="@style/OppiaThemeWithoutActionBar" />
android:theme="@style/OppiaThemeWithoutActionBar"
android:label="@string/faq_activity_label" />
<activity
android:name=".app.help.faq.faqsingle.FAQSingleActivity"
android:theme="@style/OppiaThemeWithoutActionBar" />
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<string name="FAQs">FAQs</string>
<string name="featured_questions">Featured Questions</string>
<string name="frequently_asked_questions">Frequently Asked Questions</string>
<string name="faq_activity_label">FAQs (Frequently Asked Questions)</string>
<string name="frequently_asked_questions_FAQ">Frequently Asked Questions (FAQs)</string>
<string name="info">Info</string>
<string name="lessons">Lessons</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package org.oppia.android.app.faq

import android.app.Application
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import com.google.common.truth.Truth.assertThat
import dagger.Component
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityComponent
import org.oppia.android.app.application.ActivityComponentFactory
import org.oppia.android.app.application.ApplicationComponent
import org.oppia.android.app.application.ApplicationInjector
import org.oppia.android.app.application.ApplicationInjectorProvider
import org.oppia.android.app.application.ApplicationModule
import org.oppia.android.app.application.ApplicationStartupListenerModule
import org.oppia.android.app.help.faq.FAQListActivity
import org.oppia.android.app.player.state.hintsandsolution.HintsAndSolutionConfigModule
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.domain.classify.InteractionsModule
import org.oppia.android.domain.classify.rules.continueinteraction.ContinueModule
import org.oppia.android.domain.classify.rules.dragAndDropSortInput.DragDropSortInputModule
import org.oppia.android.domain.classify.rules.fractioninput.FractionInputModule
import org.oppia.android.domain.classify.rules.imageClickInput.ImageClickInputModule
import org.oppia.android.domain.classify.rules.itemselectioninput.ItemSelectionInputModule
import org.oppia.android.domain.classify.rules.multiplechoiceinput.MultipleChoiceInputModule
import org.oppia.android.domain.classify.rules.numberwithunits.NumberWithUnitsRuleModule
import org.oppia.android.domain.classify.rules.numericinput.NumericInputRuleModule
import org.oppia.android.domain.classify.rules.ratioinput.RatioInputModule
import org.oppia.android.domain.classify.rules.textinput.TextInputRuleModule
import org.oppia.android.domain.onboarding.ExpirationMetaDataRetrieverModule
import org.oppia.android.domain.oppialogger.LogStorageModule
import org.oppia.android.domain.oppialogger.loguploader.LogUploadWorkerModule
import org.oppia.android.domain.oppialogger.loguploader.WorkManagerConfigurationModule
import org.oppia.android.domain.question.QuestionModule
import org.oppia.android.domain.topic.PrimeTopicAssetsControllerModule
import org.oppia.android.testing.RobolectricModule
import org.oppia.android.testing.TestAccessibilityModule
import org.oppia.android.testing.TestDispatcherModule
import org.oppia.android.testing.TestLogReportingModule
import org.oppia.android.testing.time.FakeOppiaClockModule
import org.oppia.android.util.caching.testing.CachingTestModule
import org.oppia.android.util.gcsresource.GcsResourceModule
import org.oppia.android.util.logging.LoggerModule
import org.oppia.android.util.logging.firebase.FirebaseLogUploaderModule
import org.oppia.android.util.parser.GlideImageLoaderModule
import org.oppia.android.util.parser.HtmlParserEntityTypeModule
import org.oppia.android.util.parser.ImageParsingModule
import org.robolectric.annotation.Config
import org.robolectric.annotation.LooperMode
import javax.inject.Inject
import javax.inject.Singleton

/** Tests for [FAQListActivity]. */
@RunWith(AndroidJUnit4::class)
@LooperMode(LooperMode.Mode.PAUSED)
@Config(application = FaqListActivityTest.TestApplication::class, qualifiers = "port-xxhdpi")
class FaqListActivityTest {

@get:Rule
val activityTestRule: ActivityTestRule<FAQListActivity> = ActivityTestRule(
FAQListActivity::class.java, /* initialTouchMode= */ true, /* launchActivity= */ false
)

@Inject
lateinit var context: Context

@Before
fun setUp() {
setUpTestApplicationComponent()
}

@Test
fun testFaqListActivity_hasCorrectActivityLabel() {
activityTestRule.launchActivity(createFaqListActivityIntent())
val title = activityTestRule.activity.title

// Verify that the activity label is correct as a proxy to verify TalkBack will announce the
// correct string when it's read out.
assertThat(title).isEqualTo(context.getString(R.string.faq_activity_label))
Copy link
Member

Choose a reason for hiding this comment

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

@rt4914 random thought: given we keep repeating this context in a bunch of places, could we maybe introduce an extension method to contextualize this? E.g. introducing a flow that would let us do:

assertThat(activityTestRule.activity).hasTalkBackLabel(R.string.faq_activity_label)

I was thinking at first that we could maybe do this with an extension function, but I actually think we will need to implement a custom subject (https://truth.dev/extension.html) since unfortunately AndroidX doesn't include one for Activity (https://developer.android.com/training/testing/fundamentals#assertions). This might lead to other nice wins when testing activities, and we could establish other extensions as we need them. Might be worth filing an issue to track. @anandwana001 as well since this falls under testing.

Note that I do not suggest doing any of this work in this PR--let's keep the current pattern & consider doing the above.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. @anandwana001 Can you file an issue for this?

Copy link
Contributor

Choose a reason for hiding this comment

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

@BenHenning is Custome Subject is available in Kotlin?
Reference - google/truth#536

I just had a quick look over what a custom subject is and tried this gist, could you check once if it is the correct way?
https://gist.github.com/anandwana001/9bccce1f9a0413af5f86ec12dc331d24

I will look into more on this today and see how to have a clean implementation.

Copy link
Member

Choose a reason for hiding this comment

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

Custom subjects should work fine in Kotlin. Did you observe something that suggests they won’t?

Copy link
Member

Choose a reason for hiding this comment

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

(From what I can tell the issue you linked to is for using extensions which is actually why I was thinking custom subjects originally).

}

private fun setUpTestApplicationComponent() {
ApplicationProvider.getApplicationContext<TestApplication>().inject(this)
}

private fun createFaqListActivityIntent(): Intent {
return FAQListActivity.createFAQListActivityIntent(
ApplicationProvider.getApplicationContext()
)
}

// TODO(#59): Figure out a way to reuse modules instead of needing to re-declare them.
// TODO(#1675): Add NetworkModule once data module is migrated off of Moshi.
@Singleton
@Component(
modules = [
RobolectricModule::class,
TestDispatcherModule::class, ApplicationModule::class,
LoggerModule::class, ContinueModule::class, FractionInputModule::class,
ItemSelectionInputModule::class, MultipleChoiceInputModule::class,
NumberWithUnitsRuleModule::class, NumericInputRuleModule::class, TextInputRuleModule::class,
DragDropSortInputModule::class, ImageClickInputModule::class, InteractionsModule::class,
GcsResourceModule::class, GlideImageLoaderModule::class, ImageParsingModule::class,
HtmlParserEntityTypeModule::class, QuestionModule::class, TestLogReportingModule::class,
TestAccessibilityModule::class, LogStorageModule::class, CachingTestModule::class,
PrimeTopicAssetsControllerModule::class, ExpirationMetaDataRetrieverModule::class,
ViewBindingShimModule::class, RatioInputModule::class,
ApplicationStartupListenerModule::class, LogUploadWorkerModule::class,
WorkManagerConfigurationModule::class, HintsAndSolutionConfigModule::class,
FirebaseLogUploaderModule::class, FakeOppiaClockModule::class
]
)
interface TestApplicationComponent : ApplicationComponent {
@Component.Builder
interface Builder : ApplicationComponent.Builder

fun inject(faqListActivityTest: FaqListActivityTest)
}

class TestApplication : Application(), ActivityComponentFactory, ApplicationInjectorProvider {
private val component: TestApplicationComponent by lazy {
DaggerFaqListActivityTest_TestApplicationComponent.builder()
.setApplication(this)
.build() as TestApplicationComponent
}

fun inject(faqListActivityTest: FaqListActivityTest) {
component.inject(faqListActivityTest)
}

override fun createActivityComponent(activity: AppCompatActivity): ActivityComponent {
return component.getActivityComponentBuilderProvider().get().setActivity(activity).build()
}

override fun getApplicationInjector(): ApplicationInjector = component
}
}