Skip to content

Commit 460d5ec

Browse files
committed
[IMP] website: add tests for all snippets (drag and drop)
Image gallery snippet when dropped is throwing a traceback. This lead to the editor not usable anymore, as any JS error will prevent any further action (no JS will work anymore). This introduce a test that will drag and drop every snippet in a page and click on it to load its settings in the right panel. Note that it will remove the snippet before drag & dropping the next one, as having too many snippet will impact the perf, even killing the browser entirely if there is a lot. task-2604383 closes #74135 Signed-off-by: Jérémy Kersten (jke) <[email protected]>
1 parent 1c44278 commit 460d5ec

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
odoo.define("website.tour.snippets_all_drag_and_drop", async function (require) {
2+
"use strict";
3+
4+
const tour = require("web_tour.tour");
5+
6+
let snippetsNames = (new URL(document.location.href)).searchParams.get('snippets_names') || '';
7+
snippetsNames = snippetsNames.split(',');
8+
let steps = [];
9+
let n = 0;
10+
for (const snippet of snippetsNames) {
11+
n++;
12+
const snippetSteps = [{
13+
content: `Drop ${snippet} snippet [${n}/${snippetsNames.length}]`,
14+
trigger: `#oe_snippets .oe_snippet:has( > [data-snippet='${snippet}']) .oe_snippet_thumbnail`,
15+
run: "drag_and_drop #wrap",
16+
}, {
17+
content: `Edit ${snippet} snippet`,
18+
trigger: `#wrap.o_editable [data-snippet='${snippet}']`,
19+
}, {
20+
content: `check ${snippet} setting are loaded, wait panel is visible`,
21+
trigger: ".o_we_customize_panel",
22+
run: function () {}, // it's a check
23+
}, {
24+
content: `Remove the ${snippet} snippet`, // Avoid bad perf if many snippets
25+
trigger: "we-button.oe_snippet_remove:last"
26+
}, {
27+
content: `click on 'BLOCKS' tab (${snippet})`,
28+
trigger: ".o_we_add_snippet_btn",
29+
}];
30+
31+
if (snippet === 's_google_map') {
32+
snippetSteps.splice(1, 3, {
33+
content: 'Close API Key popup',
34+
trigger: ".modal-footer .btn-secondary",
35+
});
36+
} else if (snippet === 's_popup') {
37+
snippetSteps[2]['in_modal'] = false;
38+
snippetSteps.splice(3, 2, {
39+
content: `Hide the ${snippet} popup`,
40+
trigger: ".s_popup_close",
41+
});
42+
} else if (['s_newsletter_block', 's_newsletter_subscribe_form', 's_newsletter_subscribe_popup'].includes(snippet)) {
43+
snippetSteps.splice(1, 0, {
44+
content: `Confirm the ${snippet} popup`,
45+
trigger: `.modal-footer button.btn-primary`,
46+
});
47+
}
48+
if (snippet === 's_newsletter_subscribe_popup') {
49+
snippetSteps.splice(3, 2, {
50+
content: `Hide the ${snippet} popup`,
51+
trigger: "button.close",
52+
});
53+
}
54+
steps = steps.concat(snippetSteps);
55+
}
56+
57+
tour.register("snippets_all_drag_and_drop", {
58+
test: true,
59+
}, [
60+
{
61+
content: "Ensure snippets are actually passed at the test.",
62+
trigger: "#oe_snippets",
63+
run: function () {
64+
// safety check, otherwise the test might "break" one day and
65+
// receive no steps. The test would then not test anything anymore
66+
// without us noticing it.
67+
if (steps.lenth < 280) {
68+
console.error("This test is not behaving as it should.");
69+
}
70+
},
71+
},
72+
// This first step is needed as it will be used later for inner snippets
73+
// Without this, it will dropped inside the footer and will need an extra
74+
// selector.
75+
{
76+
content: "Drop s_text_image snippet",
77+
trigger: "#oe_snippets .oe_snippet:has( > [data-snippet='s_text_image']) .oe_snippet_thumbnail",
78+
run: "drag_and_drop #wrap"
79+
},
80+
{
81+
content: "Edit s_text_image snippet",
82+
trigger: "#wrap.o_editable [data-snippet='s_text_image']"
83+
},
84+
{
85+
content: "check setting are loaded, wait panel is visible",
86+
trigger: ".o_we_customize_panel"
87+
},
88+
{
89+
content: "click on 'BLOCKS' tab",
90+
trigger: ".o_we_add_snippet_btn"
91+
},
92+
].concat(steps)
93+
);
94+
});

addons/website/tests/test_snippets.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# -*- coding: utf-8 -*-
22
# Part of Odoo. See LICENSE file for full copyright and licensing details.
33

4+
from lxml import html
5+
46
import odoo
57
import odoo.tests
8+
from odoo.addons.website.tools import MockRequest
69

710

811
@odoo.tests.common.tagged('post_install', '-at_install', 'website_snippets')
@@ -13,3 +16,11 @@ def test_01_empty_parents_autoremove(self):
1316

1417
def test_02_default_shape_gets_palette_colors(self):
1518
self.start_tour("/?enable_editor=1", "default_shape_gets_palette_colors", login='admin')
19+
20+
def test_03_snippets_all_drag_and_drop(self):
21+
with MockRequest(self.env, website=self.env['website'].browse(1)):
22+
snippets_template = self.env['ir.ui.view'].render_public_asset('website.snippets')
23+
html_template = html.fromstring(snippets_template)
24+
data_snippet_els = html_template.xpath("//*[@class='o_panel' and not(contains(@class, 'd-none'))]//*[@data-snippet]")
25+
snippets_names = ','.join([el.attrib['data-snippet'] for el in data_snippet_els])
26+
self.start_tour("/?enable_editor=1&snippets_names=%s" % snippets_names, "snippets_all_drag_and_drop", login='admin', timeout=300)

0 commit comments

Comments
 (0)