Skip to content

Commit

Permalink
Merge pull request newfold-labs#5 from newfold-labs/add/plugin-test-w…
Browse files Browse the repository at this point in the history
…orklfow

Add/plugin test worklfow
  • Loading branch information
wpscholar authored Dec 15, 2023
2 parents 5668c20 + eb00e1e commit b595380
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 87 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/brand-plugin-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Build and Test Module Updates in Brand Plugins
on:
pull_request:
types: [ opened, reopened, ready_for_review, synchronize ]
branches:
- main
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true

jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.extract_branch.outputs.branch }}
steps:

- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch

bluehost:
name: Bluehost Build and Test
needs: setup
uses: newfold-labs/workflows/.github/workflows/module-plugin-test.yml@main
with:
module-repo: ${{ github.repository }}
module-branch: ${{ needs.setup.outputs.branch }}
plugin-repo: 'bluehost/bluehost-wordpress-plugin'
secrets: inherit

hostgator:
name: HostGator Build and Test
needs: setup
uses: newfold-labs/workflows/.github/workflows/module-plugin-test.yml@main
with:
module-repo: ${{ github.repository }}
module-branch: ${{ needs.setup.outputs.branch }}
plugin-repo: 'newfold-labs/wp-plugin-hostgator'
secrets: inherit

web:
name: Web.com Build and Test
needs: setup
uses: newfold-labs/workflows/.github/workflows/module-plugin-test.yml@main
with:
module-repo: ${{ github.repository }}
module-branch: ${{ needs.setup.outputs.branch }}
plugin-repo: 'newfold-labs/wp-plugin-web'
secrets: inherit

crazydomains:
name: Crazy Domains Build and Test
needs: setup
uses: newfold-labs/workflows/.github/workflows/module-plugin-test.yml@main
with:
module-repo: ${{ github.repository }}
module-branch: ${{ needs.setup.outputs.branch }}
plugin-repo: 'newfold-labs/wp-plugin-crazy-domains'
secrets: inherit

mojo:
name: Mojo Build and Test
needs: setup
uses: newfold-labs/workflows/.github/workflows/module-plugin-test.yml@main
with:
module-repo: ${{ github.repository }}
module-branch: ${{ needs.setup.outputs.branch }}
plugin-repo: 'newfold-labs/wp-plugin-mojo'
secrets: inherit
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v16
201 changes: 114 additions & 87 deletions tests/cypress/integration/deactivation-survey.cy.js
Original file line number Diff line number Diff line change
@@ -1,105 +1,132 @@
// <reference types="Cypress" />

