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 #387, #1771: Show concept cards #1637

Merged
merged 63 commits into from
Sep 3, 2020
Merged

Conversation

BenHenning
Copy link
Member

@BenHenning BenHenning commented Aug 13, 2020

Fixes #387.
Fixes #1771.

Add support for showing concept cards via custom tags at certain points in a lesson. This introduces a new mechanism for handling custom tags. It's been integrated for both concept cards & our list tags; other tags aren't yet integrated (specifically image which is specially handled by Android's HTML parser, anyway). We will hopefully be able to leverage this to simplify #1328, as well.

This is a continuation of #422 and #731 that's been brought up-to-date with develop.

This doesn't add support for concept cards in questions. #1771 is tracking that.

Testing instructions for explorations:

  • Go to Meaning of Equal parts Exploration
  • State 1-> Option D
  • State 2-> 3/2 answer
  • You will notice concept-card link there.

Testing instructions for questions:

  • Go to Fractions topic
  • Practice tab
  • Select Mixed Numbers subtopic
  • Start session
  • Once you see the question "Amir says the shaded black part of the picture below represents the fraction 1/3" and select the fourth option: "No. Amir has mixed up the numerator and denominator...."
  • The concept card link should show up here

BenHenning and others added 25 commits November 19, 2019 15:46
card as one of the remediation pathways for 'the meaning of equal parts'
lesson.
This piggybacks off of the solution introduced in #1276 for Robolectric.
That PR allows Robolectric tests in app module to share dependencies
with production components by creating a test application & telling
Robolectric to use it instead of OppiaApplication via a @config
annotation.

This PR achieves the same thing by using a custom test runner that reads
the same annotation and forces Espresso & instrumentation to use the
test application instead of the default OppiaApplication. This setup
will be easier once #59 is finished since we can specify the application
in per-test manifests that both Robolectric & Espresso will respect.

Note that while this lets the same test coroutine dispatchers work in
both production & test code for Espresso, some additional work was
needed to ensure the coroutines behave correctly. In particular, the
coroutines use a fake system clock in Robolectric that requires explicit
synchronization points in the tests to allow the clock to move forward
& properly coordinate execution between background & main thread
operations. However, in Espresso, since everything is using a real clock
an idling resource is the preferred way to synchronize execution: it
allows the background coroutines to operate in real-time much like they
would in production, and then notify Espresso when completed. The test
dispatchers API is now setup to support both synchronization mechanisms
for both Robolectric & Espresso (the idling resource does nothing on
Robolectric and the force synchronization effectively does nothing on
Espresso).

The first test being demonstrated as now stable is SplashActivityTest
(as part of downstream work in #1397.
Espresso.

Note that some issues were found during this: #1612 (#1611 was found a
few weeks ago, but it also affects these tests). To ensure the tests can
still be run, a @runon annotation was added to allow tests to target
specific test platforms. The tests that currently fail on Robolectric
due to #1611 and #1612 are disabled for that platform. The test suite as
a whole has been verified to pass in its current state on both
Robolectric and Espresso (on a Pixel XL).

The aim of this PR is to actually enable critical state fragment tests
in CI, so both StateFragmentTest and StateFragmentLocalTest are being
enabled in GitHub actions.
…abilize-state-fragment-test

Conflicts:
	app/src/sharedTest/java/org/oppia/app/player/state/StateFragmentTest.kt
Conflicts:
	app/src/sharedTest/java/org/oppia/app/player/state/StateFragmentTest.kt
Conflicts:
	app/src/main/java/org/oppia/app/player/exploration/ExplorationActivity.kt
	app/src/main/java/org/oppia/app/player/exploration/ExplorationFragment.kt
	app/src/main/java/org/oppia/app/player/exploration/ExplorationFragmentPresenter.kt
	app/src/main/java/org/oppia/app/player/state/StateFragment.kt
	app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.kt
	app/src/main/java/org/oppia/app/testing/TopicTestActivity.kt
	app/src/main/java/org/oppia/app/testing/TopicTestActivityForStory.kt
	app/src/main/java/org/oppia/app/topic/TopicActivity.kt
	domain/src/main/assets/fractions_exploration1.json
	utility/src/main/java/org/oppia/util/parser/HtmlParser.kt
@BenHenning BenHenning changed the title Fix #387: Show concept cards Fix #387: Show concept cards [DO NOT MERGE] Aug 13, 2020
@BenHenning BenHenning marked this pull request as draft August 13, 2020 03:18
Oppia's test dispatchers. Note that this does not actually introduce the
service--that will happen in a new branch.
coroutines, plus a test to verify that it fundamentally follows one
interpretation of ExecutorService's API.
@BenHenning BenHenning changed the title Fix #387: Show concept cards [Blocked: #1630] Fix #387, #1771: Show concept cards [Blocked: #1630] Sep 3, 2020
@BenHenning BenHenning linked an issue Sep 3, 2020 that may be closed by this pull request
@BenHenning
Copy link
Member Author

BenHenning commented Sep 3, 2020

A lot has changed:

  1. Questions are now supported (with tests)
  2. Fixed the crash @anandwana001 was hitting, but there's now a potential flake in that same question. The answer image doesn't consistently load for me. @anandwana001 / @rt4914 can you verify if this is happening to you, too?
  3. Added tests for the custom handler
  4. A bunch of other miscellaneous fixes that were needed along the way

This should be ready for submission if the flake is localized to me or not caused by this PR.

PTAL.

@rt4914
Copy link
Contributor

rt4914 commented Sep 3, 2020

@BenHenning @anandwana001
I haven't checked the entire code in detail. But I have done following things:

  1. Checked that concept card is working in exploration and question player.
  2. The image related issues are coming from develop and not from this PR. The issue is main observed we take actions in app very quickly.
  3. The screenshots below are from develop.
    Screenshot_1599107062
    Screenshot_1599107094

Base automatically changed from stabilize-state-fragment-test to develop September 3, 2020 05:44
@BenHenning
Copy link
Member Author

Thanks @rt4914! I filed #1781 to track. In that case, this PR is unblocked from being able to be submitted.

@BenHenning BenHenning changed the title Fix #387, #1771: Show concept cards [Blocked: #1630] Fix #387, #1771: Show concept cards Sep 3, 2020
@BenHenning BenHenning removed their assignment Sep 3, 2020
Copy link
Contributor

@anandwana001 anandwana001 left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks @BenHenning
Below are the test results
Screenshot 2020-09-03 at 11 40 50

Screenshot 2020-09-03 at 11 43 13

Screenshot 2020-09-03 at 11 45 08

Espresso - QuestionPlayerActivityTest
Screenshot 2020-09-03 at 11 46 20

androidx.test.espresso.PerformException: Error performing 'single click' on view 'with id: org.oppia.app:id/selection_interaction_recyclerview'.
at androidx.test.espresso.PerformException$Builder.build(PerformException.java:86)
at androidx.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:87)
at androidx.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:59)
at androidx.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:322)
at androidx.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:178)
at androidx.test.espresso.ViewInteraction.perform(ViewInteraction.java:119)
at org.oppia.app.topic.questionplayer.QuestionPlayerActivityTest.clickSelection(QuestionPlayerActivityTest.kt:244)
at org.oppia.app.topic.questionplayer.QuestionPlayerActivityTest.selectMultipleChoiceOption(QuestionPlayerActivityTest.kt:232)

