mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 04:00:59 +01:00
web: delete locked notes on vault delete
Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
@@ -193,4 +193,16 @@ export class SettingsViewModel {
|
||||
.locator("input");
|
||||
await titleFormatInput.fill(format);
|
||||
}
|
||||
|
||||
async deleteVault(password: string) {
|
||||
const item = await this.navigation.findItem("Vault");
|
||||
await item?.click();
|
||||
|
||||
const deleteVaultButton = this.page
|
||||
.locator(getTestId("setting-delete-vault"))
|
||||
.locator("button");
|
||||
|
||||
await deleteVaultButton.click();
|
||||
await fillPasswordDialog(this.page, password);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,6 +192,21 @@ export async function createHistorySession(page: Page, locked = false) {
|
||||
};
|
||||
}
|
||||
|
||||
function randomWord(length = 5) {
|
||||
const chars = "abcdefghijklmnopqrstuvwxyz";
|
||||
return Array.from(
|
||||
{ length },
|
||||
() => chars[Math.floor(Math.random() * chars.length)]
|
||||
).join("");
|
||||
}
|
||||
|
||||
function randomNote(): Note {
|
||||
return {
|
||||
title: `${randomWord()} ${randomWord()}`,
|
||||
content: Array.from({ length: 5 }, () => randomWord()).join(" ")
|
||||
};
|
||||
}
|
||||
|
||||
export {
|
||||
USER,
|
||||
NOTE,
|
||||
@@ -207,5 +222,6 @@ export {
|
||||
orderByOptions,
|
||||
sortByOptions,
|
||||
groupByOptions,
|
||||
APP_LOCK_PASSWORD
|
||||
APP_LOCK_PASSWORD,
|
||||
randomNote
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import { test, expect } from "@playwright/test";
|
||||
import { AppModel } from "./models/app.model";
|
||||
import { getTestId, NOTE, PASSWORD } from "./utils";
|
||||
import { getTestId, NOTE, PASSWORD, randomNote, USER } from "./utils";
|
||||
|
||||
test("locking a note should show vault unlocked status", async ({ page }) => {
|
||||
const app = new AppModel(page);
|
||||
@@ -125,3 +125,28 @@ test("clicking on vault unlocked status should lock the readonly note", async ({
|
||||
|
||||
expect(await note?.isLockedNotePasswordFieldVisible()).toBe(true);
|
||||
});
|
||||
|
||||
test("deleting the vault should permanently delete locked notes", async ({
|
||||
page
|
||||
}) => {
|
||||
const app = new AppModel(page);
|
||||
await app.auth.goto();
|
||||
await app.auth.login(USER.CURRENT);
|
||||
|
||||
const noteData = randomNote();
|
||||
let notes = await app.goToNotes();
|
||||
let note = await notes.createNote(noteData);
|
||||
await note?.contextMenu.lock(PASSWORD);
|
||||
|
||||
const settings = await app.goToSettings();
|
||||
await settings.deleteVault(USER.CURRENT.password!);
|
||||
await settings.close();
|
||||
|
||||
notes = await app.goToNotes();
|
||||
note = await notes.findNote(noteData);
|
||||
expect(note).toBeUndefined();
|
||||
|
||||
const trash = await app.goToTrash();
|
||||
const trashNote = await trash.findItem(noteData.title);
|
||||
expect(trashNote).toBeUndefined();
|
||||
});
|
||||
|
||||
@@ -22,6 +22,7 @@ import { showPasswordDialog } from "../dialogs/password-dialog";
|
||||
import { showToast } from "../utils/toast";
|
||||
import { VAULT_ERRORS } from "@notesnook/core";
|
||||
import { strings } from "@notesnook/intl";
|
||||
import { useStore as useAppStore } from "../stores/app-store";
|
||||
|
||||
class Vault {
|
||||
static async createVault() {
|
||||
@@ -34,6 +35,7 @@ class Vault {
|
||||
},
|
||||
validate: async ({ password }) => {
|
||||
await db.vault.create(password);
|
||||
useAppStore.getState().setIsVaultCreated(true);
|
||||
showToast("success", strings.vaultCreated());
|
||||
return true;
|
||||
}
|
||||
@@ -63,25 +65,19 @@ class Vault {
|
||||
if (!(await db.vault.exists())) return false;
|
||||
const result = await showPasswordDialog({
|
||||
title: strings.deleteVault(),
|
||||
subtitle: strings.deleteVaultDesc(),
|
||||
message: strings.deleteVaultDesc(),
|
||||
inputs: {
|
||||
password: {
|
||||
label: strings.accountPassword(),
|
||||
autoComplete: "current-password"
|
||||
}
|
||||
},
|
||||
checks: {
|
||||
deleteAllLockedNotes: {
|
||||
text: strings.deleteAllNotes(),
|
||||
default: false
|
||||
}
|
||||
},
|
||||
validate: ({ password }) => {
|
||||
return db.user.verifyPassword(password);
|
||||
}
|
||||
});
|
||||
if (result) {
|
||||
await db.vault.delete(result.deleteAllLockedNotes);
|
||||
await db.vault.delete();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -42,9 +42,7 @@ export const VaultSettings: SettingsGroup[] = [
|
||||
type: "button",
|
||||
title: strings.create(),
|
||||
action: () => {
|
||||
Vault.createVault().then((res) => {
|
||||
useAppStore.getState().setIsVaultCreated(res);
|
||||
});
|
||||
Vault.createVault();
|
||||
},
|
||||
variant: "secondary"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user