describe('Plugin Deactivation Survey', () => {
describe( 'Plugin Deactivation Survey', () => {
before( () => {
cy.visit( '/wp-admin/plugins.php' );

before(() => {
cy.visit('/wp-admin/plugins.php');
// ignore notifications errors if there are any
cy.intercept(
{
method: 'GET',
url: /newfold-notifications/,
},
{ body: {} }
);
} );

// ignore notifications errors if there are any
cy.intercept({
method: 'GET',
url: /newfold-notifications/,
}, { body: {} });
it( 'Plugin deactivate link opens modal', () => {
// body does not have no scroll class
cy.get( 'body' ).should( 'not.have.class', 'nfd-noscroll' );
cy.get( '.nfd-deactivation-survey__content' ).should( 'not.exist' );

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

it('Plugin deactivate link opens modal', () => {
// body does not have no scroll class
cy.get('body').should('not.have.class', 'nfd-noscroll');
cy.get('.nfd-deactivation-survey__content').should('not.exist');
// body has no scroll class
cy.get( 'body' ).should( 'have.class', 'nfd-noscroll' );

// click link
cy.get('.deactivate a[id*="' + Cypress.env('pluginId') + '"]').click();
// modal exists
cy.get( '.nfd-deactivation-survey__content' )
.scrollIntoView()
.should( 'be.visible' );
} );

// body has no scroll class
cy.get('body').should('have.class', 'nfd-noscroll');

// modal exists
cy.get('.nfd-deactivation-survey__content')
.scrollIntoView()
.should('be.visible');
});
it( 'Cancel button exists and exits modal', () => {
cy.get( 'button[nfd-deactivation-survey-destroy]' ).should(
'be.visible'
);
cy.get( 'button[nfd-deactivation-survey-destroy]' ).click();

it('Cancel button exists and exits modal', () => {
cy.get('button[nfd-deactivation-survey-destroy]')
.should('be.visible');
cy.get('button[nfd-deactivation-survey-destroy]').click();
cy.get( 'body' ).should( 'not.have.class', 'nfd-noscroll' );
cy.get( '.nfd-deactivation-survey__content' ).should( 'not.exist' );
} );

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

it('Skip button deactivates plugin', () => {
// ignore notifications errors if there are any
cy.intercept({
method: 'GET',
url: /newfold-notifications/,
}, { body: {} });
cy.intercept({
it( 'Skip button deactivates plugin', () => {
// ignore notifications errors if there are any
cy.intercept(
{
method: 'GET',
url: /newfold-notifications/,
},
{ body: {} }
);
cy.intercept( {
method: 'POST',
url: /newfold-data(\/|%2F)v1(\/|%2F)events/,
}).as('surveyEvent');
} ).as( 'surveyEvent' );

// reopen modal
cy.get('.deactivate a[id*="' + Cypress.env('pluginId') + '"]').click();
// skip & deactivate functions
// reopen modal
cy.get(
'.deactivate a[id*="' + Cypress.env( 'pluginId' ) + '"]'
).click();
// skip & deactivate functions

cy.get('button[nfd-deactivation-survey-skip]')
.should('be.visible');
cy.get('button[nfd-deactivation-survey-skip]').click();
cy.wait('@surveyEvent')
// .its('request.body.action').should('eq', 'deactivation_survey_freeform')
.its('request.body.data.survey_input').should('eq', 'No input');
// verify modal closed
cy.get('.nfd-deactivation-survey__content').should('not.exist');
// 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');
// reactivate plugin
cy.get('.activate a[id*="' + Cypress.env('pluginId') + '"]').click();
cy.wait(500);
});
cy.get( 'button[nfd-deactivation-survey-skip]' ).should( 'be.visible' );
cy.get( 'button[nfd-deactivation-survey-skip]' ).click();
cy.wait( '@surveyEvent' )
// .its('request.body.action').should('eq', 'deactivation_survey_freeform')
.its( 'request.body.data.survey_input' )
.should( 'eq', 'No input' );
// verify modal closed
cy.get( '.nfd-deactivation-survey__content' ).should( 'not.exist' );
// 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'
);
// reactivate plugin
cy.get(
'.activate a[id*="' + Cypress.env( 'pluginId' ) + '"]'
).click();
cy.wait( 500 );
} );

it('Survey successfully deactivates plugin', () => {
// ignore notifications errors if there are any
cy.intercept({
method: 'GET',
url: /newfold-notifications/,
}, { body: {} });
cy.intercept({
it( 'Survey successfully deactivates plugin', () => {
// ignore notifications errors if there are any
cy.intercept(
{
method: 'GET',
url: /newfold-notifications/,
},
{ body: {} }
);
cy.intercept( {
method: 'POST',
url: /newfold-data(\/|%2F)v1(\/|%2F)events/,
}).as('surveyEvent');

// reopen modal
cy.get('.deactivate a[id*="' + Cypress.env('pluginId') + '"]').click();
// can enter reason
const ugcReason = 'automated testing';
cy.get('#nfd-deactivation-survey__input').type(ugcReason);
// submit and deactivate works
cy.get('input[nfd-deactivation-survey-submit]')
.should('be.visible');
cy.get('input[nfd-deactivation-survey-submit]').click();
cy.wait('@surveyEvent')
// .its('request.body.action').should('eq', 'deactivation_survey_freeform')
.its('request.body.data.survey_input').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');
// reactivate plugin
cy.get('.activate a[id*="' + Cypress.env('pluginId') + '"]').click();
cy.wait(500);
});
} ).as( 'surveyEvent' );

});
// reopen modal
cy.get(
'.deactivate a[id*="' + Cypress.env( 'pluginId' ) + '"]'
).click();
// can enter reason
const ugcReason = 'automated testing';
cy.get( '#nfd-deactivation-survey__input' ).type( ugcReason );
// submit and deactivate works
cy.get( 'input[nfd-deactivation-survey-submit]' ).should(
'be.visible'
);
cy.get( 'input[nfd-deactivation-survey-submit]' ).click();
cy.wait( '@surveyEvent' )
// .its('request.body.action').should('eq', 'deactivation_survey_freeform')
.its( 'request.body.data.survey_input' )
.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'
);
// reactivate plugin
cy.get(
'.activate a[id*="' + Cypress.env( 'pluginId' ) + '"]'
).click();
cy.wait( 500 );
} );
} );

0 comments on commit b595380

Please sign in to comment.