tests for variants
This commit is contained in:
parent
5f413d16fc
commit
03c6149f6f
8 changed files with 87 additions and 71 deletions
|
@ -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
|
||||
|
|
|
@ -20,6 +20,7 @@ class Warehouse {
|
|||
}
|
||||
warehouse{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}`;
|
||||
|
|
|
@ -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']"
|
||||
};
|
||||
|
|
|
@ -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']",
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -37,7 +37,6 @@ Cypress.Commands.add("waitForGraph", operationName => {
|
|||
}
|
||||
}
|
||||
});
|
||||
cy.wait(`@${operationName}`);
|
||||
});
|
||||
|
||||
Cypress.Commands.add("sendRequestWithQuery", query =>
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue