Merge pull request #2689 from creative-commoners/pulls/4.9/behat

MNT Update behat tests
This commit is contained in:
Maxime Rainville 2021-11-18 17:17:27 +13:00 committed by GitHub
commit b888dc1414
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 217 additions and 3 deletions

View File

@ -5,6 +5,7 @@ Feature: Create a page
Background:
Given a "page" "MyPage"
And a "virtual page" "MyVirtualPage"
And a "group" "AUTHOR group" has permissions "Access to 'Pages' section"
And I am logged in with "ADMIN" permissions
@ -25,8 +26,15 @@ Feature: Create a page
And I should see a "Add new" button in CMS Content Toolbar
When I press the "Add new" button
And I select the "Under another page" radio button
And I select "MyPage" in the "#Form_AddForm_ParentID_Holder" tree dropdown
# Virtual page doesn't allow children, page radio button below should be disabled
And I select "MyVirtualPage" in the "#Form_AddForm_ParentID_Holder" tree dropdown
And I wait for 2 seconds
Then I should see a "#Form_AddForm_PageType_Page[disabled]" element
# Normal pages allows children, page radio button below should not be disabled
When I select "MyPage" in the "#Form_AddForm_ParentID_Holder" tree dropdown
And I wait for 2 seconds
And I select the "Page" radio button
Then I should not see a "#Form_AddForm_PageType_Page[disabled]" element
And I press the "Create" button
Then I should see an edit page form

View File

@ -22,3 +22,6 @@ Feature: Duplicate a page
And I press the "Publish" button
Then I should see "Page1" in the tree
And I should see "Duplicate Page" in the tree
When I follow "Duplicate Page"
Then I should see "Page1a"
And I should see "Page1b"

View File

@ -4,8 +4,10 @@ Feature: Edit a page
So that I correct errors and provide new information
Background:
Given a "page" "About Us"
Given I am logged in with "ADMIN" permissions
Given a "page" "About Us" has the "Content" "<p>My content</p>"
And a "image" "assets/file1.jpg"
#And a file "assets/file1.jpg" with changes "image"="assets/folder1/file2.jpg" and "page"="About Us"
And I am logged in with "ADMIN" permissions
And I go to "/admin/pages"
Then I should see "About Us" in the tree
@ -38,3 +40,88 @@ Feature: Edit a page
When I click on "Settings" in the header tabs
Then the "Settings" header tab should be active
And the "Content" header tab should not be active
Scenario: Frontend changes
When I click on "About Us" in the tree
# Change URL segment
And I press the "Edit" button
Then the rendered HTML should contain "/about-us"
And I fill in "Form_EditForm_URLSegment" with "about-modified-us"
And I press the "OK" button
Then the rendered HTML should contain "/about-modified-us"
# Add metadata
When I click on the "#ui-accordion-Form_EditForm_Metadata-header-0" element
And I wait for 1 second
And I fill in "Meta Description" with "MyMetaDesc"
# Modified content is not displayed on the live site
When I press the "Save" button
And I go to "/about-modified-us?stage=Stage"
Then I should see "About Us"
And I go to "/about-modified-us"
Then I should not see "About Us"
# Assert URL segment + metadata on frontend
When I go to "/admin/pages"
And I click on "About Us" in the tree
And I press the "Publish" button
And I go to "/about-modified-us"
Then I should see "About Us"
And the rendered HTML should contain "<meta name=\"description\" content=\"MyMetaDesc\""
# Link to an email address
When I go to "/admin/pages"
And I click on "About Us" in the tree
Scenario: TinyMCE asset linking
When I click on "About Us" in the tree
# Embed files from the "Files" section of the admin area
And I click on the "div[aria-label='Insert from Files'] button" element
And I click on the ".gallery__files .gallery-item__thumbnail" element
And I press the "Insert file" button
# Link to a file in the "Files" section of the admin area
And I click on the "div[aria-label='Insert link [Ctrl+K]'] button" element
And I select "Link to a file" from the TinyMCE menu with javascript
And I click on the ".gallery__files .gallery-item__thumbnail" element
And I fill in "Form_fileInsertForm_Text" with "MyImage"
And I press the "Link to file" button
# Embed media from a URL
And I click on the "div[aria-label='Insert media via URL'] button" element
And I fill in "Form_remoteCreateForm_Url" with "https://www.youtube.com/watch?v=ScMzIvxBSi4"
And I press "Add media"
And I wait for 15 seconds
And I press "Insert media"
# Assert on frontend
And I press the "Publish" button
And I go to "/about-us"
# insert from files
Then the rendered HTML should contain "<img src=\"/assets/file1.jpg\""
# link to a file
Then the rendered HTML should contain "<a href=\"/assets/file1.jpg\">"
# media embed
Then the rendered HTML should contain "src=\"https://www.youtube.com/embed/ScMzIvxBSi4?feature=oembed\""
Scenario: Change page type
When I click on "About Us" in the tree
And I click the "Settings" CMS tab
And I select "Virtual Page" from the "#Form_EditForm_ClassName" field with javascript
And I press the "Save" button
Then I should see "Please choose a linked page in the main content fields in order to publish"
Scenario: Change permission levels for who can view and edit the page, at an individual page level
When I click on "About Us" in the tree
And I click the "Settings" CMS tab
And I select the "Form_EditForm_CanViewType_LoggedInUsers" radio button
And I press the "Publish" button
# Logout and assert frontend not visible to not-logged-in users
And I go to "/Security/login"
And I press the "Log in as someone else" button
And I go to "/about-us"
Then I should not see "About us"

