import { describe, expect, test } from "@odoo/hoot"; import { press, queryAllTexts } from "@odoo/hoot-dom"; import { animationFrame } from "@odoo/hoot-mock"; import { setupEditor, testEditor } from "./_helpers/editor"; import { getContent } from "./_helpers/selection"; import { insertText, redo, undo } from "./_helpers/user_actions"; import { execCommand } from "./_helpers/userCommands"; function columnsContainer(contents) { return `
[]
[]
[] |
[] |
abcd
") + column(6, "abcd
") + column(6, "[]abcd
", stepFunction: columnize(2), contentAfterEdit: /* eslint-disable */ columnsContainer( column(6, "[]abcd
") + column(6, `[]abcd
") + column(6, "abcd
") + column(4, "abcd
") + column(6, "abcd
") + column(3, "i[]j
") ), stepFunction: columnize(2), contentAfter: columnsContainer( column(6, "abcd
") + column(6, "i[]j
") ), }); }); test("apply '2 columns' powerbox command", async () => { const { el, editor } = await setupEditor("ab[]cd
"); await insertText(editor, "/2columns"); await animationFrame(); expect(".active .o-we-command-name").toHaveText("2 columns"); await press("enter"); expect(getContent(el)).toBe( `ab[]cd
abcd
") + column(4, "[]
abcd
") + column(4, `[]
abcd
") + column(4, "[]
ab[]cd
", stepFunction: columnize(3), /* eslint-disable */ contentAfterEdit: columnsContainer( column(4, "ab[]cd
") + column(4, `ab[]cd
") + column(4, "abcd
") + column(6, "abcd
") + column(4, "abcd
") + column(3, "ij
") ), stepFunction: columnize(3), contentAfter: columnsContainer( column(4, "abcd
") + column(4, "ij
") ), }); }); test("apply '3 columns' powerbox command", async () => { const { el, editor } = await setupEditor("ab[]cd
"); await insertText(editor, "/3columns"); await animationFrame(); expect(".active .o-we-command-name").toHaveText("3 columns"); await press("enter"); expect(getContent(el)).toBe( `ab[]cd
abcd
") + column(3, "[]
abcd
") + column(3, "[]
abcd[]
", stepFunction: columnize(4), contentAfter: columnsContainer( column(3, "abcd[]
") + column(3, "abcd
") + column(6, "abcd
") + column(3, "abcd
") + column(4, "ij
") ), stepFunction: columnize(4), contentAfter: columnsContainer( column(3, "abcd
") + column(3, "ij
") + column(3, "ab[]cd
"); await insertText(editor, "/4columns"); await animationFrame(); expect(".active .o-we-command-name").toHaveText("4 columns"); await press("enter"); expect(getContent(el)).toBe( `ab[]cd
ab[]cd
", stepFunction: columnize(0), contentAfter: "ab[]cd
", }); }); test("should turn 2 columns into text", async () => { await testEditor({ contentBefore: columnsContainer( column(6, "abcd
") + column(6, "abcd
abcd
") + column(4, "ij
") ), stepFunction: columnize(0), contentAfter: "abcd
ij
", }); }); test("should turn 4 columns into text", async () => { await testEditor({ contentBefore: columnsContainer( column(3, "abcd
") + column(3, "ij
") + column(3, "[]
abcd
ij
[]
ab[]cd
"); await insertText(editor, "/columns"); await animationFrame(); expect(queryAllTexts(".o-we-command-name")).toEqual([ "2 columns", "3 columns", "4 columns", ]); // add 2 columns await press("enter"); expect(getContent(el)).toBe( `ab[]cd
ab[]cd
ab[]cd
", stepFunction: (editor) => { columnize(2)(editor); columnize(3)(editor); columnize(4)(editor); columnize(3)(editor); columnize(2)(editor); columnize(0)(editor); }, // A paragraph was created for each column + after them and // they were all kept. contentAfter: "ab[]cd
ab[]cd
" + "ab[]cd
" + "[]
", stepFunction: async (editor) => { columnize(2)(editor); undo(editor); await insertText(editor, "x"); }, contentAfter: "x[]
", }); }); test("should work properly after undo and then redo", async () => { await testEditor({ contentBefore: "[]
", stepFunction: async (editor) => { columnize(2)(editor); undo(editor); redo(editor); await insertText(editor, "x"); }, contentAfter: columnsContainer(column(6, "x[]
") + column(6, "