Skip to content

Commit 60b3761

Browse files
committed
test(registry): pin a copy keeping a descendant's own visibility
1 parent 486859c commit 60b3761

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

‎packages/cli/src/registry/motionBlurShutter.browser.test.ts‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,16 @@ function makeTimeline(onTo?: () => void): Fake {
116116
return { tl, currentTime: () => now, fire: () => onUpdate?.(), trackers: () => trackers };
117117
}
118118

119-
/**
120-
* happy-dom resolves no transforms of its own, so the element's computed style is the trajectory.
121-
* The stub also answers the declaration enumeration the style replay uses, and the perspective.
122-
*/
123119
/** What the browser resolves for the target: the marker's !important rule wins, else the inline value. */
124120
function wordVisibility(word: Element): string {
125121
if (word.hasAttribute(HIDING)) return "hidden";
126122
return (word as HTMLElement).style.visibility || "visible";
127123
}
128124

125+
/**
126+
* happy-dom resolves no transforms of its own, so the element's computed style is the trajectory.
127+
* The stub also answers the declaration enumeration the style replay uses, and the perspective.
128+
*/
129129
function installComputedStyle(
130130
word: Element,
131131
currentTime: () => number,
@@ -583,6 +583,36 @@ describe("motion-blur declarative attribute", () => {
583583
expect(target.groups()[0]?.children).toHaveLength(5);
584584
});
585585

586+
it("keeps a descendant's own visibility in a copy, not one it only inherits", async () => {
587+
const target = declare("");
588+
const own = document.createElement("span");
589+
const inheriting = document.createElement("span");
590+
target.word.append(own, inheriting);
591+
const visibility = new Map<Element, string>([
592+
[target.word, "hidden"],
593+
[own, "visible"],
594+
[inheriting, "hidden"],
595+
]);
596+
const mocked = globalThis.getComputedStyle;
597+
globalThis.getComputedStyle = ((element: Element) => {
598+
const value = visibility.get(element);
599+
if (value === undefined) return mocked(element);
600+
return Object.assign(Object.create(mocked(element)), ["visibility"], {
601+
length: 1,
602+
getPropertyValue: (name: string) => (name === "visibility" ? value : ""),
603+
});
604+
}) as typeof globalThis.getComputedStyle;
605+
606+
target.register();
607+
target.fire();
608+
await Promise.resolve();
609+
610+
const copy = target.groups()[0]?.children[0];
611+
if (!copy) throw new Error("motion-blur group carries no copies");
612+
expect((copy.children[0] as HTMLElement).style.visibility).toBe("visible");
613+
expect((copy.children[1] as HTMLElement).style.visibility).toBe("");
614+
});
615+
586616
it("leaves a target alone when another composition registers", async () => {
587617
// One page can hold several compositions, and a target belongs to the nearest one.
588618
const target = declare("");

0 commit comments

Comments
 (0)