test for create variant

This commit is contained in:
Karolina Rakoczy 2021-02-09 14:06:10 +01:00
parent 2a9e420420
commit 1664bad52a
4 changed files with 103 additions and 2 deletions

View file

@ -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']"
};

View file

@ -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']"
};

View file

@ -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";
// <reference types="cypress" />
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);
});
});
});
});
});

View file

@ -1,4 +1,4 @@
export const URL_LIST = {
export const urlList = {
dashbord: "/",
channels: "/channels/",
products: "/products/",