oppia-android icon indicating copy to clipboard operation
oppia-android copied to clipboard

[BUG]: Fix Robolectric append/replaceText handling in EditTextInputAction and add corresponding tests.

Open theayushyadav11 opened this issue 7 months ago • 2 comments

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 EditTextInputAction class where appending or replacing text didn’t behave correctly in Robolectric environments. Specifically: (addressed in PR #5617 )

  • appendText does not work correctly as it replaces the text rather than appending it.

  • Both actions incorrectly called EditText.setText(text), meaning that even when appendText() 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() and replaceText() needed to differentiate between Robolectric and Espresso environments.


2. Adding Corresponding Tests

  • [ ] Tests still need to be added to ensure the behavior of EditTextInputAction remains 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() and replaceText() apply the correct text values
  • Validate that the logic paths in the updated updateText() method execute correctly for both isAppend=true and isAppend=false

Steps To Reproduce

  1. Write a Robolectric test using EditTextInputAction.appendText() to input text into an EditText.
  2. Set initial text in the EditText (e.g., "123").
  3. Use appendText("45") and expect the final text to be "12345".
  4. Run the test in Robolectric.
  5. 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

theayushyadav11 avatar Apr 30 '25 04:04 theayushyadav11

Hello @adhiamboperes :) I would like to work on this issue.

shrimpnaur avatar Jun 01 '25 21:06 shrimpnaur

Hi @shrimpnaur , feel free to make a pr.

theayushyadav11 avatar Jun 02 '25 13:06 theayushyadav11