View File

@ -0,0 +1,74 @@
Feature: Sitetree
As an author
I want to operate the sitetree
So that I can operate my website
Background:
Given the "group" "EDITOR group" has permissions "CMS_ACCESS_LeftAndMain" and "SITETREE_REORGANISE"
And I am logged in with "EDITOR" permissions
And a "page" "One"
And a "page" "Two"
And a "page" "Three"
And I go to "/admin/pages"
# @modal is required to use "I confirm the dialog"
@modal
Scenario: Operation sitetree
Then the site tree order should be "--One,--Two,--Three"
And I should not see a ".status-modified" element
# Drag and drop to reorder pages
When I drag the "#record-1 > a .text" element to the "#record-3 > a .text" element
And I wait for 3 seconds
Then the site tree order should be "--Two,--One,--Three"
And I should see a ".status-modified" element
When I click on the ".toast__close" element
# Drag and drop change nesting levels for pages
When I drag the "#record-2 > a .text" element to the "#record-1 > a .text" element
And I wait for 3 seconds
Then the site tree order should be "--One,---Two,--Three"
When I click on the ".toast__close" element
# Publish pages in a batch
When I press the "Batch actions" button
When I click on the "#record-1 .jstree-checkbox" element
And I click on the "#record-2 .jstree-checkbox" element
And I click on the "#record-3 .jstree-checkbox" element
And I select "Publish" from the "Form_BatchActionsForm_Action" field with javascript
And I click on the "#Form_BatchActionsForm_action_submit" element
And I confirm the dialog
Then I should see a "Published 3 pages" success toast
When I click on the ".toast__close" element
# Wait a little time to ensure the last toast is cleared
And I wait for 2 seconds
# Unpublish pages in a batch
When I click on the "#record-2 .jstree-checkbox" element
And I select "Unpublish" from the "Form_BatchActionsForm_Action" field with javascript
And I click on the "#Form_BatchActionsForm_action_submit" element
And I confirm the dialog
Then I should see a "Unpublished 1 pages" success toast
When I click on the ".toast__close" element
And I wait for 2 seconds
# Unpublish and archive pages in a batch
When I click on the "#record-3 .jstree-checkbox" element
And I select "Unpublish and archive" from the "Form_BatchActionsForm_Action" field with javascript
And I click on the "#Form_BatchActionsForm_action_submit" element
# Surprisingly unpublish and archive doesn't have a dialog
# And I confirm the dialog
# Assertion does not work for some reason despite screenshot showing the toast message
# Then I should see a "Deleted 1 pages from draft and live, and sent them to the archive" success toast
When I go to "/admin/pages"
Then I should not see "Three"
# Toggle list and tree views
Then I should not see a "#Form_ListViewForm_Page" element
When I click on the "[data-view='listview']" element
And I wait for 5 seconds
Then I should see a "#Form_ListViewForm_Page" element
When I click on the "[data-view='treeview']" element
And I wait for 5 seconds
Then I should not see a "#Form_ListViewForm_Page" element

View File

@ -81,6 +81,10 @@ class FixtureContext extends BehatFixtureContext
$obj->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
}
// These functions should be in a FeatureContext, however framework FeatureContext is already
// loaded and adding another FeatureContext within CMS that extends SilverStripeContext will
// expose duplicate functions to behat e.g. FillField
/**
* @When /^I see the "([^"]+)" element$/
* @param $selector
@ -113,4 +117,42 @@ class FixtureContext extends BehatFixtureContext
Assert::assertNotNull($radioButton);
Assert::assertEquals($value, $radioButton->getAttribute($attribute));
}
/**
* Assumes you've just opened the Insert link menu, e.g.
* I click on the "div[aria-label='Insert link [Ctrl+K]'] button" element
*
* @When /^I select "(.+?)" from the TinyMCE menu with javascript$/
* @param string $label
*/
public function iSelectFromTheTinyMceMenu($label)
{
// :visible and :contains are jQuery css selectors
$js = <<<JS
jQuery(".mce-menu-item:visible span:contains('{$label}')").click();
JS;
$this->getMainContext()->getSession()->executeScript($js);
}
/**
* e.g. --PageOne,--PageTwo,---PageTwoChild,--PageThree
*
* @Then /^the site tree order should be "(.+?)"$/
* @param string $label
*/
public function theSiteTreeOrderShouldBe($expected)
{
$js = <<<JS
jQuery('.jstree-no-checkboxes .item')
.map((i, el) => {
let d = '';
jQuery(el).parents('li').each(() => d += '-');
return d + jQuery(el).html();
})
.get()
.join()
JS;
$actual = $this->getMainContext()->getSession()->evaluateScript($js);
Assert::assertEquals($expected, $actual);
}
}