Both these test result says failure due to click issue pointing at

 @Suppress("SameParameterValue")
  private fun clickSelection(optionPosition: Int, targetViewId: Int) {
    scrollToViewType(SELECTION_INTERACTION)
    onView(
      atPositionOnView(
        recyclerViewId = R.id.selection_interaction_recyclerview,
        position = optionPosition,
        targetViewId = targetViewId
      )
    ).perform(click())
    testCoroutineDispatchers.runCurrent()
  }

@anandwana001 anandwana001 removed their assignment Sep 3, 2020
@BenHenning
Copy link
Member Author

@anandwana001 all of the tests are passing on my Pixel XL locally with Espresso. Can you provide the errors & stack traces you're seeing?

Also, can you close the old comment threads in this PR if they're resolved?

@anandwana001
Copy link
Contributor

@anandwana001 all of the tests are passing on my Pixel XL locally with Espresso. Can you provide the errors & stack traces you're seeing?

Also, can you close the old comment threads in this PR if they're resolved?

Resolved previous comments.
Regarding the test, might some AS issue I have that's I they are failing. I will try running these test cases again by clean and rebuild.

@anandwana001
Copy link
Contributor

anandwana001 commented Sep 3, 2020

@anandwana001 all of the tests are passing on my Pixel XL locally with Espresso. Can you provide the errors & stack traces you're seeing?
Also, can you close the old comment threads in this PR if they're resolved?

Resolved previous comments.
Regarding the test, might some AS issue I have that's I they are failing. I will try running these test cases again by clean and rebuild.

Tried again and these two test cases failed again with the same stack trace on Nexus 4 API 28
https://gist.github.com/anandwana001/1cd52e6f38b8e2830973f66bd4f3a7e3

Passes on Pixel XL
Screenshot 2020-09-03 at 12 17 18

@BenHenning
Copy link
Member Author

Per discussion over chat with Akshay, it appears this is tied to testing on a small device. Akshay reported it passing on a Pixel XL. We should shore up the tests for smaller screens, but that should be done as part of a broader initiative.

@BenHenning
Copy link
Member Author

Thanks all for the reviews!

@BenHenning BenHenning merged commit 56e91e4 into develop Sep 3, 2020
@BenHenning BenHenning deleted the show-concept-card-links branch September 3, 2020 07:05
prayutsu pushed a commit to prayutsu/oppia-android that referenced this pull request Sep 3, 2020
* Add support for showing concept cards in feedback, and add a concept
card as one of the remediation pathways for 'the meaning of equal parts'
lesson.

* Introduce test coroutine dispatchers support in Espresso.

