Skip to content

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

feat: improve checkout & enable checkout tests

thecodrr13e73afe4008
diff --git a/apps/web/__e2e__/checkout.test.js b/apps/web/__e2e__/checkout.test.js
index d9d2acd36..909d38006 100644
--- a/apps/web/__e2e__/checkout.test.js
+++ b/apps/web/__e2e__/checkout.test.js
@@ -1,5 +1,5 @@
-const { Page, test, expect } = require("@playwright/test");
-const { getTestId, isTestAll, loginUser } = require("./utils");
+const { test, expect } = require("@playwright/test");
+const { getTestId, loginUser } = require("./utils");
test.setTimeout(45 * 1000);
/**
@@ -14,8 +14,6 @@ test.beforeEach(async ({ page: _page, baseURL }) => {
await page.waitForSelector(getTestId("routeHeader"));
});
-if (!isTestAll()) test.skip();
-
const plans = [
{ key: "monthly", title: "Monthly", coupon: "INTRO50" },
{ key: "yearly", title: "Yearly", coupon: "YEAR15" },
@@ -122,7 +120,9 @@ test("change plans", async ({ page }, info) => {
});
});
-test("confirm plan prices", async ({ page }) => {
+test("confirm plan prices", async ({ page }, info) => {
+ info.setTimeout(0);
+
await loginUser();
await page.goto("/#/buy/");
@@ -158,10 +158,10 @@ test("changing locale should show localized prices", async ({ page }, info) => {
});
});
-test("applying coupon should change discount & total price", async ({ page }, {
- setTimeout,
-}) => {
- setTimeout(0);
+test("applying coupon should change discount & total price", async ({
+ page,
+}, info) => {
+ info.setTimeout(0);
await loginUser();
@@ -191,8 +191,8 @@ test("applying coupon should change discount & total price", async ({ page }, {
});
});
-test("apply coupon through url", async ({ page }, { setTimeout }) => {
- setTimeout(0);
+test("apply coupon through url", async ({ page }, info) => {
+ info.setTimeout(0);
await loginUser();
for (let plan of plans) {
@@ -211,10 +211,8 @@ test("apply coupon through url", async ({ page }, { setTimeout }) => {
}
});
-test("apply coupon after changing country", async ({ page }, {
- setTimeout,
-}) => {
- setTimeout(0);
+test("apply coupon after changing country", async ({ page }, info) => {
+ info.setTimeout(0);
await loginUser();
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
index fa9c192dc..4df59a7ba 100644
--- 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
@@ -1,5 +1,5 @@
-subtotal: ₹350
+subtotal: ₹370
tax: ₹70
-discount: -₹210
-total: ₹210
-then ₹410/mo
\ No newline at end of file
+discount: -₹220
+total: ₹220
+then ₹430/mo
\ No newline at end of file
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
index 4fe57ada1..70a969862 100644
--- 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
@@ -1,4 +1,4 @@
-subtotal: ₹350
+subtotal: ₹370
tax: ₹70
discount: ₹0
-total: ₹410/mo
\ No newline at end of file
+total: ₹430/mo
\ No newline at end of file
diff --git a/apps/web/src/components/dialogs/buy-dialog/buy-dialog.tsx b/apps/web/src/components/dialogs/buy-dialog/buy-dialog.tsx
index 034c7329b..0ada79ed3 100644
--- a/apps/web/src/components/dialogs/buy-dialog/buy-dialog.tsx
+++ b/apps/web/src/components/dialogs/buy-dialog/buy-dialog.tsx
@@ -304,7 +304,10 @@ function TrialOrUpgrade(props: TrialOrUpgradeProps) {
p={1}
sx={{ borderRadius: "default" }}
>
- Please sign up or login to use your coupon: <b>{couponCode}</b>
+ {user
+ ? "Please select a plan to use your coupon:"
+ : `Please sign up or login to use your coupon:`}{" "}
+ <b>{couponCode}</b>
</Text>
)}
</>
@@ -326,6 +329,7 @@ function SelectedPlan(props: SelectedPlanProps) {
]);
const onApplyCoupon = useCheckoutStore((store) => store.onApplyCoupon);
+ const couponCode = useCheckoutStore((store) => store.couponCode);
const couponInputRef = useRef<HTMLInputElement>();
const applyCoupon = useCallback(() => {
@@ -347,9 +351,14 @@ function SelectedPlan(props: SelectedPlanProps) {
const couponValue = couponInputRef.current.value;
const isInvalidCoupon =
- !!couponValue && couponValue !== pricingInfo?.coupon;
+ (!!couponValue && couponValue !== pricingInfo?.coupon) ||
+ (!!couponCode && couponCode !== pricingInfo?.coupon);
+
setIsInvalidCoupon(isInvalidCoupon);
- if (isInvalidCoupon) return;
+ if (isInvalidCoupon) {
+ if (couponCode) couponInputRef.current.value = couponCode;
+ return;
+ }
const pricingInfoCoupon = pricingInfo?.coupon || "";
if (couponValue !== pricingInfoCoupon) {
diff --git a/apps/web/src/views/settings.js b/apps/web/src/views/settings.js
index 7d1165b47..4e998af5c 100644
--- a/apps/web/src/views/settings.js
+++ b/apps/web/src/views/settings.js
@@ -931,14 +931,14 @@ function AccountStatus(props) {
mt={1}
onClick={() => {
if (user.isEmailConfirmed)
- showBuyDialog("monthly", isTrial ? "TRIAL2PRO" : undefined);
+ showBuyDialog(undefined, isTrial ? "TRIAL2PRO" : undefined);
else showEmailVerificationDialog();
}}
>
{isProCancelled
? "Resubscribe to Notesnook Pro"
: isTrial
- ? "Upgrade at 50% OFF (first month)"
+ ? "Upgrade at 50% OFF"
: user.isEmailConfirmed
? "Upgrade to Notesnook Pro"
: "Confirm your email to sync your notes."}