add tests for creating vouchers for 3.1 (#1844)

This commit is contained in:
Karolina Rakoczy 2022-02-11 15:39:10 +01:00 committed by GitHub
parent f5a8db9f2e
commit f86a3559b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 569 additions and 13 deletions

View file

@ -6,5 +6,17 @@ export const VOUCHERS_SELECTORS = {
"[name='discountType'][value='VALUE_PERCENTAGE']", "[name='discountType'][value='VALUE_PERCENTAGE']",
fixedDiscountRadioButton: "[name='discountType'][value='VALUE_FIXED']", fixedDiscountRadioButton: "[name='discountType'][value='VALUE_FIXED']",
shippingDiscountRadioButton: "[name='discountType'][value='SHIPPING']", shippingDiscountRadioButton: "[name='discountType'][value='SHIPPING']",
discountValueInputs: "[name='value']" discountValueInputs: "[name='value']",
limits: {
usageLimitCheckbox: '[data-test-id="has-usage-limit"]',
usageLimitTextField: '[data-test-id="usage-limit"]',
applyOncePerCustomerCheckbox: '[data-test-id="apply-once-per-customer"]',
onlyForStaffCheckbox: '[data-test-id="only-for-staff"]'
},
requirements: {
minOrderValueCheckbox: '[name="requirementsPicker"][value="ORDER"]',
minAmountOfItemsCheckbox: '[name="requirementsPicker"][value="ITEM"]',
minCheckoutItemsQuantityInput: '[name="minCheckoutItemsQuantity"]',
minOrderValueInput: '[name="minSpent"]'
}
}; };

View file

@ -164,8 +164,8 @@ filterTests({ definedTags: ["stagedOnly"] }, () => {
simpleCard.brand = paymentCards.cards.simpleCard.brand; simpleCard.brand = paymentCards.cards.simpleCard.brand;
simpleCard.encryptedSecurityCode = simpleCard.encryptedSecurityCode =
paymentCards.encryptedSecurityCodes.unknown; paymentCards.encryptedSecurityCodes.unknown;
completeCheckout(checkout.id, simpleCard).then(({ checkoutErrors }) => { completeCheckout(checkout.id, simpleCard).then(({ errors }) => {
expect(checkoutErrors).to.have.length(1); expect(errors).to.have.length(1);
}); });
}); });
@ -174,8 +174,8 @@ filterTests({ definedTags: ["stagedOnly"] }, () => {
errorCard.encryptedCardNumber = errorCard.encryptedCardNumber =
paymentCards.cards.errorCard.encryptedCardNumber; paymentCards.cards.errorCard.encryptedCardNumber;
errorCard.brand = paymentCards.cards.errorCard.brand; errorCard.brand = paymentCards.cards.errorCard.brand;
completeCheckout(checkout.id, errorCard).then(({ checkoutErrors }) => { completeCheckout(checkout.id, errorCard).then(({ errors }) => {
expect(checkoutErrors).to.have.length(1); expect(errors).to.have.length(1);
}); });
}); });
@ -184,8 +184,8 @@ filterTests({ definedTags: ["stagedOnly"] }, () => {
closeAccount.encryptedCardNumber = closeAccount.encryptedCardNumber =
paymentCards.cards.closeAccount.encryptedCardNumber; paymentCards.cards.closeAccount.encryptedCardNumber;
closeAccount.brand = paymentCards.cards.closeAccount.brand; closeAccount.brand = paymentCards.cards.closeAccount.brand;
completeCheckout(checkout.id, closeAccount).then(({ checkoutErrors }) => { completeCheckout(checkout.id, closeAccount).then(({ errors }) => {
expect(checkoutErrors).to.have.length(1); expect(errors).to.have.length(1);
}); });
}); });
}); });

View file

