From 8a750c4b44459774f6557e1977de558e9e02dc32 Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Thu, 29 Jun 2023 11:12:11 +0000 Subject: [PATCH] [FIX] website: fix failing unsplash beacon test The unsplash beacon public widget is started before the test assets JS is loaded. Because of this, the approach in [1] fails sporadically. If the result from the `/web_unsplash/get_app_id` RPC is obtained before the test assets JS is loaded, the beacon patch is not applied in time, and the test fails. This commit applies the patch within the actual page HTML to avoid this issue. [1]: https://github.com/odoo/odoo/commit/a5abc766424f34074be3ae7a97ad7c6e9583f9c5 runbot-22610 closes odoo/odoo#127809 X-original-commit: 3f64135ff136addfad7c4c79e8c19cc33f8b19cf Signed-off-by: Guillaume Dieleman (gdi) --- .../static/tests/tours/unsplash_beacon.js | 15 +--------- addons/website/tests/test_unsplash_beacon.py | 28 ++++++++++++++++++- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/addons/website/static/tests/tours/unsplash_beacon.js b/addons/website/static/tests/tours/unsplash_beacon.js index 16677a80f02..8a97659f638 100644 --- a/addons/website/static/tests/tours/unsplash_beacon.js +++ b/addons/website/static/tests/tours/unsplash_beacon.js @@ -2,22 +2,9 @@ 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", + url: "/", steps: [{ content: "Verify whether beacon was sent.", trigger: 'img[data-beacon="sent"]', diff --git a/addons/website/tests/test_unsplash_beacon.py b/addons/website/tests/test_unsplash_beacon.py index d2f896ea664..6a92133a50d 100644 --- a/addons/website/tests/test_unsplash_beacon.py +++ b/addons/website/tests/test_unsplash_beacon.py @@ -16,8 +16,34 @@ class TestUnsplashBeacon(odoo.tests.HttpCase):
+ +
''' # Access page. - self.start_tour("/?test_unsplash_beacon", "test_unsplash_beacon") + self.start_tour('/', 'test_unsplash_beacon')