Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wpalani committed Jul 6, 2024
1 parent 50963f7 commit defa2e6
Showing 1 changed file with 132 additions and 62 deletions.
194 changes: 132 additions & 62 deletions tests/cypress/integration/deactivation-survey.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,40 @@ describe( 'Plugin Deactivation Survey', () => {
},
{ body: {} }
);
} );

it( 'Plugin deactivate link opens modal, clicking out closes modal', () => {
// body does not have no scroll class
cy.get( 'body' ).should( 'not.have.class', 'nfd-noscroll' );
cy.get( '.nfd-deactivation-survey__container' ).should( 'not.exist' );
Cypress.Commands.add( 'triggerDeactivationModal', () => {
cy.get(
'.deactivate a[id*="' + Cypress.env( 'pluginId' ) + '"]'
).click();
} );

Cypress.Commands.add( 'verifyModalClosed', () => {
cy.get( '.nfd-deactivation-survey__container' ).should(
'not.exist'
);
cy.get( 'body' ).should( 'not.have.class', 'nfd-noscroll' );
} );

Cypress.Commands.add( 'verifyPluginDeactivated', () => {
cy.get(
'.deactivate a[id*="' + Cypress.env( 'pluginId' ) + '"]'
).should( 'not.exist' );
cy.get(
'.activate a[id*="' + Cypress.env( 'pluginId' ) + '"]'
).should( 'exist' );
} );

Cypress.Commands.add( 'reactivatePlugin', () => {
cy.get(
'.activate a[id*="' + Cypress.env( 'pluginId' ) + '"]'
).click();
cy.wait( 500 );
} );
} );

