Skip to content

Commit

Permalink
home page e2e update - cypress (#4488)
Browse files Browse the repository at this point in the history
  • Loading branch information
wojteknowacki authored and poulch committed Dec 18, 2023
1 parent a2549a0 commit e70720c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 151 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-birds-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

update old versions and new home page e2e test - cypress
158 changes: 9 additions & 149 deletions cypress/e2e/homePage/homePageAnalitics.js
Original file line number Diff line number Diff line change
@@ -1,170 +1,30 @@
/// <reference types="cypress"/>
/// <reference types="../../support"/>

import faker from "faker";

import { HOMEPAGE_SELECTORS } from "../../elements/homePage/homePage-selectors";
import { urlList } from "../../fixtures/urlList";
import { createCustomer } from "../../support/api/requests/Customer";
import * as homePageUtils from "../../support/api/utils/homePageUtils";
import {
createReadyToFulfillOrder,
createWaitingForCaptureOrder,
} from "../../support/api/utils/ordersUtils";
import * as productsUtils from "../../support/api/utils/products/productsUtils";
import {
changeChannel,
getOrdersReadyForCaptureRegex,
getOrdersReadyToFulfillRegex,
getProductsOutOfStockRegex,
getSalesAmountRegex,
getTodaysOrdersRegex,
} from "../../support/pages/homePage";

describe("As an admin I want to see correct information on dashboard home page", () => {
const startsWith = "CyHomeAnalytics";
const productPrice = 22;
const shippingPrice = 12;
const randomName = startsWith + faker.datatype.number();
const randomEmail = `${startsWith}${randomName}@example.com`;

let customer;
let defaultChannel;
let createdVariants;
let productType;
let attribute;
let category;
let warehouse;
let shippingMethod;
let address;
let ordersReadyToFulfillRegexp;
let ordersReadyForCaptureRegexp;
let productsOutOfStockRegexp;
let salesAmountRegexp;
let ordersRegexp;

before(() => {
cy.loginUserViaRequest();
productsUtils
.createProductWithShipping({
name: randomName,
productPrice,
shippingPrice,
newChannel: true,
})
.then(resp => {
createdVariants = resp.variantsList;
address = resp.address;
warehouse = resp.warehouse;
defaultChannel = resp.defaultChannel;
shippingMethod = resp.shippingMethod;
attribute = resp.attribute;
category = resp.category;
productType = resp.productType;

createCustomer(randomEmail, randomName, address).then(
customerResp => (customer = customerResp),
);

homePageUtils
.getOrdersReadyToFulfill(defaultChannel.slug)
.then(ordersReadyToFulfillBefore => {
ordersReadyToFulfillRegexp = getOrdersReadyToFulfillRegex(
ordersReadyToFulfillBefore,
1,
);
});

homePageUtils
.getOrdersReadyForCapture(defaultChannel.slug)
.then(ordersReadyForCaptureBefore => {
ordersReadyForCaptureRegexp = getOrdersReadyForCaptureRegex(
ordersReadyForCaptureBefore,
1,
);
});

homePageUtils
.getProductsOutOfStock(defaultChannel.slug)
.then(productsOutOfStockBefore => {
productsOutOfStockRegexp = getProductsOutOfStockRegex(
productsOutOfStockBefore,
1,
);
});

homePageUtils.getSalesAmount(defaultChannel.slug).then(salesAmount => {
salesAmountRegexp = getSalesAmountRegex(
salesAmount,
(productPrice + shippingPrice) * 2,
);
});

homePageUtils
.getTodaysOrders(defaultChannel.slug)
.then(ordersBefore => {
ordersRegexp = getTodaysOrdersRegex(ordersBefore, 2);
});
})
.then(() => {
createReadyToFulfillOrder({
customerId: customer.id,
shippingMethod,
channelId: defaultChannel.id,
variantsList: createdVariants,
address,
});

createWaitingForCaptureOrder({
channelSlug: defaultChannel.slug,
email: randomEmail,
variantsList: createdVariants,
shippingMethodName: shippingMethod.name,
address,
});

const productOutOfStockRandomName =
startsWith + faker.datatype.number();

productsUtils.createProductInChannel({
name: productOutOfStockRandomName,
channelId: defaultChannel.id,
warehouseId: warehouse.id,
quantityInWarehouse: 0,
productTypeId: productType.id,
attributeId: attribute.id,
categoryId: category.id,
price: productPrice,
});
});
});

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

it(
"should display correct information on dashboard home page. SALEOR_2004 - migration in progress - to delete when done",
{ tags: ["@homePage", "@allEnv", "@critical"] },
() => {
cy.visit(urlList.homePage);
changeChannel(defaultChannel.name);
cy.contains(HOMEPAGE_SELECTORS.orders, ordersRegexp).should("be.visible");
cy.contains(
HOMEPAGE_SELECTORS.ordersReadyToFulfill,
ordersReadyToFulfillRegexp,
).should("be.visible");
cy.contains(
HOMEPAGE_SELECTORS.paymentsWaitingForCapture,
ordersReadyForCaptureRegexp,
).should("be.visible");
cy.contains(HOMEPAGE_SELECTORS.sales, salesAmountRegexp).should(
"be.visible",
);
cy.contains(
HOMEPAGE_SELECTORS.productsOutOfStock,
productsOutOfStockRegexp,
).should("be.visible");
cy.get(HOMEPAGE_SELECTORS.activity).should("be.visible");
cy.get(HOMEPAGE_SELECTORS.activity)
.find("ul")
.find("li")
.should("have.length.above", 1);
cy.get(HOMEPAGE_SELECTORS.sales).should("be.visible");
cy.get(HOMEPAGE_SELECTORS.productsOutOfStock).should("be.visible");

cy.get(HOMEPAGE_SELECTORS.topProducts).should("be.visible");
},
);
});
4 changes: 2 additions & 2 deletions cypress/elements/homePage/homePage-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export const HOMEPAGE_SELECTORS = {
topProducts: "[data-test-id='top-products']",
ordersReadyToFulfill: "[data-test-id='orders-to-fulfill']",
paymentsWaitingForCapture: "[data-test-id='orders-to-capture']",
productsOutOfStock: "[data-test-id='products-out-of-stock']",
welcomeMessage: "[data-test-id='welcome-header']"
productsOutOfStock: "[data-test-id*='out-of-stock']",
welcomeMessage: "[data-test-id='welcome-header']",
};

0 comments on commit e70720c

Please sign in to comment.