Skip to content

Commit 915ea43

Browse files
test(studio): the sealed parity gate counts an undo that adds, removes or renames an element (#9085)
* test(studio): the timeline's live retime and playhead in both modes * test(studio): live retime and playhead run on a served page against a saved file with ids * test(studio): the sealed parity gate counts the timeline's live retime and playhead * test(studio): undo and redo of a style, a timing and a tween show in place in both modes * test(studio): the sealed parity gate counts redo and undo of a timing or a tween in place * test(studio): the sealed parity gate counts an undo that adds, removes or renames an element
1 parent 556d449 commit 915ea43

2 files changed

Lines changed: 54 additions & 5 deletions

File tree

‎packages/studio/src/utils/undoInPlace.browser.test.ts‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Real Chrome: undo and redo of a style, a clip's timing and a tween show in the live preview, with no reload.
1+
// Real Chrome: undo and redo of a style, timing or tween show in place; one that changes which elements exist reloads.
22
import { readFileSync } from "node:fs";
33
import { createRequire } from "node:module";
44
import type { Browser, Frame, Page } from "puppeteer-core";
@@ -50,7 +50,7 @@ const scripts = () => ({
5050
});
5151

5252
/** Studio's history applying the file `restored` over `previous` at 2 s, as undo and redo both do. */
53-
const restore = (page: Page, previous: Film, restored: Film, version: number) =>
53+
const restoreHtml = (page: Page, previous: string, restored: string, version: number) =>
5454
page.evaluate(
5555
(files, at) => {
5656
const w = window as unknown as { hfStudio: Studio; __reloads?: number };
@@ -64,9 +64,11 @@ const restore = (page: Page, previous: Film, restored: Film, version: number) =>
6464
at,
6565
);
6666
},
67-
{ "index.html": { previous: file(previous), restored: file(restored) } },
67+
{ "index.html": { previous, restored } },
6868
version,
6969
);
70+
const restore = (page: Page, previous: Film, restored: Film, version: number) =>
71+
restoreHtml(page, file(previous), file(restored), version);
7072

7173
const shown = (frame: Frame) =>
7274
frame.evaluate(() => {
@@ -124,3 +126,31 @@ it.each(MODES)("a %s preview shows a tween edit undone in place", async (mode) =
124126
expect(await reloads(page)).toBe(0);
125127
await page.close();
126128
});
129+
130+
const C_CARD = `<div id="c" data-hf-id="hf-cccc" class="clip" data-start="0" data-duration="4" data-track-index="3"></div>`;
131+
const STRUCTURAL: Array<[string, (saved: string) => string]> = [
132+
["adds", (saved) => saved.replace("</div><script>", () => ` ${C_CARD}\n </div><script>`)],
133+
["removes", (saved) => saved.replace(/\s*<div id="b"[^>]*><\/div>/, "")],
134+
[
135+
"renames",
136+
(saved) => saved.replace('id="b" data-hf-id="hf-bbbb"', 'id="b2" data-hf-id="hf-b222"'),
137+
],
138+
];
139+
const CASES = MODES.flatMap((mode) =>
140+
STRUCTURAL.map(([change, edit]) => [mode, change, edit] as const),
141+
);
142+
143+
// Applying an added, removed or renamed element in place could leave the frame half-restored, so both modes reload.
144+
it.each(CASES)(
145+
"a %s preview reloads, patching nothing in place, for an undo that %s an element",
146+
async (mode, _, edit) => {
147+
const { page, frame } = await open(mode);
148+
const before = await frame.evaluate(() => document.getElementById("root")!.outerHTML);
149+
const strategy = await restoreHtml(page, file(SAVED), edit(file(SAVED)), 1);
150+
expect(strategy).toBe("full");
151+
expect(await reloads(page)).toBe(1);
152+
expect(await frame.evaluate(() => document.getElementById("root")!.outerHTML)).toBe(before);
153+
expect(await shown(frame)).toMatchObject({ sameDocument: true });
154+
await page.close();
155+
},
156+
);

‎packages/studio/tests/sealed-parity/manifest.json‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,27 @@
344344
},
345345
{
346346
"id": "undo-structural",
347-
"behaviour": "An undo that adds, removes or renames an element",
348-
"tests": []
347+
"behaviour": "An undo that adds, removes or renames an element reloads the preview",
348+
"tests": [
349+
{
350+
"kind": "vitest",
351+
"package": "studio",
352+
"file": "src/utils/undoInPlace.browser.test.ts",
353+
"name": "a %s preview reloads, patching nothing in place, for an undo that adds an element"
354+
},
355+
{
356+
"kind": "vitest",
357+
"package": "studio",
358+
"file": "src/utils/undoInPlace.browser.test.ts",
359+
"name": "a %s preview reloads, patching nothing in place, for an undo that removes an element"
360+
},
361+
{
362+
"kind": "vitest",
363+
"package": "studio",
364+
"file": "src/utils/undoInPlace.browser.test.ts",
365+
"name": "a %s preview reloads, patching nothing in place, for an undo that renames an element"
366+
}
367+
]
349368
},
350369
{
351370
"id": "layers-after-undo-restack",

0 commit comments

Comments
 (0)