From 55dab0e7d1b93e9162f5ff41eb93fff11b68c176 Mon Sep 17 00:00:00 2001 From: "Francois (fge)" Date: Thu, 15 Jul 2021 14:34:22 +0000 Subject: [PATCH] [IMP] web: use of a default OS for tests The purpose of this commit is to have a test environment that does not depend on the OS of the machine on which the Odoo server is deployed. Because the navigator.platform is deprecated, we will use the navigator.userAgent to identify the OS. --- .../static/src/core/browser/feature_detection.js | 2 +- .../tests/core/hotkeys/hotkey_service_tests.js | 16 ++-------------- addons/web/static/tests/helpers/utils.js | 1 + addons/web/static/tests/setup.js | 3 +++ .../webclient/commands/command_service_tests.js | 16 ++-------------- 5 files changed, 9 insertions(+), 29 deletions(-) diff --git a/addons/web/static/src/core/browser/feature_detection.js b/addons/web/static/src/core/browser/feature_detection.js index 58dd52b0451..b493ceeb204 100644 --- a/addons/web/static/src/core/browser/feature_detection.js +++ b/addons/web/static/src/core/browser/feature_detection.js @@ -16,7 +16,7 @@ export function isBrowserChrome() { } export function isMacOS() { - return Boolean(browser.navigator.platform.match(/Mac/i)); + return Boolean(browser.navigator.userAgent.match(/Mac/i)); } export function isMobileOS() { diff --git a/addons/web/static/tests/core/hotkeys/hotkey_service_tests.js b/addons/web/static/tests/core/hotkeys/hotkey_service_tests.js index c1d34345bbb..1dfbd7147a4 100644 --- a/addons/web/static/tests/core/hotkeys/hotkey_service_tests.js +++ b/addons/web/static/tests/core/hotkeys/hotkey_service_tests.js @@ -139,12 +139,6 @@ QUnit.test("hook", async (assert) => { QUnit.test("non-MacOS usability", async (assert) => { assert.expect(6); - patchWithCleanup(browser, { - navigator: { - platform: "OdooOS", - }, - }); - const hotkey = env.services.hotkey; const key = "q"; @@ -186,7 +180,7 @@ QUnit.test("MacOS usability", async (assert) => { patchWithCleanup(browser, { navigator: { - platform: "Mac", + userAgent: browser.navigator.userAgent.replace(/\([^)]*\)/, "(MacOs)"), }, }); @@ -491,12 +485,6 @@ QUnit.test("registrations and elements belong to the correct UI owner", async (a QUnit.test("replace the overlayModifier for non-MacOs", async (assert) => { assert.expect(3); - patchWithCleanup(browser, { - navigator: { - platform: "OdooOS", - }, - }); - const hotkeyService = serviceRegistry.get("hotkey"); patchWithCleanup(hotkeyService, { overlayModifier: "alt+shift", @@ -531,7 +519,7 @@ QUnit.test("replace the overlayModifier for MacOs", async (assert) => { patchWithCleanup(browser, { navigator: { - platform: "Mac", + userAgent: browser.navigator.userAgent.replace(/\([^)]*\)/, "(MacOs)"), }, }); diff --git a/addons/web/static/tests/helpers/utils.js b/addons/web/static/tests/helpers/utils.js index 553ffd913e5..4b130a11578 100644 --- a/addons/web/static/tests/helpers/utils.js +++ b/addons/web/static/tests/helpers/utils.js @@ -199,6 +199,7 @@ export function triggerHotkey(hotkey, addOverlayModParts = false, eventAttrs = { } window.dispatchEvent(new KeyboardEvent("keydown", eventAttrs)); + window.dispatchEvent(new KeyboardEvent("keyup", eventAttrs)); } export async function legacyExtraNextTick() { diff --git a/addons/web/static/tests/setup.js b/addons/web/static/tests/setup.js index 6143793a7a8..b99c5470c3c 100644 --- a/addons/web/static/tests/setup.js +++ b/addons/web/static/tests/setup.js @@ -113,6 +113,9 @@ function patchBrowserWithCleanup() { originalRemoveEventListener(...arguments); }); }, + navigator: { + userAgent: browser.navigator.userAgent.replace(/\([^)]*\)/, "(X11; Linux x86_64)"), + }, // in tests, we never want to interact with the real url or reload the page location: mockLocation, history: { diff --git a/addons/web/static/tests/webclient/commands/command_service_tests.js b/addons/web/static/tests/webclient/commands/command_service_tests.js index 3dfbef016fa..2438272afba 100644 --- a/addons/web/static/tests/webclient/commands/command_service_tests.js +++ b/addons/web/static/tests/webclient/commands/command_service_tests.js @@ -406,12 +406,6 @@ QUnit.test("data-command-category", async (assert) => { }); QUnit.test("display shortcuts correctly for non-MacOS ", async (assert) => { - patchWithCleanup(browser, { - navigator: { - platform: "OdooOS", - }, - }); - class MyComponent extends Component {} MyComponent.components = { TestComponent }; MyComponent.template = xml` @@ -448,7 +442,7 @@ QUnit.test("display shortcuts correctly for non-MacOS ", async (assert) => { QUnit.test("display shortcuts correctly for MacOS ", async (assert) => { patchWithCleanup(browser, { navigator: { - platform: "Mac", + userAgent: browser.navigator.userAgent.replace(/\([^)]*\)/, "(MacOs)"), }, }); @@ -488,12 +482,6 @@ QUnit.test("display shortcuts correctly for MacOS ", async (assert) => { QUnit.test( "display shortcuts correctly for non-MacOS with a new overlayModifier", async (assert) => { - patchWithCleanup(browser, { - navigator: { - platform: "OdooOS", - }, - }); - const hotkeyService = serviceRegistry.get("hotkey"); patchWithCleanup(hotkeyService, { overlayModifier: "alt+control", @@ -523,7 +511,7 @@ QUnit.test( QUnit.test("display shortcuts correctly for MacOS with a new overlayModifier", async (assert) => { patchWithCleanup(browser, { navigator: { - platform: "Mac", + userAgent: browser.navigator.userAgent.replace(/\([^)]*\)/, "(MacOs)"), }, });