From 0791c31654fcf848d208e06771a8bdb6174d98a8 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Thu, 3 Feb 2022 13:08:03 +0000 Subject: [PATCH] [FIX] web_editor: correct reference to editable in tests Some tests depended on a variable to be defined, which was only defined in other tests. X-original-commit: d3e30a532526e7be54d6153a3ed375ff30d8f8e3 Part-of: odoo/odoo#84513 --- .../static/tests/convert_inline_tests.js | 85 +++++++++---------- 1 file changed, 41 insertions(+), 44 deletions(-) diff --git a/addons/web_editor/static/tests/convert_inline_tests.js b/addons/web_editor/static/tests/convert_inline_tests.js index 14d0b880187..61882c104c2 100644 --- a/addons/web_editor/static/tests/convert_inline_tests.js +++ b/addons/web_editor/static/tests/convert_inline_tests.js @@ -2,11 +2,8 @@ import convertInline from '@web_editor/js/backend/convert_inline'; import {getGridHtml, getTableHtml, getRegularGridHtml, getRegularTableHtml} from 'web_editor.test_utils'; - QUnit.module('web_editor', {}, function () { QUnit.module('convert_inline', {}, function () { - let $editable; - QUnit.module('Convert Bootstrap grids to tables'); // Test bootstrapToTable, cardToTable and listGroupToTable @@ -14,7 +11,7 @@ QUnit.module('convert_inline', {}, function () { assert.expect(4); // 1x1 - $editable = $(`
${getRegularGridHtml(1, 1)}
`); + let $editable = $(`
${getRegularGridHtml(1, 1)}
`); convertInline.bootstrapToTable($editable); assert.strictEqual($editable.html(), getRegularTableHtml(1, 1, 12, 100), "should have converted a 1x1 grid to an equivalent table"); @@ -41,7 +38,7 @@ QUnit.module('convert_inline', {}, function () { assert.expect(4); // 1x13 - $editable = $(`
${getRegularGridHtml(1, 13)}
`); + let $editable = $(`
${getRegularGridHtml(1, 13)}
`); convertInline.bootstrapToTable($editable); assert.strictEqual($editable.html(), getRegularTableHtml(1, 12, 1, 8.33).slice(0, -8) + @@ -82,7 +79,7 @@ QUnit.module('convert_inline', {}, function () { assert.expect(4); // 2x1 - $editable = $(`
${getRegularGridHtml(2, 1)}
`); + let $editable = $(`
${getRegularGridHtml(2, 1)}
`); convertInline.bootstrapToTable($editable); assert.strictEqual($editable.html(), getRegularTableHtml(2, 1, 12, 100), "should have converted a 2x1 grid to an equivalent table"); @@ -109,7 +106,7 @@ QUnit.module('convert_inline', {}, function () { assert.expect(4); // 2x[13,1] - $editable = $(`
${getRegularGridHtml(2, [13, 1])}
`); + let $editable = $(`
${getRegularGridHtml(2, [13, 1])}
`); convertInline.bootstrapToTable($editable); assert.strictEqual($editable.html(), getRegularTableHtml(1, 12, 1, 8.33).slice(0, -8) + @@ -146,7 +143,7 @@ QUnit.module('convert_inline', {}, function () { assert.expect(2); // 1x2 - $editable = $(`
${getGridHtml([[8, 4]])}
`); + let $editable = $(`
${getGridHtml([[8, 4]])}
`); convertInline.bootstrapToTable($editable); assert.strictEqual($editable.html(), getTableHtml([[[8, 66.67], [4, 33.33]]]), "should have converted a 1x2 irregular grid to an equivalent table"); @@ -161,7 +158,7 @@ QUnit.module('convert_inline', {}, function () { assert.expect(2); // 1x2 - $editable = $(`
${getGridHtml([[8, 5]])}
`); + let $editable = $(`
${getGridHtml([[8, 5]])}
`); convertInline.bootstrapToTable($editable); assert.strictEqual($editable.html(), getTableHtml([ [[8, 66.67], [4, 33.33, '']], @@ -183,7 +180,7 @@ QUnit.module('convert_inline', {}, function () { assert.expect(2); // 2x2 - $editable = $(`
${getGridHtml([[1, 11], [2, 10]])}
`); + let $editable = $(`
${getGridHtml([[1, 11], [2, 10]])}
`); convertInline.bootstrapToTable($editable); assert.strictEqual($editable.html(), getTableHtml([[[1, 8.33], [11, 91.67]], [[2, 16.67], [10, 83.33]]]), "should have converted a 2x2 irregular grid to an equivalent table"); @@ -198,7 +195,7 @@ QUnit.module('convert_inline', {}, function () { assert.expect(3); // 2x2 (both rows overflow) - $editable = $(`
${getGridHtml([[6, 8], [7, 9]])}
`); + let $editable = $(`
${getGridHtml([[6, 8], [7, 9]])}
`); convertInline.bootstrapToTable($editable); assert.strictEqual($editable.html(), getTableHtml([ @@ -234,8 +231,8 @@ QUnit.module('convert_inline', {}, function () { QUnit.test('convert a card to a table', async function (assert) { assert.expect(1); - $editable.html( - `
` + + const $editable = $( + `
` + `
` + `HEADER` + `
` + @@ -246,7 +243,7 @@ QUnit.module('convert_inline', {}, function () { `` + - `
`); + `
`); convertInline.cardToTable($editable); assert.strictEqual($editable.html(), getRegularTableHtml(3, 1, 12, 100) @@ -277,8 +274,8 @@ QUnit.module('convert_inline', {}, function () { QUnit.test('convert a list group to a table', async function (assert) { assert.expect(1); - $editable.html( - ``); convertInline.listGroupToTable($editable); assert.strictEqual($editable.html(), getRegularTableHtml(3, 1, 12, 100) @@ -306,12 +303,12 @@ QUnit.module('convert_inline', {}, function () { QUnit.test('convert rgb color to hexadecimal', async function (assert) { assert.expect(1); - $editable.html( - `
` + + const $editable = $( + `
` + `
` + `

