26
26
import static androidx .test .espresso .matcher .ViewMatchers .*;
27
27
import static org .hamcrest .Matchers .*;
28
28
29
+ import androidx .test .espresso .Espresso ;
30
+
29
31
/**
30
32
* Android tests for the multi-agent SettingsActivity.
31
33
* Tests agent list UI, CRUD operations, and dialog functionality.
@@ -304,6 +306,10 @@ public void testAgentWithSystemPromptAndDescription() {
304
306
public void testDialogCancellation () {
305
307
scenario = ActivityScenario .launch (SettingsActivity .class );
306
308
309
+ // Verify initial empty state
310
+ onView (withId (R .id .layoutEmptyState ))
311
+ .check (matches (isDisplayed ()));
312
+
307
313
// Open add agent dialog
308
314
onView (withId (R .id .fabAddAgent ))
309
315
.perform (click ());
@@ -312,11 +318,29 @@ public void testDialogCancellation() {
312
318
onView (withId (R .id .editAgentName ))
313
319
.perform (typeText ("Test Agent" ));
314
320
321
+ // Close soft keyboard before clicking Cancel
322
+ Espresso .closeSoftKeyboard ();
323
+
315
324
// Cancel dialog
316
325
onView (withText ("Cancel" ))
317
326
.perform (click ());
318
327
319
- // Should remain in empty state (no agents added)
328
+ // Wait for any UI transitions to complete
329
+ try {
330
+ Thread .sleep (100 );
331
+ } catch (InterruptedException e ) {
332
+ Thread .currentThread ().interrupt ();
333
+ }
334
+
335
+ // Verify no agents were actually added to the repository
336
+ scenario .onActivity (activity -> {
337
+ MultiAgentRepository repo = MultiAgentRepository .getInstance (activity );
338
+ java .util .List <AgentProfile > currentAgents = repo .getAgents ().getValue ();
339
+ android .util .Log .d ("SettingsActivityTest" , "Agents count after cancel: " +
340
+ (currentAgents != null ? currentAgents .size () : "null" ));
341
+ });
342
+
343
+ // The main assertion: empty state should still be displayed
320
344
onView (withId (R .id .layoutEmptyState ))
321
345
.check (matches (isDisplayed ()));
322
346
}
0 commit comments