mirror of
https://github.com/SoPat712/Speeder.git
synced 2026-10-08 19:05:02 -04:00
fix(settings): confirm destructive defaults reset
This commit is contained in:
5 files changed
+28
-1
No files matched your search
@@ -42,6 +42,7 @@ function applyJSDOMWindow(win) {
|
||||
win.Date = globalThis.Date;
|
||||
win.open = vi.fn();
|
||||
win.close = vi.fn();
|
||||
win.confirm = vi.fn(() => true);
|
||||
}
|
||||
|
||||
function loadHtmlString(html, options) {
|
||||
|
||||
@@ -27,4 +27,5 @@ export function applyJSDOMWindow(win) {
|
||||
|
||||
win.open = vi.fn();
|
||||
win.close = vi.fn();
|
||||
win.confirm = vi.fn(() => true);
|
||||
}
|
||||
@@ -390,4 +390,22 @@ describe("options page", () => {
|
||||
).toEqual(expect.any(Number));
|
||||
expect(chrome.storage.local.__state.unrelatedLocalValue).toBe("keep");
|
||||
});
|
||||
|
||||
it("leaves settings untouched when restoring defaults is cancelled", async () => {
|
||||
const chrome = await setupOptions({ sync: { rememberSpeed: true } });
|
||||
window.confirm.mockReturnValueOnce(false);
|
||||
chrome.storage.sync.set.mockClear();
|
||||
chrome.storage.sync.remove.mockClear();
|
||||
chrome.storage.local.set.mockClear();
|
||||
chrome.storage.local.remove.mockClear();
|
||||
|
||||
globalThis.restore_defaults();
|
||||
|
||||
expect(window.confirm).toHaveBeenCalledOnce();
|
||||
expect(chrome.storage.sync.set).not.toHaveBeenCalled();
|
||||
expect(chrome.storage.sync.remove).not.toHaveBeenCalled();
|
||||
expect(chrome.storage.local.set).not.toHaveBeenCalled();
|
||||
expect(chrome.storage.local.remove).not.toHaveBeenCalled();
|
||||
expect(chrome.storage.sync.__state.rememberSpeed).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user