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, setSelection } from "./_helpers/selection"; import { insertText, redo, undo } from "./_helpers/user_actions"; import { execCommand } from "./_helpers/userCommands"; import { nodeSize } from "@html_editor/utils/position"; function columnsContainer(contents) { return `
[]
[]
[] |
[] |
abcd
") + column(6, "abcd
") + column(6, "[]abcd
", stepFunction: columnize(2), contentAfterEdit: /* eslint-disable */ columsDuringEditContainer( columnDuringEdit(6, "[]abcd
") + columnDuringEdit(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
") + columnDuringEdit(4, `[]
abcd
") + column(4, "[]
ab[]cd
", stepFunction: columnize(3), /* eslint-disable */ contentAfterEdit: columsDuringEditContainer( columnDuringEdit(4, "ab[]cd
") + columnDuringEdit(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, "a
b[]
", stepFunction: async (editor) => { columnize(2)(editor); const editable = editor.editable; const children = editable.querySelectorAll("p"); const lastP = children[children.length - 1]; lastP.innerHTML = "ab"; setSelection({ anchorNode: lastP.firstChild, anchorOffset: 0 }); await press(["shift", "arrowUp"]); }, contentAfter: "a]
" + columnsContainer(column(6, "b
") + column(6, "[ab
", }); }); test("should be able to select across columns using Shift + ArrowDown", async () => { await testEditor({ contentBefore: "a
b[]
", stepFunction: async (editor) => { columnize(2)(editor); const editable = editor.editable; const children = editable.querySelectorAll("p"); const lastP = children[children.length - 1]; lastP.innerHTML = "ab"; const firstP = children[0]; setSelection({ anchorNode: firstP.lastChild, anchorOffset: nodeSize(firstP) }); await press(["shift", "arrowDown"]); }, contentAfter: "a[
" + columnsContainer(column(6, "b
") + column(6, "]ab
", }); }); });