From 03c6149f6fababd01e2a09c36b5e56e00bed0cef Mon Sep 17 00:00:00 2001 From: Karolina Rakoczy Date: Fri, 19 Feb 2021 09:45:34 +0100 Subject: [PATCH] tests for variants --- cypress/apiRequests/Product.js | 3 +- cypress/apiRequests/Warehouse.js | 1 + cypress/elements/catalog/product-selectors.js | 3 +- .../elements/catalog/variants-selectors.js | 1 + cypress/integration/productsVariants.js | 117 ++++++++++-------- cypress/steps/products/VariantsSteps.js | 30 ++--- cypress/support/index.js | 1 - cypress/utils/productsUtils.js | 2 +- 8 files changed, 87 insertions(+), 71 deletions(-) diff --git a/cypress/apiRequests/Product.js b/cypress/apiRequests/Product.js index 16b7d2a30..3e1763da0 100644 --- a/cypress/apiRequests/Product.js +++ b/cypress/apiRequests/Product.js @@ -46,7 +46,7 @@ class Product { } } }`; - cy.sendRequestWithQuery(mutation); + return cy.sendRequestWithQuery(mutation); } updateChannelPriceInVariant(variantId, channelId) { @@ -135,6 +135,7 @@ class Product { slug: "${slug}" isShippingRequired: true productAttributes: "${attributeId}" + variantAttributes: "${attributeId}" }){ productErrors{ field diff --git a/cypress/apiRequests/Warehouse.js b/cypress/apiRequests/Warehouse.js index 8237a9333..2bbf18c15 100644 --- a/cypress/apiRequests/Warehouse.js +++ b/cypress/apiRequests/Warehouse.js @@ -20,6 +20,7 @@ class Warehouse { } warehouse{ id + name } } }`; diff --git a/cypress/elements/catalog/product-selectors.js b/cypress/elements/catalog/product-selectors.js index 9e4fe4fed..c55f5384f 100644 --- a/cypress/elements/catalog/product-selectors.js +++ b/cypress/elements/catalog/product-selectors.js @@ -24,12 +24,11 @@ export const PRODUCTS_SELECTORS = { goBackButton: "[data-test-id='app-header-back-button']", assignedChannels: "[data-test='channel-availability-item']", publishedRadioButton: "[role=radiogroup]", - visibleInListingsButton: "[class*='MuiFormControlLabel']", addVariantsButton: "[data-test*='button-add-variant']", publishedRadioButtons: "[name*='isPublished']", availableForPurchaseRadioButtons: "[name*='isAvailableForPurchase']", radioButtonsValueTrue: "[value='true']", radioButtonsValueFalse: "[value='false']", - visibleInListingButton: "[name*='visibleInListings']", + visibleInListingsButton: "[name*='visibleInListings']", emptyProductRow: "[class*='Skeleton']" }; diff --git a/cypress/elements/catalog/variants-selectors.js b/cypress/elements/catalog/variants-selectors.js index 946bd29b6..719aa3e7e 100644 --- a/cypress/elements/catalog/variants-selectors.js +++ b/cypress/elements/catalog/variants-selectors.js @@ -2,6 +2,7 @@ export const VARIANTS_SELECTORS = { attributeCheckbox: "[name*='value:']", nextButton: "[class*='MuiButton-containedPrimary']", priceInput: "[name*='channel-price']", + costPriceInput: "[name*='channel-costPrice']", warehouseCheckboxes: "[name*='warehouse:']", skuInput: "input[class*='MuiInputBase'][type='text']", attributeSelector: "[data-test='attribute-value']", diff --git a/cypress/integration/productsVariants.js b/cypress/integration/productsVariants.js index 63d6b025d..a8b7d98e6 100644 --- a/cypress/integration/productsVariants.js +++ b/cypress/integration/productsVariants.js @@ -2,10 +2,10 @@ import faker from "faker"; import { visit } from "graphql"; import Channels from "../apiRequests/Channels"; +import ProductDetails from "../apiRequests/frontShop/ProductDetails"; import Product from "../apiRequests/Product"; -import ShopInfo from "../apiRequests/ShopInfo"; import VariantsSteps from "../steps/products/VariantsSteps"; -import { urlList } from "../url/url-list"; +import { urlList } from "../url/urlList"; import ChannelsUtils from "../utils/channelsUtils"; import ProductsUtils from "../utils/productsUtils"; import ShippingUtils from "../utils/shippingUtils"; @@ -18,8 +18,8 @@ describe("creating variants", () => { const channelsUtils = new ChannelsUtils(); const shippingUtils = new ShippingUtils(); const product = new Product(); - const shopInfo = new ShopInfo(); const channels = new Channels(); + const productDetails = new ProductDetails(); const variantsSteps = new VariantsSteps(); @@ -32,7 +32,7 @@ describe("creating variants", () => { before(() => { cy.clearSessionData().loginUserViaRequest(); shippingUtils.deleteShipping(startsWith); - productUtils.deleteProducts(startsWith); + productUtils.deleteProperProducts(startsWith); const name = `${startsWith}${faker.random.number()}`; channelsUtils @@ -43,7 +43,7 @@ describe("creating variants", () => { }) .then(fixtureAddresses => shippingUtils.createShipping( - channel.id, + defaultChannel.id, name, fixtureAddresses.plAddress, 10 @@ -60,14 +60,11 @@ describe("creating variants", () => { 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()}`; + const price = 10; let createdProduct; product @@ -81,41 +78,47 @@ describe("creating variants", () => { true, true ); - cy.visit(`${urlList.products}${productId}`); - variantsSteps.createFirstVariant(warehouse.id); - cy.getProductDetails(product.id, defaultChannel.slug).then( - productDetailsResp => { + cy.visit(`${urlList.products}${createdProduct.id}`); + variantsSteps.createFirstVariant(name, warehouse.id, price); + productDetails + .getProductDetails(createdProduct.id, defaultChannel.slug) + .then(productDetailsResp => { expect(productDetailsResp.body[0].data.product.name).to.equal(name); expect( productDetailsResp.body[0].data.product.variants[0].pricing.price .gross.amount - ).to.equal(10); - } - ); + ).to.equal(price); + }); }); }); it("should create several variants", () => { const name = `${startsWith}${faker.random.number()}`; const secondVariantSku = `${startsWith}${faker.random.number()}`; + const variantsPrice = 5; + let createdProduct; productUtils .createProductInChannel( name, + defaultChannel.id, + warehouse.id, + 1, productType.id, attribute.id, category.id, - defaultChannel.id, - true, - true, - true, - warehouse.id, - 10, - 10 + variantsPrice ) .then(() => { - cy.visit(`${urlList.products}${productId}`); - variantsSteps.createVariant(secondVariantSku, warehouse.name); + createdProduct = productUtils.getCreatedProduct(); + cy.visit(`${urlList.products}${createdProduct.id}`); + variantsSteps.createVariant( + secondVariantSku, + warehouse.name, + variantsPrice + ); }) - .then(() => cy.getProductDetails(productId, defaultChannel.slug)) + .then(() => + productDetails.getProductDetails(createdProduct.id, defaultChannel.slug) + ) .then(productDetailsResp => { expect(productDetailsResp.body[0].data.product.name).to.equal(name); expect(productDetailsResp.body[0].data.product.variants).to.have.length( @@ -124,24 +127,30 @@ describe("creating variants", () => { expect( productDetailsResp.body[0].data.product.variants[0].pricing.price .gross.amount - ).to.equal(10); + ).to.equal(variantsPrice); expect( productDetailsResp.body[0].data.product.variants[1].pricing.price .gross.amount - ).to.equal(10); + ).to.equal(variantsPrice); }); }); it("should create variant for many channels", () => { const name = `${startsWith}${faker.random.number()}`; let newChannel; + let createdProduct; channels .createChannel(true, name, name, "PLN") .then(resp => { - newChannel = resp.body.data.createdChannel.channel; - product.createProduct(attribute.id, name, productType.id, category.id); + newChannel = resp.body.data.channelCreate.channel; + productUtils.createProduct( + attribute.id, + name, + productType.id, + category.id + ); }) - .then(resp => { - const createdProduct = resp.body.data.productCreate.product; + .then(() => { + createdProduct = productUtils.getCreatedProduct(); product.updateChannelInProduct( createdProduct.id, defaultChannel.id, @@ -149,6 +158,8 @@ describe("creating variants", () => { true, true ); + }) + .then(() => { product.updateChannelInProduct( createdProduct.id, newChannel.id, @@ -156,26 +167,28 @@ describe("creating variants", () => { true, true ); + }) + .then(() => { + cy.visit(`${urlList.products}${createdProduct.id}`); + variantsSteps.createFirstVariant(warehouse.id); + productDetails.getProductDetails(product.id, defaultChannel.slug); + }) + .then(productDetailsResp => { + expect(productDetailsResp.body[0].data.product.name).to.equal(name); + expect( + productDetailsResp.body[0].data.product.variants[0].pricing.price + .gross.amount + ).to.equal(10); + }) + .then(() => { + productDetails.getProductDetails(product.id, newChannel.slug); + }) + .then(productDetailsResp => { + expect(productDetailsResp.body[0].data.product.name).to.equal(name); + expect( + productDetailsResp.body[0].data.product.variants[0].pricing.price + .gross.amount + ).to.equal(10); }); - visit(`${urlList.products}${productId}`); - variantsSteps.createFirstVariant(warehouse.id); - cy.getProductDetails(product.id, defaultChannel.slug).then( - productDetailsResp => { - expect(productDetailsResp.body[0].data.product.name).to.equal(name); - expect( - productDetailsResp.body[0].data.product.variants[0].pricing.price - .gross.amount - ).to.equal(10); - } - ); - cy.getProductDetails(product.id, newChannel.slug).then( - productDetailsResp => { - expect(productDetailsResp.body[0].data.product.name).to.equal(name); - expect( - productDetailsResp.body[0].data.product.variants[0].pricing.price - .gross.amount - ).to.equal(10); - } - ); }); }); diff --git a/cypress/steps/products/VariantsSteps.js b/cypress/steps/products/VariantsSteps.js index 4863e4022..98a20bb69 100644 --- a/cypress/steps/products/VariantsSteps.js +++ b/cypress/steps/products/VariantsSteps.js @@ -1,6 +1,7 @@ +import { PRODUCTS_SELECTORS } from "../../elements/catalog/product-selectors"; import { VARIANTS_SELECTORS } from "../../elements/catalog/variants-selectors"; class VariantsSteps { - createFirstVariant(sku, warehouseId) { + createFirstVariant(sku, warehouseId, price) { cy.get(PRODUCTS_SELECTORS.addVariantsButton) .click() .get(VARIANTS_SELECTORS.attributeCheckbox) @@ -9,18 +10,18 @@ class VariantsSteps { .get(VARIANTS_SELECTORS.nextButton) .click() .get(VARIANTS_SELECTORS.priceInput) - .type(10) - .get(`[name*='${warehouseId}']`) + .forEach(priceInput => cy.priceInput.type(price)); + cy.get(`[name*='${warehouseId}']`) .click() .get(VARIANTS_SELECTORS.nextButton) .click() .get(VARIANTS_SELECTORS.skuInput) - .type(sku) - .get(VARIANTS_SELECTORS.nextButton) - .click() - .waitForGraph("ProductVariantBulkCreate"); + .type(sku); + cy.waitForGraph("ProductVariantBulkCreate"); + cy.get(VARIANTS_SELECTORS.nextButton).click(); + cy.wait("@ProductVariantBulkCreate"); } - createVariant(sku, warehouseName) { + createVariant(sku, warehouseName, price, costPrice = price) { cy.get(PRODUCTS_SELECTORS.addVariantsButton) .click() .get(VARIANTS_SELECTORS.attributeSelector) @@ -29,16 +30,17 @@ class VariantsSteps { .first() .click() .get(VARIANTS_SELECTORS.priceInput) - .type(10) + .type(price) + .get(VARIANTS_SELECTORS.costPriceInput) + .type(costPrice) .get(VARIANTS_SELECTORS.skuInputInAddVariant) .type(sku) .get(VARIANTS_SELECTORS.addWarehouseButton) - .click() - .get(VARIANTS_SELECTORS.warehouseOption) - .contains(warehouseName) - .click() - .get(VARIANTS_SELECTORS.saveButton) .click(); + cy.contains(VARIANTS_SELECTORS.warehouseOption, warehouseName).click(); + cy.waitForGraph("VariantCreate"); + cy.get(VARIANTS_SELECTORS.saveButton).click(); + cy.wait("@VariantCreate"); } } export default VariantsSteps; diff --git a/cypress/support/index.js b/cypress/support/index.js index f6115623a..3c72c2f3f 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -37,7 +37,6 @@ Cypress.Commands.add("waitForGraph", operationName => { } } }); - cy.wait(`@${operationName}`); }); Cypress.Commands.add("sendRequestWithQuery", query => diff --git a/cypress/utils/productsUtils.js b/cypress/utils/productsUtils.js index c1c633bd1..94948cdb5 100644 --- a/cypress/utils/productsUtils.js +++ b/cypress/utils/productsUtils.js @@ -19,7 +19,7 @@ class ProductsUtils { name, productTypeId, categoryId - ).then(() => this.createVariant(this.product.id, name)); + ).then(() => this.createVariant(this.product.id, name, attributeId)); } createProductInChannel(