saleor-dashboard/cypress/integration/products/publishedProducts.js

95 lines
3.1 KiB
JavaScript
Raw Normal View History

2021-02-12 14:36:13 +00:00
import faker from "faker";
import ProductSteps from "../../steps/productSteps";
import { URL_LIST } from "../../url/url-list";
import ChannelsUtils from "../../utils/channelsUtils";
import FrontShopProductUtils from "../../utils/frontShop/frontShopProductUtils";
import ProductsUtils from "../../utils/productsUtils";
// <reference types="cypress" />
describe("Publish products", () => {
const channelsUtils = new ChannelsUtils();
const productsUtils = new ProductsUtils();
const productSteps = new ProductSteps();
const frontShopProductUtils = new FrontShopProductUtils();
const startsWith = "Cy-";
const name = `${startsWith}${faker.random.number()}`;
2021-02-18 15:28:29 +00:00
let productType;
let attribute;
let category;
2021-02-12 14:36:13 +00:00
before(() => {
cy.clearSessionData().loginUserViaRequest();
2021-02-18 15:28:29 +00:00
productsUtils.deleteProperProducts(startsWith);
2021-02-12 14:36:13 +00:00
productsUtils.createTypeAttributeAndCategoryForProduct(name).then(() => {
2021-02-18 15:28:29 +00:00
productType = productsUtils.getProductType();
attribute = productsUtils.getAttribute();
category = productsUtils.getCategory();
2021-02-12 14:36:13 +00:00
});
});
beforeEach(() => {
cy.clearSessionData().loginUserViaRequest();
});
it("should update product to published", () => {
const productName = `${startsWith}${faker.random.number()}`;
channelsUtils.getDefaultChannel().then(defaultChannel => {
productsUtils
.createProductInChannel(
productName,
2021-02-18 15:28:29 +00:00
productType.id,
attribute.id,
category.id,
2021-02-12 14:36:13 +00:00
defaultChannel.id,
false,
false,
true
)
.then(() => {
const productId = productsUtils.getCreatedProductId();
const productUrl = `${URL_LIST.products}${productId}`;
productSteps.updateProductPublish(productUrl, true);
frontShopProductUtils
.isProductVisible(productId, defaultChannel.slug, productName)
.then(isVisible => {
expect(isVisible).to.be.eq(true);
});
});
});
});
it("should update product to not published", () => {
const productName = `${startsWith}${faker.random.number()}`;
channelsUtils.getDefaultChannel().then(defaultChannel => {
productsUtils
.createProductInChannel(
productName,
2021-02-18 15:28:29 +00:00
productType.id,
attribute.id,
category.id,
2021-02-12 14:36:13 +00:00
defaultChannel.id,
true,
false,
true
)
.then(() => {
const productId = productsUtils.getCreatedProductId();
const productUrl = `${URL_LIST.products}${productId}`;
productSteps.updateProductPublish(productUrl, false);
frontShopProductUtils
.isProductVisible(productId, defaultChannel.slug, productName)
.then(isVisible => {
expect(isVisible).to.be.eq(false);
});
cy.loginInShop().then(() => {
frontShopProductUtils
.isProductVisible(productId, defaultChannel.slug, productName)
.then(isVisible => {
expect(isVisible).to.be.eq(true);
});
});
});
});
});
});