Skip to content

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

mobile: misc bug fixes

Ammar Ahmedee33875edfeb
diff --git a/apps/mobile/app/components/sheets/paywall/index.tsx b/apps/mobile/app/components/sheets/paywall/index.tsx
index 05e6b5b25..195352a10 100644
--- a/apps/mobile/app/components/sheets/paywall/index.tsx
+++ b/apps/mobile/app/components/sheets/paywall/index.tsx
@@ -3,7 +3,7 @@ import { SubscriptionPlan, SubscriptionProvider } from "@notesnook/core";
import { strings } from "@notesnook/intl";
import { useThemeColors } from "@notesnook/theme";
import { useEffect } from "react";
-import { View } from "react-native";
+import { Platform, View } from "react-native";
import Config from "react-native-config";
import usePricingPlans, {
PlanOverView
@@ -61,6 +61,12 @@ export default function PaywallSheet<Tid extends FeatureId>(props: {
pricingPlans.user?.subscription.provider ===
SubscriptionProvider.STREETWRITERS;
+ const isCurrentPlatform =
+ (pricingPlans.user?.subscription.provider === SubscriptionProvider.APPLE &&
+ Platform.OS === "ios") ||
+ (pricingPlans.user?.subscription.provider === SubscriptionProvider.GOOGLE &&
+ Platform.OS === "android");
+
return !pricingPlans.currentPlan ? null : (
<View
style={{
@@ -189,7 +195,8 @@ export default function PaywallSheet<Tid extends FeatureId>(props: {
onPress={() => {
if (
pricingPlans.user?.subscription.plan ===
- SubscriptionPlan.LEGACY_PRO
+ SubscriptionPlan.LEGACY_PRO ||
+ !isCurrentPlatform
) {
ToastManager.show({
message: strings.cannotChangePlan(),
diff --git a/apps/mobile/app/components/sheets/plan-limits/index.tsx b/apps/mobile/app/components/sheets/plan-limits/index.tsx
index c8c99ac0d..d5170a07a 100644
--- a/apps/mobile/app/components/sheets/plan-limits/index.tsx
+++ b/apps/mobile/app/components/sheets/plan-limits/index.tsx
@@ -7,7 +7,7 @@ import {
import { strings } from "@notesnook/intl";
import { useThemeColors } from "@notesnook/theme";
import { useEffect, useState } from "react";
-import { View } from "react-native";
+import { Platform, View } from "react-native";
import { ScrollView } from "react-native-actions-sheet";
import { eSendEvent, ToastManager } from "../../../services/event-manager";
import Navigation from "../../../services/navigation";
@@ -34,6 +34,12 @@ export function PlanLimits() {
.catch((e) => console.log(e));
}, []);
+ const isCurrentPlatform =
+ (user?.subscription.provider === SubscriptionProvider.APPLE &&
+ Platform.OS === "ios") ||
+ (user?.subscription.provider === SubscriptionProvider.GOOGLE &&
+ Platform.OS === "android");
+
return (
<ScrollView
style={{
@@ -79,7 +85,8 @@ export function PlanLimits() {
))}
{(user?.subscription.provider === SubscriptionProvider.PADDLE ||
- user?.subscription.provider === SubscriptionProvider.STREETWRITERS) &&
+ user?.subscription.provider === SubscriptionProvider.STREETWRITERS ||
+ !isCurrentPlatform) &&
PremiumService.get() ? null : (
<Button
title={strings.changePlan()}
diff --git a/apps/mobile/app/components/ui/sheet/index.js b/apps/mobile/app/components/ui/sheet/index.js
index d4a4054fd..4aaa5903a 100644
--- a/apps/mobile/app/components/ui/sheet/index.js
+++ b/apps/mobile/app/components/ui/sheet/index.js
@@ -132,6 +132,7 @@ const SheetWrapper = ({
width: 100,
backgroundColor: colors.secondary.background
}}
+ safeAreaInsets={insets}
statusBarTranslucent
drawUnderStatusBar={true}
containerStyle={style}
diff --git a/apps/mobile/app/screens/settings/settings-data.tsx b/apps/mobile/app/screens/settings/settings-data.tsx
index 7f4669c6f..bd810ed0e 100644
--- a/apps/mobile/app/screens/settings/settings-data.tsx
+++ b/apps/mobile/app/screens/settings/settings-data.tsx
@@ -99,9 +99,16 @@ export const settingsGroups: SettingSection[] = [
const subscriptionProviderInfo =
strings.subscriptionProviderInfo[user?.subscription?.provider];
+ const isCurrentPlatform =
+ (user.subscription.provider === SubscriptionProvider.APPLE &&
+ Platform.OS === "ios") ||
+ (user.subscription.provider === SubscriptionProvider.GOOGLE &&
+ Platform.OS === "android");
+
if (
- user.subscription?.provider === SubscriptionProvider.GOOGLE ||
- user.subscription?.provider === SubscriptionProvider.APPLE
+ (user.subscription?.provider === SubscriptionProvider.GOOGLE ||
+ user.subscription?.provider === SubscriptionProvider.APPLE) &&
+ isCurrentPlatform
) {
RNIap.deepLinkToSubscriptions({
sku: user?.subscription.productId
diff --git a/apps/mobile/app/screens/settings/user-section.jsx b/apps/mobile/app/screens/settings/user-section.jsx
index 3556bd24f..93cba9fe2 100644
--- a/apps/mobile/app/screens/settings/user-section.jsx
+++ b/apps/mobile/app/screens/settings/user-section.jsx
@@ -18,11 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { formatBytes } from "@notesnook/common";
-import {
- SubscriptionPlan,
- SubscriptionProvider,
- SubscriptionStatus
-} from "@notesnook/core";
+import { SubscriptionPlan, SubscriptionProvider } from "@notesnook/core";
import { strings } from "@notesnook/intl";
import { useThemeColors } from "@notesnook/theme";
import { useNetInfo } from "@react-native-community/netinfo";
@@ -40,13 +36,13 @@ import { TimeSince } from "../../components/ui/time-since";
import Paragraph from "../../components/ui/typography/paragraph";
import { presentSheet, ToastManager } from "../../services/event-manager";
import Navigation from "../../services/navigation";
+import PremiumService from "../../services/premium";
import { useThemeStore } from "../../stores/use-theme-store";
import { SyncStatus, useUserStore } from "../../stores/use-user-store";
import { planToDisplayName } from "../../utils/constants";
import { AppFontSize } from "../../utils/size";
import { DefaultAppStyles } from "../../utils/styles";
import { SectionItem } from "./section-item";
-import PremiumService from "../../services/premium";
export const getTimeLeft = (t2) => {
let daysRemaining = dayjs(t2).diff(dayjs(), "days");
@@ -136,6 +132,12 @@ const SettingsUserSection = ({ item }) => {
const used = user?.storageUsed || 0;
const total = user?.totalStorage || 0;
+ const isCurrentPlatform =
+ (user.subscription.provider === SubscriptionProvider.APPLE &&
+ Platform.OS === "ios") ||
+ (user.subscription.provider === SubscriptionProvider.GOOGLE &&
+ Platform.OS === "android");
+
return (
<>
{user ? (
@@ -339,7 +341,8 @@ const SettingsUserSection = ({ item }) => {
{(user.subscription.provider === SubscriptionProvider.PADDLE ||
user.subscription.provider ===
- SubscriptionProvider.STREETWRITERS) &&
+ SubscriptionProvider.STREETWRITERS ||
+ !isCurrentPlatform) &&
PremiumService.get() ? null : (
<Button
title={
diff --git a/apps/mobile/app/services/premium.ts b/apps/mobile/app/services/premium.ts
index 6a744986e..8ca5bd9d9 100644
--- a/apps/mobile/app/services/premium.ts
+++ b/apps/mobile/app/services/premium.ts
@@ -217,7 +217,7 @@ const subscriptions = {
try {
let result = await fetch(
__DEV__
- ? "http://192.168.100.79:4264/apple/verify"
+ ? "https://payments.streetwriters.co/apple/verify"
: "https://payments.streetwriters.co/apple/verify",
requestData
);
diff --git a/apps/mobile/e2e/tests/note.e2e.ts b/apps/mobile/e2e/tests/note.e2e.ts
index a4ad34874..2dcde6e14 100644
--- a/apps/mobile/e2e/tests/note.e2e.ts
+++ b/apps/mobile/e2e/tests/note.e2e.ts
@@ -1,129 +1,133 @@
-/*
-This file is part of the Notesnook project (https://notesnook.com/)
-
-Copyright (C) 2023 Streetwriters (Private) Limited
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
import { notesnook } from "../test.ids";
-import { Tests } from "./utils";
+import { TestBuilder } from "./utils";
describe("NOTE TESTS", () => {
it("Create a note in editor", async () => {
- await Tests.prepare();
- await Tests.createNote();
+ await TestBuilder.create().prepare().createNote().run();
});
it("Open and close a note", async () => {
- await Tests.prepare();
- await Tests.createNote();
- await Tests.fromId(notesnook.ids.note.get(0)).waitAndTap();
- await Tests.exitEditor();
+ await TestBuilder.create()
+ .prepare()
+ .createNote()
+ .waitAndTapById(notesnook.ids.note.get(0))
+ .exitEditor()
+ .run();
});
it("Notes properties should show", async () => {
- await Tests.prepare();
- await Tests.createNote();
- await Tests.fromId(notesnook.listitem.menu).waitAndTap();
- await Tests.sleep(500);
- await Tests.fromText("Created at").isVisible();
+ await TestBuilder.create()
+ .prepare()
+ .createNote()
+ .waitAndTapById(notesnook.listitem.menu)
+ .wait(500)
+ .isVisibleByText("Created at")
+ .run();
});
it("Favorite and unfavorite a note", async () => {
- await Tests.prepare();
- let note = await Tests.createNote();
- await Tests.fromId(notesnook.listitem.menu).waitAndTap();
- await Tests.sleep(500);
- await Tests.fromId("icon-favorite").waitAndTap();
- await device.pressBack();
- await Tests.fromId("icon-star").isVisible();
- await Tests.navigate("Favorites");
- await Tests.fromText(note.body).isVisible();
- await Tests.fromId(notesnook.listitem.menu).waitAndTap();
- await Tests.sleep(500);
- await Tests.fromId("icon-favorite").waitAndTap();
- await device.pressBack();
- await Tests.fromText(note.body).isNotVisible();
- await Tests.navigate("Notes");
+ await TestBuilder.create()
+ .prepare()
+ .createNote()
+ .saveResult()
+ .waitAndTapById(notesnook.listitem.menu)
+ .wait(500)
+ .waitAndTapById("icon-favorite")
+ .pressBack()
+ .isVisibleById("icon-star")
+ .navigate("Favorites")
+ .processResult(async (note) => {
+ await TestBuilder.create()
+ .isVisibleByText(note.body)
+ .waitAndTapById(notesnook.listitem.menu)
+ .wait(500)
+ .waitAndTapById("icon-favorite")
+ .pressBack()
+ .isNotVisibleByText(note.body)
+ .navigate("Notes")
+ .run();
+ })
+ .run();
});
it("Pin a note to top", async () => {
- await Tests.prepare();
- await Tests.createNote();
- await Tests.fromId(notesnook.listitem.menu).waitAndTap();
- await Tests.sleep(500);
- await Tests.fromId("icon-pin").waitAndTap();
- await device.pressBack();
- await Tests.fromText("PINNED").isVisible();
- await Tests.fromId("icon-pinned").isVisible();
- await Tests.fromId(notesnook.listitem.menu).waitAndTap();
- await Tests.sleep(500);
- await Tests.fromId("icon-pin").waitAndTap();
- await device.pressBack();
- await Tests.fromText("icon-pinned").isNotVisible();
+ await TestBuilder.create()
+ .prepare()
+ .createNote()
+ .waitAndTapById(notesnook.listitem.menu)
+ .wait(500)
+ .waitAndTapById("icon-pin")
+ .pressBack()
+ .isVisibleByText("PINNED")
+ .isVisibleById("icon-pinned")
+ .waitAndTapById(notesnook.listitem.menu)
+ .wait(500)
+ .waitAndTapById("icon-pin")
+ .pressBack()
+ .isNotVisibleByText("icon-pinned")
+ .run();
});
it.skip("Pin a note in notifications", async () => {
- await Tests.prepare();
- await Tests.createNote();
- await Tests.fromId(notesnook.listitem.menu).waitAndTap();
- await Tests.fromId("icon-pin-to-notifications").waitAndTap();
- await Tests.fromText("Unpin from notifications").isVisible();
- await Tests.fromId("icon-pin-to-notifications").waitAndTap();
- await Tests.fromText("Pin to notifications").isVisible();
+ await TestBuilder.create()
+ .prepare()
+ .createNote()
+ .waitAndTapById(notesnook.listitem.menu)
+ .waitAndTapById("icon-pin-to-notifications")
+ .isVisibleByText("Unpin from notifications")
+ .waitAndTapById("icon-pin-to-notifications")
+ .isVisibleByText("Pin to notifications")
+ .run();
});
it("Copy note", async () => {
- await Tests.prepare();
- await Tests.createNote();
- await Tests.fromId(notesnook.listitem.menu).waitAndTap();
- await Tests.sleep(500);
- await Tests.fromId("icon-copy").isVisible();
- await Tests.fromId("icon-copy").waitAndTap();
+ await TestBuilder.create()
+ .prepare()
+ .createNote()
+ .waitAndTapById(notesnook.listitem.menu)
+ .wait(500)
+ .isVisibleById("icon-copy")
+ .waitAndTapById("icon-copy")
+ .run();
});
it("Assign colors to a note", async () => {
- await Tests.prepare();
- let note = await Tests.createNote();
- await Tests.fromId(notesnook.listitem.menu).waitAndTap();
- await Tests.sleep(500);
- await Tests.fromText("Add color").waitAndTap();
- await Tests.fromId("color-title-input").element.typeText("Test color");
- await Tests.fromText("Add color").waitAndTap();
- await Tests.fromId("icon-check").isVisible();
- await Tests.fromId("icon-color-#efefef").waitAndTap();
- await Tests.fromId("icon-check").isNotVisible();
- await Tests.fromId("icon-color-#efefef").waitAndTap();
- await device.pressBack();
- await Tests.navigate("Test color");
- await Tests.fromText(note.body).isVisible();
+ await TestBuilder.create()
+ .prepare()
+ .createNote()
+ .saveResult()
+ .waitAndTapById(notesnook.listitem.menu)
+ .wait(500)
+ .waitAndTapByText("Add color")
+ .typeTextById("color-title-input", "Test color")
+ .waitAndTapByText("Add color")
+ .isVisibleById("icon-check")
+ .waitAndTapById("icon-color-#efefef")
+ .isNotVisibleById("icon-check")
+ .waitAndTapById("icon-color-#efefef")
+ .pressBack()
+ .navigate("Test color")
+ .processResult(async (note) => {
+ await TestBuilder.create().isVisibleByText(note.body).run();
+ })
+ .run();
});
it("Delete & restore a note", async () => {
- await Tests.prepare();
- await Tests.createNote();
- await Tests.fromId(notesnook.listitem.menu).waitAndTap();
- await Tests.sleep(500);
- await Tests.fromId("icon-trash").waitAndTap();
- await Tests.navigate("Trash");
- await Tests.fromId(notesnook.listitem.menu).waitAndTap();
- await Tests.sleep(500);
- await Tests.fromText("Restore").waitAndTap();
- await device.pressBack();
- await Tests.fromText(
- "Test note description that is very long and should not fit in text."
- ).isVisible();
+ await TestBuilder.create()
+ .prepare()
+ .createNote()
+ .waitAndTapById(notesnook.listitem.menu)
+ .wait(500)
+ .waitAndTapById("icon-trash")
+ .navigate("Trash")
+ .waitAndTapById(notesnook.listitem.menu)
+ .wait(500)
+ .waitAndTapByText("Restore")
+ .pressBack()
+ .isVisibleByText(
+ "Test note description that is very long and should not fit in text."
+ )
+ .run();
});
});
diff --git a/apps/mobile/e2e/tests/utils.ts b/apps/mobile/e2e/tests/utils.ts
index 799b9b3c8..f9d051303 100644
--- a/apps/mobile/e2e/tests/utils.ts
+++ b/apps/mobile/e2e/tests/utils.ts
@@ -151,9 +151,15 @@ const Tests = {
class TestBuilder {
private steps: (() => Promise<void> | void)[] = [];
private result: any;
-
+ private savedResult: any;
constructor() {}
+ saveResult() {
+ return this.addStep(() => {
+ this.savedResult = this.result;
+ });
+ }
+
addStep(step: () => Promise<void> | void) {
this.steps.push(step);
return this;
@@ -161,13 +167,13 @@ class TestBuilder {
awaitLaunch() {
return this.addStep(async () => {
- this.result = await Tests.awaitLaunch();
+ await Tests.awaitLaunch();
});
}
wait(duration: number) {
- return this.addStep(() => {
- this.result = Tests.sleep(duration);
+ return this.addStep(async () => {
+ await Tests.sleep(duration);
});
}
@@ -185,7 +191,7 @@ class TestBuilder {
exitEditor() {
return this.addStep(async () => {
- this.result = await Tests.exitEditor();
+ await Tests.exitEditor();
});
}
@@ -197,101 +203,106 @@ class TestBuilder {
navigate(screen: RouteName | ({} & string)) {
return this.addStep(async () => {
- this.result = await Tests.navigate(screen);
+ await Tests.navigate(screen);
});
}
openSideMenu() {
return this.addStep(async () => {
- this.result = await Tests.openSideMenu();
+ await Tests.openSideMenu();
});
}
prepare() {
return this.addStep(async () => {
- this.result = await Tests.prepare();
+ await Tests.prepare();
});
}
createNotebook(title = "Notebook 1", description = true) {
return this.addStep(async () => {
- this.result = await Tests.createNotebook(title, description);
+ await Tests.createNotebook(title, description);
});
}
matchSnapshot(element: Element, name: string) {
return this.addStep(async () => {
- this.result = await Tests.matchSnapshot(element, name);
+ await Tests.matchSnapshot(element, name);
});
}
isVisibleById(id: string, timeout?: number) {
return this.addStep(async () => {
const element = new Element("id", id);
- this.result = await element.isVisible(timeout);
+ await element.isVisible(timeout);
});
}
isVisibleByText(text: string, timeout?: number) {
return this.addStep(async () => {
const element = new Element("text", text);
- this.result = await element.isVisible(timeout);
+ await element.isVisible(timeout);
});
}
isNotVisibleById(id: string, timeout?: number) {
return this.addStep(async () => {
const element = new Element("id", id);
- this.result = await element.isNotVisible(timeout);
+ await element.isNotVisible(timeout);
});
}
isNotVisibleByText(text: string, timeout?: number) {
return this.addStep(async () => {
const element = new Element("text", text);
- this.result = await element.isNotVisible(timeout);
+ await element.isNotVisible(timeout);
});
}
waitAndTapById(id: string, timeout?: number) {
return this.addStep(async () => {
const element = new Element("id", id);
- this.result = await element.waitAndTap(timeout);
+ await element.waitAndTap(timeout);
});
}
waitAndTapByText(text: string, timeout?: number) {
return this.addStep(async () => {
const element = new Element("text", text);
- this.result = await element.waitAndTap(timeout);
+ await element.waitAndTap(timeout);
});
}
tapById(id: string, point?: Detox.Point2D) {
return this.addStep(async () => {
const element = new Element("id", id);
- this.result = await element.tap(point);
+ await element.tap(point);
});
}
tapByText(text: string, point?: Detox.Point2D) {
return this.addStep(async () => {
const element = new Element("text", text);
- this.result = await element.tap(point);
+ await element.tap(point);
});
}
- processResult(callback: (result: any) => void) {
+ processResult(callback: (result: any) => Promise<void>) {
return this.addStep(async () => {
- if (this.result !== undefined) {
- callback(this.result);
- this.result = undefined; // Clear the result after processing
+ if (this.savedResult) {
+ await callback(this.savedResult);
} else {
throw new Error("No result to process.");
}
});
}
+ typeTextById(id: string, text: string) {
+ return this.addStep(async () => {
+ await Element.fromId(id).element.typeText(text);
+ });
+ }
+
pressBack(count = 1) {
return this.addStep(async () => {
for (let i = 0; i < count; i++) {
@@ -302,7 +313,7 @@ class TestBuilder {
async run() {
for (const step of this.steps) {
- const result = step();
+ const result = step.call(this);
if (result instanceof Promise) {
await result;
}