[IMP] website: test unsplash beacon
This commit ensures that the unsplash beacon calls home when an unsplash image appears on a page. To achieve this it patches the RPC call when the test URL contains the test name as parameter. The patch cancels the actual beacon call to avoid polluting data during the test, but marks the image as having had its beacon message sent. The test then simply checks if this marker appears on the image. task-3360109 closes odoo/odoo#126522 X-original-commit: 1b0f25130b461e7b531548363c680200c7363e7f Signed-off-by: Outagant Mehdi (mou) <mou@odoo.com> Signed-off-by: Benoit Socias (bso) <bso@odoo.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { registry } from "@web/core/registry";
|
||||
|
||||
if (window.location.search.includes("test_unsplash_beacon")) {
|
||||
// Patch RPC call.
|
||||
const oldGet = $.get.bind($);
|
||||
$.get = (url, data, success, dataType) => {
|
||||
if (url === "https://views.unsplash.com/v") {
|
||||
const imageEl = document.querySelector(`img[src^="/unsplash/${data.photo_id}/"]`);
|
||||
imageEl.dataset.beacon = "sent";
|
||||
return;
|
||||
}
|
||||
return oldGet(url, data, success, dataType);
|
||||
};
|
||||
}
|
||||
|
||||
registry.category("web_tour.tours").add("test_unsplash_beacon", {
|
||||
test: true,
|
||||
url: "/?test_unsplash_beacon",
|
||||
steps: [{
|
||||
content: "Verify whether beacon was sent.",
|
||||
trigger: 'img[data-beacon="sent"]',
|
||||
isCheck: true,
|
||||
}],
|
||||
});
|
||||
@@ -27,6 +27,7 @@ from . import test_res_users
|
||||
from . import test_snippets
|
||||
from . import test_theme
|
||||
from . import test_ui
|
||||
from . import test_unsplash_beacon
|
||||
from . import test_views
|
||||
from . import test_views_inherit_module_update
|
||||
from . import test_website_favicon
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import odoo.tests
|
||||
|
||||
|
||||
@odoo.tests.common.tagged('post_install', '-at_install')
|
||||
class TestUnsplashBeacon(odoo.tests.HttpCase):
|
||||
|
||||
def test_01_beacon(self):
|
||||
self.env['ir.config_parameter'].sudo().set_param('unsplash.app_id', '123456')
|
||||
# Create page with unsplash image.
|
||||
page = self.env['website.page'].search([('url', '=', '/'), ('website_id', '=', 1)])
|
||||
page.arch = '''<t name="Homepage" t-name="website.homepage1">
|
||||
<t t-call="website.layout">
|
||||
<t t-set="pageName" t-value="'homepage'"/>
|
||||
<div id="wrap" class="oe_structure oe_empty">
|
||||
<img src="/unsplash/pYyOZ8q7AII/306/fairy.jpg"/>
|
||||
</div>
|
||||
</t>
|
||||
</t>'''
|
||||
# Access page.
|
||||
self.start_tour("/?test_unsplash_beacon", "test_unsplash_beacon")
|
||||
Reference in New Issue
Block a user