From 8388b3e4a9bb814e6b0e1be4d8e8108539e3f370 Mon Sep 17 00:00:00 2001 From: Sabina Talipova Date: Thu, 2 Nov 2023 14:32:44 +1300 Subject: [PATCH] MNT New Behat tests for toast messages --- code/LeftAndMain.php | 5 ++ .../features/gridfield-toast-messages.feature | 65 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 tests/behat/features/gridfield-toast-messages.feature diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php index 6fdf89c41..d24a7d845 100644 --- a/code/LeftAndMain.php +++ b/code/LeftAndMain.php @@ -864,6 +864,11 @@ public function redirect($url, $code = 302) if ($this->getRequest()->isAjax()) { $response = $this->getResponse(); $response->addHeader('X-ControllerURL', $url); + + /** Since in some cases we need to pass additional headers, + * but we lose these headers (X-Pjax and X-Status) when we set new response + * we should explicitly add them again from received request. + **/ if ($this->getRequest()->getHeader('X-Pjax') && !$response->getHeader('X-Pjax')) { $response->addHeader('X-Pjax', $this->getRequest()->getHeader('X-Pjax')); } diff --git a/tests/behat/features/gridfield-toast-messages.feature b/tests/behat/features/gridfield-toast-messages.feature new file mode 100644 index 000000000..d9567d234 --- /dev/null +++ b/tests/behat/features/gridfield-toast-messages.feature @@ -0,0 +1,65 @@ +Feature: Show toast messages + As an author + I want to see toast message in the CMS when I create, edit, delete, publish, unpublish, archive a record + + Background: + Given the "Company" "Company A" with "Category"="Other" + And the "Company" "Company B" with "Category"="Other" + And the "Company" "Company C" with "Category"="Other" + And the "Employee" "Employee A" with "Company"="1" + And the "Employee" "Employee B" with "Company"="1" + And the "Employee" "Employee C" with "Company"="1" + And the "group" "EDITOR" has permissions "Access to 'Pages' section" and "Access to 'Test ModelAdmin' section" and "TEST_DATAOBJECT_EDIT" + And I am logged in as a member of "EDITOR" group + And I go to "/admin/test" + + Scenario: I can see toast message when I successfully create or publish a record + When I press the "Add Company" button + And I fill in "Name" with "My Company" + And I press the "Create" button + Then I should see a "Saved Company "My Company" successfully" success toast + And I fill in "Name" with "My New Company" + And I wait for 5 seconds + And I press the "Publish" button + Then I should see a "Published Company "My New Company"" success toast + + Scenario: I can see toast message when I successfully unpublish and archive a record + When I click "Company B" in the "#Form_EditForm" element + And I press the "Publish" button + Then I should see a "Published Company "Company B"" success toast + And I wait for 5 seconds + And I click "More options" in the "#ActionMenus" element + And I press the "Unpublish" button, confirming the dialog + Then I should see a "Unpublished Company "Company B"" success toast + And I click "More options" in the "#ActionMenus" element + And I press the "Archive" button, confirming the dialog + And I should not see "Validation Error" + And I should see a "Archived Company "Company B"" success toast + And I should not see "Company B" in the "#Form_EditForm" element + + Scenario: I can see toast message when I successfully delete a record + When I click "Company A" in the "#Form_EditForm" element + And I click "Employees" in the ".ui-tabs-nav" element + Then I should see "Employee A" in the "#Form_ItemEditForm_Employees" element + And I click "Employee A" in the "#Form_ItemEditForm_Employees" element + And I press the "Delete" button, confirming the dialog + Then I should see a "Deleted Employee "Employee A"" success toast + Then I should not see "Employee A" in the "#Form_ItemEditForm_Employees" element + + Scenario: I can see toast message when I have validation errors + When I click "Company C" in the "#Form_EditForm" element + And I fill in "Name" with "" + And I press the "Save" button + Then I should see "Validation Error" + And I fill in "Name" with "New Company C" + And I press the "Save" button + Then I should see a "Saved Company "New Company C" successfully" success toast + + Scenario: I can see toast message when I have validation errors when I edit a nested record + When I click "Company A" in the "#Form_EditForm" element + And I click "Employees" in the ".ui-tabs-nav" element + Then I should see "Employee B" in the "#Form_ItemEditForm_Employees" element + And I click "Employee B" in the "#Form_ItemEditForm_Employees" element + And I fill in "Name" with "" + And I press the "Save" button + Then I should see "Validation Error"