From c9dcbe75ee33c73f9585b94b54189f23874a434b Mon Sep 17 00:00:00 2001 From: Neven Date: Wed, 8 Feb 2017 11:34:44 -0600 Subject: [PATCH] Remove "Edit preface" if book doesn't exist --- .../com/orgzly/android/espresso/BooksTest.java | 15 +++++++++++++++ .../orgzly/android/ui/fragments/BookFragment.java | 15 +++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/src/androidTest/java/com/orgzly/android/espresso/BooksTest.java b/app/src/androidTest/java/com/orgzly/android/espresso/BooksTest.java index 9196e8a7a..2ae281e02 100644 --- a/app/src/androidTest/java/com/orgzly/android/espresso/BooksTest.java +++ b/app/src/androidTest/java/com/orgzly/android/espresso/BooksTest.java @@ -100,6 +100,21 @@ public void testReturnToNonExistentBookByPressingBack() { onView(allOf(withText("This notebook does not exist any more."), isDisplayed())).check(doesNotExist()); } + @Test + public void testEnterPrefaceForNonExistentBook() { + onView(allOf(withText("book-one"), isDisplayed())).perform(click()); + onView(withId(R.id.drawer_layout)).perform(open()); + onView(withText("Notebooks")).perform(click()); + onView(allOf(withText("book-one"), isDisplayed())).perform(longClick()); + onData(hasToString(containsString("Delete"))).perform(click()); + onView(withText(R.string.ok)).perform(click()); + pressBack(); + onView(withId(R.id.fragment_book_view_flipper)).check(matches(isDisplayed())); + + openContextualActionModeOverflowMenu(); + onView(withText(R.string.edit_book_preface)).check(doesNotExist()); + } + @Test public void testExport() { onView(allOf(withText("book-one"), isDisplayed())).perform(longClick()); diff --git a/app/src/main/java/com/orgzly/android/ui/fragments/BookFragment.java b/app/src/main/java/com/orgzly/android/ui/fragments/BookFragment.java index 7281c446f..9a4e0b820 100644 --- a/app/src/main/java/com/orgzly/android/ui/fragments/BookFragment.java +++ b/app/src/main/java/com/orgzly/android/ui/fragments/BookFragment.java @@ -379,10 +379,17 @@ public void onPrepareOptionsMenu(Menu menu) { MenuItem item; - /* Hide cycle-visibility item if book does not exist. */ - item = menu.findItem(R.id.books_options_menu_item_cycle_visibility); - if (item != null && mBook == null) { - item.setVisible(false); + /* Hide some items if book doesn't exist. */ + if (mBook == null) { + item = menu.findItem(R.id.books_options_menu_item_cycle_visibility); + if (item != null) { + item.setVisible(false); + } + + item = menu.findItem(R.id.books_options_menu_book_preface); + if (item != null) { + item.setVisible(false); + } } // /* Toggle paste item visibility. */