Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

test: improve checkout tests

thecodrr202ced99dc00
diff --git a/apps/web/__e2e__/checkout.test.js b/apps/web/__e2e__/checkout.test.js
index 3ad9d81ff..1b5870add 100644
--- a/apps/web/__e2e__/checkout.test.js
+++ b/apps/web/__e2e__/checkout.test.js
@@ -3,6 +3,7 @@ const { getTestId, isTestAll, loginUser } = require("./utils");
const { isAbsent, isPresent } = require("./utils/conditions");
const path = require("path");
+test.setTimeout(45 * 1000);
/**
* @type {Page}
*/
@@ -36,6 +37,17 @@ async function getPrices() {
return prices;
}
+/**
+ *
+ * @param {string} prices
+ */
+function roundOffPrices(prices) {
+ return prices.replaceAll(/(\d+.\d+)/gm, (str, price) => {
+ price = parseFloat(price);
+ return isNaN(price) ? 0 : Math.ceil(Math.round(price) / 10) * 10;
+ });
+}
+
async function getPaddleFrame(selector = "inlineComplianceBarContainer") {
await page.waitForSelector(`.checkout-container iframe`);
@@ -50,7 +62,8 @@ async function getPaddleFrame(selector = "inlineComplianceBarContainer") {
async function changeCountry(paddleFrame, countryCode, pinCode) {
await paddleFrame.selectOption(
getPaddleTestId("countriesSelect"),
- countryCode
+ countryCode,
+ { force: true }
);
if (pinCode)
@@ -58,7 +71,26 @@ async function changeCountry(paddleFrame, countryCode, pinCode) {
await paddleFrame.click(getPaddleTestId("locationFormSubmitButton"));
- await page.waitForTimeout(1000);
+ await paddleFrame.waitForSelector(
+ getPaddleTestId("inlineComplianceBarContainer")
+ );
+}
+
+async function forEachPlan(action) {
+ for (let i = 0; i < plans.length; ++i) {
+ const plan = plans[i];
+
+ const planTestId = getTestId(`checkout-plan-${plan.key}`);
+ await page.isEnabled(planTestId, { timeout: 10000 });
+
+ await page.click(planTestId);
+
+ await action(plan);
+
+ if (i < plans.length - 1) {
+ await page.click(getTestId("checkout-plan-change"));
+ }
+ }
}
test("change plans", async ({ page }) => {
@@ -66,16 +98,11 @@ test("change plans", async ({ page }) => {
await page.goto("/#/buy/");
- for (let plan of plans) {
- const planTestId = getTestId(`checkout-plan-${plan.key}`);
- await page.click(planTestId);
-
+ await forEachPlan(async (plan) => {
await expect(
page.innerText(getTestId("checkout-plan-title"))
).resolves.toBe(plan.title);
-
- await page.click(getTestId("checkout-plan-change"));
- }
+ });
});
test("confirm plan prices", async ({ page }) => {
@@ -83,16 +110,10 @@ test("confirm plan prices", async ({ page }) => {
await page.goto("/#/buy/");
- for (let plan of plans) {
- const planTestId = getTestId(`checkout-plan-${plan.key}`);
- await page.click(planTestId);
-
- expect((await getPrices()).join("\n")).toMatchSnapshot(
- `checkout-${plan.key}-prices.txt`
- );
-
- await page.click(getTestId("checkout-plan-change"));
- }
+ await forEachPlan(async (plan) => {
+ const prices = roundOffPrices((await getPrices()).join("\n"));
+ expect(prices).toMatchSnapshot(`checkout-${plan.key}-prices.txt`);
+ });
});
test("changing locale should show localized prices", async ({ page }) => {
@@ -100,22 +121,14 @@ test("changing locale should show localized prices", async ({ page }) => {
await page.goto("/#/buy/");
- for (let plan of plans) {
- const planTestId = getTestId(`checkout-plan-${plan.key}`);
- await page.click(planTestId);
-
+ await forEachPlan(async (plan) => {
const paddleFrame = await getPaddleFrame();
await changeCountry(paddleFrame, "IN", "110001");
- const prices = await getPrices();
-
- expect(prices.join("\n")).toMatchSnapshot(
- `checkout-${plan.key}-IN-prices.txt`
- );
-
- await page.click(getTestId("checkout-plan-change"));
- }
+ const prices = roundOffPrices((await getPrices()).join("\n"));
+ expect(prices).toMatchSnapshot(`checkout-${plan.key}-IN-prices.txt`);
+ });
});
test("applying coupon should change discount & total price", async ({ page }, {
@@ -127,12 +140,7 @@ test("applying coupon should change discount & total price", async ({ page }, {
await page.goto("/#/buy/");
- for (let plan of plans) {
- const planTestId = getTestId(`checkout-plan-${plan.key}`);
- await page.isEnabled(planTestId, { timeout: 10000 });
-
- await page.click(planTestId);
-
+ await forEachPlan(async (plan) => {
await getPaddleFrame();
await page.fill(getTestId("checkout-coupon-code"), plan.coupon);
@@ -140,16 +148,12 @@ test("applying coupon should change discount & total price", async ({ page }, {
await getPaddleFrame();
- const prices = await getPrices();
+ const prices = roundOffPrices((await getPrices()).join("\n"));
- expect(prices.join("\n")).toMatchSnapshot(
+ expect(prices).toMatchSnapshot(
`checkout-${plan.key}-discounted-prices.txt`
);
-
- await page.click(getTestId("checkout-plan-change"));
-
- await page.waitForTimeout(1000);
- }
+ });
});
test("apply coupon through url", async ({ page }) => {
@@ -160,9 +164,8 @@ test("apply coupon through url", async ({ page }) => {
await getPaddleFrame();
- const prices = await getPrices();
-
- expect(prices.join("\n")).toMatchSnapshot(
+ const prices = roundOffPrices((await getPrices()).join("\n"));
+ expect(prices).toMatchSnapshot(
`checkout-${plan.key}-discounted-prices.txt`
);
}
@@ -177,31 +180,19 @@ test("apply coupon after changing country", async ({ page }, {
await page.goto("/#/buy/");
- for (let plan of plans) {
- const planTestId = getTestId(`checkout-plan-${plan.key}`);
- await page.isEnabled(planTestId, { timeout: 10000 });
-
- await page.click(planTestId);
-
+ await forEachPlan(async (plan) => {
const paddleFrame = await getPaddleFrame();
await changeCountry(paddleFrame, "IN", "110001");
- await page.waitForTimeout(2000); // TODO unreliable
-
await page.fill(getTestId("checkout-coupon-code"), plan.coupon);
await page.press(getTestId("checkout-coupon-code"), "Enter");
await getPaddleFrame();
- const prices = await getPrices();
-
- expect(prices.join("\n")).toMatchSnapshot(
+ const prices = roundOffPrices((await getPrices()).join("\n"));
+ expect(prices).toMatchSnapshot(
`checkout-${plan.key}-IN-discounted-prices.txt`
);
-
- await page.click(getTestId("checkout-plan-change"));
-
- await page.waitForTimeout(1000);
- }
+ });
});
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-IN-discounted-prices-Chromium-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-IN-discounted-prices-Chromium-linux.txt
new file mode 100644
index 000000000..5511cc82b
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-IN-discounted-prices-Chromium-linux.txt
@@ -0,0 +1,5 @@
+subtotal: ₹410
+tax: ₹40
+discount: -₹210
+total: ₹240
+then ₹470/mo
\ No newline at end of file
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-IN-discounted-prices-Firefox-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-IN-discounted-prices-Firefox-linux.txt
new file mode 100644
index 000000000..5511cc82b
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-IN-discounted-prices-Firefox-linux.txt
@@ -0,0 +1,5 @@
+subtotal: ₹410
+tax: ₹40
+discount: -₹210
+total: ₹240
+then ₹470/mo
\ No newline at end of file
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-IN-discounted-prices-WebKit-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-IN-discounted-prices-WebKit-linux.txt
new file mode 100644
index 000000000..5d13e5e3d
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-IN-discounted-prices-WebKit-linux.txt
@@ -0,0 +1,5 @@
+subtotal: ₹410
+tax: ₹40
+discount: -₹210
+total: ₹240
+then ₹470/mo
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-IN-prices-Chromium-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-IN-prices-Chromium-linux.txt
new file mode 100644
index 000000000..76abca1c0
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-IN-prices-Chromium-linux.txt
@@ -0,0 +1,4 @@
+subtotal: ₹410
+tax: ₹70
+discount: ₹0
+total: ₹470/mo
\ No newline at end of file
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-IN-prices-Firefox-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-IN-prices-Firefox-linux.txt
new file mode 100644
index 000000000..76abca1c0
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-IN-prices-Firefox-linux.txt
@@ -0,0 +1,4 @@
+subtotal: ₹410
+tax: ₹70
+discount: ₹0
+total: ₹470/mo
\ No newline at end of file
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-IN-prices-WebKit-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-IN-prices-WebKit-linux.txt
new file mode 100644
index 000000000..660cfc41f
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-IN-prices-WebKit-linux.txt
@@ -0,0 +1,4 @@
+subtotal: ₹410
+tax: ₹70
+discount: ₹0
+total: ₹470/mo
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-discounted-prices-Chromium-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-discounted-prices-Chromium-linux.txt
new file mode 100644
index 000000000..3e6ce3205
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-discounted-prices-Chromium-linux.txt
@@ -0,0 +1,5 @@
+subtotal: $10
+tax: $0
+discount: -$10
+total: $10
+then $10/mo
\ No newline at end of file
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-discounted-prices-Firefox-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-discounted-prices-Firefox-linux.txt
new file mode 100644
index 000000000..3e6ce3205
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-discounted-prices-Firefox-linux.txt
@@ -0,0 +1,5 @@
+subtotal: $10
+tax: $0
+discount: -$10
+total: $10
+then $10/mo
\ No newline at end of file
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-discounted-prices-WebKit-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-discounted-prices-WebKit-linux.txt
new file mode 100644
index 000000000..ba4b6d366
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-discounted-prices-WebKit-linux.txt
@@ -0,0 +1,5 @@
+subtotal: $10
+tax: $0
+discount: -$10
+total: $10
+then $10/mo
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-prices-Chromium-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-prices-Chromium-linux.txt
new file mode 100644
index 000000000..3c65aafcb
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-prices-Chromium-linux.txt
@@ -0,0 +1,4 @@
+subtotal: $10
+tax: $0
+discount: $0
+total: $10/mo
\ No newline at end of file
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-prices-Firefox-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-prices-Firefox-linux.txt
new file mode 100644
index 000000000..3c65aafcb
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-prices-Firefox-linux.txt
@@ -0,0 +1,4 @@
+subtotal: $10
+tax: $0
+discount: $0
+total: $10/mo
\ No newline at end of file
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-prices-WebKit-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-prices-WebKit-linux.txt
new file mode 100644
index 000000000..e9391ad34
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-monthly-prices-WebKit-linux.txt
@@ -0,0 +1,4 @@
+subtotal: $10
+tax: $0
+discount: $0
+total: $10/mo
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-IN-discounted-prices-Chromium-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-IN-discounted-prices-Chromium-linux.txt
new file mode 100644
index 000000000..8cc760564
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-IN-discounted-prices-Chromium-linux.txt
@@ -0,0 +1,5 @@
+subtotal: ₹4510
+tax: ₹590
+discount: -₹680
+total: ₹4420
+then ₹5190/yr
\ No newline at end of file
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-IN-discounted-prices-Firefox-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-IN-discounted-prices-Firefox-linux.txt
new file mode 100644
index 000000000..8cc760564
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-IN-discounted-prices-Firefox-linux.txt
@@ -0,0 +1,5 @@
+subtotal: ₹4510
+tax: ₹590
+discount: -₹680
+total: ₹4420
+then ₹5190/yr
\ No newline at end of file
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-IN-discounted-prices-WebKit-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-IN-discounted-prices-WebKit-linux.txt
new file mode 100644
index 000000000..8d79581c3
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-IN-discounted-prices-WebKit-linux.txt
@@ -0,0 +1,5 @@
+subtotal: ₹4510
+tax: ₹590
+discount: -₹680
+total: ₹4420
+then ₹5190/yr
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-IN-prices-Chromium-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-IN-prices-Chromium-linux.txt
new file mode 100644
index 000000000..624436abe
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-IN-prices-Chromium-linux.txt
@@ -0,0 +1,4 @@
+subtotal: ₹4510
+tax: ₹690
+discount: ₹0
+total: ₹5190/yr
\ No newline at end of file
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-IN-prices-Firefox-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-IN-prices-Firefox-linux.txt
new file mode 100644
index 000000000..624436abe
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-IN-prices-Firefox-linux.txt
@@ -0,0 +1,4 @@
+subtotal: ₹4510
+tax: ₹690
+discount: ₹0
+total: ₹5190/yr
\ No newline at end of file
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-IN-prices-WebKit-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-IN-prices-WebKit-linux.txt
new file mode 100644
index 000000000..a17b2eda2
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-IN-prices-WebKit-linux.txt
@@ -0,0 +1,4 @@
+subtotal: ₹4510
+tax: ₹690
+discount: ₹0
+total: ₹5190/yr
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-discounted-prices-Chromium-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-discounted-prices-Chromium-linux.txt
new file mode 100644
index 000000000..d8ca4d5cd
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-discounted-prices-Chromium-linux.txt
@@ -0,0 +1,5 @@
+subtotal: $50
+tax: $0
+discount: -$10
+total: $50
+then $50/yr
\ No newline at end of file
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-discounted-prices-Firefox-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-discounted-prices-Firefox-linux.txt
new file mode 100644
index 000000000..d8ca4d5cd
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-discounted-prices-Firefox-linux.txt
@@ -0,0 +1,5 @@
+subtotal: $50
+tax: $0
+discount: -$10
+total: $50
+then $50/yr
\ No newline at end of file
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-discounted-prices-WebKit-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-discounted-prices-WebKit-linux.txt
new file mode 100644
index 000000000..0aa1e9a79
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-discounted-prices-WebKit-linux.txt
@@ -0,0 +1,5 @@
+subtotal: $50
+tax: $0
+discount: -$10
+total: $50
+then $50/yr
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-prices-Chromium-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-prices-Chromium-linux.txt
new file mode 100644
index 000000000..a9b5bd67e
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-prices-Chromium-linux.txt
@@ -0,0 +1,4 @@
+subtotal: $50
+tax: $0
+discount: $0
+total: $50/yr
\ No newline at end of file
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-prices-Firefox-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-prices-Firefox-linux.txt
new file mode 100644
index 000000000..a9b5bd67e
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-prices-Firefox-linux.txt
@@ -0,0 +1,4 @@
+subtotal: $50
+tax: $0
+discount: $0
+total: $50/yr
\ No newline at end of file
diff --git a/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-prices-WebKit-linux.txt b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-prices-WebKit-linux.txt
new file mode 100644
index 000000000..935d93119
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js-snapshots/checkout-yearly-prices-WebKit-linux.txt
@@ -0,0 +1,4 @@
+subtotal: $50
+tax: $0
+discount: $0
+total: $50/yr
diff --git a/apps/web/src/common/checkout.js b/apps/web/src/common/checkout.js
index 96d21f5a1..7f0a8e2c2 100644
--- a/apps/web/src/common/checkout.js
+++ b/apps/web/src/common/checkout.js
@@ -63,6 +63,9 @@ function inlineCheckout({ user, plan, coupon, country, onCheckoutLoaded }) {
const { Paddle } = window;
if (!Paddle) return;
+ const container = document.getElementsByClassName("checkout-container")[0];
+ if (!container) return;
+
if (coupon) {
trackEvent(ANALYTICS_EVENTS.offerClaimed, `[${coupon}] redeemed!`);
} else {