[FIX] web,mail,web_tour,test_main_flows,tests: no hardcoded user agent
Main Flow Tour Mobile shouldn't require a specific `user_agent` as it targets a small screen and not a mobile platform (iOS, Android...). Actually, during refactoring of the tours (odoo/odoo@3a798039d6), a confusion was made between the legacy `isMobile`, which represents a small screen (cf. `env.isSmall`) and `isMobileOS`, which targets "mobile" platforms (ie. iOS, Android...) independently of the screen size. This commit applies the proper condition (isSmall) for the tours management and removes the useless `user_agent` property. It also removes the logic added to support custom user_agent in the Chrome automation for testing. closes odoo/odoo#116186 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { browser } from "@web/core/browser/browser";
|
||||
import { MEDIAS_BREAKPOINTS, SIZES, uiService } from "@web/core/ui/ui_service";
|
||||
import { MEDIAS_BREAKPOINTS, SIZES, utils } from "@web/core/ui/ui_service";
|
||||
import { patchWithCleanup } from "@web/../tests/helpers/utils";
|
||||
|
||||
import config from "web.config";
|
||||
@@ -92,7 +92,7 @@ function patchUiSize({ height, size, width }) {
|
||||
innerWidth: width,
|
||||
innerHeight: height || browser.innerHeight,
|
||||
});
|
||||
patchWithCleanup(uiService, {
|
||||
patchWithCleanup(utils, {
|
||||
getSize() {
|
||||
return size;
|
||||
},
|
||||
|
||||
@@ -119,10 +119,16 @@ export function getMediaQueryLists() {
|
||||
// window size handling.
|
||||
const MEDIAS = getMediaQueryLists();
|
||||
|
||||
export const uiService = {
|
||||
export const utils = {
|
||||
getSize() {
|
||||
return MEDIAS.findIndex((media) => media.matches);
|
||||
},
|
||||
isSmall(ui = {}) {
|
||||
return (ui.size || utils.getSize()) <= SIZES.SM;
|
||||
},
|
||||
};
|
||||
|
||||
export const uiService = {
|
||||
start(env) {
|
||||
// block/unblock code
|
||||
const bus = new EventBus();
|
||||
@@ -169,7 +175,7 @@ export const uiService = {
|
||||
|
||||
const ui = {
|
||||
bus,
|
||||
size: this.getSize(),
|
||||
size: utils.getSize(),
|
||||
get activeElement() {
|
||||
return activeElems[activeElems.length - 1];
|
||||
},
|
||||
@@ -177,7 +183,7 @@ export const uiService = {
|
||||
return blockCount > 0;
|
||||
},
|
||||
get isSmall() {
|
||||
return ui.size <= SIZES.SM;
|
||||
return utils.isSmall(ui);
|
||||
},
|
||||
block,
|
||||
unblock,
|
||||
@@ -189,7 +195,7 @@ export const uiService = {
|
||||
// listen to media query status changes
|
||||
const updateSize = () => {
|
||||
const prevSize = ui.size;
|
||||
ui.size = this.getSize();
|
||||
ui.size = utils.getSize();
|
||||
if (ui.size !== prevSize) {
|
||||
bus.trigger("resize");
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import { markup, whenReady, reactive } from "@odoo/owl";
|
||||
import { browser } from "@web/core/browser/browser";
|
||||
import { isMobileOS } from "@web/core/browser/feature_detection";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { MacroEngine } from "@web/core/macro";
|
||||
import { registry } from "@web/core/registry";
|
||||
@@ -73,27 +72,9 @@ function extractRegisteredTours() {
|
||||
return tours;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TourStep} step
|
||||
* @param {TourMode} mode
|
||||
*/
|
||||
function shouldOmit(step, mode) {
|
||||
const isDefined = (key, obj) => key in obj && obj[key] !== undefined;
|
||||
const getEdition = () =>
|
||||
session.server_version_info.slice(-1)[0] === "e" ? "enterprise" : "community";
|
||||
const correctEdition = isDefined("edition", step) ? step.edition === getEdition() : true;
|
||||
const correctDevice = isDefined("mobile", step) ? step.mobile === isMobileOS() : true;
|
||||
return (
|
||||
!correctEdition ||
|
||||
!correctDevice ||
|
||||
// `step.auto = true` means omitting a step in a manual tour.
|
||||
(mode === "manual" && step.auto)
|
||||
);
|
||||
}
|
||||
|
||||
export const tourService = {
|
||||
dependencies: ["orm", "effect"],
|
||||
start: async (_env, { orm, effect }) => {
|
||||
dependencies: ["orm", "effect", "ui"],
|
||||
start: async (_env, { orm, effect, ui }) => {
|
||||
await whenReady();
|
||||
|
||||
const tours = extractRegisteredTours();
|
||||
@@ -134,6 +115,24 @@ export const tourService = {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TourStep} step
|
||||
* @param {TourMode} mode
|
||||
*/
|
||||
function shouldOmit(step, mode) {
|
||||
const isDefined = (key, obj) => key in obj && obj[key] !== undefined;
|
||||
const getEdition = () =>
|
||||
session.server_version_info.slice(-1)[0] === "e" ? "enterprise" : "community";
|
||||
const correctEdition = isDefined("edition", step) ? step.edition === getEdition() : true;
|
||||
const correctDevice = isDefined("mobile", step) ? step.mobile === ui.isSmall : true;
|
||||
return (
|
||||
!correctEdition ||
|
||||
!correctDevice ||
|
||||
// `step.auto = true` means omitting a step in a manual tour.
|
||||
(mode === "manual" && step.auto)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Tour} tour
|
||||
* @param {ReturnType<typeof createPointer>} pointer
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { markup } from "@odoo/owl";
|
||||
import { isMobileOS } from "@web/core/browser/feature_detection";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { _legacyIsVisible } from "@web/core/utils/ui";
|
||||
import { utils } from "@web/core/ui/ui_service";
|
||||
|
||||
/**
|
||||
* @typedef {string | (actions: RunningTourActionHelper) => void | Promise<void>} RunCommand
|
||||
@@ -93,7 +93,7 @@ export function getConsumeEventType(element, runCommand) {
|
||||
return "apply.daterangepicker input";
|
||||
}
|
||||
if (
|
||||
isMobileOS() &&
|
||||
utils.isSmall() &&
|
||||
element.closest(".o_field_widget")?.matches(".o_field_many2one, .o_field_many2many")
|
||||
) {
|
||||
return "click";
|
||||
|
||||
@@ -80,9 +80,5 @@ class TestUiMobile(BaseTestUi):
|
||||
browser_size = '375x667'
|
||||
touch_enabled = True
|
||||
|
||||
# Taken from user agents provided in Chrome (Version 110.0.5481.100) dev tools.
|
||||
# This is specified so that the feature_detection.js heuristics for `isMobileOS` can work.
|
||||
user_agent = 'Mozilla/5.0 (Linux; Android 10; Pixel 4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Mobile Safari/537.36'
|
||||
|
||||
def test_01_main_flow_tour_mobile(self):
|
||||
self.main_flow_tour()
|
||||
|
||||
@@ -835,7 +835,6 @@ class ChromeBrowser:
|
||||
|
||||
self.window_size = test_class.browser_size
|
||||
self.touch_enabled = test_class.touch_enabled
|
||||
self.user_agent = test_class.user_agent
|
||||
self.sigxcpu_handler = None
|
||||
self._chrome_start()
|
||||
self._find_websocket()
|
||||
@@ -985,9 +984,6 @@ class ChromeBrowser:
|
||||
# "'ontouchstart' in window"
|
||||
switches['--touch-events'] = ''
|
||||
|
||||
if self.user_agent:
|
||||
switches['--user-agent'] = self.user_agent
|
||||
|
||||
cmd = [self.executable]
|
||||
cmd += ['%s=%s' % (k, v) if v else k for k, v in switches.items()]
|
||||
url = 'about:blank'
|
||||
@@ -1554,7 +1550,6 @@ class HttpCase(TransactionCase):
|
||||
browser_size = '1366x768'
|
||||
touch_enabled = False
|
||||
allow_end_on_form = False
|
||||
user_agent = None
|
||||
|
||||
_logger: logging.Logger = None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user