44import android .widget .DatePicker ;
55
66import androidx .test .core .app .ActivityScenario ;
7- import androidx .test .espresso .contrib .RecyclerViewActions ;
87
98import com .orgzly .R ;
109import com .orgzly .android .OrgzlyTest ;
3130import static androidx .test .espresso .matcher .ViewMatchers .withId ;
3231import static androidx .test .espresso .matcher .ViewMatchers .withText ;
3332import static com .orgzly .android .espresso .EspressoUtils .closeSoftKeyboardWithDelay ;
33+ import static com .orgzly .android .espresso .EspressoUtils .contextualToolbarOverflowMenu ;
3434import static com .orgzly .android .espresso .EspressoUtils .onActionItemClick ;
3535import static com .orgzly .android .espresso .EspressoUtils .onNoteInBook ;
36- import static com .orgzly .android .espresso .EspressoUtils .onNotesInBook ;
37- import static com .orgzly .android .espresso .EspressoUtils .openContextualToolbarOverflowMenu ;
3836import static com .orgzly .android .espresso .EspressoUtils .replaceTextCloseKeyboard ;
3937import static org .hamcrest .Matchers .allOf ;
4038import static org .hamcrest .Matchers .anyOf ;
@@ -101,6 +99,9 @@ public void setUp() throws Exception {
10199 "** Note #40.\n " +
102100 "" );
103101
102+ // Empty book for tests that need to scroll down to a newly created note
103+ testUtils .setupBook ("Book B" , "" );
104+
104105 scenario = ActivityScenario .launch (MainActivity .class );
105106
106107 onView (allOf (withText ("book-name" ), isDisplayed ())).perform (click ());
@@ -127,7 +128,7 @@ public void testScheduledNoteTimeStaysTheSameAfterSetting() {
127128 onNoteInBook (9 , R .id .item_head_scheduled_text ).check (matches (allOf (withText (userDateTime ("<2014-05-26 Mon>" )), isDisplayed ())));
128129
129130 onNoteInBook (9 ).perform (longClick ());
130- onView (withId (R .id .bottom_action_bar_schedule )).perform (click ());
131+ onView (withId (R .id .schedule )).perform (click ());
131132 onView (withText (R .string .set )).perform (click ());
132133
133134 onNoteInBook (9 , R .id .item_head_scheduled_text ).check (matches (allOf (withText (userDateTime ("<2014-05-26 Mon>" )), isDisplayed ())));
@@ -141,7 +142,7 @@ public void testRemovingScheduledTimeFromMultipleNotes() {
141142 onNoteInBook (8 ).perform (longClick ());
142143 onNoteInBook (9 ).perform (click ());
143144
144- onView (withId (R .id .bottom_action_bar_schedule )).perform (click ());
145+ onView (withId (R .id .schedule )).perform (click ());
145146 onView (withText (R .string .clear )).perform (click ());
146147
147148 onNoteInBook (8 , R .id .item_head_scheduled_text ).check (matches (not (isDisplayed ())));
@@ -156,7 +157,7 @@ public void testRemovingDoneState() {
156157 onNoteInBook (5 ).perform (longClick ());
157158 onNoteInBook (8 ).perform (click ());
158159
159- onView (withId (R .id .bottom_action_bar_state )).perform (click ());
160+ onView (withId (R .id .state )).perform (click ());
160161 onView (withText ("TODO" )).perform (click ());
161162
162163 onNoteInBook (5 , R .id .item_head_title ).check (matches (withText (startsWith ("TODO" ))));
@@ -168,7 +169,7 @@ public void testClearStateTitleUnchanged() {
168169 onNoteInBook (1 , R .id .item_head_title ).check (matches (withText ("Note #1." )));
169170
170171 onNoteInBook (1 ).perform (longClick ());
171- onView (withId (R .id .bottom_action_bar_state )).perform (click ());
172+ onView (withId (R .id .state )).perform (click ());
172173 onView (withText (R .string .clear )).perform (click ());
173174
174175 onNoteInBook (1 , R .id .item_head_title ).check (matches (withText ("Note #1." )));
@@ -234,7 +235,8 @@ public void testBackFromSettingsShouldReturnToPreviousFragment() {
234235 public void testCutThenOpenNoteAtThePosition () {
235236 onNoteInBook (2 ).perform (longClick ());
236237
237- onView (withId (R .id .book_cab_cut )).perform (click ());
238+ contextualToolbarOverflowMenu ().perform (click ());
239+ onView (withText (R .string .cut )).perform (click ());
238240
239241 /* Open note at the same position as the cut one. */
240242 onNoteInBook (2 ).perform (click ());
@@ -243,7 +245,7 @@ public void testCutThenOpenNoteAtThePosition() {
243245 @ Test
244246 public void testCabForMovingNotesDisplayed () {
245247 onNoteInBook (1 ).perform (longClick ());
246- openContextualToolbarOverflowMenu ( );
248+ contextualToolbarOverflowMenu (). perform ( click () );
247249 onView (withText (R .string .move )).perform (click ());
248250 onView (withId (R .id .notes_action_move_down )).check (matches (isDisplayed ()));
249251 }
@@ -252,7 +254,7 @@ public void testCabForMovingNotesDisplayed() {
252254 public void testOrderOfMovedNote () {
253255 onNoteInBook (3 ).perform (longClick ());
254256
255- openContextualToolbarOverflowMenu ( );
257+ contextualToolbarOverflowMenu (). perform ( click () );
256258 onView (withText (R .string .move )).perform (click ());
257259 onView (withId (R .id .notes_action_move_down )).perform (click ());
258260
@@ -273,7 +275,7 @@ public void testActionModeMovingStaysOpenAfterRotation() {
273275
274276 onNoteInBook (2 ).perform (longClick ());
275277
276- openContextualToolbarOverflowMenu ( );
278+ contextualToolbarOverflowMenu (). perform ( click () );
277279 onView (withText (R .string .move )).perform (click ());
278280 onView (withId (R .id .notes_action_move_down )).check (matches (isDisplayed ()));
279281
@@ -287,23 +289,24 @@ public void testActionModeMovingStaysOpenAfterRotation() {
287289 public void testPromoting () {
288290 onNoteInBook (2 ).perform (longClick ());
289291
290- openContextualToolbarOverflowMenu ( );
292+ contextualToolbarOverflowMenu (). perform ( click () );
291293 onView (withText (R .string .move )).perform (click ());
292294 onView (withId (R .id .notes_action_move_left )).perform (click ());
293295 }
294296
295297 @ Test
296298 public void testPasteAbove () {
297299 onNoteInBook (2 ).perform (longClick ());
298-
299- onView (withId (R .id . book_cab_cut )).perform (click ());
300+ contextualToolbarOverflowMenu (). perform ( click ());
301+ onView (withText (R .string . cut )).perform (click ());
300302
301303 onNoteInBook (1 , R .id .item_head_title ).check (matches (withText (endsWith ("Note #1." ))));
302304 onNoteInBook (2 , R .id .item_head_title ).check (matches (withText (endsWith ("Note #8." ))));
303305 onNoteInBook (3 , R .id .item_head_title ).check (matches (withText (endsWith ("Note #9." ))));
304306
305307 onNoteInBook (1 ).perform (longClick ());
306- onView (withId (R .id .book_cab_paste )).perform (click ());
308+ contextualToolbarOverflowMenu ().perform (click ());
309+ onView (withText (R .string .paste )).perform (click ());
307310 onView (withText (R .string .heads_action_menu_item_paste_above )).perform (click ());
308311
309312 onNoteInBook (1 , R .id .item_head_title ).check (matches (withText (endsWith ("Note #2." ))));
@@ -320,15 +323,16 @@ public void testPasteAbove() {
320323 @ Test
321324 public void testPasteUnder () {
322325 onNoteInBook (2 ).perform (longClick ());
323-
324- onView (withId (R .id . book_cab_cut )).perform (click ());
326+ contextualToolbarOverflowMenu (). perform ( click ());
327+ onView (withText (R .string . cut )).perform (click ());
325328
326329 onNoteInBook (1 , R .id .item_head_title ).check (matches (withText (endsWith ("Note #1." ))));
327330 onNoteInBook (2 , R .id .item_head_title ).check (matches (withText (endsWith ("Note #8." ))));
328331 onNoteInBook (3 , R .id .item_head_title ).check (matches (withText (endsWith ("Note #9." ))));
329332
330333 onNoteInBook (2 ).perform (longClick ());
331- onView (withId (R .id .book_cab_paste )).perform (click ());
334+ contextualToolbarOverflowMenu ().perform (click ());
335+ onView (withText (R .string .paste )).perform (click ());
332336 onView (withText (R .string .heads_action_menu_item_paste_under )).perform (click ());
333337
334338 onNoteInBook (1 , R .id .item_head_title ).check (matches (withText (endsWith ("Note #1." ))));
@@ -342,11 +346,12 @@ public void testPasteUnder() {
342346 @ Test
343347 public void testCopyBelow () {
344348 onNoteInBook (1 ).perform (longClick ());
345-
346- onView (withId (R .id . book_cab_copy )).perform (click ());
349+ contextualToolbarOverflowMenu (). perform ( click ());
350+ onView (withText (R .string . copy )).perform (click ());
347351
348352 onNoteInBook (1 ).perform (longClick ());
349- onView (withId (R .id .book_cab_paste )).perform (click ());
353+ contextualToolbarOverflowMenu ().perform (click ());
354+ onView (withText (R .string .paste )).perform (click ());
350355 onView (withText (R .string .heads_action_menu_item_paste_below )).perform (click ());
351356
352357 onNoteInBook (1 , R .id .item_head_title ).check (matches (withText (endsWith ("Note #1." ))));
@@ -370,10 +375,10 @@ public void testCreateNewNoteUnderFolded() {
370375
371376 /* Create new note under folded. */
372377 onNoteInBook (2 ).perform (longClick ());
373- onView (withId (R .id .bottom_action_bar_new )).perform (click ());
378+ onView (withId (R .id .new_note )).perform (click ());
374379 onView (withText (R .string .new_under )).perform (click ());
375380 onView (withId (R .id .fragment_note_title )).perform (replaceTextCloseKeyboard ("Created" ));
376- onView (withId (R .id .done )).perform (click ());
381+ onView (withId (R .id .fab )).perform (click ()); // Note done
377382
378383 /* New note should not be visible. */
379384 onNoteInBook (1 , R .id .item_head_title ).check (matches (withText (endsWith ("Note #1." ))));
@@ -384,11 +389,21 @@ public void testCreateNewNoteUnderFolded() {
384389 @ Test
385390 public void testNewNoteHasCreatedAtPropertyAfterSaving () {
386391 AppPreferences .createdAt (context , true );
392+
393+ // Open an empty book
394+ pressBack ();
395+ onView (allOf (withText ("Book B" ), isDisplayed ())).perform (click ());
396+
397+ // Create a new note
387398 onView (withId (R .id .fab )).perform (click ());
388399 onView (withId (R .id .fragment_note_title )).perform (replaceTextCloseKeyboard ("Title" ));
389- onView (withId (R .id .done )).perform (click ());
390- onNotesInBook ().perform (RecyclerViewActions .actionOnItemAtPosition (41 , click ()));
400+ onView (withId (R .id .fab )).perform (click ()); // Note done
401+
402+ // Enter note
403+ onNoteInBook (1 ).perform (click ());
391404 onView (withId (R .id .fragment_note_container )).perform (swipeUp ()); // For small screens
405+
406+ // Check properties
392407 onView (allOf (withId (R .id .name ), withText (R .string .created_property_name ))).check (matches (isDisplayed ()));
393408 onView (allOf (withId (R .id .name ), withText ("" ))).check (matches (isDisplayed ()));
394409 }
@@ -404,7 +419,7 @@ public void testReturnToNonExistentNoteByPressingBack() {
404419
405420 // Delete notebook
406421 onView (allOf (withText ("book-name" ), withId (R .id .item_book_title ))).perform (longClick ());
407- openContextualToolbarOverflowMenu ( );
422+ contextualToolbarOverflowMenu (). perform ( click () );
408423 onView (withText (R .string .delete )).perform (click ());
409424 onView (withText (R .string .delete )).perform (click ());
410425
@@ -439,18 +454,18 @@ public void testSetDeadlineTimeForNewNote() {
439454 @ Test
440455 public void testToggleState () {
441456 onNoteInBook (1 ).perform (longClick ());
442- onView (withId (R .id .bottom_action_bar_done )).perform (click ());
457+ onView (withId (R .id .toggle_state )).perform (click ());
443458 onNoteInBook (1 , R .id .item_head_title ).check (matches (withText (startsWith ("DONE" ))));
444459
445- onView (withId (R .id .bottom_action_bar_done )).perform (click ());
460+ onView (withId (R .id .toggle_state )).perform (click ());
446461 onNoteInBook (1 , R .id .item_head_title ).check (matches (withText (startsWith ("TODO" ))));
447462 }
448463
449464 @ Test
450465 public void testToggleStateForAllDone () {
451466 onNoteInBook (5 ).perform (longClick ());
452467 onNoteInBook (8 ).perform (click ());
453- onView (withId (R .id .bottom_action_bar_done )).perform (click ());
468+ onView (withId (R .id .toggle_state )).perform (click ());
454469
455470 onNoteInBook (5 , R .id .item_head_title ).check (matches (withText (startsWith ("TODO" ))));
456471 onNoteInBook (8 , R .id .item_head_title ).check (matches (withText (startsWith ("TODO" ))));
@@ -460,7 +475,7 @@ public void testToggleStateForAllDone() {
460475 public void testToggleStateForAllTodo () {
461476 onNoteInBook (1 ).perform (longClick ());
462477 onNoteInBook (2 ).perform (click ());
463- onView (withId (R .id .bottom_action_bar_done )).perform (click ());
478+ onView (withId (R .id .toggle_state )).perform (click ());
464479
465480 onNoteInBook (1 , R .id .item_head_title ).check (matches (withText (startsWith ("DONE" ))));
466481 onNoteInBook (2 , R .id .item_head_title ).check (matches (withText (startsWith ("DONE" ))));
@@ -470,7 +485,7 @@ public void testToggleStateForAllTodo() {
470485 public void testToggleStateForMixed () {
471486 onNoteInBook (1 ).perform (longClick ());
472487 onNoteInBook (5 ).perform (click ());
473- onView (withId (R .id .bottom_action_bar_done )).perform (click ());
488+ onView (withId (R .id .toggle_state )).perform (click ());
474489
475490 onNoteInBook (1 , R .id .item_head_title ).check (matches (withText (startsWith ("DONE" ))));
476491 onNoteInBook (5 , R .id .item_head_title ).check (matches (withText (startsWith ("DONE" ))));
@@ -481,7 +496,7 @@ public void testToggleStateForMixed() {
481496 public void testPreselectedStateOfSelectedNote () {
482497 onNoteInBook (3 ).perform (longClick ());
483498
484- onView (withId (R .id .bottom_action_bar_state )).perform (click ());
499+ onView (withId (R .id .state )).perform (click ());
485500
486501 onView (withText ("TODO" )).check (matches (isChecked ()));
487502 }
0 commit comments