Skip to content

Instantly share code, notes, and snippets.

@veena14cs
Created September 23, 2022 12:31
Show Gist options
  • Save veena14cs/28ed9b2c93ee55cd66121b2b33f2390a to your computer and use it in GitHub Desktop.
Save veena14cs/28ed9b2c93ee55cd66121b2b33f2390a to your computer and use it in GitHub Desktop.
Failing to match intent
@Test
fun testPoliciesFragment_forTermsOfService_opensPrivacyPolicyPage() {
launch<PoliciesFragmentTestActivity>(
PoliciesFragmentTestActivity.createPoliciesFragmentTestActivity(
getApplicationContext(),
PolicyPage.TERMS_OF_SERVICE
)
).use { activityScenario ->
activityScenario.onActivity { activity ->
testCoroutineDispatchers.runCurrent()
val htmlParser = htmlParserFactory.create(
policyOppiaTagActionListener = mockPolicyOppiaTagActionListener,
displayLocale = appLanguageLocaleHandler.getDisplayLocale()
)
val textView: TextView =
activity.findViewById(R.id.policy_description_text_view)
val htmlResult: Spannable = htmlParser.parseOppiaHtml(
getResources().getString(R.string.terms_of_service_content),
textView,
supportsLinks = true,
supportsConceptCards = false
)
textView.text = htmlResult
// Verify the displayed text is correct & has a clickable span.
val clickableSpans = htmlResult.getSpansFromWholeString(ClickableSpan::class)
assertThat(clickableSpans).isNotEmpty()
// Call each of the spans.
clickableSpans[0].onClick(textView)
// Verify that the tag listener is called.
verify(mockPolicyOppiaTagActionListener).onPolicyPageLinkClicked(
capture(policyTypeCaptor)
)
assertThat(policyTypeCaptor.value).isEqualTo(PolicyType.PRIVACY_POLICY)
// Call each of the spans.
clickableSpans[0].onClick(textView)
val policiesArguments =
PoliciesActivityParams
.newBuilder()
.setPolicyPage(PolicyPage.PRIVACY_POLICY)
.build()
intended(hasComponent(PoliciesActivity::class.java.name))
hasExtras(
hasEntry(
equalTo(PoliciesActivity.POLICIES_ACTIVITY_POLICY_PAGE_PARAMS_PROTO),
equalTo(policiesArguments)
)
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment