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")