Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vault unlock status not shown when a note was unlocked #7172

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -174,6 +174,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
Loading