Test

` + `
` + - `
` + `
` ); convertInline.normalizeColors($editable); assert.strictEqual($editable.html(), @@ -332,7 +329,7 @@ QUnit.module('convert_inline', {}, function () { `` + ``; - $editable = $(`
${testDom}
`); + let $editable = $(`
${testDom}
`); document.body.append($editable[0]); convertInline.normalizeRem($editable); assert.strictEqual($editable.html(), @@ -430,7 +427,7 @@ QUnit.module('convert_inline', {}, function () { ``; // table.o_mail_snippet_general - $editable = $(`
${testTable}
`); + const $editable = $(`
${testTable}
`); convertInline.formatTables($editable); assert.strictEqual($editable.html(), expectedTable, "should have moved the padding from table.o_mail_snippet_general and table in it to their respective cells" @@ -439,7 +436,7 @@ QUnit.module('convert_inline', {}, function () { QUnit.test('add a tbody to any table that doesn\'t have one', async function (assert) { assert.expect(1); - $editable = $(`
${`
I don't have a body :'(
`}
`); + const $editable = $(`
${`
I don't have a body :'(
`}
`); $editable.find('tr').unwrap(); convertInline.formatTables($editable); assert.strictEqual($editable.html(), `
I don't have a body :'(
`, @@ -449,7 +446,7 @@ QUnit.module('convert_inline', {}, function () { QUnit.test('add number heights to parents of elements with percent heights', async function (assert) { assert.expect(3); - $editable = $(`
${`
yup
`}
`); + let $editable = $(`
${`
yup
`}
`); convertInline.formatTables($editable); assert.strictEqual($editable.html(), `
yup
`, "should have added a 0 height to the parent of a 100% height element" @@ -470,7 +467,7 @@ QUnit.module('convert_inline', {}, function () { QUnit.test('express align-self with vertical-align on table cells', async function (assert) { assert.expect(3); - $editable = $(`
yup
`); + let $editable = $(`
yup
`); convertInline.formatTables($editable); assert.strictEqual($editable.html(), `
yup
`, "should have added a top vertical alignment" @@ -495,10 +492,10 @@ QUnit.module('convert_inline', {}, function () { QUnit.test('convert snippets to tables', async function (assert) { assert.expect(2); - $editable.html( - `
` + + let $editable = $( + `
` + `
Snippet
` + - `
` + `
` ); convertInline.addTables($editable); assert.strictEqual($editable.html(), @@ -508,10 +505,10 @@ QUnit.module('convert_inline', {}, function () { "should have converted .o_mail_snippet_general to a special table structure with a table in it" ); - $editable.html( - `
` + + $editable = $( + `
` + `
Snippet
` + - `
` + `
` ); convertInline.addTables($editable); assert.strictEqual($editable.html(), @@ -524,10 +521,10 @@ QUnit.module('convert_inline', {}, function () { QUnit.test('convert mailing bodies to tables', async function (assert) { assert.expect(2); - $editable.html( - `
` + + let $editable = $( + `
` + `
Mailing
` + - `
` + `
` ); convertInline.addTables($editable); assert.strictEqual($editable.html(), @@ -538,10 +535,10 @@ QUnit.module('convert_inline', {}, function () { "should have converted .o_layout to a special table structure with a table in it" ); - $editable.html( - `
` + + $editable = $( + `
` + `
Mailing
` + - `
` + `
` ); convertInline.addTables($editable); assert.strictEqual($editable.html(), @@ -559,7 +556,7 @@ QUnit.module('convert_inline', {}, function () { QUnit.test('convert Bootstrap classes to inline styles', async function (assert) { assert.expect(1); - $editable = $(`
${`
Hello
`}
`); + const $editable = $(`
Hello
`); convertInline.classToStyle($editable, convertInline.getCSSRules($editable[0].ownerDocument)); const containerStyle = `padding:0 16px 0 16px;margin:0 auto 0 auto;box-sizing:border-box;max-width:1140px;width:100%;`; const rowStyle = `margin:0 -16px 0 -16px;box-sizing:border-box;`; @@ -587,7 +584,7 @@ QUnit.module('convert_inline', {}, function () { border-top-left-radius: 40%; } `, 0); - $editable = $(`
${`
`}
`); + let $editable = $(`
${`
`}
`); convertInline.classToStyle($editable, convertInline.getCSSRules($editable[0].ownerDocument)); assert.strictEqual($editable.html(), `
`, @@ -784,7 +781,7 @@ QUnit.module('convert_inline', {}, function () { text-decoration-thickness: 10px; } `, 0); - $editable = $(`
${`
`}
`); + let $editable = $(`
${`
`}
`); convertInline.classToStyle($editable, convertInline.getCSSRules($editable[0].ownerDocument)); assert.strictEqual($editable.html(), `
`, @@ -960,19 +957,19 @@ QUnit.module('convert_inline', {}, function () { } `, 2); - $editable = $(`
${``}
`); + let $editable = $(`
`); convertInline.classToStyle($editable, convertInline.getCSSRules($editable[0].ownerDocument)); assert.strictEqual($editable.html(), ``, "should have prioritized the last defined style"); - $editable = $(`
${`
`}
`); + $editable = $(`
`); convertInline.classToStyle($editable, convertInline.getCSSRules($editable[0].ownerDocument)); assert.strictEqual($editable.html(), `
`, "should have prioritized the more specific style"); - $editable = $(`
${`
`}
`); + $editable = $(`
`); convertInline.classToStyle($editable, convertInline.getCSSRules($editable[0].ownerDocument)); assert.strictEqual($editable.html(), `
`, @@ -983,7 +980,7 @@ QUnit.module('convert_inline', {}, function () { color: black !important; } `, 0); - $editable = $(`
${`
`}
`); + $editable = $(`
`); convertInline.classToStyle($editable, convertInline.getCSSRules($editable[0].ownerDocument)); assert.strictEqual($editable.html(), `
`,