Skip to content

Commit

Permalink
Improve test functionality - SALEOR_215 (#5255)
Browse files Browse the repository at this point in the history
* Improve test functionality

* add changset

* improved changeset

* Add more details to changeset

* remove unnecessery line

* empty commit
  • Loading branch information
michalina-graczyk authored Nov 18, 2024
1 parent 50c1aa1 commit 4dac4f2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-laws-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Adjust inline discount test for precise floating-point comparison with .toFixed(2)
49 changes: 30 additions & 19 deletions playwright/tests/orders.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,46 +342,58 @@ for (const refund of orderRefunds) {
await expect(ordersPage.orderRefundList).not.toContainText(refund.status);
});
}
test(`TC: SALEOR_215 Inline discount is applied in a draft order @draft @discounts @e2e`, async page => {

test(`TC: SALEOR_215 Inline discount is applied in a draft order @draft @discounts @e2e`, async () => {
test.slow();

const calculateDiscountedPrice = (
undiscountedPrice: number,
discountPercentage: number,
): number => {
return undiscountedPrice - (undiscountedPrice * discountPercentage) / 100;
};

const formatPrice = (price: string): number => parseFloat(price.slice(3));

const discountedProduct = PRODUCTS.productWithDiscountChannelPLN;
const productAlreadyInBasket = ORDERS.draftOrderChannelPLN.productInBasket;
const totalPriceLocator = ordersPage.orderSummary.locator(ordersPage.totalPrice);

await ordersPage.goToExistingOrderPage(ORDERS.draftOrderChannelPLN.id);
await draftOrdersPage.basketProductList.waitFor({ state: "visible" });

const initialTotal = await ordersPage.orderSummary.locator(ordersPage.totalPrice).innerText();
const [initialTotal] = await Promise.all([
totalPriceLocator.innerText(),
draftOrdersPage.basketProductList.isVisible(),
]);

expect(initialTotal).toContain(productAlreadyInBasket.price.toString());

await draftOrdersPage.clickAddProductsButton();
await draftOrdersPage.addProductsDialog.searchForProductInDialog(discountedProduct.name);
await draftOrdersPage.addProductsDialog.selectVariantBySKU(discountedProduct.variant.sku);
await draftOrdersPage.addProductsDialog.clickConfirmButton();

await draftOrdersPage.expectElementIsHidden(draftOrdersPage.dialog);
await draftOrdersPage.expectElementIsHidden(draftOrdersPage.successBanner);

const calculatedDiscountForAddedProduct =
(await discountedProduct.variant.undiscountedPrice) -
(discountedProduct.variant.undiscountedPrice *
discountedProduct.rewardPercentageDiscountValue) /
100;

expect(discountedProduct.variant.discountedPrice).toEqual(calculatedDiscountForAddedProduct);

const undiscountedTotal =
productAlreadyInBasket.price + discountedProduct.variant.undiscountedPrice;
const expectedDiscountedPrice = calculateDiscountedPrice(
discountedProduct.variant.undiscountedPrice,
discountedProduct.rewardPercentageDiscountValue,
);

await ordersPage.totalPrice.waitFor({ state: "visible" });
expect(discountedProduct.variant.discountedPrice).toEqual(expectedDiscountedPrice);

const finalTotal = await ordersPage.orderSummary.locator(ordersPage.totalPrice).innerText();
await totalPriceLocator.waitFor({ state: "visible" });

expect(finalTotal.slice(3)).not.toContain(undiscountedTotal.toString());
const finalTotal = await totalPriceLocator.innerText();

const discountedTotal = productAlreadyInBasket.price + discountedProduct.variant.discountedPrice;
const expectedTotal = (
productAlreadyInBasket.price + discountedProduct.variant.discountedPrice
).toFixed(2);

expect(finalTotal.slice(3)).toContain(discountedTotal.toString());
expect(formatPrice(finalTotal).toFixed(2)).toEqual(expectedTotal);
});

test(`TC: SALEOR_216 Order type discount is applied to a draft order @draft @discounts @e2e`, async () => {
test.slow();
await draftOrdersPage.goToDraftOrdersListView();
Expand Down Expand Up @@ -439,7 +451,6 @@ test(`TC: SALEOR_216 Order type discount is applied to a draft order @draft @dis
PRODUCTS.productWithPriceLowerThan20.price + PRODUCTS.productWithPriceHigherThan20.price;
const finalTotalPrice = await ordersPage.orderSummary.locator(ordersPage.totalPrice).innerText();

expect(finalTotalPrice.slice(3)).not.toContain(initialSubTotalPrice);
expect(finalTotalPrice.slice(3)).not.toContain(initialSubTotalPrice);

const discountedOrderSubTotal = undiscountedOrderSubTotal - (undiscountedOrderSubTotal * 5) / 100;
Expand Down
1 change: 1 addition & 0 deletions playwright/tests/shippingMethods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ test("TC: SALEOR_37 Update a shipping method @shipping-method @e2e", async () =>
await shippingMethodsPage.rightSideDetailsPage.typeAndSelectMultipleWarehousesShippingPage(
warehousesToBeAssigned,
);
await shippingMethodsPage.expectSuccessBanner();

await shippingMethodsPage.saveShippingZone();
await shippingMethodsPage.expectSuccessBanner();
Expand Down

0 comments on commit 4dac4f2

Please sign in to comment.