Skip to content

Commit

Permalink
Merge pull request #8 from bigbite/feature/release-notes-tests
Browse files Browse the repository at this point in the history
[4] addition of non admin users privileges test
  • Loading branch information
johnmunster authored Dec 5, 2023
2 parents cab7556 + 009f3ec commit 8947245
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 31 deletions.
3 changes: 2 additions & 1 deletion cypress/e2e/example.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// <reference types="cypress" />

describe('no release notes found', () => {
it('some release notes are published', () => {
it('should have no release notes', () => {
cy.visit('/wp-admin/admin.php?page=release-notes');
cy.get('article.release-note-single').should('exist');
cy.get('article.release-note-single h1.release-note-title').contains('Release not found!');
Expand Down
48 changes: 48 additions & 0 deletions cypress/e2e/non-admin-users.cy.js
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');
})
})
})

})
73 changes: 43 additions & 30 deletions cypress/e2e/release-notes-creation.cy.js
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}`);
});
});
18 changes: 18 additions & 0 deletions cypress/seeds/RoleSeeder.php
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();
}
}

0 comments on commit 8947245

Please sign in to comment.