@ -0,0 +1,356 @@
// / <reference types="cypress"/>
// / <reference types="../../../support"/>
import faker from "faker";
import { urlList } from "../../../fixtures/urlList";
import { createChannel } from "../../../support/api/requests/Channels";
import { completeCheckout } from "../../../support/api/requests/Checkout";
import * as channelsUtils from "../../../support/api/utils/channelsUtils";
import { deleteVouchersStartsWith } from "../../../support/api/utils/discounts/vouchersUtils";
import {
addPayment,
createCheckoutWithVoucher
} from "../../../support/api/utils/ordersUtils";
import * as productsUtils from "../../../support/api/utils/products/productsUtils";
import filterTests from "../../../support/filterTests";
import {
createVoucher,
discountOptions,
loginAndCreateCheckoutForVoucherWithDiscount
} from "../../../support/pages/discounts/vouchersPage";
filterTests({ definedTags: ["all"] }, () => {
describe("As an admin I want to create voucher", () => {
const startsWith = "CyVou-";
const productPrice = 100;
const shippingPrice = 100;
let defaultChannel;
let createdChannel;
let shippingMethod;
let variants;
let address;
let dataForCheckout;
before(() => {
cy.clearSessionData().loginUserViaRequest();
channelsUtils.deleteChannelsStartsWith(startsWith);
deleteVouchersStartsWith(startsWith);
const name = `${startsWith}${faker.datatype.number()}`;
productsUtils
.createProductWithShipping({ name, productPrice, shippingPrice })
.then(
({
variantsList: variantsResp,
defaultChannel: channel,
shippingMethod: shippingMethodResp,
address: addressResp
}) => {
variants = variantsResp;
defaultChannel = channel;
shippingMethod = shippingMethodResp;
address = addressResp;
createChannel({ name });
}
)
.then(channel => {
createdChannel = channel;
dataForCheckout = {
channelSlug: defaultChannel.slug,
variantsList: variants,
address,
shippingMethodName: shippingMethod.name,
auth: "token"
};
});
});
it("should be able to create fixed price voucher. TC: SALEOR_1901", () => {
const voucherValue = 50;
const voucherCode = `${startsWith}${faker.datatype.number()}`;
const expectedAmount = productPrice + shippingPrice - voucherValue;
let checkout;
loginAndCreateCheckoutForVoucherWithDiscount({
discount: discountOptions.FIXED,
voucherValue,
voucherCode,
channelName: defaultChannel.name,
dataForCheckout
})
.then(({ addPromoCodeResp, checkout: checkoutResp }) => {
expect(addPromoCodeResp.checkout.totalPrice.gross.amount).to.be.eq(
expectedAmount
);
dataForCheckout.voucherCode = voucherCode;
checkout = checkoutResp;
addPayment(checkout.id);
})
.then(() => {
completeCheckout(checkout.id);
})
.then(({ order }) => {
expect(order.id).to.be.ok;
});
});
it("should be able to create percentage voucher. TC: SALEOR_1902", () => {
const voucherValue = 50;
const voucherCode = `${startsWith}${faker.datatype.number()}`;
const expectedAmount =
(productPrice * voucherValue) / 100 + shippingPrice;
let checkout;
loginAndCreateCheckoutForVoucherWithDiscount({
discount: discountOptions.PERCENTAGE,
voucherValue,
voucherCode,
channelName: defaultChannel.name,
dataForCheckout
})
.then(({ addPromoCodeResp, checkout: checkoutResp }) => {
expect(addPromoCodeResp.checkout.totalPrice.gross.amount).to.be.eq(
expectedAmount
);
dataForCheckout.voucherCode = voucherCode;
checkout = checkoutResp;
addPayment(checkout.id);
})
.then(() => {
completeCheckout(checkout.id);
})
.then(({ order }) => {
expect(order.id).to.be.ok;
});
});
it("should be able to create free shipping voucher. TC: SALEOR_1903", () => {
const voucherCode = `${startsWith}${faker.datatype.number()}`;
const expectedAmount = productPrice;
let checkout;
loginAndCreateCheckoutForVoucherWithDiscount({
discount: discountOptions.SHIPPING,
voucherCode,
channelName: defaultChannel.name,
dataForCheckout
})
.then(({ addPromoCodeResp, checkout: checkoutResp }) => {
expect(addPromoCodeResp.checkout.totalPrice.gross.amount).to.be.eq(
expectedAmount
);
dataForCheckout.voucherCode = voucherCode;
checkout = checkoutResp;
addPayment(checkout.id);
})
.then(() => {
completeCheckout(checkout.id);
})
.then(({ order }) => {
expect(order.id).to.be.ok;
});
});
it("should be able to create voucher not available for selected channel. TC: SALEOR_1904", () => {
const randomName = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50;
cy.clearSessionData()
.loginUserViaRequest()
.visit(urlList.vouchers);
cy.softExpectSkeletonIsVisible();
createVoucher({
voucherCode: randomName,
voucherValue,
discountOption: discountOptions.PERCENTAGE,
channelName: createdChannel.name
});
dataForCheckout.voucherCode = randomName;
createCheckoutWithVoucher(dataForCheckout).then(
({ addPromoCodeResp }) => {
const errorField = addPromoCodeResp.errors[0].field;
expect(errorField).to.be.eq("promoCode");
}
);
});
it("should be able to create voucher with limited number of times discount can be used in total. TC: SALEOR_1907", () => {
const voucherCode = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50;
const usageLimit = 1;
let firstCheckout;
loginAndCreateCheckoutForVoucherWithDiscount({
discount: discountOptions.PERCENTAGE,
voucherValue,
voucherCode,
channelName: defaultChannel.name,
dataForCheckout,
usageLimit
})
.then(({ checkout, addPromoCodeResp }) => {
expect(addPromoCodeResp.errors).to.be.empty;
firstCheckout = checkout;
dataForCheckout.voucherCode = voucherCode;
addPayment(firstCheckout.id);
})
.then(() => {
completeCheckout(firstCheckout.id);
})
.then(() => {
createCheckoutWithVoucher(dataForCheckout);
})
.then(({ addPromoCodeResp }) => {
const errorField = addPromoCodeResp.errors[0].field;
expect(errorField, "error in promo code should occur").to.be.eq(
"promoCode"
);
});
});
it("should be able to create voucher with limit to one use per customer. TC: SALEOR_1908", () => {
const voucherCode = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50;
dataForCheckout.auth = "token";
let firstCheckout;
loginAndCreateCheckoutForVoucherWithDiscount({
discount: discountOptions.PERCENTAGE,
voucherValue,
voucherCode,
channelName: defaultChannel.name,
dataForCheckout,
applyOnePerCustomer: true
})
.then(({ checkout, addPromoCodeResp }) => {
expect(addPromoCodeResp.errors).to.be.empty;
dataForCheckout.voucherCode = voucherCode;
firstCheckout = checkout;
addPayment(firstCheckout.id);
})
.then(() => {
completeCheckout(firstCheckout.id);
})
.then(() => {
createCheckoutWithVoucher(dataForCheckout);
})
.then(({ addPromoCodeResp }) => {
const errorField = addPromoCodeResp.errors[0].field;
expect(errorField, "error in promo code should occur").to.be.eq(
"promoCode"
);
// Create new checkout as other not logged in customer - voucher should be available for other customer
cy.clearSessionData();
dataForCheckout.email = "newUser@example.com";
createCheckoutWithVoucher(dataForCheckout);
})
.then(({ addPromoCodeResp }) => {
const errorField = addPromoCodeResp.errors;
expect(errorField, "No errors when adding promo code").to.be.empty;
});
});
it("should be able to create voucher with limit to staff only. TC: SALEOR_1909", () => {
const voucherCode = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50;
dataForCheckout.auth = "auth";
let firstCheckout;
loginAndCreateCheckoutForVoucherWithDiscount({
discount: discountOptions.PERCENTAGE,
voucherValue,
voucherCode,
channelName: defaultChannel.name,
dataForCheckout,
onlyStaff: true
})
.then(({ checkout, addPromoCodeResp }) => {
expect(addPromoCodeResp.errors).to.be.empty;
dataForCheckout.voucherCode = voucherCode;
firstCheckout = checkout;
addPayment(firstCheckout.id);
})
.then(() => {
completeCheckout(firstCheckout.id);
})
.then(() => {
dataForCheckout.auth = "token";
createCheckoutWithVoucher(dataForCheckout);
})
.then(({ addPromoCodeResp }) => {
const errorField = addPromoCodeResp.errors[0].field;
expect(errorField, "error in promo code should occur").to.be.eq(
"promoCode"
);
});
});
it("should be able to create voucher with minimum value of order. TC: SALEOR_1910", () => {
const voucherCode = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50;
const minOrderValue = productPrice * 1.5;
dataForCheckout.productQuantity = 1;
let checkout;
loginAndCreateCheckoutForVoucherWithDiscount({
discount: discountOptions.PERCENTAGE,
voucherValue,
voucherCode,
channelName: defaultChannel.name,
dataForCheckout,
minOrderValue
})
.then(({ addPromoCodeResp }) => {
const errorField = addPromoCodeResp.errors[0].field;
dataForCheckout.voucherCode = voucherCode;
expect(errorField, "error in promo code should occur").to.be.eq(
"promoCode"
);
dataForCheckout.productQuantity = 2;
createCheckoutWithVoucher(dataForCheckout);
})
.then(({ checkout: checkoutResp, addPromoCodeResp }) => {
checkout = checkoutResp;
const errorField = addPromoCodeResp.errors;
expect(errorField, "No errors when adding promo code").to.be.empty;
});
});
it("should create voucher with min product quantity. TC: SALEOR_1911", () => {
const voucherCode = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50;
const minAmountOfItems = 2;
dataForCheckout.productQuantity = 1;
let checkout;
loginAndCreateCheckoutForVoucherWithDiscount({
discount: discountOptions.PERCENTAGE,
voucherValue,
voucherCode,
channelName: defaultChannel.name,
dataForCheckout,
minAmountOfItems
})
.then(({ addPromoCodeResp }) => {
const errorField = addPromoCodeResp.errors[0].field;
dataForCheckout.voucherCode = voucherCode;
expect(errorField, "error in promo code should occur").to.be.eq(
"promoCode"
);
dataForCheckout.productQuantity = 2;
createCheckoutWithVoucher(dataForCheckout);
})
.then(({ checkout: checkoutResp, addPromoCodeResp }) => {
checkout = checkoutResp;
const errorField = addPromoCodeResp.errors;
expect(errorField, "No errors when adding promo code").to.be.empty;
});
});
});
});

