2021-02-04 11:15:27 +00:00
|
|
|
import faker from "faker";
|
|
|
|
|
|
|
|
import ShopInfo from "../../apiRequests/ShopInfo";
|
|
|
|
import { PRODUCTS_SELECTORS } from "../../elements/catalog/product-selectors";
|
|
|
|
import { SEARCH_SELECTORS } from "../../elements/frontend-elements/search-selectors";
|
|
|
|
import SearchSteps from "../../steps/frontendSteps/searchSteps";
|
|
|
|
import { URL_LIST } from "../../url/url-list";
|
|
|
|
import ChannelsUtils from "../../utils/channelsUtils";
|
|
|
|
import ProductsUtils from "../../utils/productsUtils";
|
|
|
|
|
|
|
|
// <reference types="cypress" />
|
|
|
|
describe("Products", () => {
|
|
|
|
const channelsUtils = new ChannelsUtils();
|
|
|
|
const productsUtils = new ProductsUtils();
|
|
|
|
const searchSteps = new SearchSteps();
|
|
|
|
|
|
|
|
const shopInfo = new ShopInfo();
|
|
|
|
|
|
|
|
const startsWith = "Cy-";
|
|
|
|
const name = `${startsWith}${faker.random.number()}`;
|
|
|
|
let productTypeId;
|
|
|
|
let attributeId;
|
|
|
|
let categoryId;
|
|
|
|
|
|
|
|
before(() => {
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
productsUtils.deleteProducts(startsWith);
|
|
|
|
productsUtils.createTypeAttributeAndCategoryForProduct(name).then(() => {
|
|
|
|
productTypeId = productsUtils.getProductTypeId();
|
|
|
|
attributeId = productsUtils.getAttributeId();
|
|
|
|
categoryId = productsUtils.getCategoryId();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
shopInfo
|
|
|
|
.getShopInfo()
|
|
|
|
.its("body.data.shop.domain.url")
|
|
|
|
.as("shopUrl");
|
|
|
|
});
|
2021-02-08 09:23:12 +00:00
|
|
|
it("should display on frontend only published products", () => {
|
2021-02-04 11:15:27 +00:00
|
|
|
const productName = `${startsWith}${faker.random.number()}`;
|
|
|
|
channelsUtils.getDefaultChannel().then(defaultChannel => {
|
|
|
|
productsUtils
|
|
|
|
.createProductInChannel(
|
|
|
|
productName,
|
|
|
|
productTypeId,
|
|
|
|
attributeId,
|
|
|
|
categoryId,
|
|
|
|
defaultChannel.id,
|
|
|
|
false,
|
2021-02-08 09:23:12 +00:00
|
|
|
false,
|
|
|
|
true
|
2021-02-04 11:15:27 +00:00
|
|
|
)
|
|
|
|
.then(() => {
|
|
|
|
cy.visit(`${URL_LIST.products}${productsUtils.getCreatedProductId()}`)
|
|
|
|
.get(PRODUCTS_SELECTORS.assignedChannels)
|
|
|
|
.click()
|
|
|
|
.get(PRODUCTS_SELECTORS.publishedRadioButton)
|
|
|
|
.contains("Opublikowany")
|
|
|
|
.click()
|
|
|
|
.get(PRODUCTS_SELECTORS.saveBtn)
|
|
|
|
.click()
|
|
|
|
.waitForGraph("ProductChannelListingUpdate")
|
|
|
|
.get("@shopUrl")
|
|
|
|
.then(shopUrl => {
|
|
|
|
cy.visit(shopUrl);
|
2021-02-08 09:23:12 +00:00
|
|
|
searchSteps.searchFor(productName);
|
|
|
|
cy.get(SEARCH_SELECTORS.productItem).contains(productName);
|
2021-02-04 11:15:27 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it("shouldn't display not published product for unlogged user", () => {
|
|
|
|
const productName = `${startsWith}${faker.random.number()}`;
|
|
|
|
channelsUtils.getDefaultChannel().then(defaultChannel => {
|
|
|
|
productsUtils
|
|
|
|
.createProductInChannel(
|
|
|
|
productName,
|
|
|
|
productTypeId,
|
|
|
|
attributeId,
|
|
|
|
categoryId,
|
|
|
|
defaultChannel.id,
|
|
|
|
true,
|
2021-02-08 09:23:12 +00:00
|
|
|
false,
|
|
|
|
true
|
2021-02-04 11:15:27 +00:00
|
|
|
)
|
|
|
|
.then(() => {
|
|
|
|
cy.visit(`${URL_LIST.products}${productsUtils.getCreatedProductId()}`)
|
|
|
|
.get(PRODUCTS_SELECTORS.assignedChannels)
|
|
|
|
.click()
|
|
|
|
.get(PRODUCTS_SELECTORS.publishedRadioButton)
|
|
|
|
.contains("Nie opublikowano")
|
|
|
|
.click()
|
|
|
|
.get(PRODUCTS_SELECTORS.saveBtn)
|
|
|
|
.click()
|
|
|
|
.waitForGraph("ProductChannelListingUpdate")
|
|
|
|
.get("@shopUrl")
|
|
|
|
.then(shopUrl => {
|
|
|
|
cy.visit(shopUrl);
|
2021-02-08 09:23:12 +00:00
|
|
|
searchSteps.searchFor(productName);
|
2021-02-04 11:15:27 +00:00
|
|
|
cy.get(SEARCH_SELECTORS.productItem).should("not.exist");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-02-08 09:23:12 +00:00
|
|
|
it("should display not published product for staff member", () => {
|
2021-02-04 11:15:27 +00:00
|
|
|
const productName = `${startsWith}${faker.random.number()}`;
|
|
|
|
channelsUtils.getDefaultChannel().then(defaultChannel => {
|
|
|
|
productsUtils
|
|
|
|
.createProductInChannel(
|
|
|
|
productName,
|
|
|
|
productTypeId,
|
|
|
|
attributeId,
|
|
|
|
categoryId,
|
|
|
|
defaultChannel.id,
|
|
|
|
true,
|
2021-02-08 09:23:12 +00:00
|
|
|
false,
|
|
|
|
true
|
2021-02-04 11:15:27 +00:00
|
|
|
)
|
|
|
|
.then(() => {
|
|
|
|
cy.visit(`${URL_LIST.products}${productsUtils.getCreatedProductId()}`)
|
|
|
|
.get(PRODUCTS_SELECTORS.assignedChannels)
|
|
|
|
.click()
|
|
|
|
.get(PRODUCTS_SELECTORS.publishedRadioButton)
|
|
|
|
.contains("Nie opublikowano")
|
|
|
|
.click()
|
|
|
|
.get(PRODUCTS_SELECTORS.saveBtn)
|
|
|
|
.click()
|
|
|
|
.waitForGraph("ProductChannelListingUpdate")
|
|
|
|
.get("@shopUrl")
|
|
|
|
.then(shopUrl => {
|
|
|
|
cy.visit(shopUrl)
|
|
|
|
.loginInShop()
|
|
|
|
.then(() => {
|
2021-02-08 09:23:12 +00:00
|
|
|
searchSteps.searchFor(productName);
|
|
|
|
cy.get(SEARCH_SELECTORS.productItem).contains(productName);
|
2021-02-04 11:15:27 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|