2024-05-03 12:40:35 +03:00
/* @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 <span class=" ${ HIGHLIGHT _CLASS } ">odoo</span> ` ,
searchTerm : "odoo" ,
} ,
{
input : '<a href="https://www.odoo.com">https://www.odoo.com</a>' ,
output : ` <a href="https://www.odoo.com">https://www.<span class=" ${ HIGHLIGHT _CLASS } ">odoo</span>.com</a> ` ,
searchTerm : "odoo" ,
} ,
{
input : '<a href="https://www.odoo.com">Odoo</a>' ,
output : ` <a href="https://www.odoo.com"><span class=" ${ HIGHLIGHT _CLASS } ">Odoo</span></a> ` ,
searchTerm : "odoo" ,
} ,
{
2024-05-08 11:31:09 +03:00
input : '<a href="https://www.odoo.com">Odoo</a>Talismanis a free software' ,
2024-05-03 12:40:35 +03:00
output : ` <a href="https://www.odoo.com"><span class=" ${ HIGHLIGHT _CLASS } ">Odoo</span></a> <span class=" ${ HIGHLIGHT _CLASS } ">Odoo</span> is a free software ` ,
searchTerm : "odoo" ,
} ,
{
input : "odoo is a free software" ,
output : ` <span class=" ${ HIGHLIGHT _CLASS } ">odoo</span> is a free software ` ,
searchTerm : "odoo" ,
} ,
{
input : "software ODOO is a free" ,
output : ` software <span class=" ${ HIGHLIGHT _CLASS } ">ODOO</span> is a free ` ,
searchTerm : "odoo" ,
} ,
{
input : ` <ul>
< li > Odoo < / l i >
< li > < a href = "https://odoo.com" > Odoo ERP < / a > B e s t E R P < / l i >
< / u l > ` ,
output : ` <ul>
< li > < span class = "${HIGHLIGHT_CLASS}" > Odoo < / s p a n > < / l i >
< li > < a href = "https://odoo.com" > < span class = "${HIGHLIGHT_CLASS}" > Odoo < / s p a n > E R P < / a > B e s t E R P < / l i >
< / u l > ` ,
searchTerm : "odoo" ,
} ,
{
input : "test <strong>Odoo</strong> test" ,
output : ` <span class=" ${ HIGHLIGHT _CLASS } ">test</span> <strong><span class=" ${ HIGHLIGHT _CLASS } ">Odoo</span></strong> <span class=" ${ HIGHLIGHT _CLASS } ">test</span> ` ,
searchTerm : "odoo test" ,
} ,
{
input : "test <br> test" ,
output : ` <span class=" ${ HIGHLIGHT _CLASS } ">test</span> <br> <span class=" ${ HIGHLIGHT _CLASS } ">test</span> ` ,
searchTerm : "odoo test" ,
} ,
{
input : "<strong>test</strong> test" ,
output : ` <strong><span class=" ${ HIGHLIGHT _CLASS } ">test</span></strong> <span class=" ${ HIGHLIGHT _CLASS } ">test</span> ` ,
searchTerm : "test" ,
} ,
{
input : "<strong>a</strong> test" ,
output : ` <strong><span class=" ${ HIGHLIGHT _CLASS } ">a</span></strong> <span class=" ${ HIGHLIGHT _CLASS } ">test</span> ` ,
searchTerm : "a test" ,
} ,
{
input : "&amp;" ,
output : ` <span class=" ${ HIGHLIGHT _CLASS } ">&amp;</span> ` ,
searchTerm : "&" ,
} ,
{
input : "&amp;" ,
output : ` <span class=" ${ HIGHLIGHT _CLASS } ">&</span>amp; ` ,
searchTerm : "&" ,
} ,
{
input : "<strong>test</strong> hello" ,
output : ` <strong><span class=" ${ HIGHLIGHT _CLASS } ">test</span></strong> <span class=" ${ HIGHLIGHT _CLASS } ">hello</span> ` ,
searchTerm : "test hello" ,
} ,
{
input : "<p><strong>test</strong> hello</p>" ,
output : ` <p><strong><span class=" ${ HIGHLIGHT _CLASS } ">test</span></strong> <span class=" ${ HIGHLIGHT _CLASS } ">hello</span></p> ` ,
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 : "<p><strong>test</strong> hello</p>" ,
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 : "<strong>test</strong> hello" } ) ;
} ) ;