Skip to content

Commit e540cfb

Browse files
Teodor Ciuraruclaude
andcommitted
refactor(android-java): simplify test - no scrolling needed for top documents
- Remove all scrolling logic since seeded documents with inverted timestamps appear at top - Direct assertion only - much simpler and faster - Remove unused RecyclerViewActions and ViewActions imports - Test completes in ~9 seconds instead of ~20+ seconds - Cleaner, more focused test that matches the actual use case 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fca01b0 commit e540cfb

1 file changed

Lines changed: 5 additions & 34 deletions

File tree

android-java/app/src/androidTest/java/com/example/dittotasks/ExampleInstrumentedTest.java

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import androidx.test.espresso.NoMatchingViewException;
55
import androidx.test.espresso.ViewAssertion;
66
import androidx.test.espresso.assertion.ViewAssertions;
7-
import androidx.test.espresso.contrib.RecyclerViewActions;
87
import androidx.test.espresso.matcher.ViewMatchers;
98
import androidx.test.core.app.ActivityScenario;
109
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -17,7 +16,6 @@
1716
import org.junit.runner.RunWith;
1817

1918
import static androidx.test.espresso.Espresso.onView;
20-
import static androidx.test.espresso.action.ViewActions.*;
2119
import static androidx.test.espresso.matcher.ViewMatchers.*;
2220
import static org.hamcrest.Matchers.allOf;
2321

@@ -74,38 +72,11 @@ private void performTestLogic(String title) throws InterruptedException {
7472
// Wait for RecyclerView to appear and be populated (with timeout)
7573
waitForRecyclerViewToLoad(7_000);
7674

77-
// Scroll to the cell containing the specific title (document should be seeded from GHA)
78-
Log.i("DittoTest", "Looking for pre-seeded task: " + title);
79-
80-
// Try to verify the document exists (handles duplicates by checking first occurrence)
81-
try {
82-
onView(allOf(withId(R.id.task_text), withText(title)))
83-
.check(ViewAssertions.matches(isDisplayed()));
84-
Log.i("DittoTest", "✅ Found pre-seeded task without scrolling: " + title);
85-
} catch (Exception e) {
86-
// If not immediately visible, try scrolling to find it
87-
Log.i("DittoTest", "Task not immediately visible, scrolling to find: " + title);
88-
try {
89-
onView(withId(R.id.task_list))
90-
.perform(RecyclerViewActions.scrollTo(
91-
hasDescendant(allOf(withId(R.id.task_text), withText(title)))
92-
));
93-
Log.i("DittoTest", "✅ Found and scrolled to pre-seeded task: " + title);
94-
95-
// Final assertion after scrolling
96-
onView(allOf(withId(R.id.task_text), withText(title)))
97-
.check(ViewAssertions.matches(isDisplayed()));
98-
} catch (RuntimeException scrollError) {
99-
if (scrollError.getMessage() != null && scrollError.getMessage().contains("Found more than one sub-view matching")) {
100-
Log.i("DittoTest", "Multiple matches found - checking first occurrence is displayed");
101-
// When there are duplicates, just verify at least one is displayed (good enough for the test)
102-
onView(allOf(withId(R.id.task_text), withText(title)))
103-
.check(ViewAssertions.matches(isDisplayed()));
104-
} else {
105-
throw scrollError; // Re-throw if it's a different error
106-
}
107-
}
108-
}
75+
// Verify the seeded document is visible at the top (no scrolling needed)
76+
Log.i("DittoTest", "Looking for pre-seeded task at top: " + title);
77+
onView(allOf(withId(R.id.task_text), withText(title)))
78+
.check(ViewAssertions.matches(isDisplayed()));
79+
Log.i("DittoTest", "✅ Found pre-seeded task at top: " + title);
10980

11081
// Keep screen visible for 3 seconds for BrowserStack video verification
11182
Thread.sleep(3000);

0 commit comments

Comments
 (0)