Files
odoo_source/addons/im_livechat/static/tests/composer_patch_tests.js
T
tsm-odoo a97abef2d2 [IMP] im_livechat, mail: allow livechat visitors to upload attachments
Since [1], live chat visitors are using the mail guest system for
authentication. With this change, visitors are allowed to reach the
attachment upload routes (even if nothing allows it in the frontend
for now). This commit restricts attachment upload for guest and portal
users with the `allow_visitor_upload` field that can be toggled.

At the same time, this commit enables file upload when authorized
on the frontend and for cross origin live chats.

[1]: odoo#129770

task-3332628

closes odoo/odoo#137574

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2023-10-06 18:18:29 +00:00

169 lines
6.6 KiB
JavaScript

/* @odoo-module */
import { startServer } from "@bus/../tests/helpers/mock_python_environment";
import { Command } from "@mail/../tests/helpers/command";
import { start } from "@mail/../tests/helpers/test_utils";
import { click, contains, insertText } from "@web/../tests/utils";
QUnit.module("composer (patch)");
QUnit.test("Can execute help command on livechat channels", async (assert) => {
const pyEnv = await startServer();
const guestId = pyEnv["mail.guest"].create({ name: "Visitor 11" });
const channelId = pyEnv["discuss.channel"].create({
anonymous_name: "Visitor 11",
channel_member_ids: [
[0, 0, { partner_id: pyEnv.currentPartnerId }],
Command.create({ guest_id: guestId }),
],
channel_type: "livechat",
livechat_operator_id: pyEnv.currentPartnerId,
});
const { openDiscuss } = await start({
mockRPC(route, args, originalMockRPC) {
if (args.method === "execute_command_help") {
assert.step("execute_command_help");
return true;
}
return originalMockRPC(route, args);
},
});
await openDiscuss(channelId);
await insertText(".o-mail-Composer-input", "/help");
await click(".o-mail-Composer-send:enabled");
assert.verifySteps(["execute_command_help"]);
});
QUnit.test('Receives visitor typing status "is typing"', async () => {
const pyEnv = await startServer();
const guestId = pyEnv["mail.guest"].create({ name: "Visitor 20" });
const channelId = pyEnv["discuss.channel"].create({
anonymous_name: "Visitor 20",
channel_member_ids: [
[0, 0, { partner_id: pyEnv.currentPartnerId }],
Command.create({ guest_id: guestId }),
],
channel_type: "livechat",
livechat_operator_id: pyEnv.currentPartnerId,
});
const { env, openDiscuss } = await start();
await openDiscuss(channelId);
await contains(".o-discuss-Typing", { text: "" });
const channel = pyEnv["discuss.channel"].searchRead([["id", "=", channelId]])[0];
// simulate receive typing notification from livechat visitor "is typing"
pyEnv.withGuest(guestId, () =>
env.services.rpc("/im_livechat/notify_typing", {
is_typing: true,
uuid: channel.uuid,
})
);
await contains(".o-discuss-Typing", { text: "Visitor 20 is typing..." });
});
QUnit.test('display canned response suggestions on typing ":"', async () => {
const pyEnv = await startServer();
const guestId = pyEnv["mail.guest"].create({ name: "Mario" });
const channelId = pyEnv["discuss.channel"].create({
anonymous_name: "Mario",
channel_member_ids: [
[0, 0, { partner_id: pyEnv.currentPartnerId }],
Command.create({ guest_id: guestId }),
],
channel_type: "livechat",
livechat_operator_id: pyEnv.currentPartnerId,
});
pyEnv["mail.shortcode"].create({
source: "hello",
substitution: "Hello! How are you?",
});
const { openDiscuss } = await start();
await openDiscuss(channelId);
await contains(".o-mail-Composer-input");
await contains(".o-mail-Composer-suggestionList .o-open", { count: 0 });
await insertText(".o-mail-Composer-input", ":");
await contains(".o-mail-Composer-suggestionList .o-open");
});
QUnit.test("use a canned response", async () => {
const pyEnv = await startServer();
const guestId = pyEnv["mail.guest"].create({ name: "Mario" });
const channelId = pyEnv["discuss.channel"].create({
anonymous_name: "Mario",
channel_member_ids: [
[0, 0, { partner_id: pyEnv.currentPartnerId }],
Command.create({ guest_id: guestId }),
],
channel_type: "livechat",
livechat_operator_id: pyEnv.currentPartnerId,
});
pyEnv["mail.shortcode"].create({
source: "hello",
substitution: "Hello! How are you?",
});
const { openDiscuss } = await start();
await openDiscuss(channelId);
await contains(".o-mail-Composer-suggestionList");
await contains(".o-mail-Composer-suggestionList .o-open", { count: 0 });
await contains(".o-mail-Composer-input", { value: "" });
await insertText(".o-mail-Composer-input", ":");
await click(".o-mail-Composer-suggestion");
await contains(".o-mail-Composer-input", { value: "Hello! How are you? " });
});
QUnit.test("use a canned response some text", async () => {
const pyEnv = await startServer();
const guestId = pyEnv["mail.guest"].create({ name: "Mario" });
const channelId = pyEnv["discuss.channel"].create({
anonymous_name: "Mario",
channel_member_ids: [
[0, 0, { partner_id: pyEnv.currentPartnerId }],
Command.create({ guest_id: guestId }),
],
channel_type: "livechat",
livechat_operator_id: pyEnv.currentPartnerId,
});
pyEnv["mail.shortcode"].create({
source: "hello",
substitution: "Hello! How are you?",
});
const { openDiscuss } = await start();
await openDiscuss(channelId);
await contains(".o-mail-Composer-suggestionList");
await contains(".o-mail-Composer-input", { value: "" });
await insertText(".o-mail-Composer-input", "bluhbluh ");
await contains(".o-mail-Composer-input", { value: "bluhbluh " });
await insertText(".o-mail-Composer-input", ":");
await click(".o-mail-Composer-suggestion");
await contains(".o-mail-Composer-input", { value: "bluhbluh Hello! How are you? " });
});
QUnit.test("add an emoji after a canned response", async () => {
const pyEnv = await startServer();
const guestId = pyEnv["mail.guest"].create({ name: "Visitor 20" });
const channelId = pyEnv["discuss.channel"].create({
anonymous_name: "Visitor 20",
channel_member_ids: [
[0, 0, { partner_id: pyEnv.currentPartnerId }],
Command.create({ guest_id: guestId }),
],
channel_type: "livechat",
livechat_operator_id: pyEnv.currentPartnerId,
});
pyEnv["mail.shortcode"].create({
source: "hello",
substitution: "Hello! How are you?",
});
const { openDiscuss } = await start();
await openDiscuss(channelId);
await contains(".o-mail-Composer-suggestionList");
await contains(".o-mail-Composer-input", { value: "" });
await insertText(".o-mail-Composer-input", ":");
await click(".o-mail-Composer-suggestion");
await contains(".o-mail-Composer-input", { value: "Hello! How are you? " });
await click("button[aria-label='Emojis']");
await click(".o-Emoji", { text: "😊" });
await contains(".o-mail-Composer-input", { value: "Hello! How are you? 😊" });
});