Skip to content

Commit 8858469

Browse files
author
Sabina Talipova
committed
MNT New Behat tests for toast messages
1 parent 8e6ffcf commit 8858469

File tree

5 files changed

+99
-5
lines changed

5 files changed

+99
-5
lines changed

client/dist/js/bundle.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/lang/src/en.json

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"Admin.REMOVE_LINK": "Remove link",
2424
"Admin.SELECTONEPAGE": "Please select at least one page",
2525
"Admin.VALIDATIONERROR": "Validation Error",
26+
"Admin.DELETE_CONFIRM_MESSAGE": "Deleted",
27+
"Admin.ARCHIVE_CONFIRM_MESSAGE": "Archived",
2628
"Admin.VALIDATION_ERRORS_IN_TAB": "This tab contains validation errors.",
2729
"Admin.VALIDATION_ERRORS_IN_TAB_SCREEN_READER": "(Has validation errors)",
2830
"Admin.VALIDATION_ERRORS_ON_PAGE": "There are validation errors on this page, please fix them before saving or publishing.",

client/src/legacy/GridField.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ $.entwine('ss', function($) {
557557
});
558558

559559
// Covers both tabular delete button, and the button on the detail form
560-
$('.grid-field .grid-field__col-compact .action--delete, .grid-field .grid-field__col-compact .action--archive, .cms-edit-form .btn-toolbar .action--delete, .cms-edit-form .btn-toolbar .action--archive').entwine({
560+
$('.grid-field .grid-field__col-compact .action--delete, .grid-field .grid-field__col-compact .action--archive, .cms-edit-form .btn-toolbar .action--delete, .cms-edit-form .btn-toolbar .action--archive, .grid-field__col-compact .gridfield-button-unlink').entwine({
561561
onclick: function(e){
562562
const confirmMessage = $(this).hasClass('action--archive')
563563
? i18n._t('Admin.ARCHIVECONFIRMMESSAGE', 'Are you sure you want to archive this record?')
@@ -569,6 +569,14 @@ $.entwine('ss', function($) {
569569
} else {
570570
this._super(e);
571571
}
572+
573+
const toastNotificationMessage = $(this).hasClass('action--archive')
574+
? ss.i18n._t('Admin.ARCHIVE_CONFIRM_MESSAGE', 'Archived')
575+
: ss.i18n._t('Admin.DELETE_CONFIRM_MESSAGE', 'Deleted');
576+
577+
if (!$(this).hasClass('action--delete')) {
578+
jQuery.noticeAdd({text: toastNotificationMessage, type: 'success', stayTime: 5000, inEffect: {left: '0', opacity: 'show'}});
579+
}
572580
}
573581
});
574582

code/LeftAndMain.php

-3
Original file line numberDiff line numberDiff line change
@@ -867,9 +867,6 @@ public function redirect($url, $code = 302)
867867
if ($this->getRequest()->getHeader('X-Pjax') && !$response->getHeader('X-Pjax')) {
868868
$response->addHeader('X-Pjax', $this->getRequest()->getHeader('X-Pjax'));
869869
}
870-
if ($this->getRequest()->getHeader('X-Status') && !$response->getHeader('X-Status')) {
871-
$response->addHeader('X-Status', $this->getRequest()->getHeader('X-Status'));
872-
}
873870
$newResponse = new LeftAndMain_HTTPResponse(
874871
$response->getBody(),
875872
$response->getStatusCode(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
Feature: Show toast messages
2+
As an author
3+
I want to see toast message in the CMS when I create, edit, delete, publish, unpublish, archive a record
4+
5+
Background:
6+
Given the "Company" "Company A" with "Category"="Other"
7+
And the "Company" "Company B" with "Category"="Other"
8+
And the "Company" "Company C" with "Category"="Other"
9+
And the "Employee" "Employee A" with "Company"="1"
10+
And the "Employee" "Employee B" with "Company"="1"
11+
And the "Employee" "Employee C" with "Company"="1"
12+
And the "group" "EDITOR" has permissions "Access to 'Pages' section" and "Access to 'Test ModelAdmin' section" and "TEST_DATAOBJECT_EDIT"
13+
And I am logged in as a member of "EDITOR" group
14+
And I go to "/admin/test"
15+
16+
Scenario: I can see toast message when I successfully create or publish a record
17+
When I press the "Add Company" button
18+
And I fill in "Name" with "My Company"
19+
And I press the "Create" button
20+
Then I should see a "Saved Company "My Company" successfully" success toast
21+
And I fill in "Name" with "My New Company"
22+
And I wait for 5 seconds
23+
And I press the "Publish" button
24+
Then I should see a "Published Company "My New Company"" success toast
25+
26+
Scenario: I can see toast message when I successfully unpublish and archive a record
27+
When I click "Company B" in the "#Form_EditForm" element
28+
And I press the "Publish" button
29+
Then I should see a "Published Company "Company B"" success toast
30+
And I wait for 5 seconds
31+
And I click "More options" in the "#ActionMenus" element
32+
And I press the "Unpublish" button, confirming the dialog
33+
Then I should see a "Unpublished Company "Company B"" success toast
34+
And I wait for 5 seconds
35+
And I click "More options" in the "#ActionMenus" element
36+
And I press the "Archive" button, confirming the dialog
37+
And I should not see "Validation Error"
38+
And I should see a "Archived Company "Company B"" success toast
39+
40+
Scenario: I can see toast message when I successfully delete a record
41+
When I click "Company A" in the "#Form_EditForm" element
42+
And I click "Employees" in the ".ui-tabs-nav" element
43+
Then I should see "Employee A" in the "#Form_ItemEditForm_Employees" element
44+
And I click "Employee A" in the "#Form_ItemEditForm_Employees" element
45+
And I press the "Delete" button, confirming the dialog
46+
Then I should see a "Deleted Employee "Employee A"" success toast
47+
Then I should not see "Employee A" in the "#Form_ItemEditForm_Employees" element
48+
49+
Scenario: I can see toast message when I successfully delete a record by clicking the Unlink button in action menu
50+
When I click "Company A" in the "#Form_EditForm" element
51+
And I click "Employees" in the ".ui-tabs-nav" element
52+
Then I should see "Employee A" in the "#Form_ItemEditForm_Employees" element
53+
And I press the "View actions" button
54+
And I click "Unlink" in the ".gridfield-button-unlink" element
55+
And I see the text "Are you sure you want to delete this record?" in the alert
56+
And I confirm the dialog
57+
And I wait for 2 seconds
58+
Then I should see a "Deleted Employee "Employee A"" success toast
59+
Then I should not see "Employee A" in the "#Form_ItemEditForm_Employees" element
60+
61+
Scenario: I can see toast message when I successfully delete a record by clicking the Archive button in action menu
62+
And I should see "Company A" in the "#Form_EditForm" element
63+
And I press the "View actions" button
64+
And I press the "Archive" button
65+
And I see the text "Are you sure you want to archive this record?" in the alert
66+
And I confirm the dialog
67+
And I wait for 2 seconds
68+
Then I should see a "Archived Company "Company A"" success toast
69+
Then I should not see "Company A" in the "#Form_EditForm" element
70+
71+
Scenario: I can see toast message when I have validation errors
72+
When I click "Company C" in the "#Form_EditForm" element
73+
And I fill in "Name" with ""
74+
And I press the "Save" button
75+
Then I should see "Validation Error"
76+
And I fill in "Name" with "New Company C"
77+
And I press the "Save" button
78+
Then I should see a "Saved Company "New Company C" successfully" success toast
79+
80+
Scenario: I can see toast message when I have validation errors when I edit a nested record
81+
When I click "Company A" in the "#Form_EditForm" element
82+
And I click "Employees" in the ".ui-tabs-nav" element
83+
Then I should see "Employee B" in the "#Form_ItemEditForm_Employees" element
84+
And I click "Employee B" in the "#Form_ItemEditForm_Employees" element
85+
And I fill in "Name" with ""
86+
And I press the "Save" button
87+
Then I should see "Validation Error"

0 commit comments

Comments
 (0)