diff --git a/cypress/elements/catalog/product-selectors.js b/cypress/elements/catalog/product-selectors.js index a4d1b6437..32e00d320 100644 --- a/cypress/elements/catalog/product-selectors.js +++ b/cypress/elements/catalog/product-selectors.js @@ -24,5 +24,6 @@ export const PRODUCTS_SELECTORS = { goBackButton: "[data-test-id='app-header-back-button']", assignedChannels: "[data-test='channel-availability-item']", publishedRadioButton: "[role=radiogroup]", - visibleInListingsButton: "[class*='MuiFormControlLabel']" + visibleInListingsButton: "[class*='MuiFormControlLabel']", + addVariantsButton: "[data-test='button-add-variants']" }; diff --git a/cypress/elements/catalog/variants-selectors.js b/cypress/elements/catalog/variants-selectors.js new file mode 100644 index 000000000..941e3a398 --- /dev/null +++ b/cypress/elements/catalog/variants-selectors.js @@ -0,0 +1,6 @@ +export const VARIANTS_SELECTORS = { + nextButton: "[class*='MuiButton-containedPrimary']", + priceinput: "[name*='variant-channel-price']", + warehouseCheckboxes: "[name*='warehouse:']", + skuInput: "input[class*='MuiInputBase'][type='text']" +}; diff --git a/cypress/integration/productsVariants.js b/cypress/integration/productsVariants.js new file mode 100644 index 000000000..f3241164d --- /dev/null +++ b/cypress/integration/productsVariants.js @@ -0,0 +1,94 @@ +import faker from "faker"; + +import Product from "../apiRequests/Product"; +import ShopInfo from "../apiRequests/ShopInfo"; +import { PRODUCTS_SELECTORS } from "../elements/catalog/product-selectors"; +import { VARIANTS_SELECTORS } from "../elements/catalog/variants-selectors"; +import { SEARCH_SELECTORS } from "../elements/frontend-elements/search-selectors"; +import SearchSteps from "../steps/frontendSteps/searchSteps"; +import { urlList } from "../url/url-list"; +import ChannelsUtils from "../utils/channelsUtils"; +import ProductsUtils from "../utils/productsUtils"; +import ShippingUtils from "../utils/shippingUtils"; + +// +describe("creating variants", () => { + const startsWith = "Cy-"; + + const productUtils = new ProductsUtils(); + const channelsUtils = new ChannelsUtils(); + const shippingUtils = new ShippingUtils(); + const product = new Product(); + const shopInfo = new ShopInfo(); + const searchSteps = new SearchSteps(); + + before(() => { + cy.clearSessionData().loginUserViaRequest(); + shippingUtils.deleteShipping(startsWith); + productUtils.deleteProducts(startsWith); + }); + + beforeEach(() => { + cy.clearSessionData().loginUserViaRequest(); + shopInfo + .getShopInfo() + .its("body.data.shop.domain.url") + .as("shopUrl"); + }); + + it("should create variant visible on frontend", () => { + const name = `${startsWith}${faker.random.number()}`; + let warehouseId; + let defaultChannel; + channelsUtils.getDefaultChannel().then(channel => { + cy.fixture("addresses").then(json => { + defaultChannel = channel; + shippingUtils + .createShipping(channel.id, name, json.plAddress, 10) + .then(() => { + warehouseId = shippingUtils.getWarehouseId(); + }); + }); + }); + productUtils.createTypeAttributeAndCategoryForProduct(name).then(() => { + const attributeId = productUtils.getAttributeId(); + const productTypeId = productUtils.getProductTypeId(); + const categoryId = productUtils.getCategoryId(); + + product + .createProduct(attributeId, name, productTypeId, categoryId) + .then(resp => { + const productId = resp.body.data.productCreate.product.id; + product.updateChannelInProduct( + productId, + defaultChannel.id, + true, + true, + true + ); + cy.visit(`${urlList.products}${productId}`) + .get(PRODUCTS_SELECTORS.addVariantsButton) + .click() + .get(VARIANTS_SELECTORS.nextButton) + .click() + .get(VARIANTS_SELECTORS.priceinput) + .type(10) + .get(`[name*='${warehouseId}']`) + .click() + .get(VARIANTS_SELECTORS.nextButton) + .click() + .get(VARIANTS_SELECTORS.skuInput) + .type(name) + .get(VARIANTS_SELECTORS.nextButton) + .click() + + .get("@shopUrl") + .then(shopUrl => { + cy.visit(shopUrl); + searchSteps.searchFor(name); + cy.get(SEARCH_SELECTORS.productItem).contains(name); + }); + }); + }); + }); +}); diff --git a/cypress/url/url-list.js b/cypress/url/url-list.js index aa047845c..3668c263d 100644 --- a/cypress/url/url-list.js +++ b/cypress/url/url-list.js @@ -1,4 +1,4 @@ -export const URL_LIST = { +export const urlList = { dashbord: "/", channels: "/channels/", products: "/products/",