Skip to content

Commit

Permalink
Merge pull request #6 from tschortsch/feat/wp58
Browse files Browse the repository at this point in the history
feat(): WordPress 5.8 compatibility
  • Loading branch information
tschortsch authored Jul 22, 2021
2 parents b26d55d + 01d0020 commit 8501e69
Show file tree
Hide file tree
Showing 21 changed files with 476 additions and 645 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
node: [ '12', '14', '16' ]
cypress: [ '5.6.0', '6.9.1', '7.4.0' ]
cypress: [ '5.6.0', '6.9.1', '7.7.0', '8.0.0' ]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"core": "WordPress/WordPress#5.7"
"core": "WordPress/WordPress#5.8"
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.3.0

* [Feature] Introduce new `wpVersion` config option to set the WordPress version where the tests are being run. Possible values are `5.7` or `5.8` (Default `5.8`).
* [Dependencies] Bump dependency versions

## 0.2.0

* [Internal] Migrate codebase to TypeScript
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ There are several options to configure the commands. These options can be define
"env": {
"cypress-wp-test-utils": {
"username": "myuser",
"password": "supersecurepassword"
"password": "supersecurepassword",
"wpVersion": 5.7
}
}
}
```

* `username`: Username which is used as the default username in the `loginUser` command.
* `password`: Password which is used as the default password in the `loginUser` command.
* `username` (`string`): Username which is used as the default username in the `loginUser` command. (Default: `admin`)
* `password` (`string`): Password which is used as the default password in the `loginUser` command. (Default: `password`)
* `wpVersion` (`5.7 | 5.8`): Version of your WordPress instance. (Default: `5.8`)

## List of available commands

Expand Down Expand Up @@ -258,11 +260,11 @@ Visits a given admin page.

## Compatibility

* WordPress 5.7.x
* WordPress 5.7, 5.8
* Node >=12
* Cypress >=5.x

Right now those commands are only compatible with WordPress 5.7.
Right now those commands are only compatible with WordPress 5.7 and 5.8.
The goal is to support further WordPress versions but since there are always a lot of changes in the editor between WordPress versions it's difficult to support all of them.

## cypress-xpath included
Expand Down
3 changes: 1 addition & 2 deletions cypress/integration/click-button.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ context('clickButton Command', () => {
it('should click on button by content', () => {
cy.insertBlock('Heading');
cy.selectBlockByName('core/heading');
cy.clickBlockToolbarButton('Options');
cy.clickButton('Copy', 'content');
cy.clickButton('Save draft', 'content');
cy.getEditedPostContent().snapshot();
});

Expand Down
1 change: 1 addition & 0 deletions cypress/integration/get-text-control-by-label.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ context('getTextControlByLabel Command', () => {
it('should return text control element by label', () => {
cy.insertBlock('Buttons');
cy.ensureSidebarOpened();
cy.openSidebarPanelWithTitle('Advanced');
cy.getTextControlByLabel('Link rel').should('have.value', '');
});
});
6 changes: 2 additions & 4 deletions cypress/integration/get-toggle-by-label.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ context('getToggleByLabel Command', () => {
});

it('should return toggle element by label', () => {
cy.insertBlock('Buttons');
cy.insertBlock('Post Date');
cy.ensureSidebarOpened();
cy.getToggleByLabel('Open in new tab')
.should('exist')
.and('not.be.checked');
cy.getToggleByLabel('Link to post').should('exist').and('not.be.checked');
});
});
19 changes: 17 additions & 2 deletions cypress/integration/insert-block.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,26 @@ context('insertBlock Command', () => {

it('should insert block', () => {
cy.insertBlock('Paragraph');
cy.get('[data-type="core/paragraph"]').should('have.length', 1);
cy.get('.edit-post-visual-editor [data-type="core/paragraph"]').should(
'have.length',
1
);
});

it('should insert correct block when multiple blocks where found', () => {
cy.insertBlock('Cloud', 'Tag Cloud');
cy.get('[data-type="core/tag-cloud"]').should('have.length', 1);
cy.get('.edit-post-visual-editor [data-type="core/tag-cloud"]').should(
'have.length',
1
);
});

it('should insert multiple blocks', () => {
cy.insertBlock('Heading');
cy.insertBlock('Heading');
cy.get('.edit-post-visual-editor [data-type="core/heading"]').should(
'have.length',
2
);
});
});
6 changes: 4 additions & 2 deletions cypress/integration/login-user.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ context('loginUser Command', () => {
});

it('should login user with different username and password', () => {
cy.loginUser('otheruser', 'otherpass');
const username = 'otheruser';
const password = 'otherpass';
cy.loginUser(username, password);
cy.get('#login_error').contains(
'Unknown username. Check again or try your email address.'
`Error: The username ${username} is not registered on this site. If you are unsure of your username, try your email address instead.`
);
});
});
4 changes: 2 additions & 2 deletions cypress/integration/select-block-by-name.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ context('selectBlockByName Command', () => {

// Select first heading block
cy.selectBlockByName('core/heading', 0);
cy.get('[data-type="core/heading"]')
cy.get('.edit-post-visual-editor [data-type="core/heading"]')
.eq(0)
.should('have.class', 'is-selected');

// Select second heading block
cy.selectBlockByName('core/heading', 1);
cy.get('[data-type="core/heading"]')
cy.get('.edit-post-visual-editor [data-type="core/heading"]')
.eq(1)
.should('have.class', 'is-selected');
});
Expand Down
5 changes: 3 additions & 2 deletions cypress/integration/set-text-control-value-by-label.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ context('setTextControlValueByLabel Command', () => {
});

it('should set text control value by label', () => {
cy.insertBlock('Buttons');
cy.insertBlock('Paragraph');
cy.ensureSidebarOpened();
cy.setTextControlValueByLabel('Link rel', 'my rel');
cy.openSidebarPanelWithTitle('Advanced');
cy.setTextControlValueByLabel('Additional CSS class(es)', 'my rel');
cy.getEditedPostContent().snapshot();
});
});
15 changes: 13 additions & 2 deletions dist/commands/open-global-block-inserter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import config from '../shared/config';
const GLOBAL_BLOCK_INSERTER_SELECTOR_57 = '.edit-post-header [aria-label="Add block"]';
const GLOBAL_BLOCK_INSERTER_SELECTOR_58 = '.edit-post-header [aria-label="Toggle block inserter"]';
/**
* Opens the global block inserter.
*/
export const openGlobalBlockInserter = () => {
cy.get('.edit-post-header [aria-label="Add block"]').click({
force: true,
const selector = config.wpVersion === 5.8
? GLOBAL_BLOCK_INSERTER_SELECTOR_58
: GLOBAL_BLOCK_INSERTER_SELECTOR_57;
cy.window().then((window) => {
const isGlobalBlockInserterOpen = window.document.querySelector(selector);
if (!isGlobalBlockInserterOpen) {
cy.get(selector).click({
force: true,
});
}
});
};
2 changes: 1 addition & 1 deletion dist/commands/search-for-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
*/
export const searchForBlock = (searchTerm) => {
cy.openGlobalBlockInserter();
cy.get('input.block-editor-inserter__search-input').type(searchTerm);
cy.get('input.block-editor-inserter__search-input').clear().type(searchTerm);
};
1 change: 1 addition & 0 deletions dist/shared/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const DEFAULT_CONFIG = {
username: 'admin',
password: 'password',
wpVersion: 5.8,
};
export default {
...DEFAULT_CONFIG,
Expand Down
Loading

0 comments on commit 8501e69

Please sign in to comment.