Debian Codegraph @

addons/mail/static/tests/gif_picker/gif_picker.test.js

raw
1 import {
2 SIZES,
3 click,
4 contains,
5 defineMailModels,
6 focus,
7 insertText,
8 openDiscuss,
9 openFormView,
10 patchUiSize,
11 scroll,
12 start,
13 startServer,
14 } from "@mail/../tests/mail_test_helpers";
15 import { describe, expect, test } from "@odoo/hoot";
16 import {
17 asyncStep,
18 getService,
19 onRpc,
20 patchWithCleanup,
21 preloadBundle,
22 waitForSteps,
23 } from "@web/../tests/web_test_helpers";
24
25 import { GifPicker } from "@mail/discuss/gif_picker/common/gif_picker";
26 import { animationFrame, queryFirst } from "@odoo/hoot-dom";
27
28 describe.current.tags("desktop");
29 defineMailModels();
30 preloadBundle("web.assets_emoji");
31
32 let gifId = 0;
33 const gifFactory = (count = 1, options = {}) => {
34 const gifs = [];
35 for (let i = 0; i < count; i++) {
36 gifs.push({
37 id: `${gifId}`,
38 title: "",
39 media_formats: {
40 tinygif: {
41 url: options.url || "https://media.tenor.com/np49Y1vrJO8AAAAM/crying-cry.gif",
42 duration: 0,
43 preview: "",
44 dims: [220, 190],
45 size: 1007885,
46 },
47 },
48 created: 1654414453.782169,
49 content_description: "Cry GIF",
50 itemurl: "https://tenor.com/view/cry-gif-25866484",
51 url: "https://tenor.com/bUHdw.gif",
52 tags: ["cry"],
53 flags: [],
54 hasaudio: false,
55 });
56 gifId++;
57 }
58 return gifs;
59 };
60
61 const rpc = {
62 search: {
63 results: gifFactory(2),
64 next: "CAgQpIGj_8WN_gIaHgoKAD-_xMQ20dMU_xIQ1MVHUnSAQxC98Y6VAAAAADAI",
65 },
66 categories: {
67 locale: "en",
68 tags: [
69 {
70 searchterm: "cry",
71 path: "/v2/search?q=cry&locale=en&component=categories&contentfilter=low",
72 image: "https://media.tenor.com/6uIlQAHIkNoAAAAM/cry.gif",
73 name: "#cry",
74 },
75 {
76 searchterm: "yes",
77 path: "/v2/search?q=yes&locale=en&component=categories&contentfilter=low",
78 image: "https://media.tenor.com/UVmpVqlpVhQAAAAM/yess-yes.gif",
79 name: "#yes",
80 },
81 {
82 searchterm: "no",
83 path: "/v2/search?q=no&locale=en&component=categories&contentfilter=low",
84 image: "https://media.tenor.com/aeswYw-86k8AAAAM/no-nooo.gif",
85 name: "#no",
86 },
87 {
88 searchterm: "lol",
89 path: "/v2/search?q=lol&locale=en&component=categories&contentfilter=low",
90 image: "https://media.tenor.com/BiseY2UXovAAAAAM/lmfao-laughing.gif",
91 name: "#lol",
92 },
93 ],
94 },
95 };
96
97 test("composer should display a GIF button", async () => {
98 const pyEnv = await startServer();
99 const channelId = pyEnv["discuss.channel"].create({ name: "" });
100 await start();
101 await openDiscuss(channelId);
102 await contains("button[title='Add GIFs']");
103 });
104
105 test("Composer GIF button should open the GIF picker (discuss app)", async () => {
106 const pyEnv = await startServer();
107 const channelId = pyEnv["discuss.channel"].create({ name: "" });
108 await start();
109 await openDiscuss(channelId);
110 await click("button[title='Add GIFs']");
111 await contains(".o-discuss-GifPicker");
112 });
113
114 test("Composer GIF button should open the GIF picker (chat window)", async () => {
115 const pyEnv = await startServer();
116 pyEnv["discuss.channel"].create({ name: "General" });
117 await start();
118 await click(".o_menu_systray i[aria-label='Messages']");
119 await click(".o-mail-NotificationItem:contains('General')");
120 await click(".o-mail-ChatWindow .o-mail-Composer [title='More Actions']");
121 await click(".o-dropdown-item:contains('Add GIFs')");
122 await contains(".o-discuss-GifPicker");
123 });
124
125 test("Not loading of GIF categories when feature is not available", async () => {
126 const pyEnv = await startServer();
127 const channelId = pyEnv["discuss.channel"].create({ name: "" });
128 let isFeatureEnabled = true;
129 onRpc("/discuss/gif/categories", () => {
130 asyncStep("/discuss/gif/categories");
131 if (isFeatureEnabled) {
132 return rpc.categories;
133 }
134 });
135 await start();
136 await openDiscuss(channelId);
137 const store = getService("mail.store");
138 store.hasGifPickerFeature = false;
139 isFeatureEnabled = false;
140 await click("button[title='Add GIFs']");
141 await contains(".o-discuss-GifPicker");
142 await animationFrame();
143 expect.verifySteps([]); // no "/discuss/gif/categories"
144 await click("button[title='Add GIFs']");
145 await contains(".o-discuss-GifPicker", { count: 0 });
146 store.hasGifPickerFeature = true;
147 isFeatureEnabled = true;
148 await click("button[title='Add GIFs']");
149 await contains(".o-discuss-GifPicker");
150 await waitForSteps(["/discuss/gif/categories"]);
151 });
152
153 test("Searching for a GIF", async () => {
154 const pyEnv = await startServer();
155 const channelId = pyEnv["discuss.channel"].create({ name: "" });
156 onRpc("/discuss/gif/search", () => rpc.search);
157 await start();
158 await openDiscuss(channelId);
159 await click("button[title='Add GIFs']");
160 await insertText("input[placeholder='Search for a GIF']", "search");
161 await contains("i[aria-label='back']");
162 await contains(".o-discuss-Gif", { count: 2 });
163 });
164
165 test("Open a GIF category trigger the search for the category", async () => {
166 const pyEnv = await startServer();
167 const channelId = pyEnv["discuss.channel"].create({ name: "" });
168 onRpc("/discuss/gif/categories", () => rpc.categories);
169 onRpc("/discuss/gif/search", () => rpc.search);
170 await start();
171 await openDiscuss(channelId);
172 await click("button[title='Add GIFs']");
173 await click("img[data-src='https://media.tenor.com/6uIlQAHIkNoAAAAM/cry.gif']");
174 await contains(".o-discuss-Gif", { count: 2 });
175 await contains("input[placeholder='Search for a GIF']", { value: "cry" });
176 });
177
178 test("Can have GIF categories with same name", async () => {
179 const pyEnv = await startServer();
180 const channelId = pyEnv["discuss.channel"].create({ name: "" });
181 onRpc("/discuss/gif/categories", () => ({
182 locale: "en",
183 tags: [
184 {
185 searchterm: "duplicate",
186 path: "/v2/search?q=duplicate&locale=en&component=categories&contentfilter=low",
187 image: "https://media.tenor.com/BiseY2UXovAAAAAM/duplicate.gif",
188 name: "#duplicate",
189 },
190 {
191 searchterm: "duplicate",
192 path: "/v2/search?q=duplicate&locale=en&component=categories&contentfilter=low",
193 image: "https://media.tenor.com/BiseY2UXovAAAAAM/duplicate.gif",
194 name: "#duplicate",
195 },
196 ],
197 }));
198 onRpc("/discuss/gif/search", () => rpc.search);
199 await start();
200 await openDiscuss(channelId);
201 await click("button[title='Add GIFs']");
202 await contains("img[data-src='https://media.tenor.com/BiseY2UXovAAAAAM/duplicate.gif']", {
203 count: 2,
204 });
205 });
206
207 test("Reopen GIF category list when going back", async () => {
208 const pyEnv = await startServer();
209 const channelId = pyEnv["discuss.channel"].create({ name: "" });
210 onRpc("/discuss/gif/categories", () => rpc.categories);
211 onRpc("/discuss/gif/search", () => rpc.search);
212 await start();
213 await openDiscuss(channelId);
214 await click("button[title='Add GIFs']");
215 await click("img[data-src='https://media.tenor.com/6uIlQAHIkNoAAAAM/cry.gif']");
216 await click("i[aria-label='back']");
217 await contains(".o-discuss-GifPicker div[aria-label='list']");
218 });
219
220 test("Add GIF to favorite", async () => {
221 const pyEnv = await startServer();
222 const channelId = pyEnv["discuss.channel"].create({ name: "" });
223 onRpc("/discuss/gif/categories", () => rpc.categories);
224 onRpc("/discuss/gif/search", () => rpc.search);
225 await start();
226 await openDiscuss(channelId);
227 await click("button[title='Add GIFs']");
228 await click("img[data-src='https://media.tenor.com/6uIlQAHIkNoAAAAM/cry.gif']");
229 await click(":nth-child(1 of div) > .o-discuss-Gif .fa-star-o");
230 await contains(".o-discuss-Gif .fa-star");
231 await click("i[aria-label='back']");
232 await click(".o-discuss-GifPicker div[aria-label='list-item']", { text: "Favorites" });
233 await contains(".o-discuss-Gif");
234 });
235
236 test("Chatter should not have the GIF button", async () => {
237 const pyEnv = await startServer();
238 await start();
239 const partnerId = pyEnv["res.partner"].create({ name: "John Doe" });
240 await openFormView("res.partner", partnerId);
241 await click("button", { text: "Log note" });
242 await contains("button[title='Add GIFs']", { count: 0 });
243 });
244
245 test("Composer GIF button should open the GIF picker keyboard in footer", async () => {
246 const pyEnv = await startServer();
247 const channelId = pyEnv["discuss.channel"].create({ name: "General" });
248 patchUiSize({ size: SIZES.SM });
249 await start();
250 await openDiscuss(channelId);
251 await click("button[title='More Actions']");
252 await click(".dropdown-item:contains('Add GIFs')");
253 await contains(".o-mail-Composer-footer .o-discuss-GifPicker");
254 });
255
256 test("Searching for a GIF with a failling RPC should display an error", async () => {
257 const pyEnv = await startServer();
258 const channelId = pyEnv["discuss.channel"].create({ name: "" });
259 onRpc("/discuss/gif/categories", () => rpc.categories);
260 onRpc("/discuss/gif/search", () => {
261 throw new Error("Rpc failed");
262 });
263 await start();
264 await openDiscuss(channelId);
265 await click("button[title='Add GIFs']");
266 await insertText("input[placeholder='Search for a GIF']", "search");
267 await contains(".o-discuss-GifPicker-error");
268 });
269
270 test("Scrolling at the bottom should trigger the search to load more gif, even after visiting the favorite.", async () => {
271 patchWithCleanup(GifPicker.prototype, {
272 get style() {
273 return "width: 200px;height: 200px;background: #000";
274 },
275 });
276 const pyEnv = await startServer();
277 const channelId = pyEnv["discuss.channel"].create({ name: "" });
278 onRpc("/discuss/gif/categories", () => rpc.categories);
279 onRpc("/discuss/gif/search", () => {
280 const _rpc = rpc.search;
281 _rpc.results = gifFactory(4);
282 return _rpc;
283 });
284 await start();
285 await openDiscuss(channelId);
286 await click("button[title='Add GIFs']");
287 // gif picker quires extra delay before click (to give time to load initial state)
288 await contains(".o-discuss-GifPicker");
289 await click(".o-discuss-GifPicker div[aria-label='list-item']", { text: "Favorites" });
290 await click("i[aria-label='back']");
291 await click("img[data-src='https://media.tenor.com/6uIlQAHIkNoAAAAM/cry.gif']");
292 await contains(".o-discuss-Gif", { count: 4 });
293 await scroll(".o-discuss-GifPicker-content", "bottom");
294 await contains(".o-discuss-Gif", { count: 8 });
295 });
296
297 test("Pause GIF when thread is not focused", async () => {
298 const pyEnv = await startServer();
299 const channelId = pyEnv["discuss.channel"].create({ name: "" });
300 onRpc("/discuss/gif/categories", () => rpc.categories);
301 onRpc("/discuss/gif/search", () => rpc.search);
302 await start();
303 await openDiscuss(channelId);
304 await click("button[title='Add GIFs']");
305 await click("img[data-src='https://media.tenor.com/6uIlQAHIkNoAAAAM/cry.gif']");
306 await click("img[data-src='https://media.tenor.com/np49Y1vrJO8AAAAM/crying-cry.gif']:eq(0)");
307 await contains(".o-mail-LinkPreviewImage");
308 queryFirst(".o-mail-Thread").blur();
309 await contains(".o-mail-LinkPreviewImage img[data-paused]");
310 await focus(".o-mail-Thread");
311 await contains(".o-mail-LinkPreviewImage img:not([data-paused])");
312 });
313
314 test("Show help when no favorite GIF", async () => {
315 const pyEnv = await startServer();
316 const channelId = pyEnv["discuss.channel"].create({ name: "" });
317 onRpc("/discuss/gif/categories", () => rpc.categories);
318 await start();
319 await openDiscuss(channelId);
320 await click("button[title='Add GIFs']");
321 // gif picker quires extra delay before click (to give time to load initial state)
322 await contains(".o-discuss-GifPicker");
323 await click(".o-discuss-GifPicker div[aria-label='list-item']", { text: "Favorites" });
324 await contains("span", { text: "So uhh... maybe go favorite some GIFs?" });
325 });
326
327 test("Clicking GIF preview does not raise an error", async () => {
328 const pyEnv = await startServer();
329 const channelId = pyEnv["discuss.channel"].create({ name: "" });
330 onRpc("/discuss/gif/categories", () => rpc.categories);
331 onRpc("/discuss/gif/search", () => rpc.search);
332 await start();
333 await openDiscuss(channelId);
334 await click("button[title='Add GIFs']");
335 await click("img[data-src='https://media.tenor.com/6uIlQAHIkNoAAAAM/cry.gif']");
336 await click("img[data-src='https://media.tenor.com/np49Y1vrJO8AAAAM/crying-cry.gif']:eq(0)");
337 await click(".o-mail-LinkPreviewImage img");
338 await contains(".o-mail-Message");
339 });