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(
`
`
);
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
',
contentBeforeEdit: 'ab
',
stepFunction: alignLeft,
contentAfterEdit: 'ab
',
contentAfter: 'ab
',
});
});
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: '',
stepFunction: alignLeft,
contentAfter:
'',
});
});
test("should left align a node within a right-aligned node and a paragraph", async () => {
await testEditor({
contentBefore: 'e]f
',
stepFunction: alignLeft,
contentAfter:
'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:
'',
stepFunction: alignLeft,
contentAfter:
'',
});
});
test("should left align a node within a right-aligned node and a paragraph, with a left-aligned common ancestor", async () => {
await testEditor({
contentBefore:
'',
stepFunction: alignLeft,
contentAfter:
'',
});
});
test("should not left align a node that is already within a left-aligned node", async () => {
await testEditor({
contentBefore: '',
stepFunction: alignLeft,
contentAfter: '',
});
});
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: '',
stepFunction: alignCenter,
contentAfter:
'',
});
});
test("should center align a node within a right-aligned node and a paragraph", async () => {
await testEditor({
contentBefore: 'e]f
',
stepFunction: alignCenter,
contentAfter:
'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:
'',
stepFunction: alignCenter,
contentAfter:
'',
});
});
test("should center align a node within a right-aligned node and a paragraph, with a center-aligned common ancestor", async () => {
await testEditor({
contentBefore:
'',
stepFunction: alignCenter,
contentAfter:
'',
});
});
test("should not center align a node that is already within a center-aligned node", async () => {
await testEditor({
contentBefore: '',
stepFunction: alignCenter,
contentAfter: '',
});
});
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: '',
stepFunction: alignRight,
contentAfter:
'',
});
});
test("should right align a node within a center-aligned node and a paragraph", async () => {
await testEditor({
contentBefore: 'e]f
',
stepFunction: alignRight,
contentAfter:
'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:
'',
stepFunction: alignRight,
contentAfter:
'',
});
});
test("should right align a node within a center-aligned node and a paragraph, with a right-aligned common ancestor", async () => {
await testEditor({
contentBefore:
'',
stepFunction: alignRight,
contentAfter:
'',
});
});
test("should not right align a node that is already within a right-aligned node", async () => {
await testEditor({
contentBefore: '',
stepFunction: alignRight,
contentAfter: '',
});
});
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: '',
stepFunction: justify,
contentAfter:
'',
});
});
test("should justify align a node within a right-aligned node and a paragraph", async () => {
await testEditor({
contentBefore: 'e]f
',
stepFunction: justify,
contentAfter:
'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:
'',
stepFunction: justify,
contentAfter:
'',
});
});
test("should justify align a node within a right-aligned node and a paragraph, with a justify-aligned common ancestor", async () => {
await testEditor({
contentBefore:
'',
stepFunction: justify,
contentAfter:
'',
});
});
test("should not justify align a node that is already within a justify-aligned node", async () => {
await testEditor({
contentBefore: '',
stepFunction: justify,
contentAfter: '',
});
});
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: "",
stepFunction: alignTop,
contentAfter:
'',
});
});
test("should align top multiple selected cells", async () => {
await testEditor({
contentBefore: "",
stepFunction: alignTop,
contentAfter:
'',
});
});
test("should change previous alignment to top", async () => {
await testEditor({
contentBefore: `
`,
stepFunction: alignTop,
contentAfter: `
`,
});
});
});
describe("middle", () => {
test("should align middle a selected cell", async () => {
await testEditor({
contentBefore: "",
stepFunction: alignMiddle,
contentAfter:
'',
});
});
test("should align middle multiple selected cells", async () => {
await testEditor({
contentBefore: "",
stepFunction: alignMiddle,
contentAfter:
'',
});
});
test("should change previous alignment to middle", async () => {
await testEditor({
contentBefore: `
`,
stepFunction: alignMiddle,
contentAfter: `
`,
});
});
});
describe("bottom", () => {
test("should align bottom a selected cell", async () => {
await testEditor({
contentBefore: "",
stepFunction: alignBottom,
contentAfter:
'',
});
});
test("should align bottom multiple selected cells", async () => {
await testEditor({
contentBefore: "",
stepFunction: alignBottom,
contentAfter:
'',
});
});
test("should change previous alignment to bottom", async () => {
await testEditor({
contentBefore: `
`,
stepFunction: alignBottom,
contentAfter: `
`,
});
});
});