Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that the insertBlock command works properly in all cases. #128

Merged
merged 10 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@types/node": "^12.20.11",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"@wordpress/env": "^5.5.0",
"@wordpress/env": "^10.2.0",
"codecov": "^3.8.1",
"compare-versions": "^4.1.3",
"cypress": "^13.6.4",
Expand Down
16 changes: 15 additions & 1 deletion src/commands/create-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,23 @@ export const createPost = ({
// Close Welcome Guide.
cy.closeWelcomeGuide();

// Close Start Page Options.
if (postType === 'page') {
// eslint-disable-next-line cypress/no-unnecessary-waiting -- Wait for the modal to appear. Didn't find a better way to handle this.
cy.wait(500);
const modelSelector =
'.edit-post-start-page-options__modal button[aria-label="Close"]';
cy.get('body').then($body => {
if ($body.find('.edit-post-start-page-options__modal').length > 0) {
cy.get(modelSelector).click();
}
});
}

// Fill out data.
if (title.length > 0) {
cy.getBlockEditor().find(titleInput).clear().type(title);
cy.getBlockEditor().find(titleInput).clear();
cy.getBlockEditor().find(titleInput).type(title);
}

if (content.length > 0) {
Expand Down
3 changes: 1 addition & 2 deletions src/commands/insert-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ export const insertBlock = (type: string, name?: string): void => {
`.wp-block[data-type="${ns}/${rest}"]`
);
if (blockInIframe.length > 0) {
expect(blockInIframe.length).to.equal(1);
cy.wrap(blockInIframe.prop('id'));
cy.wrap(blockInIframe.last().prop('id'));
}
});
} else if (
Expand Down
2 changes: 1 addition & 1 deletion src/commands/wp-cli-eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const wpCliEval = (command: string): void => {

// which is read from it's proper location in the plugins directory
cy.exec(
`npm --silent run env run tests-cli "eval-file wp-content/plugins/${pluginName}/${fileName}"` // eslint-disable-line @typescript-eslint/restrict-template-expressions
`npm --silent run env run tests-cli -- wp eval-file wp-content/plugins/${pluginName}/${fileName}` // eslint-disable-line @typescript-eslint/restrict-template-expressions
).then(result => {
cy.exec(`rm ${fileName}`);
cy.wrap(result);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/wp-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
* ```
*/
export const wpCli = (command: string, ignoreFailures = false): void => {
const escapedCommand = command.replace(/"/g, '\\"').replace(/^wp /, '');
const escapedCommand = command.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
const options = {
failOnNonZeroExit: !ignoreFailures,
};
cy.exec(
`npm --silent run env run tests-cli "${escapedCommand}"`,
`npm --silent run env run tests-cli -- ${escapedCommand}`,
options
).then(result => {
cy.wrap(result);
Expand Down
8 changes: 4 additions & 4 deletions tests/bin/initialize.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
npm run env run tests-wordpress "chmod -c ugo+w /var/www/html"
npm run env run tests-cli "wp rewrite structure '/%postname%/' --hard"
wp-env run tests-wordpress chmod -c ugo+w /var/www/html
wp-env run tests-cli wp rewrite structure '/%postname%/' --hard

npm run env run tests-cli "wp user create user1 user1@example.test --role=author --user_pass=password1"
npm run env run tests-cli "wp user create user2 user2@example.test --role=author --user_pass=password2"
wp-env run tests-cli wp user create user1 user1@example.test --role=author --user_pass=password1
wp-env run tests-cli wp user create user2 user2@example.test --role=author --user_pass=password2
6 changes: 4 additions & 2 deletions tests/cypress/cypress-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { defineConfig } = require('cypress');
const { readConfig } = require('@wordpress/env/lib/config');
const { loadConfig } = require('@wordpress/env/lib/config');
const getCacheDirectory = require('@wordpress/env/lib/config/get-cache-directory');

module.exports = defineConfig({
chromeWebSecurity: false,
Expand Down Expand Up @@ -33,7 +34,8 @@ module.exports = defineConfig({
* @returns config Updated Cypress Config object.
*/
const setBaseUrl = async (on, config) => {
const wpEnvConfig = await readConfig('wp-env');
const cacheDirectory = await getCacheDirectory();
const wpEnvConfig = await loadConfig(cacheDirectory);

if (wpEnvConfig) {
const port = wpEnvConfig.env.tests.port || null;
Expand Down
27 changes: 19 additions & 8 deletions tests/cypress/e2e/create-post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,26 @@ describe('Command: createPost', () => {
) {
name = 'Summary';
}
cy.openDocumentSettingsPanel(name);
});

cy.get('label')
.contains('Stick to the top of the blog')
.click()
.parent()
.find('input[type="checkbox"]')
.should('be.checked');
// WP 6.6 handling.
if ($body.find('.editor-post-summary').length === 0) {
cy.openDocumentSettingsPanel(name);

cy.get('label')
.contains('Stick to the top of the blog')
.click()
.parent()
.find('input[type="checkbox"]')
.should('be.checked');
} else {
cy.get(
'.editor-post-sticky__toggle-control input[type="checkbox"]'
).check();
cy.get(
'.editor-post-sticky__toggle-control input[type="checkbox"]'
).should('be.checked');
}
});
},
});

Expand Down
28 changes: 19 additions & 9 deletions tests/cypress/e2e/open-document-settings.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { compare } from 'compare-versions';
const { randomName } = require('../support/functions');
import { getIframe } from '../../../lib/functions/get-iframe';

Expand Down Expand Up @@ -50,15 +51,19 @@ describe('Commands: openDocumentSettings*', () => {
) {
name = 'Summary';
}
cy.openDocumentSettingsPanel(name);

// Assertion: Stick to the top checkbox should be visible
cy.get('.components-panel__body .components-panel__body-title button')
.contains(name, { matchCase: false })
.then($button => {
const $panel = $button.parents('.components-panel__body');
cy.wrap($panel).should('contain', 'Stick to the top of the blog');
});
// WP 6.6 handling.
if ($body.find('.editor-post-summary').length === 0) {
cy.openDocumentSettingsPanel(name);
// Assertion: Stick to the top checkbox should be visible
cy.get('.components-panel__body .components-panel__body-title button')
.contains(name, { matchCase: false })
.then($button => {
const $panel = $button.parents('.components-panel__body');
cy.wrap($panel).should('contain', 'Stick to the top of the blog');
});
} else {
cy.get('.editor-post-sticky__toggle-control').should('be.visible');
}
});
});

Expand All @@ -83,6 +88,11 @@ describe('Commands: openDocumentSettings*', () => {
});

it('Should be able to open Discussion panel on the existing page', () => {
if (compare(Cypress.env('WORDPRESS_CORE').toString(), '6.6', '>=')) {
assert(true, 'Skipping test');
return;
}

cy.createPost({
title: randomName(),
postType: 'page',
Expand Down
2 changes: 1 addition & 1 deletion tests/cypress/e2e/wp-cli.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Command: wpCli', () => {
it('Should run cli command and receive the response', () => {
cy.wpCli('cli version')
cy.wpCli('wp cli version')
.its('stdout')
.should('match', /^WP-CLI \d+\.\d+/);
});
Expand Down
Loading