Files
odoo_source/addons/im_livechat/static/tests/composer_patch_tests.js
T
Sébastien Theys 7ea370fce7 [REF] mail, *: tests: refactor contains to further remove jQuery
* = account, base_iban, bus, calendar, crm_livechat, hr, hr_holidays,
    im_livechat, mrp, project, sms, snailmail, test_mail,
    test_mail_full, web, website_livechat, website_slides

Add support in `contains` for most operations that we use in tests.
Remove return value from `contains`.
Move into `web` module.
Remove import/export chains, directly import from correct module.

closes odoo/odoo#134652

Related: odoo/enterprise#47064
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2023-09-14 11:22:47 +00:00

202 lines
7.8 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, createFile, dragenterFiles, insertText } from "@web/../tests/utils";
QUnit.module("composer (patch)");
QUnit.test("No add attachments button", async () => {
const pyEnv = await startServer();
const channelId = pyEnv["discuss.channel"].create({
name: "Livechat 1",
channel_type: "livechat",
});
const { openDiscuss } = await start();
await openDiscuss(channelId);
await contains(".o-mail-Composer");
await contains("button[title='Attach files']", { count: 0 });
});
QUnit.test("Attachment upload via drag and drop disabled", async () => {
const pyEnv = await startServer();
const channelId = pyEnv["discuss.channel"].create({
name: "Livechat 1",
channel_type: "livechat",
});
const { openDiscuss } = await start();
await openDiscuss(channelId);
await contains(".o-mail-Composer");
const files = [
await createFile({
content: "hello, world",
contentType: "text/plain",
name: "text3.txt",
}),
];
await dragenterFiles(".o-mail-Composer-input", files);
// weak test: no guarantee that we waited long enough for the potential dropzone to show
await contains(".o-mail-Dropzone", { count: 0 });
});
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? 😊" });
});