mirror of
https://github.com/penpot/penpot.git
synced 2025-05-08 08:05:53 +02:00
33 lines
1.3 KiB
JavaScript
33 lines
1.3 KiB
JavaScript
import { describe, test, expect } from "vitest";
|
|
import { createEmptyRoot, createRoot, setRootStyles, TAG, TYPE } from './Root.js'
|
|
|
|
/* @vitest-environment jsdom */
|
|
describe("Root", () => {
|
|
test("createRoot should throw when passed invalid children", () => {
|
|
expect(() => createRoot(["Whatever"])).toThrowError(
|
|
"Invalid root children"
|
|
);
|
|
});
|
|
|
|
test("createEmptyRoot should create a new root with an empty paragraph", () => {
|
|
const emptyRoot = createEmptyRoot();
|
|
expect(emptyRoot).toBeInstanceOf(HTMLDivElement);
|
|
expect(emptyRoot.nodeName).toBe(TAG);
|
|
expect(emptyRoot.dataset.itype).toBe(TYPE);
|
|
expect(emptyRoot.firstChild).toBeInstanceOf(HTMLDivElement);
|
|
expect(emptyRoot.firstChild.firstChild).toBeInstanceOf(HTMLSpanElement);
|
|
expect(emptyRoot.firstChild.firstChild.firstChild).toBeInstanceOf(HTMLBRElement);
|
|
});
|
|
|
|
test("setRootStyles should apply only the styles of root to the root", () => {
|
|
const emptyRoot = createEmptyRoot();
|
|
setRootStyles(emptyRoot, {
|
|
["--vertical-align"]: "top",
|
|
["font-size"]: "25px"
|
|
});
|
|
expect(emptyRoot.style.getPropertyValue("--vertical-align")).toBe("top");
|
|
// We expect this style to be empty because we don't apply it
|
|
// to the root.
|
|
expect(emptyRoot.style.getPropertyValue("font-size")).toBe("");
|
|
})
|
|
});
|