[IMP] mail: replace env.browser by wowl browser

This PR prepares the ground for the one introducing the new environment in the discuss app.
Indeed, switching from `env.browser` to the wowl `browser` makes a lot of noise in the main
PR. In order to reduce this noise, this change is done now.

task-2582313

closes odoo/odoo#91622

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
tsm-odoo
2022-05-18 13:08:22 +02:00
parent 2ad762a04f
commit 52d6089e1a
10 changed files with 100 additions and 135 deletions
-1
View File
@@ -137,7 +137,6 @@
'mail/static/tests/tours/**/*',
],
'web.tests_assets': [
'mail/static/src/env/test_env.js',
'mail/static/tests/helpers/*.js',
'mail/static/tests/models/*.js',
],
-25
View File
@@ -1,25 +0,0 @@
/** @odoo-module **/
/**
* @param {Object} [providedEnv={}]
* @returns {Object}
*/
export function addMessagingToEnv(providedEnv = {}) {
const env = { ...providedEnv };
/**
* Environment keys used in messaging.
*/
Object.assign(env, {
browser: Object.assign({
innerHeight: 1080,
innerWidth: 1920,
Notification: Object.assign({
permission: 'denied',
async requestPermission() {
return this.permission;
},
}, (env.browser && env.browser.Notification) || {}),
}, env.browser),
});
return env;
}
+3 -1
View File
@@ -6,6 +6,8 @@ import { OnChange } from '@mail/model/model_onchange';
import { clear, insertAndReplace, replace } from '@mail/model/model_field_command';
import { makeDeferred } from '@mail/utils/deferred';
import { browser } from '@web/core/browser/browser';
const { EventBus } = owl;
registerModel({
@@ -190,7 +192,7 @@ registerModel({
* @returns {Object} browser
*/
_computeBrowser() {
return this.env.browser;
return browser;
},
/**
* @private
@@ -3,7 +3,6 @@
import BusService from 'bus.BusService';
import { MessagingMenuContainer } from '@mail/components/messaging_menu_container/messaging_menu_container';
import { addMessagingToEnv } from '@mail/env/test_env';
import { insertAndReplace, replace } from '@mail/model/model_field_command';
import { ChatWindowService } from '@mail/services/chat_window_service/chat_window_service';
import { MessagingService } from '@mail/services/messaging/messaging';
@@ -22,6 +21,7 @@ import {
mock,
} from 'web.test_utils';
import Widget from 'web.Widget';
import { browser } from '@web/core/browser/browser';
import { registry } from '@web/core/registry';
import { registerCleanup } from "@web/../tests/helpers/cleanup";
import { getFixture, patchWithCleanup } from "@web/../tests/helpers/utils";
@@ -693,7 +693,6 @@ async function start(param0 = {}) {
env.session
);
env.isDebug = env.isDebug || (() => true);
env = addMessagingToEnv(env);
if (hasTimeControl) {
env = addTimeControlToEnv(env);
}
@@ -851,6 +850,9 @@ async function start(param0 = {}) {
}
// get the final test env after execution of createView/createWebClient/addMockEnvironment
testEnv = Component.env;
patchWithCleanup(browser, {
fetch: testEnv.browser.fetch,
});
// link the pyEnv to the actual mockServer after execution of createView/createWebClient/addMockEnvironment
if (pyEnv) {
pyEnv.mockServer = MockServer.currentMockServer;
@@ -2,6 +2,9 @@
import { nextTick } from '@mail/utils/utils';
import { browser } from '@web/core/browser/browser';
import { patchWithCleanup } from '@web/../tests/helpers/utils';
/**
* @param {Object} [providedEnv={}]
* @returns {Object}
@@ -15,7 +18,7 @@ import { nextTick } from '@mail/utils/utils';
let timedOutIds = [];
// key: timeoutId, value: func + remaining duration
const timeouts = new Map();
Object.assign(env.browser, {
patchWithCleanup(browser, {
clearTimeout: id => {
timeouts.delete(id);
timedOutIds = timedOutIds.filter(i => i !== id);
@@ -5,6 +5,9 @@ import {
startServer,
} from '@mail/../tests/helpers/test_utils';
import { browser } from '@web/core/browser/browser';
import { patchWithCleanup } from '@web/../tests/helpers/utils';
QUnit.module('mail', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('discuss_mobile_mailbox_selection', {}, function () {
@@ -13,13 +16,13 @@ QUnit.module('discuss_mobile_mailbox_selection_tests.js');
QUnit.test('select another mailbox', async function (assert) {
assert.expect(7);
patchWithCleanup(browser, {
innerHeight: 640,
innerWidth: 360,
});
const { click, messaging } = await start({
autoOpenDiscuss: true,
env: {
browser: {
innerHeight: 640,
innerWidth: 360,
},
device: {
isMobile: true,
},
@@ -74,6 +77,10 @@ QUnit.test('auto-select "Inbox" when discuss had channel as active thread', asyn
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create();
patchWithCleanup(browser, {
innerHeight: 640,
innerWidth: 360,
});
const { click, messaging } = await start({
autoOpenDiscuss: true,
discuss: {
@@ -82,10 +89,6 @@ QUnit.test('auto-select "Inbox" when discuss had channel as active thread', asyn
},
},
env: {
browser: {
innerHeight: 640,
innerWidth: 360,
},
device: {
isMobile: true,
},
@@ -8,6 +8,9 @@ import {
startServer,
} from '@mail/../tests/helpers/test_utils';
import { browser } from '@web/core/browser/browser';
import { patchWithCleanup } from '@web/../tests/helpers/utils';
import { file, dom } from 'web.test_utils';
const { createFile, inputFiles } = file;
const { triggerEvent } = dom;
@@ -233,12 +236,10 @@ QUnit.test('open chat from "new message" chat window should open chat in place o
},
]);
const imSearchDef = makeDeferred();
patchWithCleanup(browser, {
innerWidth: 1920,
});
const { click, createMessagingMenuComponent } = await start({
env: {
browser: {
innerWidth: 1920,
},
},
async mockRPC(route, args) {
const res = await this._super(...arguments);
if (args.method === 'im_search') {
@@ -857,13 +858,10 @@ QUnit.test('focus next visible chat window when closing current chat window with
],
},
]);
await start({
env: {
browser: {
innerWidth: 1920,
},
},
patchWithCleanup(browser, {
innerWidth: 1920,
});
await start();
assert.containsN(
document.body,
'.o_ChatWindow .o_ComposerTextInput_textarea',
@@ -1043,13 +1041,10 @@ QUnit.test('open 2 different chat windows: enough screen width [REQUIRE FOCUS]',
const pyEnv = await startServer();
const [mailChannelId1, mailChannelId2] = pyEnv['mail.channel'].create([{ name: 'mailChannel1' }, { name: 'mailChannel2' }]);
const { click, createMessagingMenuComponent, messaging } = await start({
env: {
browser: {
innerWidth: 1920, // enough to fit at least 2 chat windows
},
},
patchWithCleanup(browser, {
innerWidth: 1920, // enough to fit at least 2 chat windows
});
const { click, createMessagingMenuComponent, messaging } = await start();
await createMessagingMenuComponent();
await click(`.o_MessagingMenu_toggler`);
await click(`
@@ -1272,13 +1267,10 @@ QUnit.test('open 2 folded chat windows: check shift operations are available', a
channel_type: "chat",
};
pyEnv['mail.channel'].create([channel, chat]);
const { click } = await start({
env: {
browser: {
innerWidth: 900,
},
},
patchWithCleanup(browser, {
innerWidth: 900,
});
const { click } = await start();
assert.containsN(
document.body,
@@ -1385,13 +1377,10 @@ QUnit.test('open 3 different chat windows: not enough screen width', async funct
{ name: 'mailChannel2' },
{ name: 'mailChannel3' },
]);
const { click, createMessagingMenuComponent, messaging } = await start({
env: {
browser: {
innerWidth: 900, // enough to fit 2 chat windows but not 3
},
},
patchWithCleanup(browser, {
innerWidth: 900, // enough to fit 2 chat windows but not 3
});
const { click, createMessagingMenuComponent, messaging } = await start();
await createMessagingMenuComponent();
// open, from systray menu, chat windows of channels with Id 1, 2, then 3
@@ -1644,13 +1633,10 @@ QUnit.test('chat window: TAB cycle with 3 open chat windows [REQUIRE FOCUS]', as
],
},
]);
await start({
env: {
browser: {
innerWidth: 1920,
},
},
patchWithCleanup(browser, {
innerWidth: 1920,
});
await start();
assert.containsN(
document.body,
'.o_ChatWindow .o_ComposerTextInput_textarea',
@@ -2060,12 +2046,10 @@ QUnit.test('chat window does not fetch messages if hidden', async function (asse
name: "Channel #12",
},
]);
patchWithCleanup(browser, {
innerWidth: 900,
});
const { click, messaging } = await start({
env: {
browser: {
innerWidth: 900,
},
},
mockRPC(route, args) {
if (route === '/mail/channel/messages') {
const { channel_id } = args;
@@ -2465,13 +2449,10 @@ QUnit.test('should not have chat window hidden menu in mobile (transition from 2
const pyEnv = await startServer();
const [mailChannelId1, mailChannelId2] = pyEnv['mail.channel'].create([{ name: 'mailChannel1' }, { name: 'mailChannel1' }]);
const { click, createMessagingMenuComponent, messaging } = await start({
env: {
browser: {
innerWidth: 600, // enough to fit 1 chat window + hidden menu
},
},
patchWithCleanup(browser, {
innerWidth: 600, // enough to fit 1 chat window + hidden menu
});
const { click, createMessagingMenuComponent, messaging } = await start();
await createMessagingMenuComponent();
// open, from systray menu, chat windows of channels with id 1, 2
await click('.o_MessagingMenu_toggler');
@@ -6,6 +6,9 @@ import {
startServer,
} from '@mail/../tests/helpers/test_utils';
import { browser } from '@web/core/browser/browser';
import { patchWithCleanup } from '@web/../tests/helpers/utils';
import { makeTestPromise } from 'web.test_utils';
QUnit.module('mail', {}, function () {
@@ -806,15 +809,13 @@ QUnit.test('<br/> tags in message body preview are transformed in spaces', async
QUnit.test('rendering with OdooBot has a request (default)', async function (assert) {
assert.expect(4);
const { click, createMessagingMenuComponent } = await start({
env: {
browser: {
Notification: {
permission: 'default',
},
},
patchWithCleanup(browser, {
Notification: {
...browser.Notification,
permission: 'default',
},
});
const { click, createMessagingMenuComponent } = await start();
await createMessagingMenuComponent();
assert.ok(
@@ -843,15 +844,12 @@ QUnit.test('rendering with OdooBot has a request (default)', async function (ass
QUnit.test('rendering without OdooBot has a request (denied)', async function (assert) {
assert.expect(2);
const { click, createMessagingMenuComponent } = await start({
env: {
browser: {
Notification: {
permission: 'denied',
},
},
patchWithCleanup(browser, {
Notification: {
permission: 'denied',
},
});
const { click, createMessagingMenuComponent } = await start();
await createMessagingMenuComponent();
assert.containsNone(
@@ -871,15 +869,12 @@ QUnit.test('rendering without OdooBot has a request (denied)', async function (a
QUnit.test('rendering without OdooBot has a request (accepted)', async function (assert) {
assert.expect(2);
const { click, createMessagingMenuComponent } = await start({
env: {
browser: {
Notification: {
permission: 'granted',
},
},
patchWithCleanup(browser, {
Notification: {
permission: 'granted',
},
});
const { click, createMessagingMenuComponent } = await start();
await createMessagingMenuComponent();
assert.containsNone(
@@ -899,17 +894,17 @@ QUnit.test('rendering without OdooBot has a request (accepted)', async function
QUnit.test('respond to notification prompt (denied)', async function (assert) {
assert.expect(4);
patchWithCleanup(browser, {
Notification: {
permission: 'default',
async requestPermission() {
this.permission = 'denied';
return this.permission;
},
},
});
const { click, createMessagingMenuComponent } = await start({
env: {
browser: {
Notification: {
permission: 'default',
async requestPermission() {
this.permission = 'denied';
return this.permission;
},
},
},
services: {
notification: {
notify() {
@@ -2,6 +2,9 @@
import { start } from '@mail/../tests/helpers/test_utils';
import { browser } from '@web/core/browser/browser';
import { patchWithCleanup } from '@web/../tests/helpers/utils';
import FormView from 'web.FormView';
QUnit.module('mail', {}, function () {
@@ -14,19 +17,15 @@ QUnit.skip('notification_alert widget: display blocked notification alert', asyn
// is good for rendering... task-227947
assert.expect(1);
patchWithCleanup(browser, {
Notification: 'denied',
});
await start({
arch: `
<form>
<widget name="notification_alert"/>
</form>
`,
env: {
browser: {
Notification: {
permission: 'denied',
},
},
},
hasView: true,
model: 'mail.message',
// View params
@@ -43,19 +42,17 @@ QUnit.skip('notification_alert widget: display blocked notification alert', asyn
QUnit.test('notification_alert widget: no notification alert when granted', async function (assert) {
assert.expect(1);
patchWithCleanup(browser, {
Notification: {
permission: 'granted',
},
});
await start({
arch: `
<form>
<widget name="notification_alert"/>
</form>
`,
env: {
browser: {
Notification: {
permission: 'granted',
},
},
},
hasView: true,
model: 'mail.message',
// View params
@@ -72,19 +69,17 @@ QUnit.test('notification_alert widget: no notification alert when granted', asyn
QUnit.test('notification_alert widget: no notification alert when default', async function (assert) {
assert.expect(1);
patchWithCleanup(browser, {
Notification: {
permission: 'default',
},
});
await start({
arch: `
<form>
<widget name="notification_alert"/>
</form>
`,
env: {
browser: {
Notification: {
permission: 'default',
},
},
},
hasView: true,
model: 'mail.message',
// View params
@@ -32,6 +32,7 @@ export const browser = {
console: window.console,
history: window.history,
navigator: navigator,
Notification: window.Notification,
open: window.open.bind(window),
XMLHttpRequest: window.XMLHttpRequest,
localStorage,
@@ -49,6 +50,15 @@ Object.defineProperty(browser, "location", {
configurable: true,
});
Object.defineProperty(browser, 'innerHeight', {
get: () => window.innerHeight,
configurable: true,
});
Object.defineProperty(browser, 'innerWidth', {
get: () => window.innerWidth,
configurable: true,
});
// -----------------------------------------------------------------------------
// memory localStorage
// -----------------------------------------------------------------------------