-
Notifications
You must be signed in to change notification settings - Fork 23.2k
/
crosstab.test.js
204 lines (194 loc) · 7.94 KB
/
crosstab.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import { describe, test } from "@odoo/hoot";
/** @type {ReturnType<import("@mail/utils/common/misc").rpcWithEnv>} */
let rpc;
import {
assertSteps,
click,
contains,
defineMailModels,
insertText,
openDiscuss,
start,
startServer,
step,
triggerHotkey,
} from "../mail_test_helpers";
import { patchWithCleanup, serverState } from "@web/../tests/web_test_helpers";
import { rpcWithEnv } from "@mail/utils/common/misc";
import { mockDate } from "@odoo/hoot-mock";
describe.current.tags("desktop");
defineMailModels();
test("Messages are received cross-tab", async () => {
const pyEnv = await startServer();
const channelId = pyEnv["discuss.channel"].create({ name: "General" });
const env1 = await start({ asTab: true });
const env2 = await start({ asTab: true });
await openDiscuss(channelId, { target: env1 });
await openDiscuss(channelId, { target: env2 });
await insertText(".o-mail-Composer-input", "Hello World!", { target: env1 });
await click("button:enabled", { target: env1, text: "Send" });
await contains(".o-mail-Message-content", { target: env1, text: "Hello World!" });
await contains(".o-mail-Message-content", { target: env2, text: "Hello World!" });
});
test("Delete starred message updates counter", async () => {
const pyEnv = await startServer();
const channelId = pyEnv["discuss.channel"].create({ name: "General" });
pyEnv["mail.message"].create({
body: "Hello World!",
model: "discuss.channel",
message_type: "comment",
res_id: channelId,
starred_partner_ids: [serverState.partnerId],
});
const env1 = await start({ asTab: true });
const env2 = await start({ asTab: true });
await openDiscuss(channelId, { target: env1 });
await openDiscuss(channelId, { target: env2 });
await contains("button", { target: env2, text: "Starred1" });
await click(":nth-child(1 of .o-mail-Message) [title='Expand']", { target: env2 });
await click(".o-mail-Message-moreMenu [title='Delete']", { target: env2 });
await click("button", { text: "Confirm" }, { target: env2 });
await contains("button", { count: 0, target: env2, text: "Starred1" });
});
test("Thread rename [REQUIRE FOCUS]", async () => {
const pyEnv = await startServer();
const channelId = pyEnv["discuss.channel"].create({
create_uid: serverState.userId,
name: "General",
});
const env1 = await start({ asTab: true });
const env2 = await start({ asTab: true });
await openDiscuss(channelId, { target: env1 });
await openDiscuss(channelId, { target: env2 });
await insertText(".o-mail-Discuss-threadName:enabled", "Sales", {
replace: true,
target: env1,
});
triggerHotkey("Enter");
await contains(".o-mail-Discuss-threadName[title='Sales']", { target: env2 });
await contains(".o-mail-DiscussSidebarChannel", { target: env2, text: "Sales" });
});
test("Thread description update [REQUIRE FOCUS]", async () => {
const pyEnv = await startServer();
const channelId = pyEnv["discuss.channel"].create({
create_uid: serverState.userId,
name: "General",
});
const env1 = await start({ asTab: true });
const env2 = await start({ asTab: true });
await openDiscuss(channelId, { target: env1 });
await openDiscuss(channelId, { target: env2 });
await insertText(".o-mail-Discuss-threadDescription", "The very best channel", {
replace: true,
target: env1,
});
triggerHotkey("Enter");
await contains(".o-mail-Discuss-threadDescription[title='The very best channel']", {
target: env2,
});
});
test.skip("Channel subscription is renewed when channel is added from invite", async () => {
const now = luxon.DateTime.now();
mockDate(`${now.year}-${now.month}-${now.day} ${now.hour}:${now.minute}:${now.second}`);
const pyEnv = await startServer();
const [, channelId] = pyEnv["discuss.channel"].create([
{ name: "R&D" },
{ name: "Sales", channel_member_ids: [] },
]);
// Patch the date to consider those channels as already known by the server
// when the client starts.
const later = now.plus({ seconds: 10 });
mockDate(
`${later.year}-${later.month}-${later.day} ${later.hour}:${later.minute}:${later.second}`
);
const env = await start();
patchWithCleanup(env.services.bus_service, {
forceUpdateChannels() {
step("update-channels");
},
});
await openDiscuss();
await contains(".o-mail-DiscussSidebarChannel");
env.services.orm.call("discuss.channel", "add_members", [[channelId]], {
partner_ids: [serverState.partnerId],
});
await contains(".o-mail-DiscussSidebarChannel", { count: 2 });
await assertSteps(["update-channels"]); // FIXME: sometimes 1 or 2 update-channels
});
test("Adding attachments", async () => {
const pyEnv = await startServer();
const channelId = pyEnv["discuss.channel"].create({ name: "Hogwarts Legacy" });
const messageId = pyEnv["mail.message"].create({
body: "Hello world!",
model: "discuss.channel",
res_id: channelId,
message_type: "comment",
});
const env1 = await start({ asTab: true });
const env2 = await start({ asTab: true });
await openDiscuss(channelId, { target: env1 });
await openDiscuss(channelId, { target: env2 });
const attachmentId = pyEnv["ir.attachment"].create({
name: "test.txt",
mimetype: "text/plain",
});
rpc = rpcWithEnv(env1);
rpc("/mail/message/update_content", {
body: "Hello world!",
attachment_ids: [attachmentId],
message_id: messageId,
});
await contains(".o-mail-AttachmentCard", { target: env2, text: "test.txt" });
});
test("Remove attachment from message", async () => {
const pyEnv = await startServer();
const channelId = pyEnv["discuss.channel"].create({ name: "General" });
const attachmentId = pyEnv["ir.attachment"].create({
name: "test.txt",
mimetype: "text/plain",
});
pyEnv["mail.message"].create({
attachment_ids: [attachmentId],
body: "Hello World!",
message_type: "comment",
model: "discuss.channel",
res_id: channelId,
});
const env1 = await start({ asTab: true });
const env2 = await start({ asTab: true });
await openDiscuss(channelId, { target: env1 });
await openDiscuss(channelId, { target: env2 });
await contains(".o-mail-AttachmentCard", { target: env1, text: "test.txt" });
await click(".o-mail-AttachmentCard-unlink", { target: env2 });
await click(".modal-footer .btn", { text: "Ok", target: env2 });
await contains(".o-mail-AttachmentCard", { count: 0, target: env1, text: "test.txt" });
});
test("Message delete notification", async () => {
const pyEnv = await startServer();
const messageId = pyEnv["mail.message"].create({
body: "Needaction message",
model: "res.partner",
res_id: serverState.partnerId,
needaction: true,
needaction_partner_ids: [serverState.partnerId], // not needed, for consistency
});
pyEnv["mail.notification"].create({
mail_message_id: messageId,
notification_type: "inbox",
notification_status: "sent",
res_partner_id: serverState.partnerId,
});
await start();
await openDiscuss();
await click("[title='Expand']");
await click("[title='Mark as Todo']");
await contains("button", { text: "Inbox", contains: [".badge", { text: "1" }] });
await contains("button", { text: "Starred", contains: [".badge", { text: "1" }] });
const [partner] = pyEnv["res.partner"].read(serverState.partnerId);
pyEnv["bus.bus"]._sendone(partner, "mail.message/delete", {
message_ids: [messageId],
});
await contains(".o-mail-Message", { count: 0 });
await contains("button", { text: "Inbox", contains: [".badge", { count: 0 }] });
await contains("button", { text: "Starred", contains: [".badge", { count: 0 }] });
});