tests for variants

This commit is contained in:
Karolina Rakoczy 2021-02-19 09:45:34 +01:00
parent 5f413d16fc
commit 03c6149f6f
8 changed files with 87 additions and 71 deletions

View file

@ -46,7 +46,7 @@ class Product {
} }
} }
}`; }`;
cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
updateChannelPriceInVariant(variantId, channelId) { updateChannelPriceInVariant(variantId, channelId) {
@ -135,6 +135,7 @@ class Product {
slug: "${slug}" slug: "${slug}"
isShippingRequired: true isShippingRequired: true
productAttributes: "${attributeId}" productAttributes: "${attributeId}"
variantAttributes: "${attributeId}"
}){ }){
productErrors{ productErrors{
field field

View file

@ -20,6 +20,7 @@ class Warehouse {
} }
warehouse{ warehouse{
id id
name
} }
} }
}`; }`;

View file

@ -24,12 +24,11 @@ export const PRODUCTS_SELECTORS = {
goBackButton: "[data-test-id='app-header-back-button']", goBackButton: "[data-test-id='app-header-back-button']",
assignedChannels: "[data-test='channel-availability-item']", assignedChannels: "[data-test='channel-availability-item']",
publishedRadioButton: "[role=radiogroup]", publishedRadioButton: "[role=radiogroup]",
visibleInListingsButton: "[class*='MuiFormControlLabel']",
addVariantsButton: "[data-test*='button-add-variant']", addVariantsButton: "[data-test*='button-add-variant']",
publishedRadioButtons: "[name*='isPublished']", publishedRadioButtons: "[name*='isPublished']",
availableForPurchaseRadioButtons: "[name*='isAvailableForPurchase']", availableForPurchaseRadioButtons: "[name*='isAvailableForPurchase']",
radioButtonsValueTrue: "[value='true']", radioButtonsValueTrue: "[value='true']",
radioButtonsValueFalse: "[value='false']", radioButtonsValueFalse: "[value='false']",
visibleInListingButton: "[name*='visibleInListings']", visibleInListingsButton: "[name*='visibleInListings']",
emptyProductRow: "[class*='Skeleton']" emptyProductRow: "[class*='Skeleton']"
}; };

View file

