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

chore: improve clear cart core e2e tests #15886

Merged
merged 12 commits into from
Jun 27, 2022
3 changes: 2 additions & 1 deletion projects/storefrontapp-e2e-cypress/cypress/helpers/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,10 @@ export function logOutAndNavigateToEmptyCart() {

export function addProducts() {
const prods = products.slice(0, 3);
prods.forEach((product) => {
prods.forEach((product, index) => {
cy.visit(`/product/${product.code}`);
clickAddToCart();
checkAddedToCartDialog(index + 1);
closeAddedToCartDialog();
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,77 +1,74 @@
import * as cart from '../../../helpers/cart';
import { visitHomePage, signOutUser } from '../../../helpers/checkout-flow';
import { viewportContext } from '../../../helpers/viewport-context';
import { signOutUser, visitHomePage } from '../../../helpers/checkout-flow';
import * as alerts from '../../../helpers/global-message';

describe('Clear Cart', () => {
before(() => {
cart.registerCartUser();
});

viewportContext(['desktop', 'mobile'], () => {
context('Clear cart of anonymous user', () => {
before(() => {
cy.window().then((win) => win.sessionStorage.clear());
visitHomePage();
});
context('Clear cart of anonymous user', () => {
before(() => {
cy.window().then((win) => win.sessionStorage.clear());
visitHomePage();
});

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

afterEach(() => {
cy.saveLocalStorage();
});
afterEach(() => {
cy.saveLocalStorage();
});

it('should add products to the cart', () => {
cart.addProducts();
cart.verifyCartNotEmpty();
});
it('should add products to the cart', () => {
cart.addProducts();
cart.verifyCartNotEmpty();
});

it('should be able to cancel before clearing the cart', () => {
cart.goToCart();
cart.cancelClearCart();
cart.verifyCartNotEmpty();
});
it('should be able to cancel before clearing the cart', () => {
cart.goToCart();
cart.cancelClearCart();
cart.verifyCartNotEmpty();
});

it('should clear cart for anynonymous user', () => {
cart.goToCart();
cart.clearActiveCart();
cart.validateEmptyCart();
});
it('should clear cart for anynonymous user', () => {
cart.goToCart();
cart.clearActiveCart();
cart.validateEmptyCart();
});
});

context('Clear Cart for registered user', () => {
before(() => {
cy.window().then((win) => win.sessionStorage.clear());
visitHomePage();
});
context('Clear Cart for registered user', () => {
before(() => {
cy.window().then((win) => win.sessionStorage.clear());
visitHomePage();
});

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

afterEach(() => {
cy.saveLocalStorage();
});
afterEach(() => {
cy.saveLocalStorage();
});

it('should add products to the cart', () => {
cart.loginCartUser();
cart.addProducts();
cart.verifyCartNotEmpty();
});
it('should add products to the cart', () => {
cart.loginCartUser();
cart.addProducts();
cart.verifyCartNotEmpty();
});

it('should clear cart for registered user and have new cart Id', () => {
cart.goToCart();
cart.saveCartId();
cart.clearActiveCart();
alerts
.getSuccessAlert()
.should('contain', `Active cart cleared successfully.`);
cart.validateEmptyCart();
cart.verifyCartIdAfterClearCart();
signOutUser();
});
it('should clear cart for registered user and have new cart Id', () => {
cart.goToCart();
cart.saveCartId();
cart.clearActiveCart();
alerts
.getSuccessAlert()
.should('contain', `Active cart cleared successfully.`);
cart.validateEmptyCart();
cart.verifyCartIdAfterClearCart();
signOutUser();
});
});
});