feat: release design system engine, studio and component contracts
This commit is contained in:
1 parent
ff1065fb27
commit
3943b946d6
693 files changed
+175546
-3894
No files matched your search
@@ -6,13 +6,29 @@ test("unsaved guard protects unload and ordinary navigation, permits safe links,
|
||||
const window = new Window({ url: "https://email.example.com/builder/one" });
|
||||
const root = window.document.createElement("main");
|
||||
window.document.body.append(root);
|
||||
let dirty = true, allow = false, confirmations = 0;
|
||||
const guard = mountUnsavedChangesGuard(root as unknown as HTMLElement, { hasUnsavedChanges: () => dirty, confirmLeave: () => { confirmations++; return allow; } });
|
||||
const unload = () => { const event = new window.Event("beforeunload", { cancelable: true }); window.dispatchEvent(event); return event.defaultPrevented; };
|
||||
let dirty = true,
|
||||
allow = false,
|
||||
confirmations = 0;
|
||||
const guard = mountUnsavedChangesGuard(root as unknown as HTMLElement, {
|
||||
hasUnsavedChanges: () => dirty,
|
||||
confirmLeave: () => {
|
||||
confirmations++;
|
||||
return allow;
|
||||
},
|
||||
});
|
||||
const unload = () => {
|
||||
const event = new window.Event("beforeunload", { cancelable: true });
|
||||
window.dispatchEvent(event);
|
||||
return event.defaultPrevented;
|
||||
};
|
||||
const click = (href: string, target = "") => {
|
||||
const link = window.document.createElement("a"); link.href = href; link.target = target; root.append(link);
|
||||
const link = window.document.createElement("a");
|
||||
link.href = href;
|
||||
link.target = target;
|
||||
root.append(link);
|
||||
const event = new window.MouseEvent("click", { bubbles: true, cancelable: true });
|
||||
link.dispatchEvent(event); return event.defaultPrevented;
|
||||
link.dispatchEvent(event);
|
||||
return event.defaultPrevented;
|
||||
};
|
||||
expect(unload()).toBe(true);
|
||||
expect(click("/builder/two")).toBe(true);
|
||||
@@ -23,6 +39,8 @@ test("unsaved guard protects unload and ordinary navigation, permits safe links,
|
||||
expect(click("/builder/two")).toBe(false);
|
||||
dirty = false;
|
||||
expect(unload()).toBe(false);
|
||||
guard.destroy(); guard.destroy(); dirty = true;
|
||||
guard.destroy();
|
||||
guard.destroy();
|
||||
dirty = true;
|
||||
expect(unload()).toBe(false);
|
||||
});
|
||||
Reference in new issue
Block a user