Skip to content

Commit

Permalink
Add a test for the double click on image and for the save mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
loco-odoo committed Nov 18, 2024
1 parent 4f3ad34 commit e3c7fe5
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
4 changes: 3 additions & 1 deletion addons/html_builder/static/tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
patchWithCleanup,
getService,
} from "@web/../tests/web_test_helpers";
import { defineMailModels } from "@mail/../tests/mail_test_helpers";
import { defineMailModels, startServer } from "@mail/../tests/mail_test_helpers";
import { advanceTime, animationFrame, click, queryOne } from "@odoo/hoot-dom";
import { getWebsiteSnippets } from "./snippets_getter.hoot";
import { SnippetsMenu } from "@html_builder/builder/snippets_menu";
Expand All @@ -32,6 +32,8 @@ export function defineWebsiteModels() {
}

export async function setupWebsiteBuilder(websiteContent, { snippets } = {}) {
const pyEnv = await startServer();
pyEnv["website"].create({});
let editor;
await mountWithCleanup(WebClient);
await getService("action").doAction({
Expand Down
26 changes: 26 additions & 0 deletions addons/html_builder/static/tests/images.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { expect, test } from "@odoo/hoot";
import { animationFrame, dblclick } from "@odoo/hoot-dom";
import { defineWebsiteModels, openSnippetsMenu, setupWebsiteBuilder } from "./helpers";

defineWebsiteModels();

const base64Img =
"data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA\n AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO\n 9TXL0Y4OHwAAAABJRU5ErkJggg==";

test("double click on Image", async () => {
await setupWebsiteBuilder(`<div><img class=a_nice_img src='${base64Img}'></div>`);
await openSnippetsMenu();
expect(".modal-content").toHaveCount(0);
await dblclick(":iframe img.a_nice_img");
await animationFrame();
expect(".modal-content:contains(Select a media) .o_upload_media_button").toHaveCount(1);
});

test("double click on text", async () => {
await setupWebsiteBuilder("<div><p class=text_class>Text</p></div>");
await openSnippetsMenu();
expect(".modal-content").toHaveCount(0);
await dblclick(":iframe .text_class");
await animationFrame();
expect(".modal-content").toHaveCount(0);
});
30 changes: 30 additions & 0 deletions addons/html_builder/static/tests/save.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { expect, test } from "@odoo/hoot";
import { defineWebsiteModels, openSnippetsMenu, setupWebsiteBuilder } from "./helpers";
import { insertText } from "@html_editor/../tests/_helpers/user_actions";
import { setContent } from "@html_editor/../tests/_helpers/selection";
import { onRpc } from "@web/../tests/web_test_helpers";

defineWebsiteModels();

test("basic save", async () => {
const result = [];
onRpc("ir.ui.view", "save", ({ args }) => {
result.push(args[1]);
return true;
});
const { getEditor } = await setupWebsiteBuilder(getEditable('<h1 class="title">Hello</h1>'));
await openSnippetsMenu();
const editor = getEditor();
setContent(editor.editable, getEditable('<h1 class="title">Hello[]</h1>'));
await insertText(editor, "test");
expect(":iframe #wrap").toHaveClass("o_dirty");
// await click(".o-snippets-top-actions button:contains(Save)");
// expect(result.length).toBe(1);
// expect(result[0]).toBe(
// '<div id="wrap" data-oe-model="ir.ui.view" data-oe-id="539" data-oe-field="arch"><h1 class="title">Hellotest</h1></div>'
// );
});

function getEditable(inWrap) {
return `<div id="wrap" data-oe-model="ir.ui.view" data-oe-id="539" data-oe-field="arch">${inWrap}</div>`;
}
12 changes: 10 additions & 2 deletions addons/html_builder/static/tests/snippets_menu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,23 @@ test("navigate between builder tab don't fetch snippet description again", async
});

test("undo and redo buttons", async () => {
const { getEditor } = await setupWebsiteBuilder("<p> Text </p>");
const { getEditor } = await setupWebsiteBuilder(getEditable("<p> Text </p>"));
expect(".o_menu_systray .o-website-btn-custo-primary").toHaveCount(1);
await openSnippetsMenu();
expect(":iframe #wrap").not.toHaveClass("o_dirty");
const editor = getEditor();
setContent(editor.editable, "<p> Text[] </p>");
setContent(editor.editable, getEditable("<p> Text[] </p>"));
await insertText(editor, "a");
expect(editor.editable).toHaveInnerHTML("<p> Texta </p>");
expect(":iframe #wrap").toHaveClass("o_dirty");
await animationFrame();
await click(".o-snippets-menu button.fa-undo");
await animationFrame();
expect(editor.editable).toHaveInnerHTML("<p> Text </p>");
expect(":iframe #wrap").not.toHaveClass("o_dirty");
await click(".o-snippets-menu button.fa-repeat");
expect(editor.editable).toHaveInnerHTML("<p> Texta </p>");
expect(":iframe #wrap").toHaveClass("o_dirty");
});

test("display group snippet", async () => {
Expand Down Expand Up @@ -246,3 +250,7 @@ test("drag & drop inner content block + undo/redo", async () => {
expect(queryOne(".o-website-snippetsmenu .fa-undo").disabled).toBe(true);
expect(queryOne(".o-website-snippetsmenu .fa-repeat").disabled).toBe(false);
});

function getEditable(inWrap) {
return `<div id="wrap" data-oe-model="ir.ui.view" data-oe-id="539" data-oe-field="arch">${inWrap}</div>`;
}

0 comments on commit e3c7fe5

Please sign in to comment.