import { elementBlockAlignmentAttrs, getElementBlockAlignment, } from "./alignment"; describe("getElementBlockAlignment", () => { test("reads align from an element block", () => { expect( getElementBlockAlignment({ name: "tableberg/text", attributes: { align: "center" }, }) ).toBe("center"); }); test("reads the icon's alignment from its styles", () => { expect( getElementBlockAlignment({ name: "tableberg/icon", attributes: { align: "right", styles: { align: "center" } }, }) ).toBe("center"); }); test("an alignment never set is the default", () => { expect( getElementBlockAlignment({ name: "tableberg/button", attributes: {} }) ).toBe("left"); expect( getElementBlockAlignment({ name: "tableberg/icon", attributes: {} }) ).toBe("left"); }); }); describe("elementBlockAlignmentAttrs", () => { test("sets align on an element block", () => { expect( elementBlockAlignmentAttrs( { name: "tableberg/text", attributes: {} }, "right" ) ).toEqual({ align: "right" }); }); test("sets the icon's alignment in its styles and keeps the rest", () => { expect( elementBlockAlignmentAttrs( { name: "tableberg/icon", attributes: { styles: { rotation: 45, color: "#f00" } }, }, "center" ) ).toEqual({ styles: { rotation: 45, color: "#f00", align: "center" } }); }); });