[BUG]: Fix Robolectric append/replaceText handling in EditTextInputAction and add corresponding tests.
Describe the bug
This issue tracks the bug fix and upcoming tests related to EditTextInputAction used in test infrastructure for EditText input.
1. The Issue
-
[x] There was a bug in the
EditTextInputActionclass where appending or replacing text didn’t behave correctly in Robolectric environments. Specifically: (addressed in PR #5617 ) -
appendTextdoes not work correctly as it replaces the text rather than appending it. -
Both actions incorrectly called
EditText.setText(text), meaning that even whenappendText()was used, it replaced the entire content instead of appending to it. -
This issue was masked by passing transitive test cases, but broke the intended behavior of append vs. replace differentiation.
-
The logic for handling
appendText()andreplaceText()needed to differentiate between Robolectric and Espresso environments.
2. Adding Corresponding Tests
- [ ] Tests still need to be added to ensure the behavior of
EditTextInputActionremains correct across test environments.
To achieve this, we should:
- Add a dedicated test class (similar to the one for TextInputAction)
- Write Robolectric-based tests verifying
appendText()andreplaceText()apply the correct text values - Validate that the logic paths in the updated
updateText()method execute correctly for bothisAppend=trueandisAppend=false
Steps To Reproduce
- Write a Robolectric test using
EditTextInputAction.appendText()to input text into anEditText. - Set initial text in the
EditText(e.g., "123"). - Use
appendText("45")and expect the final text to be "12345". - Run the test in Robolectric.
- Observe that the text becomes "45" instead of "12345", indicating that
appendText()is replacing rather than appending the text.
Concered file: testing/src/main/java/org/oppia/android/testing/espresso/EditTextInputAction.kt
Expected Behavior
When using EditTextInputAction.appendText() in Robolectric-based tests, the provided text should be appended to the existing contents of the EditText, preserving the original text.
Similarly, when using replaceText(), the original text in the EditText should be completely replaced with the new input.
These behaviors should match how Espresso handles typeText() and replaceText() on physical/emulated devices.
Screenshots/Videos
No response
What device/emulator are you using?
No response
Which Android version is your device/emulator running?
No response
Which version of the Oppia Android app are you using?
No response
Additional Context
No response
Hello @adhiamboperes :) I would like to work on this issue.
Hi @shrimpnaur , feel free to make a pr.