From 2f94f078e36cf65fa8c7b1d640c030b415714cdc Mon Sep 17 00:00:00 2001 From: Christopher Wilkinson Date: Thu, 26 Sep 2019 22:51:24 +0100 Subject: [PATCH] Fix Book form (create) returning to the full books list on cancel Fixes #1662 Added a small block of logic to determine the correct URL to attribute to the cancel button on a given page create form. If adding a book from a bookshelf, return to the bookshelf. If editing a book, return to the book. In all other cases, return to the full books list. --- resources/views/books/form.blade.php | 11 ++++++++++- tests/Entity/EntityTest.php | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/resources/views/books/form.blade.php b/resources/views/books/form.blade.php index 8960b4135..91a3899de 100644 --- a/resources/views/books/form.blade.php +++ b/resources/views/books/form.blade.php @@ -36,6 +36,15 @@
- {{ trans('common.cancel') }} + getUrl(); + } else if (isset($book)) { + $cancelUrl = $book->getUrl(); + } else { + $cancelUrl = '/books'; + } + ?> + {{ trans('common.cancel') }}
\ No newline at end of file diff --git a/tests/Entity/EntityTest.php b/tests/Entity/EntityTest.php index a3fb1cfe1..c28ca8b3e 100644 --- a/tests/Entity/EntityTest.php +++ b/tests/Entity/EntityTest.php @@ -1,5 +1,6 @@ assertEquals('parta-partb-partc', $book->slug); } + public function test_shelf_cancel_creation_returns_to_correct_place() + { + $shelf = Bookshelf::first(); + + // Cancel button from shelf goes back to shelf + $this->asEditor()->visit($shelf->getUrl('/create-book')) + ->see('Cancel') + ->click('Cancel') + ->seePageIs($shelf->getUrl()); + + // Cancel button from books goes back to books + $this->asEditor()->visit('/create-book') + ->see('Cancel') + ->click('Cancel') + ->seePageIs('/books'); + + // Cancel button from book edit goes back to book + $book = Book::first(); + + $this->asEditor()->visit($book->getUrl('/edit')) + ->see('Cancel') + ->click('Cancel') + ->seePageIs($book->getUrl()); + } + }