// click link
cy.get(
'.deactivate a[id*="' + Cypress.env( 'pluginId' ) + '"]'
).click();
it( 'Plugin deactivate link opens modal', () => {
// click "Deactivate" link from plugins list
cy.triggerDeactivationModal();

// body has no scroll class
cy.get( 'body' ).should( 'have.class', 'nfd-noscroll' );
Expand All @@ -41,43 +64,75 @@ describe( 'Plugin Deactivation Survey', () => {

// overlay exists
cy.get( '.nfd-deactivation-survey__overlay' ).should( 'exist' );

cy.get( '.nfd-deactivation-survey__overlay' ).click( { force: true } );

cy.get( 'body' ).should( 'not.have.class', 'nfd-noscroll' );
cy.get( '.nfd-deactivation-survey__content' ).should( 'not.exist' );
} );

it( 'Are You Sure Interstitial exists, cancel button exits modal', () => {
// click link to open modal
it( 'Step 1 content renders correctly', () => {
cy.get(
'.deactivate a[id*="' + Cypress.env( 'pluginId' ) + '"]'
).click();

cy.get( '.nfd-deactivation-sure .nfd-deactivation__content-title' ).should( 'be.visible' );
cy.get( '.nfd-deactivation-sure .nfd-deactivation__content-subtitle' ).should( 'be.visible' );
'.nfd-deactivation-sure .nfd-deactivation__header-title'
).should( 'be.visible' );
cy.get(
'.nfd-deactivation-sure .nfd-deactivation__header-subtitle'
).should( 'be.visible' );
cy.get( '.nfd-deactivation-sure .nfd-deactivation__cards' ).should( 'be.visible' );
cy.get( '.nfd-deactivation-sure .nfd-deactivation__helptext' ).should( 'be.visible' );

// Check content matches deactivation runtime data
cy.get(
'.nfd-deactivation-sure .nfd-deactivation__content-title'
'.nfd-deactivation-sure .nfd-deactivation__header-title'
).contains( newfoldDeactivationSurvey.strings.sureTitle );

cy.get( 'button[nfd-deactivation-survey-destroy]' ).should(
// Cancel button exists
cy.get(
'.nfd-deactivation-sure button[nfd-deactivation-survey-destroy]'
).should( 'be.visible' );

// Continue button exists
cy.get(
'.nfd-deactivation-sure button[nfd-deactivation-survey-next]'
).should( 'be.visible' );

// Go to next step
cy.get(
'.nfd-deactivation-sure button[nfd-deactivation-survey-next]'
).click();
} );

it( 'Step 2 content renders correctly', () => {
cy.get(
'.nfd-deactivation-survey .nfd-deactivation__header-title'
).should( 'be.visible' );
cy.get(
'.nfd-deactivation-survey .nfd-deactivation__header-subtitle'
).should( 'be.visible' );
cy.get( '.nfd-deactivation-survey .nfd-deactivation-label' ).should(
'be.visible'
);
cy.get( '.nfd-deactivation-survey .nfd-deactivation-textarea' ).should(
'be.visible'
);
cy.get( 'button[nfd-deactivation-survey-next]' ).should( 'be.visible' );

// Check content matches deactivation runtime data
cy.get(
'.nfd-deactivation-sure button[nfd-deactivation-survey-destroy]'
).click();
'.nfd-deactivation-survey .nfd-deactivation__header-title'
).contains( newfoldDeactivationSurvey.strings.surveyTitle );

// Cancel button exists
cy.get(
'.nfd-deactivation-survey button[nfd-deactivation-survey-destroy]'
).should( 'be.visible' );

// Submit button exists
cy.get(
'.nfd-deactivation-survey input[nfd-deactivation-survey-submit]'
).should( 'be.visible' );

cy.get( 'body' ).should( 'not.have.class', 'nfd-noscroll' );
cy.get( '.nfd-deactivation-survey__content' ).should( 'not.exist' );
// Skip button exists
cy.get(
'.nfd-deactivation-survey button[nfd-deactivation-survey-skip]'
).should( 'be.visible' );
} );

it( 'Continue button exists and advances to survey, skip button functions', () => {
it( 'Skip action works', () => {
// ignore notifications errors if there are any
cy.intercept(
{
Expand All @@ -91,13 +146,6 @@ describe( 'Plugin Deactivation Survey', () => {
url: /newfold-data(\/|%2F)v1(\/|%2F)events/,
} ).as( 'surveyEvent' );

// click link to open modal
cy.get(
'.deactivate a[id*="' + Cypress.env( 'pluginId' ) + '"]'
).click();

cy.get( 'button[nfd-deactivation-survey-next]' ).click();

// skip & deactivate functions
cy.get( 'button[nfd-deactivation-survey-skip]' ).should( 'be.visible' );
cy.get( 'button[nfd-deactivation-survey-skip]' ).click();
Expand All @@ -106,22 +154,14 @@ describe( 'Plugin Deactivation Survey', () => {
.its( 'request.body.data.survey_input' )
.should( 'eq', '(Skipped)' );
// verify modal closed
cy.get( '.nfd-deactivation-survey__container' ).should( 'not.exist' );
cy.verifyModalClosed();
// verify plugin is deactivated
cy.get(
'.deactivate a[id*="' + Cypress.env( 'pluginId' ) + '"]'
).should( 'not.exist' );
cy.get( '.activate a[id*="' + Cypress.env( 'pluginId' ) + '"]' ).should(
'exist'
);
cy.verifyPluginDeactivated();
// reactivate plugin
cy.get(
'.activate a[id*="' + Cypress.env( 'pluginId' ) + '"]'
).click();
cy.wait( 500 );
cy.reactivatePlugin();
} );

it( 'Survey successfully deactivates plugin', () => {
it( 'Submit action works', () => {
// ignore notifications errors if there are any
cy.intercept(
{
Expand All @@ -136,10 +176,9 @@ describe( 'Plugin Deactivation Survey', () => {
} ).as( 'surveyEvent' );

// click link to open modal
cy.get(
'.deactivate a[id*="' + Cypress.env( 'pluginId' ) + '"]'
).click();
cy.triggerDeactivationModal();

// go to step 2
cy.get( 'button[nfd-deactivation-survey-next]' ).click();

// can enter reason
Expand All @@ -156,20 +195,51 @@ describe( 'Plugin Deactivation Survey', () => {
.should( 'eq', ugcReason );
cy.wait( 500 );
// verify plugin is deactivated
cy.get(
'.deactivate a[id*="' + Cypress.env( 'pluginId' ) + '"]'
).should( 'not.exist' );
cy.get( '.activate a[id*="' + Cypress.env( 'pluginId' ) + '"]' ).should(
'exist'
);
cy.verifyPluginDeactivated();
// reactivate plugin
cy.reactivatePlugin();
} );

it( 'Modal closes properly', () => {
// On overlay click
cy.triggerDeactivationModal();
cy.get( '.nfd-deactivation-survey__overlay' ).click( { force: true } );
cy.verifyModalClosed();

// On step 1 cancel button click
cy.triggerDeactivationModal();
cy.get(
'.activate a[id*="' + Cypress.env( 'pluginId' ) + '"]'
'.nfd-deactivation-sure button[nfd-deactivation-survey-destroy]'
).click();
cy.wait( 500 );
cy.verifyModalClosed();

// On ESC key press (step 1)
cy.triggerDeactivationModal();
cy.get( 'body' ).type( '{esc}' );
cy.verifyModalClosed();

// On step 2 cancel button click
cy.triggerDeactivationModal();
cy.get(
'.nfd-deactivation-sure button[nfd-deactivation-survey-next]'
).click();
cy.get(
'.nfd-deactivation-survey button[nfd-deactivation-survey-destroy]'
).click();
cy.verifyModalClosed();

// On ESC key press (step 2)
cy.triggerDeactivationModal();
cy.get(
'.nfd-deactivation-sure button[nfd-deactivation-survey-next]'
).click();
cy.get( 'body' ).type( '{esc}' );
cy.verifyModalClosed();
} );
} );

after(()=>{
cy.exec( `npx wp-env run cli wp plugin activate ${ Cypress.env( 'pluginSlug' ) }` );
});
after( () => {
cy.exec(
`npx wp-env run cli wp plugin activate ${ Cypress.env( 'pluginSlug' ) }`
);
} );

0 comments on commit defa2e6

Please sign in to comment.