Skip to content

Commit

Permalink
test: fix shortcutKey test case
Browse files Browse the repository at this point in the history
  • Loading branch information
cuixiaorui committed Aug 14, 2024
1 parent d3e10cb commit 9420bba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions apps/client/composables/user/shortcutKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ export function useShortcutKeyMode() {
}
}

function reset() {
showModal.value = false;
currentKeyType.value = "";
shortcutKeyStr.value = "";
shortcutKeys.value = { ...DEFAULT_SHORTCUT_KEYS };
hasSameShortcutKey.value = false;
localStorage.removeItem(SHORTCUT_KEYS);
}

return {
showModal, // 弹框对象
shortcutKeys, // 快捷键对象
Expand All @@ -158,5 +167,6 @@ export function useShortcutKeyMode() {
handleKeydown,
handleEdit,
handleCloseDialog,
reset,
};
}
6 changes: 4 additions & 2 deletions apps/client/composables/user/tests/shortcutKey.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {

describe("user defined shortcut key", () => {
beforeEach(() => {
localStorage.clear();
const { reset } = useShortcutKeyMode();
reset();
});

describe("shortcut key data", () => {
Expand All @@ -30,7 +31,8 @@ describe("user defined shortcut key", () => {
};

localStorage.setItem(SHORTCUT_KEYS, JSON.stringify(storeShortcutKeys));
const { shortcutKeys } = useShortcutKeyMode();
const { shortcutKeys, setShortcutKeys } = useShortcutKeyMode();
setShortcutKeys();

expect(shortcutKeys.value).toEqual(storeShortcutKeys);
});
Expand Down

0 comments on commit 9420bba

Please sign in to comment.