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

Close Welcome Guide #42

Merged
merged 2 commits into from
Mar 31, 2022
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
22 changes: 22 additions & 0 deletions src/commands/close-welcome-guide.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Close Welcome Guide
*
* @example
* ```
* cy.closeWelcomeGuide()
* ```
*/
export const closeWelcomeGuide = (): void => {
const titleInput = 'h1.editor-post-title__input, #post-title-0';
const closeButtonSelector =
'button[aria-label="Close dialog"], button[aria-label="Disable tips"]';

// Wait for edit page to load
cy.get(titleInput).should('exist');

cy.get('body').then($body => {
if ($body.find(closeButtonSelector).length > 0) {
cy.get(closeButtonSelector).click();
}
});
};
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/// <reference types="cypress" />

// Import commands.
import { closeWelcomeGuide } from './commands/close-welcome-guide';
import { wpCliEval } from './commands/wp-cli-eval';
import { wpCli } from './commands/wp-cli';
import { deactivatePlugin } from './commands/deactivate-plugin';
Expand All @@ -20,6 +21,7 @@ import { createPost } from './commands/create-post';
declare global {
namespace Cypress {
interface Chainable<Subject> {
closeWelcomeGuide: typeof closeWelcomeGuide;
wpCliEval: typeof wpCliEval;
wpCli: typeof wpCli;
deactivatePlugin: typeof deactivatePlugin;
Expand All @@ -39,6 +41,7 @@ declare global {
}

// Register commands
Cypress.Commands.add('closeWelcomeGuide', closeWelcomeGuide);
Cypress.Commands.add('wpCliEval', wpCliEval);
Cypress.Commands.add('wpCli', wpCli);
Cypress.Commands.add('deactivatePlugin', deactivatePlugin);
Expand Down
52 changes: 52 additions & 0 deletions tests/cypress/integration/close-welcome-guide.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
describe('Command: closeWelcomeGuide', () => {
before(() => {
cy.login();

// Disable Classic Editor if it's enabled
cy.visit('/wp-admin/options-writing.php');
cy.get('body').then($body => {
if (
$body.find('.classic-editor-options').length !== 0 &&
$body.find('#classic-editor-classic').is(':checked')
) {
cy.get('#classic-editor-block').click();
cy.get('#submit').click();
}
});

// Ignore WP 5.2 Synchronous XHR error.
Cypress.on('uncaught:exception', (err, runnable) => {
if (
err.message.includes(
"Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://localhost:8889/wp-admin/admin-ajax.php': Synchronous XHR in page dismissal"
)
) {
return false;
}
});
});

beforeEach(() => {
cy.login();
});

it('Should be able to Close Welcome Guide', () => {
const welcomeGuideWindow = '.edit-post-welcome-guide';

cy.visit('/wp-admin/post-new.php');
cy.closeWelcomeGuide();
cy.get(welcomeGuideWindow).should('not.exist');
});

it('Should not fail closing Welcome Guide', () => {
const welcomeGuideWindow = '.edit-post-welcome-guide';

cy.visit('/wp-admin/post-new.php');
cy.closeWelcomeGuide();
cy.get(welcomeGuideWindow).should('not.exist');

cy.visit('/wp-admin/post-new.php');
cy.closeWelcomeGuide();
cy.get(welcomeGuideWindow).should('not.exist');
});
});