| 1 |
import { |
| 2 |
defineParams, |
| 3 |
patchWithCleanup, |
| 4 |
preloadBundle, |
| 5 |
serverState, |
| 6 |
} from "@web/../tests/web_test_helpers"; |
| 7 |
|
| 8 |
import { |
| 9 |
click, |
| 10 |
contains, |
| 11 |
defineMailModels, |
| 12 |
insertText, |
| 13 |
openDiscuss, |
| 14 |
scroll, |
| 15 |
start, |
| 16 |
startServer, |
| 17 |
triggerHotkey, |
| 18 |
} from "@mail/../tests/mail_test_helpers"; |
| 19 |
import { describe, getFixture, test } from "@odoo/hoot"; |
| 20 |
|
| 21 |
import { queryFirst } from "@odoo/hoot-dom"; |
| 22 |
|
| 23 |
describe.current.tags("desktop"); |
| 24 |
defineMailModels(); |
| 25 |
preloadBundle("web.assets_emoji"); |
| 26 |
|
| 27 |
test("emoji picker correctly handles translations with special characters", async () => { |
| 28 |
defineParams({ |
| 29 |
translations: { |
| 30 |
"Japanese โhereโ button": `Bouton "ici" japonais`, |
| 31 |
"heavy dollar sign": `Symbole du dollar\nlourd`, |
| 32 |
}, |
| 33 |
}); |
| 34 |
const pyEnv = await startServer(); |
| 35 |
const channelId = pyEnv["discuss.channel"].create({ name: "" }); |
| 36 |
await start(); |
| 37 |
await openDiscuss(channelId); |
| 38 |
await click("button[title='Add Emojis']"); |
| 39 |
await insertText(".o-EmojiPicker-search input", "ici"); |
| 40 |
await contains(`.o-Emoji[title='Bouton "ici" japonais']`); |
| 41 |
await insertText(".o-EmojiPicker-search input", "dollar", { replace: true }); |
| 42 |
await contains(`.o-Emoji[title*='Symbole du dollar']`); |
| 43 |
}); |
| 44 |
|
| 45 |
test("search emoji from keywords", async () => { |
| 46 |
const pyEnv = await startServer(); |
| 47 |
const channelId = pyEnv["discuss.channel"].create({ name: "" }); |
| 48 |
await start(); |
| 49 |
await openDiscuss(channelId); |
| 50 |
await click("button[title='Add Emojis']"); |
| 51 |
await insertText("input[placeholder='Search emoji']", "mexican"); |
| 52 |
await contains(".o-Emoji", { text: "๐ฎ" }); |
| 53 |
await insertText(".o-EmojiPicker-search input", "9", { replace: true }); |
| 54 |
await contains(".o-Emoji:eq(0)", { text: "๐" }); |
| 55 |
await contains(".o-Emoji:eq(1)", { text: "๐ค" }); |
| 56 |
await contains(".o-Emoji:eq(2)", { text: "9๏ธโฃ" }); |
| 57 |
}); |
| 58 |
|
| 59 |
test("search emoji from keywords should be case insensitive", async () => { |
| 60 |
const pyEnv = await startServer(); |
| 61 |
const channelId = pyEnv["discuss.channel"].create({ name: "" }); |
| 62 |
await start(); |
| 63 |
await openDiscuss(channelId); |
| 64 |
await click("button[title='Add Emojis']"); |
| 65 |
await insertText("input[placeholder='Search emoji']", "ok"); |
| 66 |
await contains(".o-Emoji", { text: "๐" })OK |
| 67 |
}); |
| 68 |
|
| 69 |
test("search emoji from keywords with special regex character", async () => { |
| 70 |
const pyEnv = await startServer(); |
| 71 |
const channelId = pyEnv["discuss.channel"].create({ name: "" }); |
| 72 |
await start(); |
| 73 |
await openDiscuss(channelId); |
| 74 |
await click("button[title='Add Emojis']"); |
| 75 |
await insertText("input[placeholder='Search emoji']", "(blood"); |
| 76 |
await contains(".o-Emoji", { text: "๐" }); |
| 77 |
}); |
| 78 |
|
| 79 |
test("updating search emoji should scroll top", async () => { |
| 80 |
const pyEnv = await startServer(); |
| 81 |
const channelId = pyEnv["discuss.channel"].create({ name: "" }); |
| 82 |
await start(); |
| 83 |
await openDiscuss(channelId); |
| 84 |
await click("button[title='Add Emojis']"); |
| 85 |
await contains(".o-EmojiPicker-content", { scroll: 0 }); |
| 86 |
await scroll(".o-EmojiPicker-content", 150); |
| 87 |
await insertText("input[placeholder='Search emoji']", "m"); |
| 88 |
await contains(".o-EmojiPicker-content", { scroll: 0 }); |
| 89 |
}); |
| 90 |
|
| 91 |
test("Press Escape in emoji picker closes the emoji picker", async () => { |
| 92 |
const pyEnv = await startServer(); |
| 93 |
const channelId = pyEnv["discuss.channel"].create({ name: "" }); |
| 94 |
await start(); |
| 95 |
await openDiscuss(channelId); |
| 96 |
await click("button[title='Add Emojis']"); |
| 97 |
triggerHotkey("Escape"); |
| 98 |
await contains(".o-EmojiPicker", { count: 0 }); |
| 99 |
}); |
| 100 |
|
| 101 |
test("Basic keyboard navigation", async () => { |
| 102 |
const pyEnv = await startServer(); |
| 103 |
const channelId = pyEnv["discuss.channel"].create({ name: "" }); |
| 104 |
await start(); |
| 105 |
await openDiscuss(channelId); |
| 106 |
await contains(".o-mail-Composer-input:focus"); |
| 107 |
await click("button[title='Add Emojis']"); |
| 108 |
await contains(".o-Emoji[data-index='0'].o-active"); |
| 109 |
|
| 110 |
const emojis = Array.from( |
| 111 |
getFixture().querySelectorAll(".o-EmojiPicker-category[data-category='1'] ~ .o-Emoji") |
| 112 |
); |
| 113 |
const baseOffset = emojis[0].offsetTop; |
| 114 |
const breakIndex = emojis.findIndex((item) => item.offsetTop > baseOffset); |
| 115 |
const EMOJI_PER_ROW = breakIndex === -1 ? emojis.length : breakIndex; |
| 116 |
triggerHotkey("ArrowRight"); |
| 117 |
await contains(".o-EmojiPicker-content .o-Emoji[data-index='1'].o-active"); |
| 118 |
triggerHotkey("ArrowDown"); |
| 119 |
await contains(`.o-EmojiPicker-content .o-Emoji[data-index='${EMOJI_PER_ROW + 1}'].o-active`); |
| 120 |
triggerHotkey("ArrowLeft"); |
| 121 |
await contains(`.o-EmojiPicker-content .o-Emoji[data-index='${EMOJI_PER_ROW}'].o-active`); |
| 122 |
triggerHotkey("ArrowUp"); |
| 123 |
await contains(".o-EmojiPicker-content .o-Emoji[data-index='0'].o-active"); |
| 124 |
const { codepoints } = queryFirst( |
| 125 |
".o-EmojiPicker-content .o-Emoji[data-index='0'].o-active" |
| 126 |
).dataset; |
| 127 |
triggerHotkey("Enter"); |
| 128 |
await contains(".o-EmojiPicker", { count: 0 }); |
| 129 |
await contains(".o-mail-Composer-input", { value: codepoints }); |
| 130 |
}); |
| 131 |
|
| 132 |
test("recent category (basic)", async () => { |
| 133 |
const pyEnv = await startServer(); |
| 134 |
const channelId = pyEnv["discuss.channel"].create({ name: "" }); |
| 135 |
await start(); |
| 136 |
await openDiscuss(channelId); |
| 137 |
await click("button[title='Add Emojis']"); |
| 138 |
await contains(".o-EmojiPicker-navbar [title='Frequently used']", { count: 0 }); |
| 139 |
await click(".o-EmojiPicker-content .o-Emoji", { text: "๐" }); |
| 140 |
await click("button[title='Add Emojis']"); |
| 141 |
await contains(".o-EmojiPicker-navbar [title='Frequently used']"); |
| 142 |
await contains(".o-Emoji", { |
| 143 |
text: "๐", |
| 144 |
after: ["span", { textContent: "Frequently used" }], |
| 145 |
before: ["span", { textContent: "Smileys & Emotion" }], |
| 146 |
}); |
| 147 |
}); |
| 148 |
|
| 149 |
test("search emojis prioritize frequently used emojis", async () => { |
| 150 |
const pyEnv = await startServer(); |
| 151 |
const channelId = pyEnv["discuss.channel"].create({ name: "" }); |
| 152 |
await start(); |
| 153 |
await openDiscuss(channelId); |
| 154 |
await click("button[title='Add Emojis']"); |
| 155 |
await contains(".o-EmojiPicker-navbar [title='Frequently used']", { count: 0 }); |
| 156 |
await click(".o-EmojiPicker-content .o-Emoji", { text: "๐คฅ" }); |
| 157 |
await click("button[title='Add Emojis']"); |
| 158 |
await contains(".o-EmojiPicker-navbar [title='Frequently used']"); |
| 159 |
await insertText("input[placeholder='Search emoji']", "lie"); |
| 160 |
await contains(".o-EmojiPicker-sectionIcon", { count: 0 }); |
| 161 |
await contains(".o-EmojiPicker-content .o-Emoji:eq(0)", { text: "๐คฅ" }); |
| 162 |
}); |
| 163 |
|
| 164 |
test("search matches only frequently used emojis", async () => { |
| 165 |
const pyEnv = await startServer(); |
| 166 |
const channelId = pyEnv["discuss.channel"].create({ name: "" }); |
| 167 |
await start(); |
| 168 |
await openDiscuss(channelId); |
| 169 |
await click("button[title='Add Emojis']"); |
| 170 |
await contains(".o-EmojiPicker-navbar [title='Frequently used']", { count: 0 }); |
| 171 |
await click(".o-EmojiPicker-content .o-Emoji", { text: "๐ฅฆ" }); |
| 172 |
await click("button[title='Add Emojis']"); |
| 173 |
await contains(".o-EmojiPicker-navbar [title='Frequently used']"); |
| 174 |
await insertText(".o-EmojiPicker-search input", "brocoli"); |
| 175 |
await contains(".o-EmojiPicker-sectionIcon", { count: 0 }); |
| 176 |
await contains(".o-EmojiPicker-content .o-Emoji:eq(0)", { text: "๐ฅฆ" }); |
| 177 |
await contains(".o-EmojiPicker-content .o-Emoji", { count: 1 }); |
| 178 |
await contains(".o-EmojiPicker-content", { text: "No emoji matches your search", count: 0 }); |
| 179 |
await insertText(".o-EmojiPicker-search input", "2"); |
| 180 |
await contains(".o-EmojiPicker-content", { text: "No emoji matches your search" }); |
| 181 |
}); |
| 182 |
|
| 183 |
test("emoji usage amount orders frequent emojis", async () => { |
| 184 |
const pyEnv = await startServer(); |
| 185 |
const channelId = pyEnv["discuss.channel"].create({ name: "" }); |
| 186 |
await start(); |
| 187 |
await openDiscuss(channelId); |
| 188 |
await click("button[title='Add Emojis']"); |
| 189 |
await click(".o-EmojiPicker-content .o-Emoji", { text: "๐" }); |
| 190 |
await click("button[title='Add Emojis']"); |
| 191 |
await click(".o-EmojiPicker-content .o-Emoji", { text: "๐ฝ" }); |
| 192 |
await click("button[title='Add Emojis']"); |
| 193 |
await click(".o-EmojiPicker-content .o-Emoji", { text: "๐ฝ" }); |
| 194 |
await click("button[title='Add Emojis']"); |
| 195 |
await contains(".o-Emoji", { |
| 196 |
text: "๐ฝ", |
| 197 |
after: ["span", { textContent: "Frequently used" }], |
| 198 |
before: [ |
| 199 |
".o-Emoji", |
| 200 |
{ |
| 201 |
text: "๐", |
| 202 |
after: ["span", { textContent: "Frequently used" }], |
| 203 |
before: ["span", { textContent: "Smileys & Emotion" }], |
| 204 |
}, |
| 205 |
], |
| 206 |
}); |
| 207 |
}); |
| 208 |
|
| 209 |
test("first category should be highlighted by default", async () => { |
| 210 |
const pyEnv = await startServer(); |
| 211 |
const channelId = pyEnv["discuss.channel"].create({ name: "" }); |
| 212 |
await start(); |
| 213 |
await openDiscuss(channelId); |
| 214 |
await click("button[title='Add Emojis']"); |
| 215 |
await contains(".o-EmojiPicker-navbar :nth-child(1 of .o-Emoji).o-active"); |
| 216 |
}); |
| 217 |
|
| 218 |
test("selecting an emoji while holding down the Shift key prevents the emoji picker from closing", async () => { |
| 219 |
const pyEnv = await startServer(); |
| 220 |
const channelId = pyEnv["discuss.channel"].create({ name: "" }); |
| 221 |
await start(); |
| 222 |
await openDiscuss(channelId); |
| 223 |
await click("button[title='Add Emojis']"); |
| 224 |
await click(".o-EmojiPicker-content .o-Emoji", { shiftKey: true, text: "๐บ" }); |
| 225 |
await contains(".o-EmojiPicker-navbar [title='Frequently used']"); |
| 226 |
await contains(".o-EmojiPicker"); |
| 227 |
await contains(".o-mail-Composer-input", { value: "๐บ" }); |
| 228 |
}); |
| 229 |
|
| 230 |
test("shortcodes shown in emoji title in message", async () => { |
| 231 |
const pyEnv = await startServer(); |
| 232 |
const channelId = pyEnv["discuss.channel"].create({ name: "" }); |
| 233 |
pyEnv["mail.message"].create({ |
| 234 |
res_id: channelId, |
| 235 |
model: "discuss.channel", |
| 236 |
body: "๐๐", |
| 237 |
author_id: serverState.partnerId, |
| 238 |
}); |
| 239 |
await start(); |
| 240 |
await openDiscuss(channelId); |
| 241 |
await contains(".o-mail-Message", { text: "๐๐" }); |
| 242 |
await contains(".o-mail-Message span[title=':couple_with_heart:']", { text: "๐" }); |
| 243 |
await contains(".o-mail-Message span[title=':innocent: :halo:']", { text: "๐" }); |
| 244 |
}); |
| 245 |
|
| 246 |
test("Emoji picker shows failure to load emojis", async () => { |
| 247 |
|
| 248 |
patchWithCleanup(odoo.loader.modules.get("@web/core/emoji_picker/emoji_data"), { |
| 249 |
getEmojis() { |
| 250 |
return []; |
| 251 |
}, |
| 252 |
}); |
| 253 |
const pyEnv = await startServer(); |
| 254 |
const channelId = pyEnv["discuss.channel"].create({ name: "" }); |
| 255 |
await start(); |
| 256 |
await openDiscuss(channelId); |
| 257 |
await click("button[title='Add Emojis']"); |
| 258 |
await contains(".o-EmojiPicker", { text: "๐ตโ๐ซFailed to load emojis..." }); |
| 259 |
}); |