Files
odoo_source/addons/web_tour/static/tests/debug_manager_tests.js
T
Joseph CaburnayandJulien Mougenot 3a798039d6 [REF] web_tour,*: convert web_tour to owl
* The tours are now run by the `MacroEngine` defined in `macro.js`.
  * This is accomplished by converting (at runtime) the user-defined tours to
    `Macro`s. See `tour_compilers.js` for the step (and tour-to-macro) compilation.
* API is kept the same as much as possible. Basically, declaring tours stayed
  the same with some exceptions:
  * `allowInvisible` can be provided in a step to allow consuming the trigger
    element even if it is invisible.
  * `isCheck` can now be used to replace the no operation `run` that is
    traditionally signals the runner to only perform a check.
  * Before, multiple `run`s can be called simultaneously. Now, each `run` method
    is awaited before proceeding to the next step.
* If the trigger element is `disabled`, the tour runner will *not* proceed on
  calling the `run` method and the runner will stay on current step until the
  trigger element becomes `enabled`.
  * However, the tour runner is okay with `disabled` trigger element if the step
    has `isCheck = true`. As long as the trigger element is found for `isCheck`
    step, the tour runner will happily move to the next step.
* Some tours are adjusted to properly run with this new tour runner.
* When the tour failed:
  * The dom string is not logged anymore.
  * However, a warning message containing the relative location of the step will
    be logged. This is better in helping the author in locating the failed step.

**Some guidelines learned during the development:**

* Each step may trigger a dom mutation. It's a good practice to insert an
  intermediate step that *checks* the existence of an element that result from
  the action of the previous step.
* Refrain from using the `run` method for assertions. `run`, in principle, is
  provided to perform actions that are not offered by the helper. Use the
  `trigger` for assertions.
* During dev, find `SHOW_POINTER_DURATION` and set it to `250`. This will show
  the pointer (pointing to the trigger element) for 250ms when watching the
  tour.

closes odoo/odoo#107618

Task-id: 3082036
Related: odoo/enterprise#37560
Signed-off-by: Géry Debongnie <ged@odoo.com>
Co-authored-by: Julien Mougenot <jum@odoo.com>
2023-03-15 13:19:45 +01:00

88 lines
3.0 KiB
JavaScript

/** @odoo-module **/
import { disableTours } from "@web_tour/debug/debug_manager";
import { hotkeyService } from "@web/core/hotkeys/hotkey_service";
import { ormService } from "@web/core/orm_service";
import { registry } from "@web/core/registry";
import { uiService } from "@web/core/ui/ui_service";
import { browser } from "@web/core/browser/browser";
import { click, getFixture, mount, patchWithCleanup } from "@web/../tests/helpers/utils";
import { makeTestEnv } from "@web/../tests/helpers/mock_env";
import { makeFakeLocalizationService, fakeCommandService } from "@web/../tests/helpers/mock_services";
import { DebugMenuParent } from "@web/../tests/core/debug/debug_manager_tests";
const debugRegistry = registry.category("debug");
let target;
QUnit.module("Tours", (hooks) => {
QUnit.module("DebugManager");
hooks.beforeEach(async () => {
target = getFixture();
registry
.category("services")
.add("hotkey", hotkeyService)
.add("ui", uiService)
.add("orm", ormService)
.add("localization", makeFakeLocalizationService())
.add("command", fakeCommandService);
});
QUnit.test("can disable tours", async (assert) => {
debugRegistry.category("default").add("disableTours", disableTours);
const fakeLocalStorage = {
tour__sampletour1__currentIndex: "0",
tour__sampletour1__stepDelay: "0",
tour__sampletour1__keepWatchBrowser: "0",
tour__sampletour1__showPointerDuration: "0",
tour__sampletour1__mode: "manual",
tour__sampletour2__currentIndex: "0",
tour__sampletour2__stepDelay: "0",
tour__sampletour2__keepWatchBrowser: "0",
tour__sampletour2__showPointerDuration: "0",
tour__sampletour2__mode: "manual",
};
Object.defineProperties(fakeLocalStorage, {
getItem: {
value(key) {
return fakeLocalStorage[key];
},
enumerable: false,
},
removeItem: {
value(key) {
delete fakeLocalStorage[key];
},
enumerable: false,
},
});
patchWithCleanup(browser, { localStorage: fakeLocalStorage });
const mockRPC = async (_route, args) => {
if (args.method === "check_access_rights") {
return Promise.resolve(true);
}
if (args.method === "consume") {
assert.step("consume");
assert.deepEqual(args.args[0], ["sampletour1", "sampletour2"]);
return Promise.resolve(true);
}
};
const env = await makeTestEnv({ mockRPC });
await mount(DebugMenuParent, target, { env });
await click(target.querySelector("button.dropdown-toggle"));
assert.containsOnce(target, ".dropdown-item");
await click(target.querySelector(".dropdown-item"));
assert.verifySteps(["consume"]);
});
});