166 lines
5.6 KiB
JavaScript
166 lines
5.6 KiB
JavaScript
import {
|
|
click,
|
|
contains,
|
|
insertText,
|
|
openDiscuss,
|
|
start,
|
|
startServer,
|
|
} from "@mail/../tests/mail_test_helpers";
|
|
import { describe, test } from "@odoo/hoot";
|
|
import { press } from "@odoo/hoot-dom";
|
|
import { mockDate } from "@odoo/hoot-mock";
|
|
import { deserializeDateTime } from "@web/core/l10n/dates";
|
|
import { getOrigin } from "@web/core/utils/urls";
|
|
import { Command, serverState } from "@web/../tests/web_test_helpers";
|
|
import { defineWhatsAppModels } from "@whatsapp/../tests/whatsapp_test_helpers";
|
|
|
|
describe.current.tags("desktop");
|
|
defineWhatsAppModels();
|
|
|
|
test("Can join whatsapp channels from search conversation button", async () => {
|
|
const pyEnv = await startServer();
|
|
pyEnv["discuss.channel"].create([
|
|
{
|
|
name: "WhatsApp 1",
|
|
channel_type: "whatsapp",
|
|
},
|
|
{
|
|
name: "WhatsApp 2",
|
|
channel_type: "whatsapp",
|
|
channel_member_ids: [
|
|
Command.create({
|
|
unpin_dt: "2021-01-01 12:00:00",
|
|
last_interest_dt: "2021-01-01 10:00:00",
|
|
partner_id: serverState.partnerId,
|
|
}),
|
|
],
|
|
},
|
|
]);
|
|
await start();
|
|
await openDiscuss();
|
|
await click("input[placeholder='Search conversations']");
|
|
await contains(".o_command_name", { count: 5 });
|
|
await insertText("input[placeholder='Search a conversation']", "WhatsApp 2");
|
|
await contains(".o_command_name", { count: 3 });
|
|
await click(".o_command_name", { text: "WhatsApp 2" });
|
|
await contains(".o-mail-DiscussSidebar-item", { text: "WhatsApp 2" });
|
|
});
|
|
|
|
test("Clicking on cross icon in whatsapp sidebar category item unpins the channel", async () => {
|
|
const pyEnv = await startServer();
|
|
pyEnv["discuss.channel"].create({
|
|
name: "WhatsApp 1",
|
|
channel_type: "whatsapp",
|
|
});
|
|
await start();
|
|
await openDiscuss();
|
|
await click("[title='Chat Actions']", {
|
|
parent: [
|
|
".o-mail-DiscussSidebarChannel",
|
|
{
|
|
contains: [["span", { text: "WhatsApp 1" }], [".o-mail-ThreadIcon .fa-whatsapp"]],
|
|
},
|
|
],
|
|
});
|
|
await click(".o-dropdown-item:contains('Unpin Conversation')");
|
|
await contains(".o-mail-DiscussSidebarChannel", {
|
|
count: 0,
|
|
contains: ["span", { text: "WhatsApp 1" }],
|
|
});
|
|
});
|
|
|
|
test("Message unread counter in whatsapp channels", async () => {
|
|
const pyEnv = await startServer();
|
|
const channelId = pyEnv["discuss.channel"].create({
|
|
name: "WhatsApp 1",
|
|
channel_type: "whatsapp",
|
|
});
|
|
pyEnv["mail.message"].create({
|
|
author_id: serverState.partnerId,
|
|
body: "Hello!",
|
|
model: "discuss.channel",
|
|
res_id: channelId,
|
|
});
|
|
await start();
|
|
await openDiscuss(channelId);
|
|
await contains(".o-mail-DiscussSidebarChannel", {
|
|
contains: [
|
|
["span", { text: "WhatsApp 1" }],
|
|
[".badge", { text: "1" }],
|
|
],
|
|
});
|
|
});
|
|
|
|
test("whatsapp are sorted by last activity time in the sidebar: most recent at the top", async () => {
|
|
mockDate("2024-05-02 12:00:00");
|
|
const pyEnv = await startServer();
|
|
const [partnerId1, partnerId2] = pyEnv["res.partner"].create([
|
|
{ name: "George" },
|
|
{ name: "Claude" },
|
|
]);
|
|
pyEnv["discuss.channel"].create([
|
|
{
|
|
name: "WhatsApp 1",
|
|
channel_member_ids: [
|
|
Command.create({
|
|
last_interest_dt: "2021-01-01 10:00:00",
|
|
partner_id: serverState.partnerId,
|
|
}),
|
|
Command.create({ partner_id: partnerId1 }),
|
|
],
|
|
channel_type: "whatsapp",
|
|
},
|
|
{
|
|
name: "WhatsApp 2",
|
|
channel_member_ids: [
|
|
Command.create({
|
|
last_interest_dt: "2021-02-01 10:00:00",
|
|
partner_id: serverState.partnerId,
|
|
}),
|
|
Command.create({ partner_id: partnerId2 }),
|
|
],
|
|
channel_type: "whatsapp",
|
|
},
|
|
]);
|
|
await start();
|
|
await openDiscuss();
|
|
await contains(".o-mail-DiscussSidebarChannel", { count: 2 });
|
|
await contains(":nth-child(1 of .o-mail-DiscussSidebarChannel-container)", {
|
|
text: "WhatsApp 2",
|
|
});
|
|
await click(".o-mail-DiscussSidebarChannel", { text: "WhatsApp 1" });
|
|
await insertText(".o-mail-Composer-input", "Blabla");
|
|
await press("Enter");
|
|
await contains(":nth-child(1 of .o-mail-DiscussSidebarChannel-container)", {
|
|
text: "WhatsApp 1",
|
|
});
|
|
await contains(":nth-child(2 of .o-mail-DiscussSidebarChannel-container)", {
|
|
text: "WhatsApp 2",
|
|
});
|
|
});
|
|
|
|
test("Whatsapp - Sidebar channel icons should have the whatsapp partner's avatar", async () => {
|
|
const pyEnv = await startServer();
|
|
const [memberPartnerId, whatsappPartnerId] = pyEnv["res.partner"].create([
|
|
{ name: "Operator" },
|
|
{ name: "Demo" },
|
|
]);
|
|
pyEnv["discuss.channel"].create({
|
|
channel_member_ids: [
|
|
Command.create({ partner_id: serverState.partnerId }),
|
|
Command.create({ partner_id: memberPartnerId }),
|
|
Command.create({ partner_id: whatsappPartnerId }),
|
|
],
|
|
channel_type: "whatsapp",
|
|
whatsapp_partner_id: whatsappPartnerId,
|
|
});
|
|
const [partner] = pyEnv["res.partner"].search_read([["id", "=", whatsappPartnerId]]);
|
|
await start();
|
|
await openDiscuss();
|
|
await contains(
|
|
`.o-mail-DiscussSidebar-item img[data-src='${getOrigin()}/web/image/res.partner/${whatsappPartnerId}/avatar_128?unique=${
|
|
deserializeDateTime(partner.write_date).ts
|
|
}']`
|
|
);
|
|
});
|