| 1 |
import { defineHrModels } from "@hr/../tests/hr_test_helpers"; |
| 2 |
import { start } from "@mail/../tests/mail_test_helpers"; |
| 3 |
import { describe, expect, test } from "@odoo/hoot"; |
| 4 |
import { waitFor } from "@odoo/hoot-dom"; |
| 5 |
import { contains, makeMockServer, mountView, onRpc } from "@web/../tests/web_test_helpers"; |
| 6 |
import { getOrigin } from "@web/core/utils/urls"; |
| 7 |
|
| 8 |
describe.current.tags("desktop"); |
| 9 |
defineHrModels(); |
| 10 |
|
| 11 |
test("many2one in list view", async () => { |
| 12 |
const { env } = await makeMockServer(); |
| 13 |
const [partnerId_1, partnerId_2] = env["res.partner"].create([ |
| 14 |
{ name: "Mario" }, |
| 15 |
{ name: "Luigi" }, |
| 16 |
]); |
| 17 |
const [userId_1, userId_2] = env["res.users"].create([ |
| 18 |
{ partner_id: partnerId_1 }, |
| 19 |
{ partner_id: partnerId_2 }, |
| 20 |
]); |
| 21 |
const [employeeId_1, employeeId_2] = env["hr.employee.public"].create([ |
| 22 |
{ |
| 23 |
name: "Mario", |
| 24 |
user_id: userId_1, |
| 25 |
user_partner_id: partnerId_1, |
| 26 |
work_email: "[email protected]", |
| 27 |
}, |
| 28 |
{ |
| 29 |
name: "Luigi", |
| 30 |
user_id: userId_2, |
| 31 |
user_partner_id: partnerId_2, |
| 32 |
}, |
| 33 |
]); |
| 34 |
env["m2x.avatar.employee"].create([ |
| 35 |
{ |
| 36 |
employee_id: employeeId_1, |
| 37 |
employee_ids: [employeeId_1, employeeId_2], |
| 38 |
}, |
| 39 |
{ employee_id: employeeId_2 }, |
| 40 |
{ employee_id: employeeId_1 }, |
| 41 |
]); |
| 42 |
await start(); |
| 43 |
onRpc("has_group", () => false); |
| 44 |
await mountView({ |
| 45 |
type: "list", |
| 46 |
resModel: "m2x.avatar.employee", |
| 47 |
arch: `<list><field name="employee_id" widget="many2one_avatar_employee"/></list>`, |
| 48 |
}); |
| 49 |
expect(".o_data_cell div[name='employee_id']:eq(0)").toHaveText("Mario"); |
| 50 |
expect(".o_data_cell div[name='employee_id']:eq(1)").toHaveText("Luigi"); |
| 51 |
expect(".o_data_cell div[name='employee_id']:eq(2)").toHaveText("Mario"); |
| 52 |
expect("div[name='employee_id'] a").toHaveCount(0); |
| 53 |
|
| 54 |
|
| 55 |
await contains(".o_data_cell .o_m2o_avatar > img:eq(0)").click(); |
| 56 |
await waitFor(".o_avatar_card"); |
| 57 |
expect(".o_card_user_infos > span").toHaveText("Mario"); |
| 58 |
expect(".o_card_user_infos > a").toHaveText("[email protected]"); |
| 59 |
expect(".o_avatar_card_buttons button:eq(0)").toHaveText("Send message"); |
| 60 |
await contains(".o_avatar_card_buttons button:eq(0)").click(); |
| 61 |
await waitFor(".o-mail-ChatWindow"); |
| 62 |
await waitFor(".o-mail-ChatWindow-header:contains('Mario')"); |
| 63 |
|
| 64 |
|
| 65 |
await contains(".o_data_cell .o_m2o_avatar > img:eq(1)").click(); |
| 66 |
expect(".o_card_user_infos span").toHaveText("Luigi"); |
| 67 |
expect(".o_avatar_card").toHaveCount(1); |
| 68 |
expect(".o_avatar_card_buttons button:eq(0)").toHaveText("Send message"); |
| 69 |
await contains(".o_avatar_card_buttons button:eq(0)").click(); |
| 70 |
await waitFor(".o-mail-ChatWindow-header:contains('Luigi')"); |
| 71 |
expect(".o-mail-ChatWindow").toHaveCount(2); |
| 72 |
|
| 73 |
|
| 74 |
await contains(".o_data_cell .o_m2o_avatar > img:eq(2)").click(); |
| 75 |
expect(".o_card_user_infos span").toHaveText("Mario"); |
| 76 |
expect(".o_avatar_card").toHaveCount(1); |
| 77 |
expect(".o_card_user_infos span:eq(0)").toHaveText("Mario"); |
| 78 |
expect(".o_card_user_infos > a").toHaveText("[email protected]"); |
| 79 |
expect(".o_avatar_card_buttons button:eq(0)").toHaveText("Send message"); |
| 80 |
await contains(".o_avatar_card_buttons button:eq(0)").click(); |
| 81 |
await waitFor(".o-mail-ChatWindow-header:contains('Mario')"); |
| 82 |
expect(".o-mail-ChatWindow").toHaveCount(2); |
| 83 |
}); |
| 84 |
|
| 85 |
test("many2one in kanban view", async () => { |
| 86 |
const { env } = await makeMockServer(); |
| 87 |
const partnerId = env["res.partner"].create({}); |
| 88 |
const userId = env["res.users"].create({ partner_id: partnerId }); |
| 89 |
const employeeId = env["hr.employee.public"].create({ |
| 90 |
user_id: userId, |
| 91 |
user_partner_id: partnerId, |
| 92 |
}); |
| 93 |
env["m2x.avatar.employee"].create({ |
| 94 |
employee_id: employeeId, |
| 95 |
employee_ids: [employeeId], |
| 96 |
}); |
| 97 |
onRpc("has_group", () => false); |
| 98 |
await mountView({ |
| 99 |
type: "kanban", |
| 100 |
resModel: "m2x.avatar.employee", |
| 101 |
arch: `<kanban> |
| 102 |
<templates> |
| 103 |
<t t-name="card"> |
| 104 |
<field name="employee_id" widget="many2one_avatar_employee"/> |
| 105 |
</t> |
| 106 |
</templates> |
| 107 |
</kanban>`, |
| 108 |
}); |
| 109 |
expect(".o_kanban_record:eq(0)").toHaveText(""); |
| 110 |
await waitFor(".o_m2o_avatar"); |
| 111 |
expect(".o_m2o_avatar > img:eq(0)").toHaveAttribute( |
| 112 |
"data-src", |
| 113 |
`/web/image/hr.employee.public/${employeeId}/avatar_128` |
| 114 |
); |
| 115 |
}); |
| 116 |
|
| 117 |
test("many2one: click on an employee not associated with a user", async () => { |
| 118 |
const { env } = await makeMockServer(); |
| 119 |
const employeeId = env["hr.employee.public"].create({ name: "Mario" }); |
| 120 |
const avatarId = env["m2x.avatar.employee"].create({ employee_id: employeeId }); |
| 121 |
onRpc("has_group", () => false); |
| 122 |
await mountView({ |
| 123 |
type: "form", |
| 124 |
resModel: "m2x.avatar.employee", |
| 125 |
resId: avatarId, |
| 126 |
arch: `<form><field name="employee_id" widget="many2one_avatar_employee"/></form>`, |
| 127 |
}); |
| 128 |
await waitFor(".o_field_widget[name=employee_id] input:value(Mario)"); |
| 129 |
await contains(".o_m2o_avatar > img").click(); |
| 130 |
}); |
| 131 |
|
| 132 |
test("many2one with hr group widget in kanban view", async () => { |
| 133 |
const { env } = await makeMockServer(); |
| 134 |
const partnerId = env["res.partner"].create({}); |
| 135 |
const userId = env["res.users"].create({ partner_id: partnerId }); |
| 136 |
const employeeId = env["hr.employee.public"].create({ |
| 137 |
user_id: userId, |
| 138 |
user_partner_id: partnerId, |
| 139 |
}); |
| 140 |
env["m2x.avatar.employee"].create({ |
| 141 |
employee_id: employeeId, |
| 142 |
employee_ids: [employeeId], |
| 143 |
}); |
| 144 |
await mountView({ |
| 145 |
type: "kanban", |
| 146 |
resModel: "m2x.avatar.employee", |
| 147 |
arch: `<kanban> |
| 148 |
<templates> |
| 149 |
<t t-name="card"> |
| 150 |
<field name="employee_id" widget="many2one_avatar_employee"/> |
| 151 |
</t> |
| 152 |
</templates> |
| 153 |
</kanban>`, |
| 154 |
}); |
| 155 |
expect(".o_kanban_record:eq(0)").toHaveText(""); |
| 156 |
await waitFor(".o_m2o_avatar"); |
| 157 |
expect(".o_m2o_avatar > img:eq(0)").toHaveAttribute( |
| 158 |
"data-src", |
| 159 |
`/web/image/hr.employee/${employeeId}/avatar_128` |
| 160 |
); |
| 161 |
}); |
| 162 |
|
| 163 |
test("many2one with relation set in options", async () => { |
| 164 |
const { env } = await makeMockServer(); |
| 165 |
const partnerId = env["res.partner"].create({}); |
| 166 |
const userId = env["res.users"].create({ partner_id: partnerId }); |
| 167 |
const employeeId = env["hr.employee.public"].create({ |
| 168 |
user_id: userId, |
| 169 |
user_partner_id: partnerId, |
| 170 |
}); |
| 171 |
env["m2x.avatar.employee"].create({ |
| 172 |
employee_id: employeeId, |
| 173 |
employee_ids: [employeeId], |
| 174 |
}); |
| 175 |
await mountView({ |
| 176 |
type: "kanban", |
| 177 |
resModel: "m2x.avatar.employee", |
| 178 |
arch: `<kanban> |
| 179 |
<templates> |
| 180 |
<t t-name="card"> |
| 181 |
<field name="employee_id" widget="many2one_avatar_employee" options="{'relation': 'hr.employee.public'}"/> |
| 182 |
</t> |
| 183 |
</templates> |
| 184 |
</kanban>`, |
| 185 |
}); |
| 186 |
expect(".o_kanban_record:eq(0)").toHaveText(""); |
| 187 |
await waitFor(".o_m2o_avatar"); |
| 188 |
expect(".o_m2o_avatar > img:eq(0)").toHaveAttribute( |
| 189 |
"data-src", |
| 190 |
`/web/image/hr.employee.public/${employeeId}/avatar_128` |
| 191 |
); |
| 192 |
}); |
| 193 |
|
| 194 |
test("many2one without hr.group_hr_user", async () => { |
| 195 |
const { env } = await makeMockServer(); |
| 196 |
env["m2x.avatar.employee"].create({}); |
| 197 |
env["hr.employee"].create({ name: "babar" }); |
| 198 |
env["hr.employee.public"].create({ name: "babar" }); |
| 199 |
onRpc("web_name_search", (args) => { |
| 200 |
expect.step("web_name_search"); |
| 201 |
expect(args.model).toBe("hr.employee.public"); |
| 202 |
}); |
| 203 |
onRpc("web_search_read", (args) => { |
| 204 |
expect.step("web_search_read"); |
| 205 |
expect(args.model).toBe("hr.employee.public"); |
| 206 |
}); |
| 207 |
onRpc("has_group", () => false); |
| 208 |
await mountView({ |
| 209 |
type: "form", |
| 210 |
resModel: "m2x.avatar.employee", |
| 211 |
arch: `<form><field name="employee_id" widget="many2one_avatar_employee"/></form>`, |
| 212 |
}); |
| 213 |
|
| 214 |
await waitFor(".o-autocomplete--input.o_input"); |
| 215 |
await contains(".o-autocomplete--input.o_input").click(); |
| 216 |
expect.verifySteps(["web_name_search"]); |
| 217 |
|
| 218 |
await waitFor(".o_m2o_dropdown_option_search_more"); |
| 219 |
await contains(".o_m2o_dropdown_option_search_more").click(); |
| 220 |
expect.verifySteps(["web_search_read"]); |
| 221 |
}); |
| 222 |
|
| 223 |
test("many2one in form view", async () => { |
| 224 |
const { env } = await makeMockServer(); |
| 225 |
const [partnerId_1, partnerId_2] = env["res.partner"].create([ |
| 226 |
{ name: "Mario" }, |
| 227 |
{ name: "Luigi" }, |
| 228 |
]); |
| 229 |
const [userId_1, userId_2] = env["res.users"].create([ |
| 230 |
{ partner_id: partnerId_1 }, |
| 231 |
{ partner_id: partnerId_2 }, |
| 232 |
]); |
| 233 |
const [employeeId_1, employeeId_2] = env["hr.employee.public"].create([ |
| 234 |
{ |
| 235 |
user_id: userId_1, |
| 236 |
user_partner_id: partnerId_1, |
| 237 |
name: "Mario", |
| 238 |
work_email: "[email protected]", |
| 239 |
}, |
| 240 |
{ |
| 241 |
name: "Luigi", |
| 242 |
user_id: userId_2, |
| 243 |
user_partner_id: partnerId_2, |
| 244 |
}, |
| 245 |
]); |
| 246 |
const avatarId_1 = env["m2x.avatar.employee"].create({ |
| 247 |
employee_ids: [employeeId_1, employeeId_2], |
| 248 |
}); |
| 249 |
await start(); |
| 250 |
onRpc("has_group", () => false); |
| 251 |
await mountView({ |
| 252 |
type: "form", |
| 253 |
resId: avatarId_1, |
| 254 |
resModel: "m2x.avatar.employee", |
| 255 |
arch: `<form><field name="employee_ids" widget="many2many_avatar_employee"/></form>`, |
| 256 |
}); |
| 257 |
expect(".o_field_many2many_avatar_employee .o_tag").toHaveCount(2); |
| 258 |
expect(".o_field_many2many_avatar_employee .o_tag img:eq(0)").toHaveAttribute( |
| 259 |
"data-src", |
| 260 |
`${getOrigin()}/web/image/hr.employee.public/${employeeId_1}/avatar_128` |
| 261 |
); |
| 262 |
|
| 263 |
|
| 264 |
await contains(".o_field_many2many_avatar_employee .o_tag .o_m2m_avatar:eq(0)").click(); |
| 265 |
await waitFor(".o_avatar_card"); |
| 266 |
expect(".o_card_user_infos > span").toHaveText("Mario"); |
| 267 |
expect(".o_card_user_infos > a").toHaveText("[email protected]"); |
| 268 |
expect(".o_avatar_card_buttons button:eq(0)").toHaveText("Send message"); |
| 269 |
await contains(".o_avatar_card_buttons button:eq(0)").click(); |
| 270 |
await waitFor(".o-mail-ChatWindow"); |
| 271 |
await waitFor(".o-mail-ChatWindow-header:contains('Mario')"); |
| 272 |
|
| 273 |
|
| 274 |
await contains(".o_field_many2many_avatar_employee .o_tag .o_m2m_avatar:eq(1)").click(); |
| 275 |
expect(".o_card_user_infos span").toHaveText("Luigi"); |
| 276 |
expect(".o_avatar_card").toHaveCount(1); |
| 277 |
expect(".o_avatar_card_buttons button:eq(0)").toHaveText("Send message"); |
| 278 |
await contains(".o_avatar_card_buttons button:eq(0)").click(); |
| 279 |
await waitFor(".o-mail-ChatWindow-header:contains('Luigi')"); |
| 280 |
expect(".o-mail-ChatWindow").toHaveCount(2); |
| 281 |
}); |
| 282 |
|
| 283 |
test("many2one with hr group widget in form view", async () => { |
| 284 |
const { env } = await makeMockServer(); |
| 285 |
const [partnerId_1, partnerId_2] = env["res.partner"].create([{}, {}]); |
| 286 |
const [userId_1, userId_2] = env["res.users"].create([ |
| 287 |
{ partner_id: partnerId_1 }, |
| 288 |
{ partner_id: partnerId_2 }, |
| 289 |
]); |
| 290 |
const [employeeData_1, employeeData_2] = [ |
| 291 |
{ user_id: userId_1, user_partner_id: partnerId_1 }, |
| 292 |
{ user_id: userId_2, user_partner_id: partnerId_2 }, |
| 293 |
]; |
| 294 |
env["hr.employee"].create([{ ...employeeData_1 }, { ...employeeData_2 }]); |
| 295 |
const [employeeId_1, employeeId_2] = env["hr.employee.public"].create([ |
| 296 |
{ ...employeeData_1 }, |
| 297 |
{ ...employeeData_2 }, |
| 298 |
]); |
| 299 |
const avatarId_1 = env["m2x.avatar.employee"].create({ |
| 300 |
employee_ids: [employeeId_1, employeeId_2], |
| 301 |
}); |
| 302 |
expect.step(`read hr.employee ${employeeId_1}`); |
| 303 |
expect.step(`read hr.employee ${employeeId_2}`); |
| 304 |
await mountView({ |
| 305 |
type: "form", |
| 306 |
resId: avatarId_1, |
| 307 |
resModel: "m2x.avatar.employee", |
| 308 |
arch: `<form><field name="employee_ids" widget="many2many_avatar_employee"/></form>`, |
| 309 |
}); |
| 310 |
expect(".o_field_many2many_avatar_employee .o_tag").toHaveCount(2); |
| 311 |
expect(".o_field_many2many_avatar_employee .o_tag img:eq(0)").toHaveAttribute( |
| 312 |
"data-src", |
| 313 |
`${getOrigin()}/web/image/hr.employee/${employeeId_1}/avatar_128` |
| 314 |
); |
| 315 |
await contains(".o_field_many2many_avatar_employee .o_tag .o_m2m_avatar:eq(0)").click(); |
| 316 |
await contains(".o_field_many2many_avatar_employee .o_tag .o_m2m_avatar:eq(1)").click(); |
| 317 |
expect.verifySteps([ |
| 318 |
`read hr.employee ${employeeId_1}`, |
| 319 |
`read hr.employee ${employeeId_2}`, |
| 320 |
]); |
| 321 |
}); |
| 322 |
|
| 323 |
test("many2one widget in list view", async () => { |
| 324 |
const { env } = await makeMockServer(); |
| 325 |
const [partnerId_1, partnerId_2] = env["res.partner"].create([ |
| 326 |
{ name: "Mario" }, |
| 327 |
{ name: "Yoshi" }, |
| 328 |
]); |
| 329 |
const [userId_1, userId_2] = env["res.users"].create([ |
| 330 |
{ partner_id: partnerId_1 }, |
| 331 |
{ partner_id: partnerId_2 }, |
| 332 |
]); |
| 333 |
const [employeeId_1, employeeId_2] = env["hr.employee.public"].create([ |
| 334 |
{ |
| 335 |
name: "Mario", |
| 336 |
user_id: userId_1, |
| 337 |
user_partner_id: partnerId_1, |
| 338 |
work_email: "[email protected]", |
| 339 |
}, |
| 340 |
{ |
| 341 |
name: "Yoshi", |
| 342 |
user_id: userId_2, |
| 343 |
user_partner_id: partnerId_2, |
| 344 |
}, |
| 345 |
]); |
| 346 |
env["m2x.avatar.employee"].create({ |
| 347 |
employee_ids: [employeeId_1, employeeId_2], |
| 348 |
}); |
| 349 |
onRpc("has_group", () => false); |
| 350 |
await start(); |
| 351 |
await mountView({ |
| 352 |
type: "list", |
| 353 |
resModel: "m2x.avatar.employee", |
| 354 |
arch: `<list><field name="employee_ids" widget="many2many_avatar_employee"/></list>`, |
| 355 |
}); |
| 356 |
expect(".o_data_cell:first .o_field_many2many_avatar_employee > div > span").toHaveCount(2); |
| 357 |
|
| 358 |
|
| 359 |
await contains(".o_data_cell .o_m2m_avatar:eq(0)").click(); |
| 360 |
await waitFor(".o_avatar_card"); |
| 361 |
expect(".o_card_user_infos > span").toHaveText("Mario"); |
| 362 |
expect(".o_card_user_infos > a").toHaveText("[email protected]"); |
| 363 |
expect(".o_avatar_card_buttons button:eq(0)").toHaveText("Send message"); |
| 364 |
await contains(".o_avatar_card_buttons button:eq(0)").click(); |
| 365 |
await waitFor(".o-mail-ChatWindow"); |
| 366 |
await waitFor(".o-mail-ChatWindow-header:contains('Mario')"); |
| 367 |
|
| 368 |
|
| 369 |
await contains(".o_data_cell .o_m2m_avatar:eq(1)").click(); |
| 370 |
expect(".o_card_user_infos span").toHaveText("Yoshi"); |
| 371 |
expect(".o_avatar_card").toHaveCount(1); |
| 372 |
expect(".o_avatar_card_buttons button:eq(0)").toHaveText("Send message"); |
| 373 |
await contains(".o_avatar_card_buttons button:eq(0)").click(); |
| 374 |
await waitFor(".o-mail-ChatWindow-header:contains('Yoshi')"); |
| 375 |
}); |
| 376 |
|
| 377 |
test("many2many in kanban view", async () => { |
| 378 |
const { env } = await makeMockServer(); |
| 379 |
const [partnerId_1, partnerId_2] = env["res.partner"].create([ |
| 380 |
{ name: "Mario" }, |
| 381 |
{ name: "Luigi" }, |
| 382 |
]); |
| 383 |
const [userId_1, userId_2] = env["res.users"].create([ |
| 384 |
{ partner_id: partnerId_1 }, |
| 385 |
{ partner_id: partnerId_2 }, |
| 386 |
]); |
| 387 |
const [employeeId_1, employeeId_2] = env["hr.employee.public"].create([ |
| 388 |
{ |
| 389 |
user_id: userId_1, |
| 390 |
user_partner_id: partnerId_1, |
| 391 |
name: "Mario", |
| 392 |
work_email: "[email protected]", |
| 393 |
}, |
| 394 |
{ |
| 395 |
name: "Luigi", |
| 396 |
user_id: userId_2, |
| 397 |
user_partner_id: partnerId_2, |
| 398 |
}, |
| 399 |
]); |
| 400 |
env["m2x.avatar.employee"].create({ |
| 401 |
employee_ids: [employeeId_1, employeeId_2], |
| 402 |
}); |
| 403 |
onRpc("has_group", () => false); |
| 404 |
await start(); |
| 405 |
await mountView({ |
| 406 |
type: "kanban", |
| 407 |
resModel: "m2x.avatar.employee", |
| 408 |
arch: `<kanban> |
| 409 |
<templates> |
| 410 |
<t t-name="card"> |
| 411 |
<footer> |
| 412 |
<field name="employee_ids" widget="many2many_avatar_employee"/> |
| 413 |
</footer> |
| 414 |
</t> |
| 415 |
</templates> |
| 416 |
</kanban>`, |
| 417 |
}); |
| 418 |
expect( |
| 419 |
".o_kanban_record:first .o_field_many2many_avatar_employee img.o_m2m_avatar" |
| 420 |
).toHaveCount(2); |
| 421 |
expect( |
| 422 |
".o_kanban_record .o_field_many2many_avatar_employee img.o_m2m_avatar:eq(0)" |
| 423 |
).toHaveAttribute( |
| 424 |
"data-src", |
| 425 |
`${getOrigin()}/web/image/hr.employee.public/${employeeId_2}/avatar_128` |
| 426 |
); |
| 427 |
expect( |
| 428 |
".o_kanban_record .o_field_many2many_avatar_employee img.o_m2m_avatar:eq(1)" |
| 429 |
).toHaveAttribute( |
| 430 |
"data-src", |
| 431 |
`${getOrigin()}/web/image/hr.employee.public/${employeeId_1}/avatar_128` |
| 432 |
); |
| 433 |
|
| 434 |
|
| 435 |
await contains(".o_kanban_record img.o_m2m_avatar:eq(1)").click(); |
| 436 |
await waitFor(".o_avatar_card"); |
| 437 |
expect(".o_card_user_infos > span").toHaveText("Mario"); |
| 438 |
expect(".o_card_user_infos > a").toHaveText("[email protected]"); |
| 439 |
expect(".o_avatar_card_buttons button:eq(0)").toHaveText("Send message"); |
| 440 |
await contains(".o_avatar_card_buttons button:eq(0)").click(); |
| 441 |
await waitFor(".o-mail-ChatWindow"); |
| 442 |
await waitFor(".o-mail-ChatWindow-header:contains('Mario')"); |
| 443 |
|
| 444 |
|
| 445 |
await contains(".o_kanban_record img.o_m2m_avatar:eq(0)").click(); |
| 446 |
expect(".o_card_user_infos span").toHaveText("Luigi"); |
| 447 |
expect(".o_avatar_card").toHaveCount(1); |
| 448 |
expect(".o_avatar_card_buttons button:eq(0)").toHaveText("Send message"); |
| 449 |
await contains(".o_avatar_card_buttons button:eq(0)").click(); |
| 450 |
await waitFor(".o-mail-ChatWindow-header:contains('Luigi')"); |
| 451 |
expect(".o-mail-ChatWindow").toHaveCount(2); |
| 452 |
}); |
| 453 |
|
| 454 |
test("many2many: click on an employee not associated with a user", async () => { |
| 455 |
const { env } = await makeMockServer(); |
| 456 |
const partnerId = env["res.partner"].create({ name: "Luigi" }); |
| 457 |
const userId = env["res.users"].create({ partner_id: partnerId }); |
| 458 |
const [employeeId_1, employeeId_2] = env["hr.employee.public"].create([ |
| 459 |
{ |
| 460 |
name: "Mario", |
| 461 |
work_email: "[email protected]", |
| 462 |
}, |
| 463 |
{ |
| 464 |
name: "Luigi", |
| 465 |
user_id: userId, |
| 466 |
user_partner_id: partnerId, |
| 467 |
}, |
| 468 |
]); |
| 469 |
const avatarId = env["m2x.avatar.employee"].create({ |
| 470 |
employee_ids: [employeeId_1, employeeId_2], |
| 471 |
}); |
| 472 |
onRpc("has_group", () => false); |
| 473 |
await start(); |
| 474 |
await mountView({ |
| 475 |
type: "form", |
| 476 |
resModel: "m2x.avatar.employee", |
| 477 |
resId: avatarId, |
| 478 |
arch: `<form><field name="employee_ids" widget="many2many_avatar_employee"/></form>`, |
| 479 |
}); |
| 480 |
expect(".o_field_many2many_avatar_employee .o_tag").toHaveCount(2); |
| 481 |
expect(".o_field_many2many_avatar_employee .o_tag img:eq(0)").toHaveAttribute( |
| 482 |
"data-src", |
| 483 |
`${getOrigin()}/web/image/hr.employee.public/${employeeId_1}/avatar_128` |
| 484 |
); |
| 485 |
|
| 486 |
|
| 487 |
await contains(".o_field_many2many_avatar_employee .o_tag .o_m2m_avatar:eq(0)").click(); |
| 488 |
await waitFor(".o_avatar_card"); |
| 489 |
expect(".o_card_user_infos > span").toHaveText("Mario"); |
| 490 |
expect(".o_card_user_infos > a").toHaveText("[email protected]"); |
| 491 |
expect(".o_avatar_card_buttons button:eq(0)").toHaveText("View Profile"); |
| 492 |
|
| 493 |
|
| 494 |
await contains(".o_field_many2many_avatar_employee .o_tag .o_m2m_avatar:eq(1)").click(); |
| 495 |
expect(".o_card_user_infos span").toHaveText("Luigi"); |
| 496 |
expect(".o_avatar_card").toHaveCount(1); |
| 497 |
expect(".o_avatar_card_buttons button:eq(0)").toHaveText("Send message"); |
| 498 |
await contains(".o_avatar_card_buttons button:eq(0)").click(); |
| 499 |
await waitFor(".o-mail-ChatWindow-header:contains('Luigi')"); |
| 500 |
expect(".o-mail-ChatWindow").toHaveCount(1); |
| 501 |
}); |