Skip to content

Commit

Permalink
Merge pull request #22 from newfold-labs/update/tests
Browse files Browse the repository at this point in the history
Update/tests
  • Loading branch information
circlecube authored Mar 15, 2024
2 parents a2bf4fd + e9c6ea8 commit 4358628
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 87 deletions.
2 changes: 1 addition & 1 deletion tests/cypress/fixtures/stagingSwitch.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"status": "success",
"load_page": "#"
"load_page": "#/staging"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ const stagingCloneFixture = require( '../fixtures/stagingClone.json' );
const stagingDeleteFixture = require( '../fixtures/stagingDelete.json' );
const stagingCreateFixture = require( '../fixtures/stagingCreate.json' );
const stagingSwitchFixture = require( '../fixtures/stagingSwitch.json' );
const stagingStagingFixture = require( '../fixtures/stagingStaging.json' );
const stagingDeployFixture = require( '../fixtures/stagingDeploy.json' );

describe( 'Staging Page', function () {
describe( 'Staging Page - Production Environment', function () {
const appClass = '.' + Cypress.env( 'appId' );

before( () => {
Expand Down Expand Up @@ -236,86 +234,4 @@ describe( 'Staging Page', function () {

// actual reload cancelled by fixture containing a load_page value of `#`
} );
} );

describe( 'Staging Page - Staging environmant', function () {
const appClass = '.' + Cypress.env( 'appId' );

before( () => {
cy.intercept(
{
method: 'GET',
url: /newfold-staging(\/|%2F)v1(\/|%2F)staging/,
},
stagingStagingFixture
);
cy.visit(
'/wp-admin/admin.php?page=' +
Cypress.env( 'pluginId' ) +
'#/staging'
);
} );

it( 'Displays staging environemnt properly', () => {
cy.get( '#newfold-production-toggle' ).should( 'not.be.checked' );
cy.get( '.newfold-staging-prod' )
.contains( 'h3', 'Production Site' )
.should( 'be.visible' );
cy.get( '.newfold-staging-prod' )
.contains(
'label[for="newfold-production-toggle"]',
'Not currently editing'
)
.should( 'be.visible' );

cy.get( '#newfold-staging-toggle' ).should( 'be.checked' );
cy.get( '.newfold-staging-staging' )
.contains( 'h3', 'Staging Site' )
.should( 'be.visible' );
cy.get( '.newfold-staging-staging' )
.contains(
'label[for="newfold-staging-toggle"]',
'Currently editing'
)
.should( 'be.visible' );

cy.get( '#staging-clone-button' ).should( 'be.disabled' );
cy.get( '#staging-delete-button' ).should( 'be.disabled' );
cy.get( '#staging-deploy-button' ).should( 'not.be.disabled' );
} );

it( 'Deploy Works', () => {
cy.intercept(
{
method: 'POST',
url: /newfold-staging(\/|%2F)v1(\/|%2F)staging(\/|%2F)deploy/,
},
{
body: stagingDeployFixture,
delay: 500,
}
).as( 'stagingDeploy' );

cy.get( '#staging-deploy-button' ).click();
cy.get( '.nfd-modal' )
.contains( 'h1', 'Confirm Deployment' )
.should( 'be.visible' );
cy.get( '.nfd-modal .nfd-button--error' )
.contains( 'Cancel' )
.should( 'be.visible' );
cy.get( '.nfd-modal .nfd-button--primary' )
.contains( 'Deploy' )
.should( 'be.visible' )
.click();

cy.get( '.nfd-notifications' )
.contains( 'p', 'Working...' )
.should( 'be.visible' );

cy.wait( '@stagingDeploy' );

cy.get( '.nfd-notifications' )
.contains( 'p', 'Deployed' )
.should( 'be.visible' );
} );
} );
} );
85 changes: 85 additions & 0 deletions tests/cypress/integration/staging-staging.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// <reference types="Cypress" />
const stagingStagingFixture = require( '../fixtures/stagingStaging.json' );
const stagingDeployFixture = require( '../fixtures/stagingDeploy.json' );

describe( 'Staging Page - Staging Environmant', function () {
const appClass = '.' + Cypress.env( 'appId' );

before( () => {
cy.intercept(
{
method: 'GET',
url: /newfold-staging(\/|%2F)v1(\/|%2F)staging/,
},
stagingStagingFixture
);
cy.visit(
'/wp-admin/admin.php?page=' +
Cypress.env( 'pluginId' ) +
'#/staging'
);
} );

it( 'Displays staging environemnt properly', () => {
cy.get( '#newfold-production-toggle' ).should( 'not.be.checked' );
cy.get( '.newfold-staging-prod' )
.contains( 'h3', 'Production Site' )
.should( 'be.visible' );
cy.get( '.newfold-staging-prod' )
.contains(
'label[for="newfold-production-toggle"]',
'Not currently editing'
)
.should( 'be.visible' );

cy.get( '#newfold-staging-toggle' ).should( 'be.checked' );
cy.get( '.newfold-staging-staging' )
.contains( 'h3', 'Staging Site' )
.should( 'be.visible' );
cy.get( '.newfold-staging-staging' )
.contains(
'label[for="newfold-staging-toggle"]',
'Currently editing'
)
.should( 'be.visible' );

cy.get( '#staging-clone-button' ).should( 'be.disabled' );
cy.get( '#staging-delete-button' ).should( 'be.disabled' );
cy.get( '#staging-deploy-button' ).should( 'not.be.disabled' );
} );

it( 'Deploy Works', () => {
cy.intercept(
{
method: 'POST',
url: /newfold-staging(\/|%2F)v1(\/|%2F)staging(\/|%2F)deploy/,
},
{
body: stagingDeployFixture,
delay: 500,
}
).as( 'stagingDeploy' );

cy.get( '#staging-deploy-button' ).click();
cy.get( '.nfd-modal' )
.contains( 'h1', 'Confirm Deployment' )
.should( 'be.visible' );
cy.get( '.nfd-modal .nfd-button--error' )
.contains( 'Cancel' )
.should( 'be.visible' );
cy.get( '.nfd-modal .nfd-button--primary' )
.contains( 'Deploy' )
.should( 'be.visible' )
.click();

cy.get( '.nfd-notifications' )
.contains( 'p', 'Working...' )
.should( 'be.visible' );

cy.wait( '@stagingDeploy' );

cy.get( '.nfd-notifications' )
.contains( 'p', 'Deployed' )
.should( 'be.visible' );
} );
} );

0 comments on commit 4358628

Please sign in to comment.