/* @odoo-module */ import { HIGHLIGHT_CLASS, searchHighlight } from "@mail/core/common/message_search_hook"; import { triggerHotkey } from "@web/../tests/helpers/utils"; import { click, contains, insertText } from "@web/../tests/utils"; import { startServer } from "@bus/../tests/helpers/mock_python_environment"; import { start } from "../helpers/test_utils"; import { SIZES, patchUiSize } from "../helpers/patch_ui_size"; QUnit.module("Search highlight test", {}); QUnit.test("Search highlight", async (assert) => { const testCases = [ { input: "test odoo", output: `test odoo`, searchTerm: "odoo", }, { input: 'https://www.odoo.com', output: `https://www.odoo.com`, searchTerm: "odoo", }, { input: 'Odoo', output: `Odoo`, searchTerm: "odoo", }, { input: 'Odoo Odoo is a free software', output: `Odoo Odoo is a free software`, searchTerm: "odoo", }, { input: "odoo is a free software", output: `odoo is a free software`, searchTerm: "odoo", }, { input: "software ODOO is a free", output: `software ODOO is a free`, searchTerm: "odoo", }, { input: ``, output: ``, searchTerm: "odoo", }, { input: "test Odoo test", output: `test Odoo test`, searchTerm: "odoo test", }, { input: "test
test", output: `test
test`, searchTerm: "odoo test", }, { input: "test test", output: `test test`, searchTerm: "test", }, { input: "a test", output: `a test`, searchTerm: "a test", }, { input: "&", output: `&`, searchTerm: "&", }, { input: "&", output: `&`, searchTerm: "&", }, { input: "test hello", output: `test hello`, searchTerm: "test hello", }, { input: "

<strong>test</strong> hello

", output: `

<strong>test</strong> hello

`, searchTerm: "test hello", }, ]; for (const { input, output, searchTerm } of testCases) { assert.equal(searchHighlight(searchTerm, input), output); } }); QUnit.test("Display highligthed search in chatter", async () => { patchUiSize({ size: SIZES.XXL }); const pyEnv = await startServer(); const partnerId = pyEnv["res.partner"].create({ name: "John Doe" }); pyEnv["mail.message"].create({ body: "not empty", model: "res.partner", res_id: partnerId, }); const { openFormView } = await start(); await openFormView("res.partner", partnerId); await click("[title='Search Messages']"); await insertText(".o_searchview_input", "empty"); triggerHotkey("Enter"); await contains(`.o-mail-Chatter-search .o-mail-Message span.${HIGHLIGHT_CLASS}`); }); QUnit.test("Display multiple highligthed search in chatter", async () => { patchUiSize({ size: SIZES.XXL }); const pyEnv = await startServer(); const partnerId = pyEnv["res.partner"].create({ name: "John Doe" }); pyEnv["mail.message"].create({ body: "not test empty", model: "res.partner", res_id: partnerId, }); const { openFormView } = await start(); await openFormView("res.partner", partnerId); await click("[title='Search Messages']"); await insertText(".o_searchview_input", "not empty"); triggerHotkey("Enter"); await contains(`.o-mail-Chatter-search .o-mail-Message span.${HIGHLIGHT_CLASS}`, { count: 2 }); }); QUnit.test("Display highligthed search in Discuss", async () => { const pyEnv = await startServer(); const channelId = pyEnv["discuss.channel"].create({ name: "General" }); pyEnv["mail.message"].create({ author_id: pyEnv.currentPartnerId, body: "not empty", attachment_ids: [], message_type: "comment", model: "discuss.channel", res_id: channelId, }); const { openDiscuss } = await start(); await openDiscuss(channelId); await click("button[title='Search Messages']"); await insertText(".o_searchview_input", "empty"); triggerHotkey("Enter"); await contains(`.o-mail-SearchMessagesPanel .o-mail-Message span.${HIGHLIGHT_CLASS}`); }); QUnit.test("Display multiple highligthed search in Discuss", async () => { const pyEnv = await startServer(); const channelId = pyEnv["discuss.channel"].create({ name: "General" }); pyEnv["mail.message"].create({ author_id: pyEnv.currentPartnerId, body: "not prout empty", attachment_ids: [], message_type: "comment", model: "discuss.channel", res_id: channelId, }); const { openDiscuss } = await start(); await openDiscuss(channelId); await click("button[title='Search Messages']"); await insertText(".o_searchview_input", "not empty"); triggerHotkey("Enter"); await contains(`.o-mail-SearchMessagesPanel .o-mail-Message span.${HIGHLIGHT_CLASS}`, { count: 2, }); }); QUnit.test("Display highligthed with escaped character must ignore them", async () => { patchUiSize({ size: SIZES.XXL }); const pyEnv = await startServer(); const partnerId = pyEnv["res.partner"].create({ name: "John Doe" }); pyEnv["mail.message"].create({ body: "

<strong>test</strong> hello

", model: "res.partner", res_id: partnerId, }); const { openFormView } = await start(); await openFormView("res.partner", partnerId); await click("[title='Search Messages']"); await insertText(".o_searchview_input", "test hello"); triggerHotkey("Enter"); await contains(`.o-mail-Chatter-search .o-mail-Message span.${HIGHLIGHT_CLASS}`, { count: 2 }); await contains(`.o-mail-Message-body`, { text: "test hello" }); });