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

PRESS2-1489 Add Cypress Tests for site-logo step #410

Merged
merged 5 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// <reference types="Cypress" />

import { AdminBarCheck, BackButtonCheck, DarkBGCheck, DisabledNextButton, LightBGChcek, ProgressBarCheck, SkipButtonCheck } from "../wp-module-support/siteGen.cy";

describe( 'SiteGen Site Logo Step', function () {
before( () => {
cy.visit(
'wp-admin/?page=nfd-onboarding#/sitgen/step/site-logo'
);
} );

it( 'Check for the header admin bar', () => {
AdminBarCheck();
} );

it( 'Check for the existing dark background', () => {
DarkBGCheck();
} );

it( 'Check for the light background', () => {
LightBGChcek();
} );

it( 'Check the Progress Bar Value', () => {
ProgressBarCheck('33.3333%');
});

it( 'Check for back button and go back', () => {
BackButtonCheck('sitgen/step/site-logo');
} );

it( 'Check if the heading is visible', () => {
cy.get('.ai-heading').should('be.visible');
} );

it( 'Check for the skip button and click', () => {
SkipButtonCheck('sitgen/step/site-logo');
} );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verifying upon skip, url is not current URL is okay.

We need to also check if it is exactly going to next right step or not. Please verify next expected step url too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I commented on the other PR as well. We are not checking the next page URL as in future the order of pages might change and this will lead to failing of tests. Checking the curr URL is sufficient, I guess whether the current URL changes or not.


it( 'Check if the Next Button is disabled when there is no logo', () => {
DisabledNextButton();
} );

it( 'Check if Image gets uploaded and Next button is enabled', () => {
const sampleLogoPath = `vendor/newfold-labs/wp-module-onboarding/tests/cypress/fixtures/image.png`;
const LogoPreviewClass = '.nfd-onboarding-image-uploader--with-text__site_logo__preview';
if(
cy.get('.nfd-onboarding-button--site-gen-next--disabled')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an assertion, will it have a return value true/false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if the element is not visible, it'll return false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have used this in basic info step also, in earlier onboarding flow.

.should('be.visible')
){
cy.get(LogoPreviewClass)
.should('not.exist');
};
cy.get('input[type=file]', { timeout: 10000 })
.should('exist')
.selectFile( sampleLogoPath , {force: true} )
.then( () => {
cy.wait( 1000 );
cy.get(LogoPreviewClass, { timeout: 10000 } ).should( 'be.visible' );
cy.get( '.nfd-onboarding-image-uploader--with-text__site_logo__preview__reset__button' )
.scrollIntoView()
.should( 'be.visible' );
} );
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the else condition? Next is enabled which means Logo is already uploaded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes


});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click on next and verify if its going to social media step or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add this.

33 changes: 33 additions & 0 deletions tests/cypress/integration/wp-module-support/siteGen.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,36 @@ export const OptionsDetails = (className,textValue,optionsValue) => {
.click();
};
};

export const ProgressBarCheck = ( WidthPercent ) => {
cy.get('.nfd-onboarding-header__progress-bar').should('be.visible');
cy.get('.nfd-onboarding-header__progress-bar__progress')
.invoke('attr', 'style')
.then((styleAttribute) => {
const value = styleAttribute.match(/width:\s*([\d.]+%)/)[1];
expect(value).equal(WidthPercent);
});
};

export const BackButtonCheck = (currURL) => {
cy.get('.nfd-onboarding-button--dark')
.should('be.visible')
.click();
cy.url().should('not.contain', currURL);
cy.go('back');
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click Back meaning you are in site-detail step and cy.go('back') will take us to site-logo again right? Just checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yess.


export const SkipButtonCheck = (currURL) => {
cy.get('.skip-button')
.should('be.visible')
.contains('Skip for now')
.click();
cy.url().should('not.contain', currURL);
cy.go('back');
};

export const DisabledNextButton = () => {
cy.get('.nfd-onboarding-button--site-gen-next--disabled')
.should('be.visible')
.contains( 'Next' );
};