-
Notifications
You must be signed in to change notification settings - Fork 536
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
71b2ca2
Fix #2633: Add label for FAQList screen
Sparsh1212 6cdd8de
Fix #2633: Add label for FAQList screen
Sparsh1212 b6d0133
Merge branch 'develop' into a11y-faq-list
BenHenning 4b16920
Fix #2633: Add label for FAQList screen
Sparsh1212 2878a7d
Merge branch 'a11y-faq-list' of https://github.com/Sparsh1212/oppia-a…
Sparsh1212 2485cca
Fix #2633: Add label for FAQList screen
Sparsh1212 5a82904
Merge branch 'develop' into a11y-faq-list
Sparsh1212 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
145 changes: 145 additions & 0 deletions
145
app/src/sharedTest/java/org/oppia/android/app/faq/FaqListActivityTest.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,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)) | ||
} | ||
|
||
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 | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).