import { describe, expect, test } from "@odoo/hoot"; import { setupEditor, testEditor } from "./_helpers/editor"; import { alignCenter, justify, alignLeft, alignRight, alignTop, alignMiddle, alignBottom, } from "./_helpers/user_actions"; import { expandToolbar } from "./_helpers/toolbar"; test("should have align tool only if the block is content editable", async () => { for (const [contenteditable, count] of [ [false, 0], [true, 1], ]) { await setupEditor( `

ab[cde]fg

` ); await expandToolbar(); expect(".btn[name='text_align']").toHaveCount(count); } }); describe("left", () => { test("should align left", async () => { await testEditor({ contentBefore: "

ab

c[]d

", stepFunction: alignLeft, contentAfter: "

ab

c[]d

", }); }); test("should not align left a non-editable node", async () => { await testEditor({ contentBefore: '

ab

c[]d

', contentBeforeEdit: '

ab

c[]d

', stepFunction: alignLeft, contentAfterEdit: '

ab

c[]d

', contentAfter: '

ab

c[]d

', }); }); test("should align several paragraphs left", async () => { await testEditor({ contentBefore: "

a[b

c]d

", stepFunction: alignLeft, contentAfter: "

a[b

c]d

", }); }); test("should left align a node within a right-aligned node", async () => { await testEditor({ contentBefore: '

ab

c[d]e

', stepFunction: alignLeft, contentAfter: '

ab

c[d]e

', }); }); test("should left align a node within a right-aligned node and a paragraph", async () => { await testEditor({ contentBefore: '

ab

c[d

e]f

', stepFunction: alignLeft, contentAfter: '

ab

c[d

e]f

', }); }); test("should left align a node within a right-aligned node and a paragraph, with a center-aligned common ancestor", async () => { await testEditor({ contentBefore: '

ab

c[d

e]f

', stepFunction: alignLeft, contentAfter: '

ab

c[d

e]f

', }); }); test("should left align a node within a right-aligned node and a paragraph, with a left-aligned common ancestor", async () => { await testEditor({ contentBefore: '

ab

c[d

e]f

', stepFunction: alignLeft, contentAfter: '

ab

c[d

e]f

', }); }); test("should not left align a node that is already within a left-aligned node", async () => { await testEditor({ contentBefore: '

ab

c[d]e

', stepFunction: alignLeft, contentAfter: '

ab

c[d]e

', }); }); test("should left align a container within an editable that is center-aligned", async () => { await testEditor({ contentBefore: '

a[]b

', stepFunction: alignLeft, contentAfter: '

a[]b

', }); }); }); describe("center", () => { test("should align center", async () => { await testEditor({ contentBefore: "

ab

c[]d

", stepFunction: alignCenter, contentAfter: '

ab

c[]d

', }); }); test("should align several paragraphs center", async () => { await testEditor({ contentBefore: "

a[b

c]d

", stepFunction: alignCenter, contentAfter: '

a[b

c]d

', }); }); test("should center align a node within a right-aligned node", async () => { await testEditor({ contentBefore: '

ab

c[d]e

', stepFunction: alignCenter, contentAfter: '

ab

c[d]e

', }); }); test("should center align a node within a right-aligned node and a paragraph", async () => { await testEditor({ contentBefore: '

ab

c[d

e]f

', stepFunction: alignCenter, contentAfter: '

ab

c[d

e]f

', }); }); test("should center align a node within a right-aligned node and a paragraph, with a left-aligned common ancestor", async () => { await testEditor({ contentBefore: '

ab

c[d

e]f

', stepFunction: alignCenter, contentAfter: '

ab

c[d

e]f

', }); }); test("should center align a node within a right-aligned node and a paragraph, with a center-aligned common ancestor", async () => { await testEditor({ contentBefore: '

ab

c[d

e]f

', stepFunction: alignCenter, contentAfter: '

ab

c[d

e]f

', }); }); test("should not center align a node that is already within a center-aligned node", async () => { await testEditor({ contentBefore: '

ab

c[d]e

', stepFunction: alignCenter, contentAfter: '

ab

c[d]e

', }); }); test("should center align a left-aligned container within an editable that is center-aligned", async () => { await testEditor({ contentBefore: '

a[]b

', stepFunction: alignCenter, contentAfter: '

a[]b

', }); }); }); describe("right", () => { test("should align right", async () => { await testEditor({ contentBefore: "

ab

c[]d

", stepFunction: alignRight, contentAfter: '

ab

c[]d

', }); }); test("should align several paragraphs right", async () => { await testEditor({ contentBefore: "

a[b

c]d

", stepFunction: alignRight, contentAfter: '

a[b

c]d

', }); }); test("should right align a node within a center-aligned node", async () => { await testEditor({ contentBefore: '

ab

c[d]e

', stepFunction: alignRight, contentAfter: '

ab

c[d]e

', }); }); test("should right align a node within a center-aligned node and a paragraph", async () => { await testEditor({ contentBefore: '

ab

c[d

e]f

', stepFunction: alignRight, contentAfter: '

ab

c[d

e]f

', }); }); test("should right align a node within a center-aligned node and a paragraph, with a justify-aligned common ancestor", async () => { await testEditor({ contentBefore: '

ab

c[d

e]f

', stepFunction: alignRight, contentAfter: '

ab

c[d

e]f

', }); }); test("should right align a node within a center-aligned node and a paragraph, with a right-aligned common ancestor", async () => { await testEditor({ contentBefore: '

ab

c[d

e]f

', stepFunction: alignRight, contentAfter: '

ab

c[d

e]f

', }); }); test("should not right align a node that is already within a right-aligned node", async () => { await testEditor({ contentBefore: '

ab

c[d]e

', stepFunction: alignRight, contentAfter: '

ab

c[d]e

', }); }); test("should right align a container within an editable that is center-aligned", async () => { await testEditor({ contentBefore: '

a[]b

', stepFunction: alignRight, contentAfter: '

a[]b

', }); }); }); describe("justify", () => { test("should align justify", async () => { await testEditor({ contentBefore: "

ab

c[]d

", stepFunction: justify, contentAfter: '

ab

c[]d

', }); }); test("should align several paragraphs justify", async () => { await testEditor({ contentBefore: "

a[b

c]d

", stepFunction: justify, contentAfter: '

a[b

c]d

', }); }); test("should justify align a node within a right-aligned node", async () => { await testEditor({ contentBefore: '

ab

c[d]e

', stepFunction: justify, contentAfter: '

ab

c[d]e

', }); }); test("should justify align a node within a right-aligned node and a paragraph", async () => { await testEditor({ contentBefore: '

ab

c[d

e]f

', stepFunction: justify, contentAfter: '

ab

c[d

e]f

', }); }); test("should justify align a node within a right-aligned node and a paragraph, with a center-aligned common ancestor", async () => { await testEditor({ contentBefore: '

ab

c[d

e]f

', stepFunction: justify, contentAfter: '

ab

c[d

e]f

', }); }); test("should justify align a node within a right-aligned node and a paragraph, with a justify-aligned common ancestor", async () => { await testEditor({ contentBefore: '

ab

c[d

e]f

', stepFunction: justify, contentAfter: '

ab

c[d

e]f

', }); }); test("should not justify align a node that is already within a justify-aligned node", async () => { await testEditor({ contentBefore: '

ab

c[d]e

', stepFunction: justify, contentAfter: '

ab

c[d]e

', }); }); test("should justify align a container within an editable that is center-aligned", async () => { await testEditor({ contentBefore: '

a[]b

', stepFunction: justify, contentAfter: '

a[]b

', }); }); }); describe("top", () => { test("should align top a selected cell", async () => { await testEditor({ contentBefore: "
a[]b
", stepFunction: alignTop, contentAfter: '
a[]b
', }); }); test("should align top multiple selected cells", async () => { await testEditor({ contentBefore: "
a[bc]d
", stepFunction: alignTop, contentAfter: '
a[bc]d
', }); }); test("should change previous alignment to top", async () => { await testEditor({ contentBefore: `
a[b c]d
`, stepFunction: alignTop, contentAfter: `
a[b c]d
`, }); }); }); describe("middle", () => { test("should align middle a selected cell", async () => { await testEditor({ contentBefore: "
a[b]c
", stepFunction: alignMiddle, contentAfter: '
a[b]c
', }); }); test("should align middle multiple selected cells", async () => { await testEditor({ contentBefore: "
a[bc]d
", stepFunction: alignMiddle, contentAfter: '
a[bc]d
', }); }); test("should change previous alignment to middle", async () => { await testEditor({ contentBefore: `
a[b c]d
`, stepFunction: alignMiddle, contentAfter: `
a[b c]d
`, }); }); }); describe("bottom", () => { test("should align bottom a selected cell", async () => { await testEditor({ contentBefore: "
a[b]c
", stepFunction: alignBottom, contentAfter: '
a[b]c
', }); }); test("should align bottom multiple selected cells", async () => { await testEditor({ contentBefore: "
a[bc]d
", stepFunction: alignBottom, contentAfter: '
a[bc]d
', }); }); test("should change previous alignment to bottom", async () => { await testEditor({ contentBefore: `
a[b c]d
`, stepFunction: alignBottom, contentAfter: `
a[b c]d
`, }); }); });