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

115 lines
3.2 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()}`;
2021-02-18 19:32:35 +00:00
let defaultChannel;
channelsUtils
.getDefaultChannel()
.then(channel => {
defaultChannel = channel;
productsUtils.createProductInChannel(
2021-02-12 14:36:13 +00:00
productName,
2021-02-18 18:28:01 +00:00
defaultChannel.id,
null,
null,
2021-02-18 15:28:29 +00:00
productType.id,
attribute.id,
category.id,
2021-02-18 19:32:35 +00:00
1,
2021-02-12 14:36:13 +00:00
false,
false,
true
2021-02-18 19:32:35 +00:00
);
})
.then(() => {
const product = productsUtils.getCreatedProduct();
const productUrl = `${URL_LIST.products}${product.id}`;
productSteps.updateProductPublish(productUrl, true);
frontShopProductUtils.isProductVisible(
product.id,
defaultChannel.slug,
productName
);
})
.then(isVisible => {
expect(isVisible).to.be.eq(true);
});
2021-02-12 14:36:13 +00:00
});
it("should update product to not published", () => {
const productName = `${startsWith}${faker.random.number()}`;
2021-02-18 19:32:35 +00:00
let defaultChannel;
let product;
channelsUtils
.getDefaultChannel()
.then(channel => {
defaultChannel = channel;
productsUtils.createProductInChannel(
2021-02-18 18:28:01 +00:00
productName,
defaultChannel.id,
null,
null,
productType.id,
attribute.id,
2021-02-18 19:32:35 +00:00
category.id
);
})
.then(() => {
product = productsUtils.getCreatedProduct();
const productUrl = `${URL_LIST.products}${product.id}`;
productSteps.updateProductPublish(productUrl, false);
frontShopProductUtils.isProductVisible(
product.id,
defaultChannel.slug,
productName
);
})
.then(isVisible => {
expect(isVisible).to.be.eq(false);
cy.loginInShop();
})
.then(() => {
frontShopProductUtils.isProductVisible(
product.id,
defaultChannel.slug,
productName
);
})
.then(isVisible => {
expect(isVisible).to.be.eq(true);
});
2021-02-12 14:36:13 +00:00
});
});