Files
odoo_source/addons/website/tests/test_snippets.py
T
qsm-odoo e4e69d54fb [FIX] website, web_editor: prevent traceback on popup removal
Before this commit, a traceback occured when trying to remove a popup
snippet, only if content inside was clicked on before (base case but
that last part was not covered by our main test which drags and drops +
removes all snippets).

The problem is complex and annoying to solve in stable. The cause is the
combination of [1] and [2]. Indeed, with [2] we solved the snippet
activation flow to ensure the onFocus and onBlur methods are called when
needed... but that new correct implementation relies on the fact that
the number of snippet editor instances does not change for the whole
async operation of activating a snippet. That should naturally be the
case but is not because of [1]: when we remove a snippet we first
trigger a snippet activation then destroy the snippet (and its editor
instance)... but the snippet activation is not awaited at the moment.
Thus making the snippet editor instance be destroyed *during* the
snippet activation flow. Of course a better solution than this commit
must be found but this fixes the traceback with a very minimal change
for the 15.0 stable version while waiting for that miraculous solution.

[1]: https://github.com/odoo/odoo/commit/ae219ec06baf0280c76ae09b1453cc1481eece30
[2]: https://github.com/odoo/odoo/commit/0acc5e784b15d9c963660da3781763448503f33e

task-2735663

closes odoo/odoo#83378

X-original-commit: da7c1b5757a7780897c5736ddecc014a7fb50bdb
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-01-26 13:11:10 +00:00

44 lines
2.0 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from lxml import html
from odoo.tests import HttpCase, tagged
from odoo.addons.website.tools import MockRequest
@tagged('post_install', '-at_install', 'website_snippets')
class TestSnippets(HttpCase):
def test_01_empty_parents_autoremove(self):
self.start_tour("/?enable_editor=1", "snippet_empty_parent_autoremove", login='admin')
def test_02_default_shape_gets_palette_colors(self):
self.start_tour("/?enable_editor=1", "default_shape_gets_palette_colors", login='admin')
def test_03_snippets_all_drag_and_drop(self):
with MockRequest(self.env, website=self.env['website'].browse(1)):
snippets_template = self.env['ir.ui.view'].render_public_asset('website.snippets')
html_template = html.fromstring(snippets_template)
data_snippet_els = html_template.xpath("//*[@class='o_panel' and not(contains(@class, 'd-none'))]//*[@data-snippet]")
blacklist = [
's_facebook_page', # avoid call to external services (facebook.com)
's_map', # avoid call to maps.google.com
]
snippets_names = ','.join(set(el.attrib['data-snippet'] for el in data_snippet_els if el.attrib['data-snippet'] not in blacklist))
self.start_tour("/?enable_editor=1&snippets_names=%s" % snippets_names, "snippets_all_drag_and_drop", login='admin', timeout=300)
def test_04_countdown_preview(self):
self.start_tour("/?enable_editor=1", "snippet_countdown", login='admin')
def test_05_social_media(self):
self.start_tour("/?enable_editor=1", 'snippet_social_media', login="admin")
self.assertEqual(
self.env['website'].browse(1).social_instagram,
'https://instagram.com/odoo.official/',
'Social media should have been updated'
)
def test_06_snippet_popup_add_remove(self):
self.start_tour('/?enable_editor=1', 'snippet_popup_add_remove', login='admin')