From 1ea5eaab8eb1db1cc62182a41e4bb890084ddb45 Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Wed, 14 Jun 2023 13:08:48 +0000 Subject: [PATCH] [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) Signed-off-by: Benoit Socias (bso) --- .../static/tests/tours/unsplash_beacon.js | 26 +++++++++++++++++++ addons/website/tests/__init__.py | 1 + addons/website/tests/test_unsplash_beacon.py | 23 ++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 addons/website/static/tests/tours/unsplash_beacon.js create mode 100644 addons/website/tests/test_unsplash_beacon.py diff --git a/addons/website/static/tests/tours/unsplash_beacon.js b/addons/website/static/tests/tours/unsplash_beacon.js new file mode 100644 index 00000000000..16677a80f02 --- /dev/null +++ b/addons/website/static/tests/tours/unsplash_beacon.js @@ -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, + }], +}); diff --git a/addons/website/tests/__init__.py b/addons/website/tests/__init__.py index 501ceec993d..b315317b9c4 100644 --- a/addons/website/tests/__init__.py +++ b/addons/website/tests/__init__.py @@ -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 diff --git a/addons/website/tests/test_unsplash_beacon.py b/addons/website/tests/test_unsplash_beacon.py new file mode 100644 index 00000000000..d2f896ea664 --- /dev/null +++ b/addons/website/tests/test_unsplash_beacon.py @@ -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 = ''' + + +
+ +
+
+
''' + # Access page. + self.start_tour("/?test_unsplash_beacon", "test_unsplash_beacon")