Skip to content

Commit

Permalink
core: fix vault unlock event not sent when a note is unlocked (street…
Browse files Browse the repository at this point in the history
…writers#7172)

Signed-off-by: 01zulfi <[email protected]>
  • Loading branch information
01zulfi authored Dec 30, 2024
1 parent e67e637 commit b6da624
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
88 changes: 88 additions & 0 deletions apps/web/__e2e__/vault.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
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 { test, expect } from "@playwright/test";
import { AppModel } from "./models/app.model";
import { getTestId, NOTE, PASSWORD } from "./utils";

test("locking a note should show vault unlocked status", async ({ page }) => {
const app = new AppModel(page);
await app.goto();
const notes = await app.goToNotes();
const note = await notes.createNote(NOTE);
const vaultUnlockedStatus = page.locator(getTestId("vault-unlocked"));

await note?.contextMenu.lock(PASSWORD);

await expect(vaultUnlockedStatus).toBeVisible();
});

test("clicking on vault unlocked status should lock the vault", async ({
page
}) => {
const app = new AppModel(page);
await app.goto();
const notes = await app.goToNotes();
const note = await notes.createNote(NOTE);
const vaultUnlockedStatus = page.locator(getTestId("vault-unlocked"));

await note?.contextMenu.lock(PASSWORD);
await note?.openLockedNote(PASSWORD);
await vaultUnlockedStatus.waitFor({ state: "visible" });
await vaultUnlockedStatus.click();

await expect(vaultUnlockedStatus).toBeHidden();
expect(await note?.contextMenu.isLocked()).toBe(true);
});

test("opening a locked note should show vault unlocked status", async ({
page
}) => {
const app = new AppModel(page);
await app.goto();
const notes = await app.goToNotes();
const note = await notes.createNote(NOTE);
const vaultUnlockedStatus = page.locator(getTestId("vault-unlocked"));

await note?.contextMenu.lock(PASSWORD);
await vaultUnlockedStatus.waitFor({ state: "visible" });
await vaultUnlockedStatus.click();
await vaultUnlockedStatus.waitFor({ state: "hidden" });
await note?.openLockedNote(PASSWORD);

await expect(vaultUnlockedStatus).toBeVisible();
});

test("unlocking a note permanently should not show vault unlocked status", async ({
page
}) => {
const app = new AppModel(page);
await app.goto();
const notes = await app.goToNotes();
const note = await notes.createNote(NOTE);
const vaultUnlockedStatus = page.locator(getTestId("vault-unlocked"));

await note?.contextMenu.lock(PASSWORD);
await vaultUnlockedStatus.waitFor({ state: "visible" });
await vaultUnlockedStatus.click();
await vaultUnlockedStatus.waitFor({ state: "hidden" });
await note?.contextMenu.unlock(PASSWORD);

await expect(vaultUnlockedStatus).toBeHidden();
});
1 change: 1 addition & 0 deletions apps/web/src/components/status-bar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ function StatusBar() {
justifyContent: "center",
display: "flex"
}}
data-test-id="vault-unlocked"
>
<Unlock size={10} />
<Text variant="subBody" ml={1} sx={{ color: "paragraph" }}>
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/api/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default class Vault {
}

private startEraser() {
EV.publish(EVENTS.vaultUnlocked);
clearTimeout(this.erasureTimeout);
this.erasureTimeout = setTimeout(() => {
this.lock();
Expand Down Expand Up @@ -95,7 +96,6 @@ export default class Vault {
throw new Error(VAULT_ERRORS.wrongPassword);
}
this.password = password;
EV.publish(EVENTS.vaultUnlocked);
return true;
}

Expand Down

0 comments on commit b6da624

Please sign in to comment.