View file

@ -0,0 +1,101 @@
// / <reference types="cypress"/>
// / <reference types="../../../support"/>
import faker from "faker";
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
import { voucherDetailsUrl } from "../../../fixtures/urlList";
import { createChannel } from "../../../support/api/requests/Channels";
import * as channelsUtils from "../../../support/api/utils/channelsUtils";
import {
createVoucherInChannel,
deleteVouchersStartsWith
} from "../../../support/api/utils/discounts/vouchersUtils";
import { createCheckoutWithVoucher } from "../../../support/api/utils/ordersUtils";
import * as productsUtils from "../../../support/api/utils/products/productsUtils";
import filterTests from "../../../support/filterTests";
filterTests({ definedTags: ["all"] }, () => {
describe("Vouchers discounts", () => {
const startsWith = "CyVou-";
const productPrice = 100;
const shippingPrice = 100;
let defaultChannel;
let createdChannel;
let shippingMethod;
let variants;
let product;
let address;
before(() => {
cy.clearSessionData().loginUserViaRequest();
channelsUtils.deleteChannelsStartsWith(startsWith);
deleteVouchersStartsWith(startsWith);
const name = `${startsWith}${faker.datatype.number()}`;
productsUtils
.createProductWithShipping({ name, productPrice, shippingPrice })
.then(
({
variantsList: variantsResp,
defaultChannel: channel,
shippingMethod: shippingMethodResp,
address: addressResp,
product: productResp
}) => {
variants = variantsResp;
defaultChannel = channel;
shippingMethod = shippingMethodResp;
address = addressResp;
product = productResp;
createChannel({ name });
}
)
.then(channel => {
createdChannel = channel;
});
});
it("should delete voucher", () => {
const name = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50;
let voucher;
cy.clearSessionData().loginUserViaRequest();
createVoucherInChannel({
name,
productId: product.id,
channelId: defaultChannel.id,
value: voucherValue
})
.then(voucherResp => {
voucher = voucherResp;
expect(voucher.id).to.be.ok;
cy.visit(voucherDetailsUrl(voucher.id))
.addAliasToGraphRequest("VoucherDelete")
.get(BUTTON_SELECTORS.deleteButton)
.click()
.get(BUTTON_SELECTORS.submit)
.click()
.wait("@VoucherDelete");
createCheckoutForCreatedVoucher(voucher.code);
})
.then(({ addPromoCodeResp }) => {
const errorField = addPromoCodeResp.errors[0].field;
expect(errorField).to.be.eq("promoCode");
});
});
function createCheckoutForCreatedVoucher(voucherCode) {
return createCheckoutWithVoucher({
channelSlug: defaultChannel.slug,
variantsList: variants,
address,
shippingMethodName: shippingMethod.name,
voucherCode,
auth: "token"
});
}
});
});

