saleor-dashboard/cypress/integration/homePage.js

236 lines
8.2 KiB
JavaScript
Raw Normal View History

2021-02-15 09:44:50 +00:00
import faker from "faker";
import Customer from "../apiRequests/Customer";
import { HOMEPAGE_SELECTORS } from "../elements/homePage/homePage-selectors";
import HomePageSteps from "../steps/homePageSteps";
import { urlList } from "../url/urlList";
import ChannelsUtils from "../utils/channelsUtils";
import HomePageUtils from "../utils/homePageUtils";
import OrdersUtils from "../utils/ordersUtils";
import ProductsUtils from "../utils/productsUtils";
import ShippingUtils from "../utils/shippingUtils";
// <reference types="cypress" />
describe("User authorization", () => {
const startsWith = "Cy-";
const customer = new Customer();
const productsUtils = new ProductsUtils();
const shippingUtils = new ShippingUtils();
const ordersUtils = new OrdersUtils();
const channelsUtils = new ChannelsUtils();
const homePageUtils = new HomePageUtils();
const homePageSteps = new HomePageSteps();
let customerId;
let defaultChannel;
const productPrice = 22;
const shippingPrice = 12;
const randomName = startsWith + faker.random.number();
const randomEmail = randomName + "@example.com";
before(() => {
cy.clearSessionData().loginUserViaRequest();
2021-02-16 14:19:46 +00:00
productsUtils.deleteProperProducts(startsWith);
2021-02-15 09:44:50 +00:00
customer.deleteCustomers(startsWith);
shippingUtils.deleteShipping(startsWith);
2021-02-16 20:48:37 +00:00
let addresses;
2021-02-15 09:44:50 +00:00
2021-02-16 20:48:37 +00:00
channelsUtils
.getDefaultChannel()
.then(channel => {
defaultChannel = channel;
cy.fixture("addresses");
})
.then(addressesFixture => (addresses = addressesFixture))
.then(() =>
customer.createCustomer(randomEmail, randomName, addresses.plAddress)
)
.then(resp => {
customerId = resp.body.data.customerCreate.user.id;
shippingUtils.createShipping(
defaultChannel.id,
randomName,
addresses.plAddress,
shippingPrice
);
})
.then(() => {
productsUtils.createTypeAttributeAndCategoryForProduct(randomName);
})
.then(() => {
const warehouse = shippingUtils.getWarehouse();
const productType = productsUtils.getProductType();
const attribute = productsUtils.getAttribute();
const category = productsUtils.getCategory();
productsUtils.createProductInChannel(
randomName,
defaultChannel.id,
warehouse.id,
20,
productType.id,
attribute.id,
category.id,
productPrice
);
2021-02-15 09:44:50 +00:00
});
});
beforeEach(() => {
cy.clearSessionData().loginUserViaRequest();
});
it("should all elements be visible on the dashboard", () => {
cy.visit(urlList.homePage)
.softAssertVisibility(HOMEPAGE_SELECTORS.sales)
.softAssertVisibility(HOMEPAGE_SELECTORS.orders)
.softAssertVisibility(HOMEPAGE_SELECTORS.activity)
.softAssertVisibility(HOMEPAGE_SELECTORS.topProducts)
.softAssertVisibility(HOMEPAGE_SELECTORS.ordersReadyToFulfill)
.softAssertVisibility(HOMEPAGE_SELECTORS.paymentsWaitingForCapture)
.softAssertVisibility(HOMEPAGE_SELECTORS.productsOutOfStock);
});
it("should correct amount of ready to fullfil orders be displayed", () => {
homePageUtils
.getOrdersReadyToFulfill(defaultChannel.slug)
.as("ordersReadyToFulfill");
ordersUtils.createReadyToFulfillOrder(
customerId,
2021-02-16 14:19:46 +00:00
shippingUtils.getShippingMethod().id,
2021-02-15 09:44:50 +00:00
defaultChannel.id,
productsUtils.getCreatedVariants()
);
2021-02-17 11:22:24 +00:00
cy.get("@ordersReadyToFulfill").then(ordersReadyToFulfillBefore => {
const allOrdersReadyToFulfill = ordersReadyToFulfillBefore + 1;
const notANumberRegex = "\\D*";
const ordersReadyToFulfillRegexp = new RegExp(
`${notANumberRegex}${allOrdersReadyToFulfill}${notANumberRegex}`
);
2021-02-15 09:44:50 +00:00
cy.visit(urlList.homePage);
homePageSteps.changeChannel(defaultChannel.name);
2021-02-17 11:22:24 +00:00
cy.contains(
HOMEPAGE_SELECTORS.ordersReadyToFulfill,
ordersReadyToFulfillRegexp
).should("be.visible");
2021-02-15 09:44:50 +00:00
});
});
it("should correct amount of payments waiting for capture be displayed", () => {
homePageUtils
.getOrdersReadyForCapture(defaultChannel.slug)
.as("ordersReadyForCapture");
const variantsList = productsUtils.getCreatedVariants();
ordersUtils.createWaitingForCaptureOrder(
defaultChannel.slug,
randomEmail,
variantsList,
2021-02-16 14:19:46 +00:00
shippingUtils.getShippingMethod().id
2021-02-15 09:44:50 +00:00
);
2021-02-17 11:22:24 +00:00
cy.get("@ordersReadyForCapture").then(ordersReadyForCaptureBefore => {
const allOrdersReadyForCapture = ordersReadyForCaptureBefore + 1;
const notANumberRegex = "\\D*";
const ordersReadyForCaptureRegexp = new RegExp(
`${notANumberRegex}${allOrdersReadyForCapture}${notANumberRegex}`
);
2021-02-15 09:44:50 +00:00
cy.visit(urlList.homePage);
homePageSteps.changeChannel(defaultChannel.name);
2021-02-17 11:22:24 +00:00
cy.contains(
HOMEPAGE_SELECTORS.ordersReadyForCapture,
ordersReadyForCaptureRegexp
).should("be.visible");
2021-02-15 09:44:50 +00:00
});
});
it("should correct amount of products out of stock be displayed", () => {
homePageUtils
.getProductsOutOfStock(defaultChannel.slug)
.as("productsOutOfStock");
const productOutOfStockRandomName = startsWith + faker.random.number();
const productsOutOfStockUtils = new ProductsUtils();
2021-02-16 14:19:46 +00:00
const warehouse = shippingUtils.getWarehouse();
const productType = productsUtils.getProductType();
const attribute = productsUtils.getAttribute();
const category = productsUtils.getCategory();
2021-02-15 09:44:50 +00:00
productsOutOfStockUtils.createProductInChannel(
productOutOfStockRandomName,
defaultChannel.id,
2021-02-16 14:19:46 +00:00
warehouse.id,
2021-02-15 09:44:50 +00:00
0,
2021-02-16 14:19:46 +00:00
productType.id,
attribute.id,
category.id,
2021-02-15 09:44:50 +00:00
productPrice
);
2021-02-17 11:22:24 +00:00
cy.get("@productsOutOfStock").then(productsOutOfStockBefore => {
const allProductsOutOfStock = productsOutOfStockBefore + 1;
const notANumberRegex = "\\D*";
const productsOutOfStockRegexp = new RegExp(
`${notANumberRegex}${allProductsOutOfStock}${notANumberRegex}`
);
2021-02-15 09:44:50 +00:00
cy.visit(urlList.homePage);
homePageSteps.changeChannel(defaultChannel.name);
2021-02-17 11:22:24 +00:00
cy.contains(
HOMEPAGE_SELECTORS.productsOutOfStock,
productsOutOfStockRegexp
).should("be.visible");
2021-02-15 09:44:50 +00:00
});
});
it("should correct amount of sales be displayed", () => {
homePageUtils.getSalesAmount(defaultChannel.slug).as("salesAmount");
ordersUtils.createReadyToFulfillOrder(
customerId,
2021-02-16 14:19:46 +00:00
shippingUtils.getShippingMethod().id,
2021-02-15 09:44:50 +00:00
defaultChannel.id,
productsUtils.getCreatedVariants()
);
cy.get("@salesAmount").then(salesAmount => {
2021-02-17 11:22:24 +00:00
const totalAmount = salesAmount + productPrice;
const totalAmountString = totalAmount.toFixed(2);
const totalAmountIntegerValue = totalAmountString.split(".")[0];
const totalAmountDecimalValue = totalAmountString.split(".")[1];
const decimalSeparator = "[,.]";
const totalAmountIntegerWithThousandsSeparator = totalAmountIntegerValue.replace(
2021-02-16 23:11:46 +00:00
/(\d)(?=(\d{3})+(?!\d))/g,
2021-02-17 11:22:24 +00:00
"1[,.]*"
);
const totalAmountWithSeparators = `${totalAmountIntegerWithThousandsSeparator}${decimalSeparator}${totalAmountDecimalValue}`;
const notANumberRegex = "\\D*";
const salesAmountRegexp = new RegExp(
`${notANumberRegex}${totalAmountWithSeparators}${notANumberRegex}`
);
2021-02-15 09:44:50 +00:00
cy.visit(urlList.homePage);
homePageSteps.changeChannel(defaultChannel.name);
2021-02-17 11:22:24 +00:00
cy.contains(HOMEPAGE_SELECTORS.sales, salesAmountRegexp).should(
"be.visible"
);
2021-02-15 09:44:50 +00:00
});
});
it("should correct amount of orders be displayed", () => {
homePageUtils.getTodaysOrders(defaultChannel.slug).as("todaysOrders");
ordersUtils.createReadyToFulfillOrder(
customerId,
2021-02-16 14:19:46 +00:00
shippingUtils.getShippingMethod().id,
2021-02-15 09:44:50 +00:00
defaultChannel.id,
productsUtils.getCreatedVariants()
);
2021-02-17 11:22:24 +00:00
cy.get("@todaysOrders").then(ordersBefore => {
const allOrders = ordersBefore + 1;
const notANumberRegex = "\\D*";
const ordersRegexp = new RegExp(
`${notANumberRegex}${allOrders}${notANumberRegex}`
);
2021-02-15 09:44:50 +00:00
cy.visit(urlList.homePage);
homePageSteps.changeChannel(defaultChannel.name);
2021-02-17 11:22:24 +00:00
cy.contains(HOMEPAGE_SELECTORS.orders, ordersRegexp).should("be.visible");
2021-02-15 09:44:50 +00:00
});
});
});