This piggybacks off of the solution introduced in oppia#1276 for Robolectric.
That PR allows Robolectric tests in app module to share dependencies
with production components by creating a test application & telling
Robolectric to use it instead of OppiaApplication via a @config
annotation.

This PR achieves the same thing by using a custom test runner that reads
the same annotation and forces Espresso & instrumentation to use the
test application instead of the default OppiaApplication. This setup
will be easier once oppia#59 is finished since we can specify the application
in per-test manifests that both Robolectric & Espresso will respect.

Note that while this lets the same test coroutine dispatchers work in
both production & test code for Espresso, some additional work was
needed to ensure the coroutines behave correctly. In particular, the
coroutines use a fake system clock in Robolectric that requires explicit
synchronization points in the tests to allow the clock to move forward
& properly coordinate execution between background & main thread
operations. However, in Espresso, since everything is using a real clock
an idling resource is the preferred way to synchronize execution: it
allows the background coroutines to operate in real-time much like they
would in production, and then notify Espresso when completed. The test
dispatchers API is now setup to support both synchronization mechanisms
for both Robolectric & Espresso (the idling resource does nothing on
Robolectric and the force synchronization effectively does nothing on
Espresso).

The first test being demonstrated as now stable is SplashActivityTest
(as part of downstream work in oppia#1397.

* Revert "Fixes oppia#941: Add radar effect in Hints and solution (oppia#1475)"

This reverts commit 41eb10b.

* Stabilize StateFragmentTest such that it passes on both Robolectric and
Espresso.

Note that some issues were found during this: oppia#1612 (oppia#1611 was found a
few weeks ago, but it also affects these tests). To ensure the tests can
still be run, a @runon annotation was added to allow tests to target
specific test platforms. The tests that currently fail on Robolectric
due to oppia#1611 and oppia#1612 are disabled for that platform. The test suite as
a whole has been verified to pass in its current state on both
Robolectric and Espresso (on a Pixel XL).

The aim of this PR is to actually enable critical state fragment tests
in CI, so both StateFragmentTest and StateFragmentLocalTest are being
enabled in GitHub actions.

* Enable StateFragmentTest (Robolectric) & StateFragmentLocalTest for CI.

* Add thorough documentation for new dispatchers.

* Clean up comments & add additional documentation.

* Fix lint errors.

* Fix broken test after changes to FakeSystemClock.

* Fix linter errors.

* Update test lesson to include references to concept cards.

* Lint fixes & use HtmlCompat instead of Html.

* Add support for the newer & finalized tag format.

* Lint fixes.

* Use a custom executor service for Glide requests that coordinates with
Oppia's test dispatchers. Note that this does not actually introduce the
service--that will happen in a new branch.

* Introduce new executor service which allows interop with Kotlin
coroutines, plus a test to verify that it fundamentally follows one
interpretation of ExecutorService's API.

* Fix flaky timeout tests by improving cancellation cooperation for
invokeAny() and provide longer timeouts for tests that are
CPU-sensitive.

* Add documentation & clean up unused code.

* Lint fixes.

* Significantly reorganize invokeAll() to try and make it more cooperative
for cancellation, and increase timeout times in tests to reduce
flakiness for time-sensitive tests. Some tests are remaining flaky, so
ignoring those.

Re-add maybeWithTimeoutOrNull since it actually was needed.

* Lint fixes.

* Post-merge module fixes.

* Post-merge fixes with ratio input & add a TODO to improve speed of the
new coroutine executor service.

* Revert "Fixes part of oppia#40 & oppia#42: Generalisation Highfi Mobile Portrait + Landscape - Buttons (oppia#1653)"

This reverts commit 1bb1ffa.

* Ensure terminated tasks do not interfere with one another (timeouts
should happen individually for each task during termination). This fixes
a failure observed in StateFragmentLocalTest in oppia#1630.

* Ignore failing tests until oppia#1769 is resolved.

* Fix awaitTermination & improve test. Improve stack trace for test
dispatcher timeouts.

* Fix slow & broken tests in Robolectric for StateFragmentLocalTest.

* Add missing deps for StateFragmentLocalTest.

* Address TODOs (including adding support for list tags which replaces the
old handler & adds nested custom tag support), and add tests.

* Lint fixes.

* Address reviewer comments.

* Address review comments. Fix new concept card tests on Espresso & add
landscape versions (required configuring hints to show quickly to avoid
delaying the test, and fixing a bug in the espresso test dispatcher).
Add support for disabling concept cards of they aren't enabled for
parsing particular HTML (the default behavior is to ignore the custom
tag).

* Add support for concept cards in questions. Note that it's not clear how
to test verifying that pressing the exit button closes the concept card
since the exit button is part of the dialog's toolbar.

* Fix image-breaking duplicated code in HtmlParser, fix a paragraph
parsing issue in BulletTagHandler, and add tests for
CustomHtmlContentHandler.

* Lint fixes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for concept cards in questions Support showing concept cards in the exploration player
3 participants