Duplicate current test for sales to work on variants instead on products (#1491)
* Duplicate current test for sales to work on variants instead on products * remove unecessery imports * Update cypress/integration/discounts/salesForVariants.js Co-authored-by: Ewa Czerniak <ewa.czerniak@saleor.io> Co-authored-by: Ewa Czerniak <ewa.czerniak@saleor.io>
This commit is contained in:
parent
29a90f3e3d
commit
cc7626be42
7 changed files with 281 additions and 67 deletions
|
@ -7,5 +7,7 @@ export const SALES_SELECTORS = {
|
|||
startDateInput: "[name='startDate']",
|
||||
saveButton: "[data-test='button-bar-confirm']",
|
||||
productsTab: "[data-test-id='products-tab']",
|
||||
assignProducts: "[data-test-id='assign-products']"
|
||||
variantsTab: "[data-test-id='variants-tab']",
|
||||
assignProducts: "[data-test-id='assign-products']",
|
||||
assignVariants: "[data-test-id='assign-variant']"
|
||||
};
|
||||
|
|
|
@ -2,6 +2,7 @@ export const ASSIGN_ELEMENTS_SELECTORS = {
|
|||
searchInput: "[name='query']",
|
||||
tableRow: "[class*='MuiTableRow']",
|
||||
productTableRow: "[data-test-id='assign-product-table-row']",
|
||||
variantTableRow: "[data-test-id='assign-variant-table-row']",
|
||||
checkbox: "[type='checkbox']",
|
||||
submitButton: "[type='submit']",
|
||||
dialogContent: '[data-test-id="searchQuery"]'
|
||||
|
|
|
@ -18,11 +18,12 @@ import filterTests from "../../support/filterTests";
|
|||
import {
|
||||
assignProducts,
|
||||
createSale,
|
||||
createSaleWithNewProduct,
|
||||
discountOptions
|
||||
} from "../../support/pages/discounts/salesPage";
|
||||
|
||||
filterTests({ definedTags: ["all"] }, () => {
|
||||
describe("Sales discounts", () => {
|
||||
describe("Sales discounts for products", () => {
|
||||
const startsWith = "CySales-";
|
||||
|
||||
let productType;
|
||||
|
@ -80,38 +81,20 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
const discountValue = 50;
|
||||
const productPrice = 100;
|
||||
|
||||
productsUtils
|
||||
.createProductInChannel({
|
||||
name: saleName,
|
||||
channelId: defaultChannel.id,
|
||||
warehouseId: warehouse.id,
|
||||
productTypeId: productType.id,
|
||||
attributeId: attribute.id,
|
||||
categoryId: category.id,
|
||||
price: productPrice
|
||||
})
|
||||
.then(({ product: productResp }) => {
|
||||
/* Uncomment after fixing SALEOR-3367 bug
|
||||
cy.clearSessionData()
|
||||
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
|
||||
*/
|
||||
|
||||
cy.visit(urlList.sales);
|
||||
cy.softExpectSkeletonIsVisible();
|
||||
const product = productResp;
|
||||
createSale({
|
||||
saleName,
|
||||
channelName: defaultChannel.name,
|
||||
discountValue,
|
||||
discountOption: discountOptions.PERCENTAGE
|
||||
});
|
||||
assignProducts(product.name);
|
||||
getProductPrice(product.id, defaultChannel.slug);
|
||||
})
|
||||
.then(price => {
|
||||
const expectedPrice = (productPrice * discountValue) / 100;
|
||||
expect(expectedPrice).to.be.eq(price);
|
||||
});
|
||||
createSaleWithNewProduct({
|
||||
name: saleName,
|
||||
channel: defaultChannel,
|
||||
warehouseId: warehouse.id,
|
||||
productTypeId: productType.id,
|
||||
attributeId: attribute.id,
|
||||
categoryId: category.id,
|
||||
price: productPrice,
|
||||
discountOption: discountOptions.PERCENTAGE,
|
||||
discountValue
|
||||
}).then(price => {
|
||||
const expectedPrice = (productPrice * discountValue) / 100;
|
||||
expect(expectedPrice).to.be.eq(price);
|
||||
});
|
||||
});
|
||||
|
||||
it("should create fixed price discount", () => {
|
||||
|
@ -119,38 +102,20 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
const discountValue = 50;
|
||||
const productPrice = 100;
|
||||
|
||||
productsUtils
|
||||
.createProductInChannel({
|
||||
name: saleName,
|
||||
channelId: defaultChannel.id,
|
||||
warehouseId: warehouse.id,
|
||||
productTypeId: productType.id,
|
||||
attributeId: attribute.id,
|
||||
categoryId: category.id,
|
||||
price: productPrice
|
||||
})
|
||||
.then(({ product: productResp }) => {
|
||||
/* Uncomment after fixing SALEOR-3367 bug
|
||||
cy.clearSessionData()
|
||||
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
|
||||
*/
|
||||
|
||||
cy.visit(urlList.sales);
|
||||
cy.softExpectSkeletonIsVisible();
|
||||
const product = productResp;
|
||||
createSale({
|
||||
saleName,
|
||||
channelName: defaultChannel.name,
|
||||
discountValue,
|
||||
discountOption: discountOptions.FIXED
|
||||
});
|
||||
assignProducts(product.name);
|
||||
getProductPrice(product.id, defaultChannel.slug);
|
||||
})
|
||||
.then(price => {
|
||||
const expectedPrice = productPrice - discountValue;
|
||||
expect(expectedPrice).to.be.eq(price);
|
||||
});
|
||||
createSaleWithNewProduct({
|
||||
name: saleName,
|
||||
channel: defaultChannel,
|
||||
warehouseId: warehouse.id,
|
||||
productTypeId: productType.id,
|
||||
attributeId: attribute.id,
|
||||
categoryId: category.id,
|
||||
price: productPrice,
|
||||
discountOption: discountOptions.FIXED,
|
||||
discountValue
|
||||
}).then(price => {
|
||||
const expectedPrice = productPrice - discountValue;
|
||||
expect(expectedPrice).to.be.eq(price);
|
||||
});
|
||||
});
|
||||
|
||||
it("should not displayed discount not assign to channel", () => {
|
116
cypress/integration/discounts/salesForVariants.js
Normal file
116
cypress/integration/discounts/salesForVariants.js
Normal file
|
@ -0,0 +1,116 @@
|
|||
/// <reference types="cypress"/>
|
||||
/// <reference types="../../support"/>
|
||||
|
||||
import faker from "faker";
|
||||
|
||||
import * as channelsUtils from "../../support/api/utils/channelsUtils";
|
||||
import { deleteSalesStartsWith } from "../../support/api/utils/discounts/salesUtils";
|
||||
import * as productsUtils from "../../support/api/utils/products/productsUtils";
|
||||
import {
|
||||
createShipping,
|
||||
deleteShippingStartsWith
|
||||
} from "../../support/api/utils/shippingUtils";
|
||||
import filterTests from "../../support/filterTests";
|
||||
import {
|
||||
createSaleWithNewVariant,
|
||||
discountOptions
|
||||
} from "../../support/pages/discounts/salesPage";
|
||||
|
||||
filterTests({ definedTags: ["all"] }, () => {
|
||||
describe("Sales discounts for variant", () => {
|
||||
const startsWith = "CySales-";
|
||||
|
||||
let productType;
|
||||
let attribute;
|
||||
let category;
|
||||
let defaultChannel;
|
||||
let warehouse;
|
||||
|
||||
before(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
deleteSalesStartsWith(startsWith);
|
||||
productsUtils.deleteProductsStartsWith(startsWith);
|
||||
deleteShippingStartsWith(startsWith);
|
||||
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
productsUtils
|
||||
.createTypeAttributeAndCategoryForProduct({ name })
|
||||
.then(
|
||||
({
|
||||
productType: productTypeResp,
|
||||
attribute: attributeResp,
|
||||
category: categoryResp
|
||||
}) => {
|
||||
productType = productTypeResp;
|
||||
attribute = attributeResp;
|
||||
category = categoryResp;
|
||||
|
||||
channelsUtils.getDefaultChannel();
|
||||
}
|
||||
)
|
||||
.then(channel => {
|
||||
defaultChannel = channel;
|
||||
cy.fixture("addresses");
|
||||
})
|
||||
.then(addresses => {
|
||||
createShipping({
|
||||
channelId: defaultChannel.id,
|
||||
name,
|
||||
address: addresses.plAddress,
|
||||
price: 100
|
||||
});
|
||||
})
|
||||
.then(({ warehouse: warehouseResp }) => {
|
||||
warehouse = warehouseResp;
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
});
|
||||
|
||||
it("should create percentage discount", () => {
|
||||
const saleName = `${startsWith}${faker.datatype.number()}`;
|
||||
const discountValue = 50;
|
||||
const productPrice = 100;
|
||||
|
||||
createSaleWithNewVariant({
|
||||
name: saleName,
|
||||
channel: defaultChannel,
|
||||
warehouseId: warehouse.id,
|
||||
productTypeId: productType.id,
|
||||
attributeId: attribute.id,
|
||||
categoryId: category.id,
|
||||
price: productPrice,
|
||||
discountOption: discountOptions.PERCENTAGE,
|
||||
discountValue
|
||||
}).then(({ pricing }) => {
|
||||
const priceInResponse = pricing.price.gross.amount;
|
||||
const expectedPrice = (productPrice * discountValue) / 100;
|
||||
expect(expectedPrice).to.be.eq(priceInResponse);
|
||||
});
|
||||
});
|
||||
|
||||
it("should create fixed price discount", () => {
|
||||
const saleName = `${startsWith}${faker.datatype.number()}`;
|
||||
const discountValue = 50;
|
||||
const productPrice = 100;
|
||||
|
||||
createSaleWithNewVariant({
|
||||
name: saleName,
|
||||
channel: defaultChannel,
|
||||
warehouseId: warehouse.id,
|
||||
productTypeId: productType.id,
|
||||
attributeId: attribute.id,
|
||||
categoryId: category.id,
|
||||
price: productPrice,
|
||||
discountOption: discountOptions.FIXED,
|
||||
discountValue
|
||||
}).then(({ pricing }) => {
|
||||
const priceInResponse = pricing.price.gross.amount;
|
||||
const expectedPrice = productPrice - discountValue;
|
||||
expect(expectedPrice).to.be.eq(priceInResponse);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -225,3 +225,31 @@ export function getVariants(variantsList) {
|
|||
}`;
|
||||
return cy.sendRequestWithQuery(query).its("body.data.productVariants");
|
||||
}
|
||||
|
||||
export function getVariant(id, channel, auth = "auth") {
|
||||
const query = `query{
|
||||
productVariant(id:"${id}" channel:"${channel}"){
|
||||
id
|
||||
name
|
||||
pricing{
|
||||
onSale
|
||||
discount{
|
||||
gross{
|
||||
amount
|
||||
}
|
||||
}
|
||||
price{
|
||||
gross{
|
||||
amount
|
||||
}
|
||||
}
|
||||
priceUndiscounted{
|
||||
gross{
|
||||
amount
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(query, auth).its("body.data.productVariant");
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
import { SALES_SELECTORS } from "../../../elements/discounts/sales";
|
||||
import { ASSIGN_ELEMENTS_SELECTORS } from "../../../elements/shared/assign-elements-selectors";
|
||||
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
|
||||
import { urlList } from "../../../fixtures/urlList";
|
||||
import { formatDate } from "../../../support/formatData/formatDate";
|
||||
import { getVariant } from "../../api/requests/Product";
|
||||
import { createProductInChannel } from "../../api/utils/products/productsUtils";
|
||||
import { getProductPrice } from "../../api/utils/storeFront/storeFrontProductUtils";
|
||||
import { selectChannelInDetailsPages } from "../channelsPage";
|
||||
|
||||
export const discountOptions = {
|
||||
|
@ -51,3 +55,98 @@ export function assignProducts(productName) {
|
|||
cy.get(BUTTON_SELECTORS.submit).click();
|
||||
cy.waitForRequestAndCheckIfNoErrors("@SaleCataloguesAdd");
|
||||
}
|
||||
|
||||
export function assignVariants(productName, variantName) {
|
||||
cy.waitForProgressBarToNotBeVisible()
|
||||
.get(SALES_SELECTORS.variantsTab)
|
||||
.click()
|
||||
.get(SALES_SELECTORS.assignVariants)
|
||||
.click()
|
||||
.get(ASSIGN_ELEMENTS_SELECTORS.searchInput)
|
||||
.type(productName)
|
||||
.get(ASSIGN_ELEMENTS_SELECTORS.variantTableRow)
|
||||
.should("have.length", 1);
|
||||
cy.contains(ASSIGN_ELEMENTS_SELECTORS.variantTableRow, variantName)
|
||||
.find(ASSIGN_ELEMENTS_SELECTORS.checkbox)
|
||||
.click();
|
||||
cy.addAliasToGraphRequest("SaleCataloguesAdd");
|
||||
cy.get(BUTTON_SELECTORS.submit).click();
|
||||
cy.waitForRequestAndCheckIfNoErrors("@SaleCataloguesAdd");
|
||||
}
|
||||
|
||||
export function createSaleWithNewProduct({
|
||||
name,
|
||||
channel,
|
||||
warehouseId,
|
||||
productTypeId,
|
||||
attributeId,
|
||||
categoryId,
|
||||
price,
|
||||
discountOption,
|
||||
discountValue
|
||||
}) {
|
||||
return createProductInChannel({
|
||||
name,
|
||||
channelId: channel.id,
|
||||
warehouseId,
|
||||
productTypeId,
|
||||
attributeId,
|
||||
categoryId,
|
||||
price
|
||||
}).then(({ product: productResp }) => {
|
||||
/* Uncomment after fixing SALEOR-3367 bug
|
||||
cy.clearSessionData()
|
||||
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
|
||||
*/
|
||||
|
||||
cy.visit(urlList.sales);
|
||||
cy.softExpectSkeletonIsVisible();
|
||||
const product = productResp;
|
||||
createSale({
|
||||
saleName: name,
|
||||
channelName: channel.name,
|
||||
discountValue,
|
||||
discountOption
|
||||
});
|
||||
assignProducts(product.name);
|
||||
return getProductPrice(product.id, channel.slug);
|
||||
});
|
||||
}
|
||||
|
||||
export function createSaleWithNewVariant({
|
||||
name,
|
||||
channel,
|
||||
warehouseId,
|
||||
productTypeId,
|
||||
attributeId,
|
||||
categoryId,
|
||||
price,
|
||||
discountValue,
|
||||
discountOption
|
||||
}) {
|
||||
return createProductInChannel({
|
||||
name,
|
||||
channelId: channel.id,
|
||||
warehouseId,
|
||||
productTypeId,
|
||||
attributeId,
|
||||
categoryId,
|
||||
price
|
||||
}).then(({ variantsList: variantsListResp, product }) => {
|
||||
/* Uncomment after fixing SALEOR-3367 bug
|
||||
cy.clearSessionData()
|
||||
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
|
||||
*/
|
||||
cy.visit(urlList.sales);
|
||||
cy.softExpectSkeletonIsVisible();
|
||||
const variant = variantsListResp[0];
|
||||
createSale({
|
||||
saleName: name,
|
||||
channelName: channel.name,
|
||||
discountValue,
|
||||
discountOption
|
||||
});
|
||||
assignVariants(product.name, variant.name);
|
||||
return getVariant(variant.id, channel.slug, "token");
|
||||
});
|
||||
}
|
||||
|
|
|
@ -220,7 +220,10 @@ const AssignVariantDialog: React.FC<AssignVariantDialogProps> = props => {
|
|||
</TableRow>
|
||||
{maybe(() => product.variants, []).map(
|
||||
(variant, variantIndex) => (
|
||||
<TableRow key={variant.id}>
|
||||
<TableRow
|
||||
key={variant.id}
|
||||
data-test-id="assign-variant-table-row"
|
||||
>
|
||||
<TableCell />
|
||||
<TableCell className={classes.colVariantCheckbox}>
|
||||
<Checkbox
|
||||
|
|
Loading…
Reference in a new issue