import { describe, test } from "@odoo/hoot"; import { patchWithCleanup } from "@web/../tests/web_test_helpers"; import { testEditor } from "./_helpers/editor"; import { insertText } from "./_helpers/user_actions"; describe("inline code", () => { test("should convert text into inline code (start)", async () => { await testEditor({ contentBefore: "
`ab[]cd
", stepFunction: async (editor) => await insertText(editor, "`"), contentAfter: '\u200Bab
\u200B[]cd
[]ab`cd
", stepFunction: async (editor) => await insertText(editor, "`"), contentAfter: '\u200B[]ab
cd
ab`cd[]ef
", stepFunction: async (editor) => await insertText(editor, "`"), contentAfter: 'abcd
\u200B[]ef
ab[]cd`ef
", stepFunction: async (editor) => await insertText(editor, "`"), contentAfter: 'ab[]cd
ef
ab`cd[]
", stepFunction: async (editor) => await insertText(editor, "`"), contentAfter: 'abcd
\u200B[]
ab[]cd`
", stepFunction: async (editor) => await insertText(editor, "`"), contentAfter: 'ab[]cd
a`b`cd[]e`f
", stepFunction: async (editor) => await insertText(editor, "`"), // The closest PREVIOUS backtick is prioritary contentAfter: 'a`bcd
\u200B[]e`f
ab[]cd`e`f
", stepFunction: async (editor) => await insertText(editor, "`"), // If there is no previous backtick, use the closest NEXT backtick. contentAfter: 'ab[]cd
e`f
ab`cde[]fg
", stepFunction: async (editor) => await insertText(editor, "`"), contentAfter: "ab`cde`[]fg
", }); }); test("should not convert text into inline code when interrupted by linebreak", async () => { await testEditor({ contentBefore: "ab`c
d[]ef
ab`c
d`[]ef
ab`cd[]e
f
ab`cd`[]e
f
b`c[]d
", stepFunction: async (editor) => { editor.document.getSelection().anchorNode.before(document.createTextNode("a")); /** @todo fix warnings */ patchWithCleanup(console, { warn: () => {} }); await insertText(editor, "`"); }, contentAfter: 'abc
\u200B[]d
a`b[]c
", stepFunction: async (editor) => { editor.document.getSelection().anchorNode.after(document.createTextNode("d")); await insertText(editor, "`"); }, contentAfter: 'ab
\u200B[]cd
b`c[]d
", stepFunction: async (editor) => { editor.document.getSelection().anchorNode.before(document.createTextNode("a")); editor.document.getSelection().anchorNode.after(document.createTextNode("e")); await insertText(editor, "`"); }, contentAfter: 'abc
\u200B[]de
ab[]c
", stepFunction: async (editor) => { editor.document.getSelection().anchorNode.before(document.createTextNode("`")); /** @todo fix warnings */ patchWithCleanup(console, { warn: () => {} }); await insertText(editor, "`"); }, contentAfter: '\u200Bab
\u200B[]c
ab[]c
", stepFunction: async (editor) => { editor.document.getSelection().anchorNode.after(document.createTextNode("`")); await insertText(editor, "`"); }, contentAfter: 'ab[]c
`[]
", stepFunction: async (editor) => insertText(editor, "`"), contentAfter: "``[]
", }); await testEditor({ contentBefore: "``[]
", stepFunction: async (editor) => insertText(editor, "`"), contentAfter: "```[]
", }); await testEditor({ contentBefore: "```[]
", stepFunction: async (editor) => insertText(editor, "`"), contentAfter: "````[]
", }); await testEditor({ contentBefore: "````[]
", stepFunction: async (editor) => insertText(editor, "`"), contentAfter: "`````[]
", }); }); });