Skip to content

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

test: add checkout tests

thecodrr837ad7772bcb
diff --git a/apps/web/__e2e__/checkout.test.js b/apps/web/__e2e__/checkout.test.js
new file mode 100644
index 000000000..3ad9d81ff
--- /dev/null
+++ b/apps/web/__e2e__/checkout.test.js
@@ -0,0 +1,207 @@
+const { Page, test, expect } = require("@playwright/test");
+const { getTestId, isTestAll, loginUser } = require("./utils");
+const { isAbsent, isPresent } = require("./utils/conditions");
+const path = require("path");
+
+/**
+ * @type {Page}
+ */
+var page = null;
+global.page = null;
+test.beforeEach(async ({ page: _page, baseURL }) => {
+ global.page = _page;
+ page = _page;
+ await page.goto(baseURL);
+ await page.waitForSelector(getTestId("routeHeader"));
+});
+
+// if (!isTestAll()) test.skip();
+
+const plans = [
+ { key: "monthly", title: "Monthly", coupon: "INTRO50" },
+ { key: "yearly", title: "Yearly", coupon: "YEAR15" },
+];
+const pricingItems = ["subtotal", "tax", "discount", "total"];
+
+function getPaddleTestId(id) {
+ return `[data-testid="${id}"]`;
+}
+
+async function getPrices() {
+ let prices = [];
+ for (let item of pricingItems) {
+ const price = await page.innerText(getTestId(`checkout-price-${item}`));
+ prices.push(`${item}: ${price}`);
+ }
+ return prices;
+}
+
+async function getPaddleFrame(selector = "inlineComplianceBarContainer") {
+ await page.waitForSelector(`.checkout-container iframe`);
+
+ const paddleFrame = await (
+ await page.$(".checkout-container iframe")
+ ).contentFrame();
+ await paddleFrame.waitForSelector(getPaddleTestId(selector));
+
+ return paddleFrame;
+}
+
+async function changeCountry(paddleFrame, countryCode, pinCode) {
+ await paddleFrame.selectOption(
+ getPaddleTestId("countriesSelect"),
+ countryCode
+ );
+
+ if (pinCode)
+ await paddleFrame.fill(getPaddleTestId("postcodeInput"), pinCode);
+
+ await paddleFrame.click(getPaddleTestId("locationFormSubmitButton"));
+
+ await page.waitForTimeout(1000);
+}
+
+test("change plans", async ({ page }) => {
+ await loginUser();
+
+ await page.goto("/#/buy/");
+
+ for (let plan of plans) {
+ const planTestId = getTestId(`checkout-plan-${plan.key}`);
+ await page.click(planTestId);
+
+ 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 }) => {
+ await loginUser();
+
+ 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"));
+ }
+});
+
+test("changing locale should show localized prices", async ({ page }) => {
+ await loginUser();
+
+ await page.goto("/#/buy/");
+
+ for (let plan of plans) {
+ const planTestId = getTestId(`checkout-plan-${plan.key}`);
+ await page.click(planTestId);
+
+ 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"));
+ }
+});
+
+test("applying coupon should change discount & total price", async ({ page }, {
+ setTimeout,
+}) => {
+ setTimeout(60 * 1000);
+
+ await loginUser();
+
+ 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 getPaddleFrame();
+
+ 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(
+ `checkout-${plan.key}-discounted-prices.txt`
+ );
+
+ await page.click(getTestId("checkout-plan-change"));
+
+ await page.waitForTimeout(1000);
+ }
+});
+
+test("apply coupon through url", async ({ page }) => {
+ await loginUser();
+
+ for (let plan of plans) {
+ await page.goto(`/#/buy/${plan.key}/${plan.coupon}`);
+
+ await getPaddleFrame();
+
+ const prices = await getPrices();
+
+ expect(prices.join("\n")).toMatchSnapshot(
+ `checkout-${plan.key}-discounted-prices.txt`
+ );
+ }
+});
+
+test("apply coupon after changing country", async ({ page }, {
+ setTimeout,
+}) => {
+ setTimeout(60 * 1000);
+
+ await loginUser();
+
+ 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);
+
+ 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(
+ `checkout-${plan.key}-IN-discounted-prices.txt`
+ );
+
+ await page.click(getTestId("checkout-plan-change"));
+
+ await page.waitForTimeout(1000);
+ }
+});
diff --git a/apps/web/__e2e__/importer.test.js b/apps/web/__e2e__/importer.test.js
new file mode 100644
index 000000000..b6fd061ca
--- /dev/null
+++ b/apps/web/__e2e__/importer.test.js
@@ -0,0 +1,45 @@
+const { Page, test, expect } = require("@playwright/test");
+const { getTestId, isTestAll, loginUser } = require("./utils");
+const path = require("path");
+
+/**
+ * @type {Page}
+ */
+var page = null;
+global.page = null;
+test.beforeEach(async ({ page: _page, baseURL }) => {
+ global.page = _page;
+ page = _page;
+ await page.goto(baseURL);
+ await page.waitForSelector(getTestId("routeHeader"));
+});
+
+if (!isTestAll()) test.skip();
+
+test("login user & import notes", async () => {
+ await loginUser();
+
+ await page.click(getTestId("navitem-settings"));
+
+ await page.click(getTestId("settings-importer"));
+
+ await page.click(getTestId("settings-importer-import"));
+
+ const [fileChooser] = await Promise.all([
+ page.waitForEvent("filechooser"),
+ page.click(getTestId("import-dialog-select-files")),
+ ]);
+
+ await fileChooser.setFiles(path.join(__dirname, "data", "importer-data.zip"));
+
+ await page.click(getTestId("importer-dialog-notes"));
+
+ let titles = [];
+ for (let i = 0; i < 6; ++i) {
+ const noteId = getTestId(`note-${i}`);
+ const text = await page.innerText(noteId);
+ titles.push(text);
+ }
+
+ expect(titles.join("\n")).toMatchSnapshot("importer-notes-titles.txt");
+});
diff --git a/apps/web/__e2e__/user.test.js b/apps/web/__e2e__/user.test.js
index 3848a8e4e..c686b7030 100644
--- a/apps/web/__e2e__/user.test.js
+++ b/apps/web/__e2e__/user.test.js
@@ -1,11 +1,8 @@
const { Page, test, expect } = require("@playwright/test");
-const { getTestId, isTestAll } = require("./utils");
+const { getTestId, isTestAll, loginUser } = require("./utils");
const { isAbsent, isPresent } = require("./utils/conditions");
-const dotenv = require("dotenv");
const path = require("path");
-dotenv.config({ path: path.join(__dirname, ".env.local") });
-
/**
* @type {Page}
*/
@@ -18,29 +15,12 @@ test.beforeEach(async ({ page: _page, baseURL }) => {
await page.waitForSelector(getTestId("routeHeader"));
});
-const USER = {
- email: process.env.USER_EMAIL,
- password: process.env.USER_PASSWORD,
-};
-
if (!isTestAll()) test.skip();
-async function loginUser() {
- await page.click(getTestId("navitem-login"));
-
- await page.fill(getTestId("email"), USER.email);
-
- await page.fill(getTestId("password"), USER.password);
-
- await page.click(getTestId("submitButton"));
-
- await page.waitForSelector(getTestId("navitem-sync"));
-
- expect(await isPresent(getTestId("navitem-sync"))).toBe(true);
-}
-
test("login user", async () => {
await loginUser();
+
+ expect(await isPresent(getTestId("navitem-sync"))).toBe(true);
});
test("logout user", async () => {
@@ -56,31 +36,3 @@ test("logout user", async () => {
expect(await isAbsent(getTestId("navitem-sync"))).toBe(true);
});
-
-test("login user & import notes", async () => {
- await loginUser();
-
- await page.click(getTestId("navitem-settings"));
-
- await page.click(getTestId("settings-importer"));
-
- await page.click(getTestId("settings-importer-import"));
-
- const [fileChooser] = await Promise.all([
- page.waitForEvent("filechooser"),
- page.click(getTestId("import-dialog-select-files")),
- ]);
-
- await fileChooser.setFiles(path.join(__dirname, "data", "importer-data.zip"));
-
- await page.click(getTestId("importer-dialog-notes"));
-
- let titles = [];
- for (let i = 0; i < 6; ++i) {
- const noteId = getTestId(`note-${i}`);
- const text = await page.innerText(noteId);
- titles.push(text);
- }
-
- expect(titles.join("\n")).toMatchSnapshot("importer-notes-titles.txt");
-});
diff --git a/apps/web/__e2e__/utils/index.js b/apps/web/__e2e__/utils/index.js
index a630628f9..f16546a18 100644
--- a/apps/web/__e2e__/utils/index.js
+++ b/apps/web/__e2e__/utils/index.js
@@ -1,5 +1,26 @@
/* eslint-disable no-undef */
const fs = require("fs");
+const dotenv = require("dotenv");
+const path = require("path");
+
+dotenv.config({ path: path.join(__dirname, ".env.local") });
+
+const USER = {
+ email: process.env.USER_EMAIL,
+ password: process.env.USER_PASSWORD,
+};
+
+async function loginUser(user = USER) {
+ await page.click(getTestId("navitem-login"));
+
+ await page.fill(getTestId("email"), user.email);
+
+ await page.fill(getTestId("password"), user.password);
+
+ await page.click(getTestId("submitButton"));
+
+ await page.waitForSelector(getTestId("navitem-sync"));
+}
const NOTEBOOK = {
title: "Test notebook 1",
@@ -88,4 +109,5 @@ module.exports = {
getEditorContent,
getEditorContentAsHTML,
isTestAll,
+ loginUser,
};