Skip to content

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

web: fix backup/export tests

Abdullah Atta48061962b1ae
diff --git a/apps/web/__e2e__/backups.test.ts b/apps/web/__e2e__/backups.test.ts
index 224d7b29e..23ba6051d 100644
--- a/apps/web/__e2e__/backups.test.ts
+++ b/apps/web/__e2e__/backups.test.ts
@@ -74,3 +74,30 @@ test("restore an encrypted backup", async ({ page }) => {
const notebooks = await app.goToNotebooks();
expect(await notebooks.isEmpty()).toBeFalsy();
});
+
+test("turning off encrypted backups should ask for password", async ({
+ page
+}) => {
+ const app = new AppModel(page);
+ await app.auth.goto();
+ await app.auth.login(USER.CURRENT);
+ const settings = await app.goToSettings();
+
+ await settings.toggleBackupEncryption(USER.CURRENT.password);
+
+ expect(await settings.isBackupEncryptionEnabled(false)).toBe(false);
+});
+
+test("turning on encrypted backups should not ask for password", async ({
+ page
+}) => {
+ const app = new AppModel(page);
+ await app.auth.goto();
+ await app.auth.login(USER.CURRENT);
+ const settings = await app.goToSettings();
+ await settings.toggleBackupEncryption(USER.CURRENT.password);
+
+ await settings.toggleBackupEncryption();
+
+ expect(await settings.isBackupEncryptionEnabled(true)).toBe(true);
+});
diff --git a/apps/web/__e2e__/models/settings-view.model.ts b/apps/web/__e2e__/models/settings-view.model.ts
index f6db08d22..7fa558a8f 100644
--- a/apps/web/__e2e__/models/settings-view.model.ts
+++ b/apps/web/__e2e__/models/settings-view.model.ts
@@ -84,16 +84,32 @@ export class SettingsViewModel {
return !!(await item?.getTitle());
}
- async createBackup(password?: string) {
+ async isBackupEncryptionEnabled(state: boolean) {
+ const encyptBackups = this.page
+ .locator(getTestId("setting-encrypt-backups"))
+ .locator(
+ state ? `input[data-checked="true"]` : `input[data-checked="false"]`
+ );
+ await encyptBackups.waitFor({ state: "visible" });
+ return (await encyptBackups.getAttribute("data-checked")) === "true";
+ }
+
+ async toggleBackupEncryption(password?: string) {
const item = await this.navigation.findItem("Backup & export");
await item?.click();
- if (password) {
- const encyptBackups = this.page
- .locator(getTestId("setting-encrypt-backups"))
- .locator("label");
- await encyptBackups.click();
- }
+ const encyptBackups = this.page
+ .locator(getTestId("setting-encrypt-backups"))
+ .locator("label");
+
+ await encyptBackups.click();
+
+ if (password) await fillPasswordDialog(this.page, password);
+ }
+
+ async createBackup(password?: string) {
+ const item = await this.navigation.findItem("Backup & export");
+ await item?.click();
const backupData = this.page
.locator(getTestId("setting-create-backup"))
diff --git a/apps/web/src/dialogs/settings/backup-export-settings.ts b/apps/web/src/dialogs/settings/backup-export-settings.ts
index ffc135d69..33501e3a6 100644
--- a/apps/web/src/dialogs/settings/backup-export-settings.ts
+++ b/apps/web/src/dialogs/settings/backup-export-settings.ts
@@ -50,7 +50,7 @@ export const BackupExportSettings: SettingsGroup[] = [
)
useSettingStore.getState().toggleEncryptBackups();
const verified =
- useSettingStore.getState().encryptBackups ||
+ !useSettingStore.getState().encryptBackups ||
(await verifyAccount());
if (verified) await createBackup();
},
diff --git a/apps/web/src/dialogs/settings/index.tsx b/apps/web/src/dialogs/settings/index.tsx
index 7c77568be..322346e65 100644
--- a/apps/web/src/dialogs/settings/index.tsx
+++ b/apps/web/src/dialogs/settings/index.tsx
@@ -476,6 +476,7 @@ function SettingItem(props: { item: Setting }) {
disabled={isWorking}
onChange={() => workWithLoading(component.toggle)}
checked={component.isToggled()}
+ data-checked={component.isToggled()}
/>
);
case "dropdown":