diff --git a/addons/web_tour/data/web_tour_demo.xml b/addons/web_tour/data/web_tour_demo.xml deleted file mode 100644 index d3a4e5349ae..00000000000 --- a/addons/web_tour/data/web_tour_demo.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - diff --git a/addons/web_tour/models/ir_http.py b/addons/web_tour/models/ir_http.py index abcfceb484e..1e86babb6ad 100644 --- a/addons/web_tour/models/ir_http.py +++ b/addons/web_tour/models/ir_http.py @@ -9,7 +9,9 @@ class Http(models.AbstractModel): _inherit = 'ir.http' def session_info(self): - result = super(Http, self).session_info() + result = super().session_info() if result['is_admin']: + demo_modules_count = self.env['ir.module.module'].search_count([('demo', '=', True)]) result['web_tours'] = request.env['web_tour.tour'].get_consumed_tours() + result['tour_disable'] = demo_modules_count > 0 return result diff --git a/addons/web_tour/static/src/js/tour_disable.js b/addons/web_tour/static/src/js/tour_disable.js deleted file mode 100644 index fad7a14dcf6..00000000000 --- a/addons/web_tour/static/src/js/tour_disable.js +++ /dev/null @@ -1,25 +0,0 @@ -odoo.define('web_tour.DisableTour', function (require) { -"use strict"; - -var local_storage = require('web.local_storage'); -var TourManager = require('web_tour.TourManager'); -var utils = require('web_tour.utils'); - -var get_debugging_key = utils.get_debugging_key; - -TourManager.include({ - /** - * Disables tours if Odoo installed with demo data. - * - * @override - */ - _register: function (do_update, tour, name) { - // Consuming tours which are not run by test case nor currently being debugged - if (!this.running_tour && !local_storage.getItem(get_debugging_key(name))) { - this.consumed_tours.push(name); - } - return this._super.apply(this, arguments); - }, -}); - -}); diff --git a/addons/web_tour/static/src/js/tour_manager.js b/addons/web_tour/static/src/js/tour_manager.js index 1f1207c6289..97fa343b583 100644 --- a/addons/web_tour/static/src/js/tour_manager.js +++ b/addons/web_tour/static/src/js/tour_manager.js @@ -26,7 +26,7 @@ var do_before_unload = utils.do_before_unload; var get_jquery_element_from_selector = utils.get_jquery_element_from_selector; return core.Class.extend(mixins.EventDispatcherMixin, ServicesMixin, { - init: function(parent, consumed_tours) { + init: function(parent, consumed_tours, disabled = false) { mixins.EventDispatcherMixin.init.call(this); this.setParent(parent); @@ -37,6 +37,7 @@ return core.Class.extend(mixins.EventDispatcherMixin, ServicesMixin, { this.consumed_tours = (consumed_tours || []).filter(tourName => { return !local_storage.getItem(get_debugging_key(tourName)); }); + this.disabled = disabled; this.running_tour = local_storage.getItem(get_running_key()); this.running_step_delay = parseInt(local_storage.getItem(get_running_delay_key()), 10) || 0; this.edition = (_.last(session.server_version_info) === 'e') ? 'enterprise' : 'community'; @@ -128,6 +129,11 @@ return core.Class.extend(mixins.EventDispatcherMixin, ServicesMixin, { }); }, _register: function (do_update, tour, name) { + const debuggingTour = local_storage.getItem(get_debugging_key(name)); + if (this.disabled && !this.running_tour && !debuggingTour) { + this.consumed_tours.push(name); + } + if (tour.ready) return Promise.resolve(); const tour_is_consumed = this._isTourConsumed(name); @@ -146,7 +152,6 @@ return core.Class.extend(mixins.EventDispatcherMixin, ServicesMixin, { tour.ready = true; - const debuggingTour = local_storage.getItem(get_debugging_key(name)); if (debuggingTour || (do_update && (this.running_tour === name || (!this.running_tour && !tour.test && !tour_is_consumed)))) { @@ -156,7 +161,7 @@ return core.Class.extend(mixins.EventDispatcherMixin, ServicesMixin, { }, /** * Resets the given tour to its initial step, and prevent it from being - * marked as consumed at reload, by the include in tour_disable.js + * marked as consumed at reload. * * @param {string} tourName */ diff --git a/addons/web_tour/static/src/js/tour_service.js b/addons/web_tour/static/src/js/tour_service.js index a055c987396..51f895a13e7 100644 --- a/addons/web_tour/static/src/js/tour_service.js +++ b/addons/web_tour/static/src/js/tour_service.js @@ -5,6 +5,7 @@ var rootWidget = require('root.widget'); var rpc = require('web.rpc'); var session = require('web.session'); var TourManager = require('web_tour.TourManager'); +const { device } = require('web.config'); const untrackedClassnames = ["o_tooltip", "o_tooltip_content", "o_tooltip_overlay"]; @@ -32,7 +33,8 @@ return session.is_bound.then(function () { } return Promise.all(defs).then(function (results) { var consumed_tours = session.is_frontend ? results[0] : session.web_tours; - var tour_manager = new TourManager(rootWidget, consumed_tours); + const disabled = session.tour_disable || device.isMobile; + var tour_manager = new TourManager(rootWidget, consumed_tours, disabled); function _isTrackedNode(node) { if (node.classList) { diff --git a/addons/web_tour/static/tests/tour_manager_tests.js b/addons/web_tour/static/tests/tour_manager_tests.js index aa2dff5fcf8..26ebaeb398c 100644 --- a/addons/web_tour/static/tests/tour_manager_tests.js +++ b/addons/web_tour/static/tests/tour_manager_tests.js @@ -18,12 +18,13 @@ odoo.define('web_tour.tour_manager_tests', async function (require) { * @param {Object} params * @param {string[]} [params.consumed_tours] * @param {boolean} [params.debug] + * @param {boolean} [params.disabled] * @param {string} params.template inner HTML content of the widget * @param {Object[]} params.tours { {string} name, {Object} option, {Object[]} steps } */ - async function createTourManager({ consumed_tours, debug, template, tours }) { + async function createTourManager({ consumed_tours, debug, disabled, template, tours }) { const parent = await testUtils.createParent({ debug }); - const tourManager = new TourManager(parent, consumed_tours); + const tourManager = new TourManager(parent, consumed_tours, disabled); tourManager.running_step_delay = 0; for (const { name, options, steps } of tours) { tourManager.register(name, options, steps); @@ -35,23 +36,13 @@ odoo.define('web_tour.tour_manager_tests', async function (require) { }; await parent.prependTo(testUtils.prepareTarget(debug)); parent.el.innerHTML = template; - testUtils.mock.patch(TourManager, { - // Since the `tour_disable.js` script automatically sets tours as consumed - // as soon as they are registered, we override the "is consumed" to - // assert that the tour is in the `consumed_tours` param key. - _isTourConsumed: name => (consumed_tours || []).includes(name), - }); await tourManager._register_all(true); // Wait for possible tooltips to be loaded and appended. await testUtils.nextTick(); return tourManager; } - QUnit.module("Tours", { - afterEach() { - testUtils.mock.unpatch(TourManager); - }, - }, function () { + QUnit.module("Tours", function () { QUnit.module("Tour manager"); @@ -201,5 +192,26 @@ odoo.define('web_tour.tour_manager_tests', async function (require) { kanban.destroy(); tourManager.destroy(); }); + + QUnit.test("Automatic tour disabling", async function (assert) { + assert.expect(2); + + const options = { + template: ``, + tours: [{ name: "Tour", options: {}, steps: [{ trigger: '.anchor' }] }], + }; + + const enabledTM = await createTourManager({ disabled: false, ...options }); + + assert.containsOnce(document.body, '.o_tooltip:visible'); + + enabledTM.destroy(); + + const disabledTM = await createTourManager({ disabled: true, ...options }); + + assert.containsNone(document.body, '.o_tooltip:visible'); + + disabledTM.destroy(); + }); }); });