mirror of
https://github.com/SoPat712/Speeder.git
synced 2026-08-19 11:52:31 -04:00
fix(settings): confirm destructive defaults reset
This commit is contained in:
@@ -17,7 +17,7 @@ Constraints: local commits only; no push; no browser testing; one commit per fea
|
||||
|
||||
## Settings safety and validation
|
||||
|
||||
- [ ] Confirm before Restore Defaults removes preferences and remembered data.
|
||||
- [x] Confirm before Restore Defaults removes preferences and remembered data.
|
||||
- [ ] Report partial imports accurately when custom icons cannot be restored.
|
||||
- [ ] Reject malformed slash-prefixed regular expressions before saving site rules.
|
||||
|
||||
|
||||
@@ -2018,6 +2018,13 @@ function restore_options(callback) {
|
||||
}
|
||||
|
||||
function restore_defaults() {
|
||||
if (
|
||||
!window.confirm(
|
||||
"Restore all defaults? This removes saved preferences, remembered speeds, and custom icons."
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
var status = document.getElementById("status");
|
||||
var restoreButton = document.getElementById("restore");
|
||||
setOptionsSyncSettingsLoaded(false);
|
||||
|
||||
@@ -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