@ -2,6 +2,7 @@ export const VARIANTS_SELECTORS = {
attributeCheckbox: "[name*='value:']", attributeCheckbox: "[name*='value:']",
nextButton: "[class*='MuiButton-containedPrimary']", nextButton: "[class*='MuiButton-containedPrimary']",
priceInput: "[name*='channel-price']", priceInput: "[name*='channel-price']",
costPriceInput: "[name*='channel-costPrice']",
warehouseCheckboxes: "[name*='warehouse:']", warehouseCheckboxes: "[name*='warehouse:']",
skuInput: "input[class*='MuiInputBase'][type='text']", skuInput: "input[class*='MuiInputBase'][type='text']",
attributeSelector: "[data-test='attribute-value']", attributeSelector: "[data-test='attribute-value']",

View file

@ -2,10 +2,10 @@ import faker from "faker";
import { visit } from "graphql"; import { visit } from "graphql";
import Channels from "../apiRequests/Channels"; import Channels from "../apiRequests/Channels";
import ProductDetails from "../apiRequests/frontShop/ProductDetails";
import Product from "../apiRequests/Product"; import Product from "../apiRequests/Product";
import ShopInfo from "../apiRequests/ShopInfo";
import VariantsSteps from "../steps/products/VariantsSteps"; import VariantsSteps from "../steps/products/VariantsSteps";
import { urlList } from "../url/url-list"; import { urlList } from "../url/urlList";
import ChannelsUtils from "../utils/channelsUtils"; import ChannelsUtils from "../utils/channelsUtils";
import ProductsUtils from "../utils/productsUtils"; import ProductsUtils from "../utils/productsUtils";
import ShippingUtils from "../utils/shippingUtils"; import ShippingUtils from "../utils/shippingUtils";
@ -18,8 +18,8 @@ describe("creating variants", () => {
const channelsUtils = new ChannelsUtils(); const channelsUtils = new ChannelsUtils();
const shippingUtils = new ShippingUtils(); const shippingUtils = new ShippingUtils();
const product = new Product(); const product = new Product();
const shopInfo = new ShopInfo();
const channels = new Channels(); const channels = new Channels();
const productDetails = new ProductDetails();
const variantsSteps = new VariantsSteps(); const variantsSteps = new VariantsSteps();
@ -32,7 +32,7 @@ describe("creating variants", () => {
before(() => { before(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
shippingUtils.deleteShipping(startsWith); shippingUtils.deleteShipping(startsWith);
productUtils.deleteProducts(startsWith); productUtils.deleteProperProducts(startsWith);
const name = `${startsWith}${faker.random.number()}`; const name = `${startsWith}${faker.random.number()}`;
channelsUtils channelsUtils
@ -43,7 +43,7 @@ describe("creating variants", () => {
}) })
.then(fixtureAddresses => .then(fixtureAddresses =>
shippingUtils.createShipping( shippingUtils.createShipping(
channel.id, defaultChannel.id,
name, name,
fixtureAddresses.plAddress, fixtureAddresses.plAddress,
10 10
@ -60,14 +60,11 @@ describe("creating variants", () => {
beforeEach(() => { beforeEach(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
shopInfo
.getShopInfo()
.its("body.data.shop.domain.url")
.as("shopUrl");
}); });
it("should create variant visible on frontend", () => { it("should create variant visible on frontend", () => {
const name = `${startsWith}${faker.random.number()}`; const name = `${startsWith}${faker.random.number()}`;
const price = 10;
let createdProduct; let createdProduct;
product product
@ -81,41 +78,47 @@ describe("creating variants", () => {
true, true,
true true
); );
cy.visit(`${urlList.products}${productId}`); cy.visit(`${urlList.products}${createdProduct.id}`);
variantsSteps.createFirstVariant(warehouse.id); variantsSteps.createFirstVariant(name, warehouse.id, price);
cy.getProductDetails(product.id, defaultChannel.slug).then( productDetails
productDetailsResp => { .getProductDetails(createdProduct.id, defaultChannel.slug)
.then(productDetailsResp => {
expect(productDetailsResp.body[0].data.product.name).to.equal(name); expect(productDetailsResp.body[0].data.product.name).to.equal(name);
expect( expect(
productDetailsResp.body[0].data.product.variants[0].pricing.price productDetailsResp.body[0].data.product.variants[0].pricing.price
.gross.amount .gross.amount
).to.equal(10); ).to.equal(price);
} });
);
}); });
}); });
it("should create several variants", () => { it("should create several variants", () => {
const name = `${startsWith}${faker.random.number()}`; const name = `${startsWith}${faker.random.number()}`;
const secondVariantSku = `${startsWith}${faker.random.number()}`; const secondVariantSku = `${startsWith}${faker.random.number()}`;
const variantsPrice = 5;
let createdProduct;
productUtils productUtils
.createProductInChannel( .createProductInChannel(
name, name,
defaultChannel.id,
warehouse.id,
1,
productType.id, productType.id,
attribute.id, attribute.id,
category.id, category.id,
defaultChannel.id, variantsPrice
true,
true,
true,
warehouse.id,
10,
10
) )
.then(() => { .then(() => {
cy.visit(`${urlList.products}${productId}`); createdProduct = productUtils.getCreatedProduct();
variantsSteps.createVariant(secondVariantSku, warehouse.name); 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 => { .then(productDetailsResp => {
expect(productDetailsResp.body[0].data.product.name).to.equal(name); expect(productDetailsResp.body[0].data.product.name).to.equal(name);
expect(productDetailsResp.body[0].data.product.variants).to.have.length( expect(productDetailsResp.body[0].data.product.variants).to.have.length(
@ -124,24 +127,30 @@ describe("creating variants", () => {
expect( expect(
productDetailsResp.body[0].data.product.variants[0].pricing.price productDetailsResp.body[0].data.product.variants[0].pricing.price
.gross.amount .gross.amount
).to.equal(10); ).to.equal(variantsPrice);
expect( expect(
productDetailsResp.body[0].data.product.variants[1].pricing.price productDetailsResp.body[0].data.product.variants[1].pricing.price
.gross.amount .gross.amount
).to.equal(10); ).to.equal(variantsPrice);
}); });
}); });
it("should create variant for many channels", () => { it("should create variant for many channels", () => {
const name = `${startsWith}${faker.random.number()}`; const name = `${startsWith}${faker.random.number()}`;
let newChannel; let newChannel;
let createdProduct;
channels channels
.createChannel(true, name, name, "PLN") .createChannel(true, name, name, "PLN")
.then(resp => { .then(resp => {
newChannel = resp.body.data.createdChannel.channel; newChannel = resp.body.data.channelCreate.channel;
product.createProduct(attribute.id, name, productType.id, category.id); productUtils.createProduct(
attribute.id,
name,
productType.id,
category.id
);
}) })
.then(resp => { .then(() => {
const createdProduct = resp.body.data.productCreate.product; createdProduct = productUtils.getCreatedProduct();
product.updateChannelInProduct( product.updateChannelInProduct(
createdProduct.id, createdProduct.id,
defaultChannel.id, defaultChannel.id,
@ -149,6 +158,8 @@ describe("creating variants", () => {
true, true,
true true
); );
})
.then(() => {
product.updateChannelInProduct( product.updateChannelInProduct(
createdProduct.id, createdProduct.id,
newChannel.id, newChannel.id,
@ -156,26 +167,28 @@ describe("creating variants", () => {
true, true,
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);
}
);
}); });
}); });

View file

@ -1,6 +1,7 @@
import { PRODUCTS_SELECTORS } from "../../elements/catalog/product-selectors";
import { VARIANTS_SELECTORS } from "../../elements/catalog/variants-selectors"; import { VARIANTS_SELECTORS } from "../../elements/catalog/variants-selectors";
class VariantsSteps { class VariantsSteps {
createFirstVariant(sku, warehouseId) { createFirstVariant(sku, warehouseId, price) {
cy.get(PRODUCTS_SELECTORS.addVariantsButton) cy.get(PRODUCTS_SELECTORS.addVariantsButton)
.click() .click()
.get(VARIANTS_SELECTORS.attributeCheckbox) .get(VARIANTS_SELECTORS.attributeCheckbox)
@ -9,18 +10,18 @@ class VariantsSteps {
.get(VARIANTS_SELECTORS.nextButton) .get(VARIANTS_SELECTORS.nextButton)
.click() .click()
.get(VARIANTS_SELECTORS.priceInput) .get(VARIANTS_SELECTORS.priceInput)
.type(10) .forEach(priceInput => cy.priceInput.type(price));
.get(`[name*='${warehouseId}']`) cy.get(`[name*='${warehouseId}']`)
.click() .click()
.get(VARIANTS_SELECTORS.nextButton) .get(VARIANTS_SELECTORS.nextButton)
.click() .click()
.get(VARIANTS_SELECTORS.skuInput) .get(VARIANTS_SELECTORS.skuInput)
.type(sku) .type(sku);
.get(VARIANTS_SELECTORS.nextButton) cy.waitForGraph("ProductVariantBulkCreate");
.click() cy.get(VARIANTS_SELECTORS.nextButton).click();
.waitForGraph("ProductVariantBulkCreate"); cy.wait("@ProductVariantBulkCreate");
} }
createVariant(sku, warehouseName) { createVariant(sku, warehouseName, price, costPrice = price) {
cy.get(PRODUCTS_SELECTORS.addVariantsButton) cy.get(PRODUCTS_SELECTORS.addVariantsButton)
.click() .click()
.get(VARIANTS_SELECTORS.attributeSelector) .get(VARIANTS_SELECTORS.attributeSelector)
@ -29,16 +30,17 @@ class VariantsSteps {
.first() .first()
.click() .click()
.get(VARIANTS_SELECTORS.priceInput) .get(VARIANTS_SELECTORS.priceInput)
.type(10) .type(price)
.get(VARIANTS_SELECTORS.costPriceInput)
.type(costPrice)
.get(VARIANTS_SELECTORS.skuInputInAddVariant) .get(VARIANTS_SELECTORS.skuInputInAddVariant)
.type(sku) .type(sku)
.get(VARIANTS_SELECTORS.addWarehouseButton) .get(VARIANTS_SELECTORS.addWarehouseButton)
.click()
.get(VARIANTS_SELECTORS.warehouseOption)
.contains(warehouseName)
.click()
.get(VARIANTS_SELECTORS.saveButton)
.click(); .click();
cy.contains(VARIANTS_SELECTORS.warehouseOption, warehouseName).click();
cy.waitForGraph("VariantCreate");
cy.get(VARIANTS_SELECTORS.saveButton).click();
cy.wait("@VariantCreate");
} }
} }
export default VariantsSteps; export default VariantsSteps;

View file

@ -37,7 +37,6 @@ Cypress.Commands.add("waitForGraph", operationName => {
} }
} }
}); });
cy.wait(`@${operationName}`);
}); });
Cypress.Commands.add("sendRequestWithQuery", query => Cypress.Commands.add("sendRequestWithQuery", query =>

View file

@ -19,7 +19,7 @@ class ProductsUtils {
name, name,
productTypeId, productTypeId,
categoryId categoryId
).then(() => this.createVariant(this.product.id, name)); ).then(() => this.createVariant(this.product.id, name, attributeId));
} }
createProductInChannel( createProductInChannel(