[FIX] mail: open chat on very narrow devices

Before this commit, when opening a chat on a very narrow mobile
device (e.g. 300px width), there was the following crash:

```
TypeError: Cannot set properties of undefined (setting 'hidden')
```

This happens because the computed maximum amount of visible chat
windows was 0, which prevented the good opening of chat window.
Indeed, the code relied on at least a `CHAT_WINDOW_WIDTH`, which
is 360px.

This commit fixes the issue by guaranteeing that it is always
possible to make 1 chat window on the screen, regardless of the width
of the device.

closes odoo/odoo#129474

X-original-commit: 1c9289fffe2a8d0936a1afa99255777ff275c712
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
Alexandre Kühn
2023-07-25 17:36:10 +02:00
parent 7da30c7d14
commit 4a92dfa3ba
2 changed files with 14 additions and 2 deletions
@@ -68,8 +68,9 @@ export class ChatWindowService {
: CHAT_WINDOW_END_GAP_WIDTH;
const endGap = this.ui.isSmall ? 0 : CHAT_WINDOW_END_GAP_WIDTH;
const available = browser.innerWidth - startGap - endGap;
const maxAmountWithoutHidden = Math.floor(
available / (CHAT_WINDOW_WIDTH + CHAT_WINDOW_INBETWEEN_WIDTH)
const maxAmountWithoutHidden = Math.max(
1,
Math.floor(available / (CHAT_WINDOW_WIDTH + CHAT_WINDOW_INBETWEEN_WIDTH))
);
return maxAmountWithoutHidden;
}
@@ -236,6 +236,17 @@ QUnit.test("chat window: open / close", async (assert) => {
assert.verifySteps(["rpc:channel_fold/open"]);
});
QUnit.test("open chat on very narrow device should work", async (assert) => {
const pyEnv = await startServer();
patchUiSize({ width: 200 });
pyEnv["discuss.channel"].create({});
await start();
assert.ok(CHAT_WINDOW_WIDTH > 200, "Device is narrower than usual chat window width"); // scenario where this might fail
await click("button i[aria-label='Messages']");
await click(".o-mail-NotificationItem");
assert.containsOnce($, ".o-mail-ChatWindow");
});
QUnit.test(
"Mobile: closing a chat window should not update channel state on the server",
async (assert) => {