Saleor 1745 tests for discounts sales (#998)
* test plan for sales - discounts * create sale * passing tests for sales * tests for collections * remove eslint diable in sales tests * remove eslint-disable * move shared selectors * move shared selectors * fix indentation in requests * add formatDate function * remove moment * remove moment
This commit is contained in:
parent
fc597a7a7f
commit
746ce8b95f
31 changed files with 864 additions and 522 deletions
|
@ -28,8 +28,7 @@ export function getChannels() {
|
||||||
slug
|
slug
|
||||||
currencyCode
|
currencyCode
|
||||||
}
|
}
|
||||||
}
|
}`;
|
||||||
`;
|
|
||||||
return cy.sendRequestWithQuery(getChannelsInfoQuery);
|
return cy.sendRequestWithQuery(getChannelsInfoQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,7 @@ export function createCustomer(email, customerName, address, isActive = false) {
|
||||||
message
|
message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}`;
|
||||||
`;
|
|
||||||
return cy.sendRequestWithQuery(mutation);
|
return cy.sendRequestWithQuery(mutation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +75,6 @@ export function getCustomers(startsWith) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}`;
|
||||||
`;
|
|
||||||
return cy.sendRequestWithQuery(query);
|
return cy.sendRequestWithQuery(query);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,7 @@ export function addProductToOrder(orderId, variantId, quantity = 1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createDraftOrder(customerId, shippingMethodId, channelId) {
|
export function createDraftOrder(customerId, shippingMethodId, channelId) {
|
||||||
const mutation = `
|
const mutation = `mutation{
|
||||||
mutation{
|
|
||||||
draftOrderCreate(input:{
|
draftOrderCreate(input:{
|
||||||
user:"${customerId}"
|
user:"${customerId}"
|
||||||
shippingMethod:"${shippingMethodId}"
|
shippingMethod:"${shippingMethodId}"
|
||||||
|
@ -38,8 +37,7 @@ export function createDraftOrder(customerId, shippingMethodId, channelId) {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}`;
|
||||||
`;
|
|
||||||
return cy.sendRequestWithQuery(mutation);
|
return cy.sendRequestWithQuery(mutation);
|
||||||
}
|
}
|
||||||
export function completeOrder(orderId) {
|
export function completeOrder(orderId) {
|
||||||
|
|
|
@ -17,8 +17,7 @@ export function getFirstProducts(first, search) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}`;
|
||||||
`;
|
|
||||||
return cy
|
return cy
|
||||||
.sendRequestWithQuery(query)
|
.sendRequestWithQuery(query)
|
||||||
.then(resp => resp.body.data.products.edges);
|
.then(resp => resp.body.data.products.edges);
|
||||||
|
@ -61,7 +60,7 @@ export function updateChannelPriceInVariant(variantId, channelId) {
|
||||||
message
|
message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} `;
|
} `;
|
||||||
return cy.sendRequestWithQuery(mutation);
|
return cy.sendRequestWithQuery(mutation);
|
||||||
}
|
}
|
||||||
export function createProduct(attributeId, name, productType, category) {
|
export function createProduct(attributeId, name, productType, category) {
|
||||||
|
@ -76,6 +75,7 @@ export function createProduct(attributeId, name, productType, category) {
|
||||||
}){
|
}){
|
||||||
product{
|
product{
|
||||||
id
|
id
|
||||||
|
name
|
||||||
}
|
}
|
||||||
productErrors{
|
productErrors{
|
||||||
field
|
field
|
||||||
|
@ -149,7 +149,7 @@ export function createTypeProduct(name, attributeId, slug = name) {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} `;
|
} `;
|
||||||
return cy.sendRequestWithQuery(mutation);
|
return cy.sendRequestWithQuery(mutation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ export function deleteProduct(productId) {
|
||||||
message
|
message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} `;
|
} `;
|
||||||
return cy.sendRequestWithQuery(mutation);
|
return cy.sendRequestWithQuery(mutation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
35
cypress/apiRequests/Sales.js
Normal file
35
cypress/apiRequests/Sales.js
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import { getValueWithDefault } from "./utils/Utils";
|
||||||
|
|
||||||
|
export function getSales(first, searchQuery) {
|
||||||
|
const filter = getValueWithDefault(
|
||||||
|
searchQuery,
|
||||||
|
`, filter:{
|
||||||
|
search:"${searchQuery}"
|
||||||
|
}`
|
||||||
|
);
|
||||||
|
const query = `query{
|
||||||
|
sales(first:
|
||||||
|
${first} ${filter}){
|
||||||
|
edges{
|
||||||
|
node{
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy
|
||||||
|
.sendRequestWithQuery(query)
|
||||||
|
.then(resp => resp.body.data.sales.edges);
|
||||||
|
}
|
||||||
|
export function deleteSale(saleId) {
|
||||||
|
const mutation = `mutation{
|
||||||
|
saleDelete(id:"${saleId}"){
|
||||||
|
discountErrors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
export function createShippingRate(name, shippingZone) {
|
export function createShippingRate(name, shippingZone) {
|
||||||
const mutation = `
|
const mutation = `mutation{
|
||||||
mutation{
|
|
||||||
shippingPriceCreate(input:{
|
shippingPriceCreate(input:{
|
||||||
name: "${name}"
|
name: "${name}"
|
||||||
shippingZone: "${shippingZone}"
|
shippingZone: "${shippingZone}"
|
||||||
|
@ -10,14 +9,12 @@ export function createShippingRate(name, shippingZone) {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}`;
|
||||||
`;
|
|
||||||
return cy.sendRequestWithQuery(mutation);
|
return cy.sendRequestWithQuery(mutation);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createShippingZone(name, country) {
|
export function createShippingZone(name, country) {
|
||||||
const mutation = `
|
const mutation = `mutation{
|
||||||
mutation{
|
|
||||||
shippingZoneCreate(input:{
|
shippingZoneCreate(input:{
|
||||||
name: "${name}"
|
name: "${name}"
|
||||||
countries: "${country}"
|
countries: "${country}"
|
||||||
|
@ -26,14 +23,12 @@ export function createShippingZone(name, country) {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}`;
|
||||||
`;
|
|
||||||
return cy.sendRequestWithQuery(mutation);
|
return cy.sendRequestWithQuery(mutation);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addChannelToShippingMethod(shippingRateId, channelId, price) {
|
export function addChannelToShippingMethod(shippingRateId, channelId, price) {
|
||||||
const mutation = `
|
const mutation = `mutation{
|
||||||
mutation{
|
|
||||||
shippingMethodChannelListingUpdate(id:"${shippingRateId}", input:{
|
shippingMethodChannelListingUpdate(id:"${shippingRateId}", input:{
|
||||||
addChannels: {
|
addChannels: {
|
||||||
channelId:"${channelId}"
|
channelId:"${channelId}"
|
||||||
|
@ -48,8 +43,7 @@ export function addChannelToShippingMethod(shippingRateId, channelId, price) {
|
||||||
message
|
message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}`;
|
||||||
`;
|
|
||||||
return cy.sendRequestWithQuery(mutation);
|
return cy.sendRequestWithQuery(mutation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,8 @@ export function searchInShop(searchQuery) {
|
||||||
const query = `query SearchProducts {
|
const query = `query SearchProducts {
|
||||||
products(channel: "default-channel", filter:{
|
products(channel: "default-channel", filter:{
|
||||||
search: "${searchQuery}"
|
search: "${searchQuery}"
|
||||||
}, first:10){
|
},
|
||||||
|
first:10){
|
||||||
totalCount
|
totalCount
|
||||||
edges{
|
edges{
|
||||||
node{
|
node{
|
||||||
|
@ -12,6 +13,5 @@ export function searchInShop(searchQuery) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
return cy.sendRequestWithQuery(query, "token");
|
return cy.sendRequestWithQuery(query, "token");
|
||||||
}
|
}
|
||||||
|
|
4
cypress/elements/catalog/assign-products.js
Normal file
4
cypress/elements/catalog/assign-products.js
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
export const ASSIGN_PRODUCTS_SELECTORS = {
|
||||||
|
searchInput: "[name='query']",
|
||||||
|
tableRow: "[data-test-id='assign-product-table-row']"
|
||||||
|
};
|
16
cypress/elements/channels/menage-channel-availability.js
Normal file
16
cypress/elements/channels/menage-channel-availability.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
export const MENAGE_CHANNEL_AVAILABILITY = {
|
||||||
|
availableManageButton:
|
||||||
|
"[data-test-id='channels-availiability-manage-button']",
|
||||||
|
channelsAvailabilityForm:
|
||||||
|
"[data-test-id='manage-products-channels-availiability-list']",
|
||||||
|
channelAvailabilityColumn:
|
||||||
|
"[data-test='availability'][data-test-availability='true']",
|
||||||
|
channelAvailabilityList: "ul[role='menu']",
|
||||||
|
assignedChannels: "[data-test='channel-availability-item']",
|
||||||
|
publishedRadioButtons: "[name*='isPublished']",
|
||||||
|
availableForPurchaseRadioButtons: "[name*='isAvailableForPurchase']",
|
||||||
|
radioButtonsValueTrue: "[value='true']",
|
||||||
|
radioButtonsValueFalse: "[value='false']",
|
||||||
|
visibleInListingsButton: "[name*='visibleInListings']",
|
||||||
|
allChannelsInput: "[name='allChannels']"
|
||||||
|
};
|
11
cypress/elements/discounts/sales.js
Normal file
11
cypress/elements/discounts/sales.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
export const SALES_SELECTORS = {
|
||||||
|
createSaleButton: "[data-test-id='create-sale']",
|
||||||
|
nameInput: "[name='name']",
|
||||||
|
percentageOption: "[value='PERCENTAGE']",
|
||||||
|
fixedOption: "[value='FIXED']",
|
||||||
|
discountValue: "[name='value']",
|
||||||
|
startDateInput: "[name='startDate']",
|
||||||
|
saveButton: "[data-test='button-bar-confirm']",
|
||||||
|
productsTab: "[data-test-id='products-tab']",
|
||||||
|
assignProducts: "[data-test-id='assign-products']"
|
||||||
|
};
|
|
@ -1,4 +1,5 @@
|
||||||
export const BUTTON_SELECTORS = {
|
export const BUTTON_SELECTORS = {
|
||||||
back: '[data-test="back"]',
|
back: '[data-test="back"]',
|
||||||
submit: '[data-test="submit"]'
|
submit: '[data-test="submit"]',
|
||||||
|
checkbox: "[type='checkbox']"
|
||||||
};
|
};
|
||||||
|
|
179
cypress/integration/discounts/sales.js
Normal file
179
cypress/integration/discounts/sales.js
Normal file
|
@ -0,0 +1,179 @@
|
||||||
|
// <reference types="cypress" />
|
||||||
|
|
||||||
|
import faker from "faker";
|
||||||
|
|
||||||
|
import { updateChannelInProduct } from "../../apiRequests/Product";
|
||||||
|
import {
|
||||||
|
assignProducts,
|
||||||
|
createSale,
|
||||||
|
discountOptions
|
||||||
|
} from "../../steps/salesSteps";
|
||||||
|
import { urlList } from "../../url/urlList";
|
||||||
|
import * as channelsUtils from "../../utils/channelsUtils";
|
||||||
|
import * as productsUtils from "../../utils/productsUtils";
|
||||||
|
import { deleteSalesStartsWith } from "../../utils/salesUtils";
|
||||||
|
import {
|
||||||
|
createShipping,
|
||||||
|
deleteShippingStartsWith
|
||||||
|
} from "../../utils/shippingUtils";
|
||||||
|
import { getProductPrice } from "../../utils/storeFront/storeFrontProductUtils";
|
||||||
|
|
||||||
|
describe("Sales discounts", () => {
|
||||||
|
const startsWith = "Cy-";
|
||||||
|
|
||||||
|
let productType;
|
||||||
|
let attribute;
|
||||||
|
let category;
|
||||||
|
let defaultChannel;
|
||||||
|
let warehouse;
|
||||||
|
|
||||||
|
before(() => {
|
||||||
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
|
channelsUtils.deleteChannelsStartsWith(startsWith);
|
||||||
|
deleteSalesStartsWith(startsWith);
|
||||||
|
productsUtils.deleteProductsStartsWith(startsWith);
|
||||||
|
deleteShippingStartsWith(startsWith);
|
||||||
|
|
||||||
|
const name = `${startsWith}${faker.random.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.random.number()}`;
|
||||||
|
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 }) => {
|
||||||
|
cy.visit(urlList.sales);
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should create fixed price discount", () => {
|
||||||
|
const saleName = `${startsWith}${faker.random.number()}`;
|
||||||
|
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 }) => {
|
||||||
|
cy.visit(urlList.sales);
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not displayed discount not assign to channel", () => {
|
||||||
|
const saleName = `${startsWith}${faker.random.number()}`;
|
||||||
|
let channel;
|
||||||
|
let product;
|
||||||
|
const discountValue = 50;
|
||||||
|
const productPrice = 100;
|
||||||
|
|
||||||
|
channelsUtils
|
||||||
|
.createChannel({ name: saleName })
|
||||||
|
.then(channelResp => (channel = channelResp));
|
||||||
|
productsUtils
|
||||||
|
.createProductInChannel({
|
||||||
|
name: saleName,
|
||||||
|
channelId: defaultChannel.id,
|
||||||
|
warehouseId: warehouse.id,
|
||||||
|
productTypeId: productType.id,
|
||||||
|
attributeId: attribute.id,
|
||||||
|
categoryId: category.id,
|
||||||
|
price: productPrice
|
||||||
|
})
|
||||||
|
.then(({ product: productResp }) => {
|
||||||
|
product = productResp;
|
||||||
|
updateChannelInProduct({
|
||||||
|
productId: product.id,
|
||||||
|
channelId: channel.id
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
cy.visit(urlList.sales);
|
||||||
|
createSale({
|
||||||
|
saleName,
|
||||||
|
channelName: channel.name,
|
||||||
|
discountValue
|
||||||
|
});
|
||||||
|
assignProducts(product.name);
|
||||||
|
getProductPrice(product.id, defaultChannel.slug);
|
||||||
|
})
|
||||||
|
.then(price => expect(price).to.equal(productPrice));
|
||||||
|
});
|
||||||
|
});
|
57
cypress/steps/salesSteps.js
Normal file
57
cypress/steps/salesSteps.js
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
import { ASSIGN_PRODUCTS_SELECTORS } from "../elements/catalog/assign-products";
|
||||||
|
import { MENAGE_CHANNEL_AVAILABILITY } from "../elements/channels/menage-channel-availability";
|
||||||
|
import { SALES_SELECTORS } from "../elements/discounts/sales";
|
||||||
|
import { BUTTON_SELECTORS } from "../elements/shared/button-selectors";
|
||||||
|
import { formatDate } from "../support/formatDate";
|
||||||
|
|
||||||
|
export const discountOptions = {
|
||||||
|
PERCENTAGE: SALES_SELECTORS.percentageOption,
|
||||||
|
FIXED: SALES_SELECTORS.fixedOption
|
||||||
|
};
|
||||||
|
|
||||||
|
export function createSale({
|
||||||
|
saleName,
|
||||||
|
channelName,
|
||||||
|
discountValue = 10,
|
||||||
|
discountOption = discountOptions.PERCENTAGE
|
||||||
|
}) {
|
||||||
|
const todaysDate = formatDate(new Date());
|
||||||
|
|
||||||
|
cy.get(SALES_SELECTORS.createSaleButton)
|
||||||
|
.click()
|
||||||
|
.get(SALES_SELECTORS.nameInput)
|
||||||
|
.type(saleName)
|
||||||
|
.get(discountOption)
|
||||||
|
.click()
|
||||||
|
.get(MENAGE_CHANNEL_AVAILABILITY.availableManageButton)
|
||||||
|
.click()
|
||||||
|
.get(MENAGE_CHANNEL_AVAILABILITY.allChannelsInput)
|
||||||
|
.click()
|
||||||
|
.get(MENAGE_CHANNEL_AVAILABILITY.channelsAvailabilityForm)
|
||||||
|
.contains(channelName)
|
||||||
|
.click()
|
||||||
|
.get(BUTTON_SELECTORS.submit)
|
||||||
|
.click()
|
||||||
|
.get(SALES_SELECTORS.discountValue)
|
||||||
|
.type(discountValue)
|
||||||
|
.get(SALES_SELECTORS.startDateInput)
|
||||||
|
.type(todaysDate);
|
||||||
|
cy.addAliasToGraphRequest("SaleCreate");
|
||||||
|
cy.get(SALES_SELECTORS.saveButton).click();
|
||||||
|
cy.wait("@SaleCreate");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function assignProducts(productName) {
|
||||||
|
cy.get(SALES_SELECTORS.productsTab)
|
||||||
|
.click()
|
||||||
|
.get(SALES_SELECTORS.assignProducts)
|
||||||
|
.click()
|
||||||
|
.get(ASSIGN_PRODUCTS_SELECTORS.searchInput)
|
||||||
|
.type(productName);
|
||||||
|
cy.contains(ASSIGN_PRODUCTS_SELECTORS.tableRow, productName)
|
||||||
|
.find(BUTTON_SELECTORS.checkbox)
|
||||||
|
.click();
|
||||||
|
cy.addAliasToGraphRequest("SaleCataloguesAdd");
|
||||||
|
cy.get(BUTTON_SELECTORS.submit).click();
|
||||||
|
cy.wait("@SaleCataloguesAdd");
|
||||||
|
}
|
12
cypress/support/formatDate.js
Normal file
12
cypress/support/formatDate.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
export function formatDate(date) {
|
||||||
|
const day = getPeriodValue(date, { day: "2-digit" });
|
||||||
|
const month = getPeriodValue(date, { month: "2-digit" });
|
||||||
|
const year = getPeriodValue(date, { year: "numeric" });
|
||||||
|
|
||||||
|
return new Array(year, month, day).join("-");
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPeriodValue(date, option) {
|
||||||
|
const formatter = new Intl.DateTimeFormat("en-us", option);
|
||||||
|
return formatter.format(date);
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ export const urlList = {
|
||||||
orders: "orders/",
|
orders: "orders/",
|
||||||
products: "products/",
|
products: "products/",
|
||||||
warehouses: "warehouses/",
|
warehouses: "warehouses/",
|
||||||
|
sales: "discounts/sales/",
|
||||||
collections: "collections/"
|
collections: "collections/"
|
||||||
};
|
};
|
||||||
export const productDetailsUrl = productId => `${urlList.products}${productId}`;
|
export const productDetailsUrl = productId => `${urlList.products}${productId}`;
|
||||||
|
|
5
cypress/utils/salesUtils.js
Normal file
5
cypress/utils/salesUtils.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { deleteSale, getSales } from "../apiRequests/Sales";
|
||||||
|
|
||||||
|
export function deleteSalesStartsWith(startsWith) {
|
||||||
|
cy.deleteElementsStartsWith(deleteSale, getSales, startsWith, "sales");
|
||||||
|
}
|
|
@ -18,7 +18,7 @@ export const isProductVisibleInSearchResult = (resp, productName) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getProductVariants = (productId, channelSlug) =>
|
export const getProductVariants = (productId, channelSlug) => {
|
||||||
getProductDetails(productId, channelSlug).then(resp => {
|
getProductDetails(productId, channelSlug).then(resp => {
|
||||||
const variantsList = resp.body.data.product.variants;
|
const variantsList = resp.body.data.product.variants;
|
||||||
return variantsList.map(element => ({
|
return variantsList.map(element => ({
|
||||||
|
@ -26,3 +26,9 @@ export const getProductVariants = (productId, channelSlug) =>
|
||||||
price: element.pricing.price.gross.amount
|
price: element.pricing.price.gross.amount
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getProductPrice = (productId, channelSlug) =>
|
||||||
|
getProductDetails(productId, channelSlug).then(
|
||||||
|
resp => resp.body.data.product.variants[0].pricing.price.gross.amount
|
||||||
|
);
|
||||||
|
|
|
@ -165,7 +165,10 @@ const AssignProductDialog: React.FC<AssignProductDialogProps> = props => {
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableRow key={product.id}>
|
<TableRow
|
||||||
|
key={product.id}
|
||||||
|
data-test-id="assign-product-table-row"
|
||||||
|
>
|
||||||
<TableCellAvatar
|
<TableCellAvatar
|
||||||
className={classes.avatar}
|
className={classes.avatar}
|
||||||
thumbnail={maybe(() => product.thumbnail.url)}
|
thumbnail={maybe(() => product.thumbnail.url)}
|
||||||
|
@ -202,6 +205,7 @@ const AssignProductDialog: React.FC<AssignProductDialogProps> = props => {
|
||||||
<FormattedMessage {...buttonMessages.back} />
|
<FormattedMessage {...buttonMessages.back} />
|
||||||
</Button>
|
</Button>
|
||||||
<ConfirmButton
|
<ConfirmButton
|
||||||
|
data-test="submit"
|
||||||
transitionState={confirmButtonState}
|
transitionState={confirmButtonState}
|
||||||
color="primary"
|
color="primary"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
|
|
|
@ -38,17 +38,19 @@ interface TabProps<T> {
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
changeTab: (index: T) => void;
|
changeTab: (index: T) => void;
|
||||||
|
testId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Tab<T>(value: T) {
|
export function Tab<T>(value: T) {
|
||||||
const Component: React.FC<TabProps<T>> = props => {
|
const Component: React.FC<TabProps<T>> = props => {
|
||||||
const { children, isActive, changeTab } = props;
|
const { children, isActive, changeTab, testId } = props;
|
||||||
|
|
||||||
const classes = useStyles(props);
|
const classes = useStyles(props);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Typography
|
<Typography
|
||||||
component="span"
|
component="span"
|
||||||
|
data-test-id={testId}
|
||||||
className={classNames({
|
className={classNames({
|
||||||
[classes.root]: true,
|
[classes.root]: true,
|
||||||
[classes.active]: isActive
|
[classes.active]: isActive
|
||||||
|
|
|
@ -98,7 +98,11 @@ const DiscountProducts: React.FC<SaleProductsProps> = props => {
|
||||||
description: "section header"
|
description: "section header"
|
||||||
})}
|
})}
|
||||||
toolbar={
|
toolbar={
|
||||||
<Button color="primary" onClick={onProductAssign}>
|
<Button
|
||||||
|
color="primary"
|
||||||
|
onClick={onProductAssign}
|
||||||
|
data-test-id="assign-products"
|
||||||
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
defaultMessage="Assign products"
|
defaultMessage="Assign products"
|
||||||
description="button"
|
description="button"
|
||||||
|
|
|
@ -208,6 +208,7 @@ const SaleDetailsPage: React.FC<SaleDetailsPageProps> = ({
|
||||||
)}
|
)}
|
||||||
</CollectionsTab>
|
</CollectionsTab>
|
||||||
<ProductsTab
|
<ProductsTab
|
||||||
|
testId="products-tab"
|
||||||
isActive={activeTab === SaleDetailsPageTab.products}
|
isActive={activeTab === SaleDetailsPageTab.products}
|
||||||
changeTab={onTabClick}
|
changeTab={onTabClick}
|
||||||
>
|
>
|
||||||
|
|
|
@ -54,7 +54,12 @@ const SaleListPage: React.FC<SaleListPageProps> = ({
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
<PageHeader title={intl.formatMessage(sectionNames.sales)}>
|
<PageHeader title={intl.formatMessage(sectionNames.sales)}>
|
||||||
<Button onClick={onAdd} variant="contained" color="primary">
|
<Button
|
||||||
|
onClick={onAdd}
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
data-test-id="create-sale"
|
||||||
|
>
|
||||||
<FormattedMessage defaultMessage="Create Sale" description="button" />
|
<FormattedMessage defaultMessage="Create Sale" description="button" />
|
||||||
</Button>
|
</Button>
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
|
|
|
@ -73441,6 +73441,7 @@ exports[`Storyshots Views / Discounts / Sale details collections 1`] = `
|
||||||
</span>
|
</span>
|
||||||
<span
|
<span
|
||||||
class="MuiTypography-root-id Tab-root-id MuiTypography-body1-id"
|
class="MuiTypography-root-id Tab-root-id MuiTypography-body1-id"
|
||||||
|
data-test-id="products-tab"
|
||||||
>
|
>
|
||||||
Products (4)
|
Products (4)
|
||||||
</span>
|
</span>
|
||||||
|
@ -74796,6 +74797,7 @@ exports[`Storyshots Views / Discounts / Sale details default 1`] = `
|
||||||
</span>
|
</span>
|
||||||
<span
|
<span
|
||||||
class="MuiTypography-root-id Tab-root-id MuiTypography-body1-id"
|
class="MuiTypography-root-id Tab-root-id MuiTypography-body1-id"
|
||||||
|
data-test-id="products-tab"
|
||||||
>
|
>
|
||||||
Products (4)
|
Products (4)
|
||||||
</span>
|
</span>
|
||||||
|
@ -76156,6 +76158,7 @@ exports[`Storyshots Views / Discounts / Sale details form errors 1`] = `
|
||||||
</span>
|
</span>
|
||||||
<span
|
<span
|
||||||
class="MuiTypography-root-id Tab-root-id MuiTypography-body1-id"
|
class="MuiTypography-root-id Tab-root-id MuiTypography-body1-id"
|
||||||
|
data-test-id="products-tab"
|
||||||
>
|
>
|
||||||
Products (4)
|
Products (4)
|
||||||
</span>
|
</span>
|
||||||
|
@ -77538,6 +77541,7 @@ exports[`Storyshots Views / Discounts / Sale details loading 1`] = `
|
||||||
</span>
|
</span>
|
||||||
<span
|
<span
|
||||||
class="MuiTypography-root-id Tab-root-id MuiTypography-body1-id"
|
class="MuiTypography-root-id Tab-root-id MuiTypography-body1-id"
|
||||||
|
data-test-id="products-tab"
|
||||||
>
|
>
|
||||||
Products (…)
|
Products (…)
|
||||||
</span>
|
</span>
|
||||||
|
@ -78925,6 +78929,7 @@ exports[`Storyshots Views / Discounts / Sale details products 1`] = `
|
||||||
</span>
|
</span>
|
||||||
<span
|
<span
|
||||||
class="MuiTypography-root-id Tab-root-id Tab-active-id MuiTypography-body1-id"
|
class="MuiTypography-root-id Tab-root-id Tab-active-id MuiTypography-body1-id"
|
||||||
|
data-test-id="products-tab"
|
||||||
>
|
>
|
||||||
Products (4)
|
Products (4)
|
||||||
</span>
|
</span>
|
||||||
|
@ -78948,6 +78953,7 @@ exports[`Storyshots Views / Discounts / Sale details products 1`] = `
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-text-id MuiButton-textPrimary-id"
|
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-text-id MuiButton-textPrimary-id"
|
||||||
|
data-test-id="assign-products"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
|
@ -79968,6 +79974,7 @@ exports[`Storyshots Views / Discounts / Sale list default 1`] = `
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
||||||
|
data-test-id="create-sale"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
|
@ -80658,6 +80665,7 @@ exports[`Storyshots Views / Discounts / Sale list loading 1`] = `
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
||||||
|
data-test-id="create-sale"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
|
@ -81102,6 +81110,7 @@ exports[`Storyshots Views / Discounts / Sale list no channels 1`] = `
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
||||||
|
data-test-id="create-sale"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
|
@ -81792,6 +81801,7 @@ exports[`Storyshots Views / Discounts / Sale list no data 1`] = `
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
||||||
|
data-test-id="create-sale"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
|
|
Loading…
Reference in a new issue