-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from bigbite/feature/release-notes-tests
[4] addition of non admin users privileges test
- Loading branch information
Showing
4 changed files
with
111 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/// <reference types="cypress" /> | ||
|
||
const userRoles = [ | ||
{ | ||
'userRole': 'admin', | ||
'isAllowed': true, | ||
}, | ||
{ | ||
'userRole': 'editor', | ||
'isAllowed': false, | ||
}, | ||
{ | ||
'userRole': 'subscriber', | ||
'isAllowed': false, | ||
}, | ||
{ | ||
'userRole': 'contributor', | ||
'isAllowed': false, | ||
}, | ||
{ | ||
'userRole': 'author', | ||
'isAllowed': false, | ||
}, | ||
] | ||
|
||
describe('non admin users should not be able to access release notes post type', () => { | ||
|
||
userRoles.forEach((role) => { | ||
|
||
describe(`${role.userRole} access`, () => { | ||
beforeEach(() => { | ||
cy.switchUser(role.userRole); | ||
cy.visit('/admin/'); | ||
}) | ||
|
||
const roleLabel = role?.userRole ? role.userRole : role.userRole; | ||
const assertion = role?.isAllowed ? 'exist' : 'not.exist'; | ||
const assertionLabel = role?.isAllowed ? 'should' : 'should not'; | ||
|
||
|
||
it(`${roleLabel} ${assertionLabel} be able to create release notes`, () => { | ||
cy.get('#menu-posts-release-note > .wp-has-submenu > .wp-menu-name').should(assertion); | ||
cy.get('#toplevel_page_release-notes > .wp-not-current-submenu > .wp-menu-name').should('exist'); | ||
}) | ||
}) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,55 @@ | ||
describe('release note creation', () => { | ||
/// <reference types="cypress" /> | ||
|
||
describe('Administrator can create and publish release notes', () => { | ||
beforeEach(() => { | ||
cy.intercept({ method: 'POST', url: `/wp-json/wp/v2/release-note/*` }).as('releasePublished') | ||
}) | ||
cy.intercept({ method: 'POST', url: `/wp-json/wp/v2/release-note/*` }).as('releasePublished'); | ||
cy.visit("/wp-admin/edit.php?post_type=release-note"); | ||
}); | ||
|
||
it('should allow an administrator to create and publish a new release note', () => { | ||
const versionNumber = '1.0.0'; | ||
|
||
cy.get(".page-title-action").contains("Add New").click(); | ||
|
||
cy.get(".wp-block-post-title").click().type(`Release Notes - V${versionNumber}`); | ||
|
||
it('an Administrator creates a new release note with provided updates', () => { | ||
cy.visit("/wp-admin/edit.php?post_type=release-note") | ||
cy.get(".page-title-action").contains("Add New").click() | ||
cy.get(".wp-block-post-title").click().type("hello world") | ||
cy.get(".is-root-container").within(() => { | ||
cy.get("p.wp-block-paragraph").type("Overview text") | ||
cy.get("ul").eq(0).within(() => { | ||
cy.get("li").eq(0).type("list item #1{enter}") | ||
cy.get("li").eq(1).type("list item #2") | ||
cy.get("p.wp-block-paragraph").type("Overview text"); | ||
cy.get("ul").as("listBlock"); | ||
cy.get("@listBlock").eq(0).within(() => { | ||
cy.get("li").eq(0).type("list item #1{enter}"); | ||
cy.get("li").eq(1).type("list item #2"); | ||
}); | ||
cy.get("ul").eq(1).within(() => { | ||
cy.get("li").eq(0).type("list item #1{enter}") | ||
cy.get("li").eq(1).type("list item #2") | ||
cy.get("@listBlock").eq(1).within(() => { | ||
cy.get("li").eq(0).type("list item #1{enter}"); | ||
cy.get("li").eq(1).type("list item #2"); | ||
}); | ||
cy.get("ul").eq(2).within(() => { | ||
cy.get("li").eq(0).type("list item #1{enter}") | ||
cy.get("li").eq(1).type("list item #2") | ||
cy.get("@listBlock").eq(2).within(() => { | ||
cy.get("li").eq(0).type("list item #1{enter}"); | ||
cy.get("li").eq(1).type("list item #2"); | ||
}); | ||
}); | ||
cy.contains("button", "Release Note").click() | ||
cy.contains("button", "Release Info").click() | ||
cy.get(".components-input-control__container").type("1.0.0") | ||
|
||
cy.contains("button", "Publish").click() | ||
cy.contains("button", "Release Note").click(); | ||
|
||
cy.contains("button", "Release Info").click(); | ||
|
||
cy.get(".components-input-control__container").type(`${versionNumber}`); | ||
|
||
cy.contains("button", "Publish").click(); | ||
|
||
cy.get(".editor-post-publish-panel__header").within(() => { | ||
cy.contains("button", "Publish").click() | ||
cy.contains("button", "Publish").click(); | ||
}); | ||
cy.saveCurrentPost() | ||
cy.wait("@releasePublished") | ||
.its("response.statusCode") | ||
.should("eq", 200) | ||
|
||
cy.visit("wp-admin/admin.php?page=release-notes") | ||
cy.get(".menupop.release-note").should("contain", "1.0.0") | ||
cy.get(".release-note-version").should("contain", "1.0.0") | ||
|
||
cy.saveCurrentPost(); | ||
|
||
cy.wait("@releasePublished").its("response.statusCode").should("eq", 200); | ||
|
||
cy.visit("wp-admin/admin.php?page=release-notes"); | ||
|
||
cy.get(".menupop.release-note").should("contain", `${versionNumber}`); | ||
|
||
cy.get(".release-note-version").should("contain", `${versionNumber}`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
use WP_Cypress\Seeder\Seeder; | ||
use WP_Cypress\Fixtures; | ||
|
||
class RoleSeeder extends Seeder { | ||
public function run() { | ||
( new Fixtures\User( [ | ||
'role' => 'editor', | ||
'user_login' => 'editor', | ||
] ) )->create(); | ||
|
||
( new Fixtures\User( [ | ||
'role' => 'admin', | ||
'user_login' => 'admin', | ||
] ) )->create(); | ||
} | ||
} |