View file

@ -155,7 +155,7 @@ export function completeCheckout(checkoutId, paymentData) {
} }
confirmationNeeded confirmationNeeded
confirmationData confirmationData
checkoutErrors{ errors{
field field
message message
} }
@ -169,7 +169,7 @@ export function addVoucher(checkoutId, voucherCode) {
checkoutAddPromoCode(checkoutId:"${checkoutId}", checkoutAddPromoCode(checkoutId:"${checkoutId}",
promoCode:"${voucherCode}" promoCode:"${voucherCode}"
){ ){
checkoutErrors{ errors{
field field
message message
} }
@ -191,7 +191,7 @@ export function checkoutVariantsUpdate(checkoutId, variantsList) {
const mutation = `mutation{ const mutation = `mutation{
checkoutLinesUpdate(checkoutId:"${checkoutId}", checkoutLinesUpdate(checkoutId:"${checkoutId}",
lines: [${lines.join()}]){ lines: [${lines.join()}]){
checkoutErrors{ errors{
field field
message message
} }
@ -203,7 +203,7 @@ export function checkoutVariantsUpdate(checkoutId, variantsList) {
export function checkoutShippingMethodUpdate(checkoutId, shippingMethodId) { export function checkoutShippingMethodUpdate(checkoutId, shippingMethodId) {
const mutation = `mutation{ const mutation = `mutation{
checkoutShippingMethodUpdate(checkoutId:"${checkoutId}" shippingMethodId:"${shippingMethodId}"){ checkoutShippingMethodUpdate(checkoutId:"${checkoutId}" shippingMethodId:"${shippingMethodId}"){
checkoutErrors{ errors{
field field
message message
} }
@ -220,7 +220,7 @@ export function checkoutShippingAddressUpdate(checkoutId, address) {
checkoutShippingAddressUpdate(checkoutId:"${checkoutId}", checkoutShippingAddressUpdate(checkoutId:"${checkoutId}",
${shippingAddress} ${shippingAddress}
){ ){
checkoutErrors{ errors{
field field
message message
} }

View file

@ -66,6 +66,7 @@ export function createCheckoutWithVoucher({
channelSlug, channelSlug,
email = "email@example.com", email = "email@example.com",
variantsList, variantsList,
productQuantity = 1,
address, address,
shippingMethodName, shippingMethodName,
voucherCode, voucherCode,
@ -75,6 +76,7 @@ export function createCheckoutWithVoucher({
return checkoutRequest return checkoutRequest
.createCheckout({ .createCheckout({
channelSlug, channelSlug,
productQuantity,
email, email,
variantsList, variantsList,
address, address,

View file

@ -1,5 +1,8 @@
import { VOUCHERS_SELECTORS } from "../../../elements/discounts/vouchers"; import { VOUCHERS_SELECTORS } from "../../../elements/discounts/vouchers";
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors"; import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
import { urlList } from "../../../fixtures/urlList";
import { ONE_PERMISSION_USERS } from "../../../fixtures/users";
import { createCheckoutWithVoucher } from "../../api/utils/ordersUtils";
import { selectChannelInDetailsPages } from "../channelsPage"; import { selectChannelInDetailsPages } from "../channelsPage";
export const discountOptions = { export const discountOptions = {
@ -12,7 +15,12 @@ export function createVoucher({
voucherCode, voucherCode,
voucherValue, voucherValue,
discountOption, discountOption,
channelName channelName,
usageLimit,
applyOnePerCustomer,
onlyStaff,
minOrderValue,
minAmountOfItems
}) { }) {
cy.get(VOUCHERS_SELECTORS.createVoucherButton).click(); cy.get(VOUCHERS_SELECTORS.createVoucherButton).click();
selectChannelInDetailsPages(channelName); selectChannelInDetailsPages(channelName);
@ -23,7 +31,61 @@ export function createVoucher({
if (discountOption !== discountOptions.SHIPPING) { if (discountOption !== discountOptions.SHIPPING) {
cy.get(VOUCHERS_SELECTORS.discountValueInputs).type(voucherValue); cy.get(VOUCHERS_SELECTORS.discountValueInputs).type(voucherValue);
} }
if (usageLimit) {
cy.get(VOUCHERS_SELECTORS.limits.usageLimitCheckbox)
.click()
.type(usageLimit);
}
if (applyOnePerCustomer) {
cy.get(VOUCHERS_SELECTORS.limits.applyOncePerCustomerCheckbox).click();
}
if (onlyStaff) {
cy.get(VOUCHERS_SELECTORS.limits.onlyForStaffCheckbox).click();
}
if (minOrderValue) {
cy.get(VOUCHERS_SELECTORS.requirements.minOrderValueCheckbox)
.click()
.get(VOUCHERS_SELECTORS.requirements.minOrderValueInput)
.type(minOrderValue);
}
if (minAmountOfItems) {
cy.get(VOUCHERS_SELECTORS.requirements.minAmountOfItemsCheckbox)
.click()
.get(VOUCHERS_SELECTORS.requirements.minCheckoutItemsQuantityInput)
.type(minAmountOfItems);
}
cy.get(BUTTON_SELECTORS.confirm) cy.get(BUTTON_SELECTORS.confirm)
.click() .click()
.confirmationMessageShouldDisappear(); .confirmationMessageShouldDisappear();
} }
export function loginAndCreateCheckoutForVoucherWithDiscount({
discount,
voucherValue,
voucherCode,
channelName,
dataForCheckout,
usageLimit,
applyOnePerCustomer,
onlyStaff,
minOrderValue,
minAmountOfItems
}) {
cy.clearSessionData()
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
.visit(urlList.vouchers);
cy.softExpectSkeletonIsVisible();
createVoucher({
voucherCode,
voucherValue,
discountOption: discount,
channelName,
usageLimit,
applyOnePerCustomer,
onlyStaff,
minOrderValue,
minAmountOfItems
});
dataForCheckout.voucherCode = voucherCode;
return createCheckoutWithVoucher(dataForCheckout);
}

View file

@ -9,6 +9,7 @@ export interface ControlledCheckboxProps {
indeterminate?: boolean; indeterminate?: boolean;
disabled?: boolean; disabled?: boolean;
checkedIcon?: React.ReactNode; checkedIcon?: React.ReactNode;
testId?: string;
onChange(event: any); onChange(event: any);
} }
@ -20,12 +21,14 @@ export const ControlledCheckbox: React.FC<ControlledCheckboxProps> = ({
onChange, onChange,
checkedIcon, checkedIcon,
indeterminate, indeterminate,
testId,
...props ...props
}) => ( }) => (
<FormControlLabel <FormControlLabel
disabled={disabled} disabled={disabled}
control={ control={
<Checkbox <Checkbox
data-test-id={testId}
checkedIcon={checkedIcon} checkedIcon={checkedIcon}
checked={!!checked} checked={!!checked}
indeterminate={indeterminate} indeterminate={indeterminate}

View file

@ -43,6 +43,7 @@ const VoucherLimits = ({
<CardTitle title={intl.formatMessage(messages.usageLimitsTitle)} /> <CardTitle title={intl.formatMessage(messages.usageLimitsTitle)} />
<CardContent className={classes.cardContent}> <CardContent className={classes.cardContent}>
<ControlledCheckbox <ControlledCheckbox
testId="has-usage-limit"
checked={data.hasUsageLimit} checked={data.hasUsageLimit}
label={intl.formatMessage(messages.hasUsageLimit)} label={intl.formatMessage(messages.hasUsageLimit)}
name={"hasUsageLimit" as keyof VoucherDetailsPageFormData} name={"hasUsageLimit" as keyof VoucherDetailsPageFormData}
@ -54,6 +55,7 @@ const VoucherLimits = ({
{data.hasUsageLimit && {data.hasUsageLimit &&
(isNewVoucher ? ( (isNewVoucher ? (
<TextField <TextField
data-test-id="usage-limit"
disabled={disabled} disabled={disabled}
error={!!formErrors.usageLimit || data.usageLimit <= 0} error={!!formErrors.usageLimit || data.usageLimit <= 0}
helperText={getDiscountErrorMessage(formErrors.usageLimit, intl)} helperText={getDiscountErrorMessage(formErrors.usageLimit, intl)}
@ -70,6 +72,7 @@ const VoucherLimits = ({
) : ( ) : (
<Grid variant="uniform"> <Grid variant="uniform">
<TextField <TextField
data-test-id="usage-limit"
disabled={disabled} disabled={disabled}
error={!!formErrors.usageLimit || data.usageLimit <= 0} error={!!formErrors.usageLimit || data.usageLimit <= 0}
helperText={getDiscountErrorMessage( helperText={getDiscountErrorMessage(
@ -94,12 +97,14 @@ const VoucherLimits = ({
</Grid> </Grid>
))} ))}
<ControlledCheckbox <ControlledCheckbox
testId="apply-once-per-customer"
checked={data.applyOncePerCustomer} checked={data.applyOncePerCustomer}
label={intl.formatMessage(messages.applyOncePerCustomer)} label={intl.formatMessage(messages.applyOncePerCustomer)}
name={"applyOncePerCustomer" as keyof VoucherDetailsPageFormData} name={"applyOncePerCustomer" as keyof VoucherDetailsPageFormData}
onChange={onChange} onChange={onChange}
/> />
<ControlledCheckbox <ControlledCheckbox
testId="only-for-staff"
checked={data.onlyForStaff} checked={data.onlyForStaff}
label={intl.formatMessage(messages.onlyForStaff)} label={intl.formatMessage(messages.onlyForStaff)}
name={"onlyForStaff" as keyof VoucherDetailsPageFormData} name={"onlyForStaff" as keyof VoucherDetailsPageFormData}

View file

@ -89587,6 +89587,7 @@ exports[`Storyshots Views / Discounts / Voucher create default 1`] = `
<span <span
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id" class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id"
data-test-id="has-usage-limit"
> >
<span <span
class="MuiIconButton-label-id" class="MuiIconButton-label-id"
@ -89630,6 +89631,7 @@ exports[`Storyshots Views / Discounts / Voucher create default 1`] = `
<span <span
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id" class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id"
data-test-id="apply-once-per-customer"
> >
<span <span
class="MuiIconButton-label-id" class="MuiIconButton-label-id"
@ -89673,6 +89675,7 @@ exports[`Storyshots Views / Discounts / Voucher create default 1`] = `
<span <span
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id" class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id"
data-test-id="only-for-staff"
> >
<span <span
class="MuiIconButton-label-id" class="MuiIconButton-label-id"
@ -91157,6 +91160,7 @@ exports[`Storyshots Views / Discounts / Voucher create form errors 1`] = `
<span <span
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id" class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id"
data-test-id="has-usage-limit"
> >
<span <span
class="MuiIconButton-label-id" class="MuiIconButton-label-id"
@ -91200,6 +91204,7 @@ exports[`Storyshots Views / Discounts / Voucher create form errors 1`] = `
<span <span
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id" class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id"
data-test-id="apply-once-per-customer"
> >
<span <span
class="MuiIconButton-label-id" class="MuiIconButton-label-id"
@ -91243,6 +91248,7 @@ exports[`Storyshots Views / Discounts / Voucher create form errors 1`] = `
<span <span
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id" class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id"
data-test-id="only-for-staff"
> >
<span <span
class="MuiIconButton-label-id" class="MuiIconButton-label-id"
@ -93343,6 +93349,7 @@ exports[`Storyshots Views / Discounts / Voucher details default 1`] = `
<span <span
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id" class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id"
data-test-id="has-usage-limit"
> >
<span <span
class="MuiIconButton-label-id" class="MuiIconButton-label-id"
@ -93386,6 +93393,7 @@ exports[`Storyshots Views / Discounts / Voucher details default 1`] = `
<span <span
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id" class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id"
data-test-id="apply-once-per-customer"
> >
<span <span
class="MuiIconButton-label-id" class="MuiIconButton-label-id"
@ -93429,6 +93437,7 @@ exports[`Storyshots Views / Discounts / Voucher details default 1`] = `
<span <span
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id" class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id"
data-test-id="only-for-staff"
> >
<span <span
class="MuiIconButton-label-id" class="MuiIconButton-label-id"
@ -95684,6 +95693,7 @@ exports[`Storyshots Views / Discounts / Voucher details form errors 1`] = `
<span <span
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id" class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id"
data-test-id="has-usage-limit"
> >
<span <span
class="MuiIconButton-label-id" class="MuiIconButton-label-id"
@ -95727,6 +95737,7 @@ exports[`Storyshots Views / Discounts / Voucher details form errors 1`] = `
<span <span
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id" class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id"
data-test-id="apply-once-per-customer"
> >
<span <span
class="MuiIconButton-label-id" class="MuiIconButton-label-id"
@ -95770,6 +95781,7 @@ exports[`Storyshots Views / Discounts / Voucher details form errors 1`] = `
<span <span
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id" class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id"
data-test-id="only-for-staff"
> >
<span <span
class="MuiIconButton-label-id" class="MuiIconButton-label-id"
@ -97588,6 +97600,7 @@ exports[`Storyshots Views / Discounts / Voucher details loading 1`] = `
<span <span
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id" class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id"
data-test-id="has-usage-limit"
> >
<span <span
class="MuiIconButton-label-id" class="MuiIconButton-label-id"
@ -97631,6 +97644,7 @@ exports[`Storyshots Views / Discounts / Voucher details loading 1`] = `
<span <span
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id" class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id"
data-test-id="apply-once-per-customer"
> >
<span <span
class="MuiIconButton-label-id" class="MuiIconButton-label-id"
@ -97674,6 +97688,7 @@ exports[`Storyshots Views / Discounts / Voucher details loading 1`] = `
<span <span
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id" class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id"
data-test-id="only-for-staff"
> >
<span <span
class="MuiIconButton-label-id" class="MuiIconButton-label-id"