| 1 |
import { expect, resize, test } from "@odoo/hoot"; |
| 2 |
import { |
| 3 |
click, |
| 4 |
Deferred, |
| 5 |
edit, |
| 6 |
press, |
| 7 |
queryAll, |
| 8 |
queryAllTexts, |
| 9 |
queryAttribute, |
| 10 |
queryFirst, |
| 11 |
} from "@odoo/hoot-dom"; |
| 12 |
import { animationFrame, runAllTimers } from "@odoo/hoot-mock"; |
| 13 |
import { |
| 14 |
contains, |
| 15 |
clickSave, |
| 16 |
defineActions, |
| 17 |
defineModels, |
| 18 |
fields, |
| 19 |
getDropdownMenu, |
| 20 |
getService, |
| 21 |
models, |
| 22 |
mockService, |
| 23 |
mountView, |
| 24 |
mountWithCleanup, |
| 25 |
onRpc, |
| 26 |
serverState, |
| 27 |
pagerNext, |
| 28 |
pagerPrevious, |
| 29 |
} from "@web/../tests/web_test_helpers"; |
| 30 |
import { EventBus } from "@odoo/owl"; |
| 31 |
import { WebClient } from "@web/webclient/webclient"; |
| 32 |
|
| 33 |
class Partner extends models.Model { |
| 34 |
name = fields.Char(); |
| 35 |
foo = fields.Char({ default: "My little Foo Value" }); |
| 36 |
bar = fields.Boolean({ default: true }); |
| 37 |
int_field = fields.Integer(); |
| 38 |
qux = fields.Float({ digits: [16, 1] }); |
| 39 |
p = fields.One2many({ |
| 40 |
relation: "partner", |
| 41 |
relation_field: "trululu", |
| 42 |
}); |
| 43 |
trululu = fields.Many2one({ relation: "partner" }); |
| 44 |
product_id = fields.Many2one({ relation: "product" }); |
| 45 |
color = fields.Selection({ |
| 46 |
selection: [ |
| 47 |
["red", "Red"], |
| 48 |
["black", "Black"], |
| 49 |
], |
| 50 |
default: "red", |
| 51 |
}); |
| 52 |
user_id = fields.Many2one({ relation: "users" }); |
| 53 |
|
| 54 |
_records = [ |
| 55 |
{ |
| 56 |
id: 1, |
| 57 |
name: "first record", |
| 58 |
bar: true, |
| 59 |
foo: "yop", |
| 60 |
int_field: 10, |
| 61 |
qux: 0.44, |
| 62 |
p: [], |
| 63 |
trululu: 4, |
| 64 |
user_id: 17, |
| 65 |
}, |
| 66 |
{ |
| 67 |
id: 2, |
| 68 |
name: "second record", |
| 69 |
bar: true, |
| 70 |
foo: "blip", |
| 71 |
int_field: 9, |
| 72 |
qux: 13, |
| 73 |
p: [], |
| 74 |
trululu: 1, |
| 75 |
product_id: 37, |
| 76 |
user_id: 17, |
| 77 |
}, |
| 78 |
{ id: 4, name: "aaa", bar: false }, |
| 79 |
]; |
| 80 |
} |
| 81 |
|
| 82 |
class Product extends models.Model { |
| 83 |
name = fields.Char(); |
| 84 |
|
| 85 |
_records = [ |
| 86 |
{ id: 37, name: "xphone" }, |
| 87 |
{ id: 41, name: "xpad" }, |
| 88 |
]; |
| 89 |
} |
| 90 |
|
| 91 |
class Users extends models.Model { |
| 92 |
name = fields.Char(); |
| 93 |
partner_ids = fields.One2many({ |
| 94 |
relation: "partner", |
| 95 |
relation_field: "user_id", |
| 96 |
}); |
| 97 |
|
| 98 |
_records = [ |
| 99 |
{ id: 17, name: "Aline", partner_ids: [1, 2] }, |
| 100 |
{ id: 19, name: "Christine" }, |
| 101 |
]; |
| 102 |
} |
| 103 |
|
| 104 |
defineModels([Partner, Product, Users]); |
| 105 |
|
| 106 |
test("static statusbar widget on many2one field", async () => { |
| 107 |
Partner._fields.trululu = fields.Many2one({ |
| 108 |
relation: "partner", |
| 109 |
domain: "[('bar', '=', True)]", |
| 110 |
}); |
| 111 |
Partner._records[1].bar = false; |
| 112 |
|
| 113 |
onRpc("search_read", ({ kwargs }) => expect.step(kwargs.fields.toString())); |
| 114 |
await mountView({ |
| 115 |
type: "form", |
| 116 |
resModel: "partner", |
| 117 |
resId: 1, |
| 118 |
arch: /* xml */ ` |
| 119 |
<form> |
| 120 |
<header> |
| 121 |
<field name="trululu" widget="statusbar" /> |
| 122 |
</header> |
| 123 |
</form> |
| 124 |
`, |
| 125 |
}); |
| 126 |
// search_read should only fetch field display_name |
| 127 |
expect.verifySteps(["display_name"]); |
| 128 |
expect(".o_statusbar_status button:not(.dropdown-toggle)").toHaveCount(2); |
| 129 |
expect(".o_statusbar_status button:disabled").toHaveCount(5); |
| 130 |
expect('.o_statusbar_status button[data-value="4"]').toHaveClass("o_arrow_button_current"); |
| 131 |
}); |
| 132 |
|
| 133 |
test("folded statusbar widget on selection field has selected value in the toggler", async () => { |
| 134 |
mockService("ui", (env) => { |
| 135 |
Object.defineProperty(env, "isSmall", { |
| 136 |
value: true, |
| 137 |
}); |
| 138 |
return { |
| 139 |
bus: new EventBus(), |
| 140 |
size: 0, |
| 141 |
isSmall: true, |
| 142 |
}; |
| 143 |
}); |
| 144 |
await mountView({ |
| 145 |
type: "form", |
| 146 |
resModel: "partner", |
| 147 |
resId: 1, |
| 148 |
arch: /* xml */ ` |
| 149 |
<form> |
| 150 |
<header> |
| 151 |
<field name="color" widget="statusbar" /> |
| 152 |
</header> |
| 153 |
</form> |
| 154 |
`, |
| 155 |
}); |
| 156 |
|
| 157 |
expect(".o_statusbar_status button.dropdown-toggle:contains(Red)").toHaveCount(1); |
| 158 |
}); |
| 159 |
|
| 160 |
test("static statusbar widget on many2one field with domain", async () => { |
| 161 |
expect.assertions(1); |
| 162 |
|
| 163 |
serverState.userId = 17; |
| 164 |
|
| 165 |
onRpc("search_read", ({ kwargs }) => { |
| 166 |
expect(kwargs.domain).toEqual(["|", ["id", "=", 4], ["user_id", "=", 17]], { |
| 167 |
message: "search_read should sent the correct domain", |
| 168 |
}); |
| 169 |
}); |
| 170 |
await mountView({ |
| 171 |
type: "form", |
| 172 |
resModel: "partner", |
| 173 |
resId: 1, |
| 174 |
arch: /* xml */ ` |
| 175 |
<form> |
| 176 |
<header> |
| 177 |
<field name="trululu" widget="statusbar" domain="[('user_id', '=', uid)]" /> |
| 178 |
</header> |
| 179 |
</form> |
| 180 |
`, |
| 181 |
}); |
| 182 |
}); |
| 183 |
|
| 184 |
test("clickable statusbar widget on many2one field", async () => { |
| 185 |
await mountView({ |
| 186 |
type: "form", |
| 187 |
resModel: "partner", |
| 188 |
resId: 1, |
| 189 |
arch: /* xml */ ` |
| 190 |
<form> |
| 191 |
<header> |
| 192 |
<field name="trululu" widget="statusbar" options="{'clickable': 1}" /> |
| 193 |
</header> |
| 194 |
</form> |
| 195 |
`, |
| 196 |
}); |
| 197 |
|
| 198 |
expect(".o_statusbar_status button[data-value='4']").toHaveClass("o_arrow_button_current"); |
| 199 |
expect(".o_statusbar_status button[data-value='4']").not.toBeEnabled(); |
| 200 |
|
| 201 |
expect( |
| 202 |
".o_statusbar_status button.btn:not(.dropdown-toggle):not(:disabled):not(.o_arrow_button_current)" |
| 203 |
).toHaveCount(2); |
| 204 |
|
| 205 |
await click( |
| 206 |
".o_statusbar_status button.btn:not(.dropdown-toggle):not(:disabled):not(.o_arrow_button_current):eq(1)" |
| 207 |
); |
| 208 |
await animationFrame(); |
| 209 |
|
| 210 |
expect(".o_statusbar_status button[data-value='1']").toHaveClass("o_arrow_button_current"); |
| 211 |
expect(".o_statusbar_status button[data-value='1']").not.toBeEnabled(); |
| 212 |
}); |
| 213 |
|
| 214 |
test("statusbar with no status", async () => { |
| 215 |
Partner._records[1].product_id = false; |
| 216 |
Product._records = []; |
| 217 |
await mountView({ |
| 218 |
type: "form", |
| 219 |
resModel: "partner", |
| 220 |
resId: 1, |
| 221 |
arch: /* xml */ ` |
| 222 |
<form> |
| 223 |
<header> |
| 224 |
<field name="product_id" widget="statusbar" /> |
| 225 |
</header> |
| 226 |
</form> |
| 227 |
`, |
| 228 |
}); |
| 229 |
|
| 230 |
expect(".o_statusbar_status").not.toHaveClass("o_field_empty"); |
| 231 |
expect(".o_statusbar_status > :not(.d-none)").toHaveCount(0, { |
| 232 |
message: "statusbar widget should be empty", |
| 233 |
}); |
| 234 |
}); |
| 235 |
|
| 236 |
test("statusbar with tooltip for help text", async () => { |
| 237 |
Partner._fields.product_id = fields.Many2one({ |
| 238 |
relation: "product", |
| 239 |
help: "some info about the field", |
| 240 |
}); |
| 241 |
await mountView({ |
| 242 |
type: "form", |
| 243 |
resModel: "partner", |
| 244 |
resId: 1, |
| 245 |
arch: /* xml */ ` |
| 246 |
<form> |
| 247 |
<header> |
| 248 |
<field name="product_id" widget="statusbar" /> |
| 249 |
</header> |
| 250 |
</form> |
| 251 |
`, |
| 252 |
}); |
| 253 |
|
| 254 |
expect(".o_statusbar_status").not.toHaveClass("o_field_empty"); |
| 255 |
expect(".o_field_statusbar").toHaveAttribute("data-tooltip-info"); |
| 256 |
const tooltipInfo = JSON.parse(queryAttribute(".o_field_statusbar", "data-tooltip-info")); |
| 257 |
expect(tooltipInfo.field.help).toBe("some info about the field", { |
| 258 |
message: "tooltip text is present on the field", |
| 259 |
}); |
| 260 |
}); |
| 261 |
|
| 262 |
test("statusbar with required modifier", async () => { |
| 263 |
mockService("notification", { |
| 264 |
add() { |
| 265 |
expect.step("Show error message"); |
| 266 |
return () => {}; |
| 267 |
}, |
| 268 |
}); |
| 269 |
await mountView({ |
| 270 |
type: "form", |
| 271 |
resModel: "partner", |
| 272 |
arch: /* xml */ ` |
| 273 |
<form> |
| 274 |
<header> |
| 275 |
<field name="product_id" widget="statusbar" required="1"/> |
| 276 |
</header> |
| 277 |
</form> |
| 278 |
`, |
| 279 |
}); |
| 280 |
|
| 281 |
await click(".o_form_button_save"); |
| 282 |
await animationFrame(); |
| 283 |
|
| 284 |
expect(".o_form_editable").toHaveCount(1, { message: "view should still be in edit" }); |
| 285 |
// should display an 'invalid fields' notificationaveCount(1, { message: "view should still be in edit" }); |
| 286 |
expect.verifySteps(["Show error message"]); |
| 287 |
}); |
| 288 |
|
| 289 |
test.tags("desktop"); |
| 290 |
test("statusbar with no value in readonly on desktop", async () => { |
| 291 |
await mountView({ |
| 292 |
type: "form", |
| 293 |
resModel: "partner", |
| 294 |
resId: 1, |
| 295 |
arch: /* xml */ ` |
| 296 |
<form> |
| 297 |
<header> |
| 298 |
<field name="product_id" widget="statusbar" /> |
| 299 |
</header> |
| 300 |
</form> |
| 301 |
`, |
| 302 |
}); |
| 303 |
|
| 304 |
expect(".o_statusbar_status").not.toHaveClass("o_field_empty"); |
| 305 |
expect(".o_statusbar_status button:visible").toHaveCount(2); |
| 306 |
}); |
| 307 |
|
| 308 |
test.tags("mobile"); |
| 309 |
test("statusbar with no value in readonly on mobile", async () => { |
| 310 |
await mountView({ |
| 311 |
type: "form", |
| 312 |
resModel: "partner", |
| 313 |
resId: 1, |
| 314 |
arch: /* xml */ ` |
| 315 |
<form> |
| 316 |
<header> |
| 317 |
<field name="product_id" widget="statusbar" /> |
| 318 |
</header> |
| 319 |
</form> |
| 320 |
`, |
| 321 |
}); |
| 322 |
|
| 323 |
expect(".o_statusbar_status").not.toHaveClass("o_field_empty"); |
| 324 |
expect(".o_statusbar_status .dropdown-toggle:visible").toHaveCount(1); |
| 325 |
}); |
| 326 |
|
| 327 |
test("statusbar with domain but no value (create mode)", async () => { |
| 328 |
Partner._fields.trululu = fields.Many2one({ |
| 329 |
relation: "partner", |
| 330 |
domain: "[('bar', '=', True)]", |
| 331 |
}); |
| 332 |
|
| 333 |
await mountView({ |
| 334 |
type: "form", |
| 335 |
resModel: "partner", |
| 336 |
arch: /* xml */ ` |
| 337 |
<form> |
| 338 |
<header> |
| 339 |
<field name="trululu" widget="statusbar" /> |
| 340 |
</header> |
| 341 |
</form> |
| 342 |
`, |
| 343 |
}); |
| 344 |
|
| 345 |
expect(".o_statusbar_status button:disabled").toHaveCount(5); |
| 346 |
}); |
| 347 |
|
| 348 |
test("clickable statusbar should change m2o fetching domain in edit mode", async () => { |
| 349 |
Partner._fields.trululu = fields.Many2one({ |
| 350 |
relation: "partner", |
| 351 |
domain: "[('bar', '=', True)]", |
| 352 |
}); |
| 353 |
|
| 354 |
await mountView({ |
| 355 |
type: "form", |
| 356 |
resModel: "partner", |
| 357 |
resId: 1, |
| 358 |
arch: /* xml */ ` |
| 359 |
<form> |
| 360 |
<header> |
| 361 |
<field name="trululu" widget="statusbar" options="{'clickable': 1}" /> |
| 362 |
</header> |
| 363 |
</form> |
| 364 |
`, |
| 365 |
}); |
| 366 |
|
| 367 |
expect(".o_statusbar_status button:not(.dropdown-toggle)").toHaveCount(3); |
| 368 |
await click(".o_statusbar_status button:not(.dropdown-toggle):eq(-1)"); |
| 369 |
await animationFrame(); |
| 370 |
expect(".o_statusbar_status button:not(.dropdown-toggle)").toHaveCount(2); |
| 371 |
}); |
| 372 |
|
| 373 |
test.tags("desktop"); |
| 374 |
test("statusbar fold_field option and statusbar_visible attribute on desktop", async () => { |
| 375 |
Partner._records[0].bar = false; |
| 376 |
|
| 377 |
await mountView({ |
| 378 |
type: "form", |
| 379 |
resModel: "partner", |
| 380 |
resId: 1, |
| 381 |
arch: /* xml */ ` |
| 382 |
<form> |
| 383 |
<header> |
| 384 |
<field name="trululu" widget="statusbar" options="{'fold_field': 'bar'}" /> |
| 385 |
<field name="color" widget="statusbar" statusbar_visible="red" /> |
| 386 |
</header> |
| 387 |
</form> |
| 388 |
`, |
| 389 |
}); |
| 390 |
|
| 391 |
await click(".o_statusbar_status .dropdown-toggle:not(.d-none)"); |
| 392 |
await animationFrame(); |
| 393 |
|
| 394 |
expect(".o_statusbar_status:first button:visible").toHaveCount(3); |
| 395 |
expect(".o_statusbar_status:last button:visible").toHaveCount(1); |
| 396 |
expect(".o_statusbar_status button").not.toBeEnabled({ |
| 397 |
message: "no status bar buttons should be enabled", |
| 398 |
}); |
| 399 |
}); |
| 400 |
|
| 401 |
test.tags("mobile"); |
| 402 |
test("statusbar fold_field option and statusbar_visible attribute on mobile", async () => { |
| 403 |
Partner._records[0].bar = false; |
| 404 |
|
| 405 |
await mountView({ |
| 406 |
type: "form", |
| 407 |
resModel: "partner", |
| 408 |
resId: 1, |
| 409 |
arch: /* xml */ ` |
| 410 |
<form> |
| 411 |
<header> |
| 412 |
<field name="trululu" widget="statusbar" options="{'fold_field': 'bar'}" /> |
| 413 |
<field name="color" widget="statusbar" statusbar_visible="red" /> |
| 414 |
</header> |
| 415 |
</form> |
| 416 |
`, |
| 417 |
}); |
| 418 |
|
| 419 |
await click(".o_statusbar_status .dropdown-toggle:not(.d-none)"); |
| 420 |
await animationFrame(); |
| 421 |
|
| 422 |
expect(".o_statusbar_status:first .dropdown-toggle:visible").toHaveCount(1); |
| 423 |
expect(".o_statusbar_status:last .dropdown-toggle:visible").toHaveCount(1); |
| 424 |
expect(".o_statusbar_status button").not.toBeEnabled({ |
| 425 |
message: "no status bar buttons should be enabled", |
| 426 |
}); |
| 427 |
}); |
| 428 |
|
| 429 |
test.tags("desktop"); |
| 430 |
test("statusbar: choose an item from the folded menu on desktop", async () => { |
| 431 |
Partner._records[0].bar = false; |
| 432 |
|
| 433 |
await mountView({ |
| 434 |
type: "form", |
| 435 |
resModel: "partner", |
| 436 |
resId: 1, |
| 437 |
arch: /* xml */ ` |
| 438 |
<form> |
| 439 |
<header> |
| 440 |
<field name="trululu" widget="statusbar" options="{'clickable': '1', 'fold_field': 'bar'}" /> |
| 441 |
</header> |
| 442 |
</form> |
| 443 |
`, |
| 444 |
}); |
| 445 |
|
| 446 |
expect("[aria-checked='true']").toHaveText("aaa", { |
| 447 |
message: "default status is 'aaa'", |
| 448 |
}); |
| 449 |
|
| 450 |
expect(".o_statusbar_status .dropdown-toggle.o_arrow_button").toHaveText("...", { |
| 451 |
message: "button has the correct text", |
| 452 |
}); |
| 453 |
|
| 454 |
await click(".o_statusbar_status .dropdown-toggle:not(.d-none)"); |
| 455 |
await animationFrame(); |
| 456 |
await click(".o-dropdown--menu .dropdown-item"); |
| 457 |
await animationFrame(); |
| 458 |
|
| 459 |
expect("[aria-checked='true']").toHaveText("second record", { |
| 460 |
message: "status has changed to the selected dropdown item", |
| 461 |
}); |
| 462 |
}); |
| 463 |
|
| 464 |
test.tags("mobile"); |
| 465 |
test("statusbar: choose an item from the folded menu on mobile", async () => { |
| 466 |
Partner._records[0].bar = false; |
| 467 |
|
| 468 |
await mountView({ |
| 469 |
type: "form", |
| 470 |
resModel: "partner", |
| 471 |
resId: 1, |
| 472 |
arch: /* xml */ ` |
| 473 |
<form> |
| 474 |
<header> |
| 475 |
<field name="trululu" widget="statusbar" options="{'clickable': '1', 'fold_field': 'bar'}" /> |
| 476 |
</header> |
| 477 |
</form> |
| 478 |
`, |
| 479 |
}); |
| 480 |
|
| 481 |
expect("[aria-checked='true']").toHaveText("aaa", { |
| 482 |
message: "default status is 'aaa'", |
| 483 |
}); |
| 484 |
|
| 485 |
expect(".o_statusbar_status .dropdown-toggle:visible").toHaveText("aaa", { |
| 486 |
message: "button has the correct text", |
| 487 |
}); |
| 488 |
|
| 489 |
await click(".o_statusbar_status .dropdown-toggle:not(.d-none)"); |
| 490 |
await animationFrame(); |
| 491 |
await click(".o-dropdown--menu .dropdown-item:nth-child(2)"); |
| 492 |
await animationFrame(); |
| 493 |
|
| 494 |
expect("[aria-checked='true']").toHaveText("second record", { |
| 495 |
message: "status has changed to the selected dropdown item", |
| 496 |
}); |
| 497 |
}); |
| 498 |
|
| 499 |
test("statusbar with dynamic domain", async () => { |
| 500 |
Partner._fields.trululu = fields.Many2one({ |
| 501 |
relation: "partner", |
| 502 |
domain: "[('int_field', '>', qux)]", |
| 503 |
}); |
| 504 |
Partner._records[2].int_field = 0; |
| 505 |
onRpc("search_read", () => { |
| 506 |
rpcCount++; |
| 507 |
}); |
| 508 |
let rpcCount = 0; |
| 509 |
await mountView({ |
| 510 |
type: "form", |
| 511 |
resModel: "partner", |
| 512 |
resId: 1, |
| 513 |
arch: /* xml */ ` |
| 514 |
<form> |
| 515 |
<header> |
| 516 |
<field name="trululu" widget="statusbar" /> |
| 517 |
</header> |
| 518 |
<field name="qux" /> |
| 519 |
<field name="foo" /> |
| 520 |
</form> |
| 521 |
`, |
| 522 |
}); |
| 523 |
|
| 524 |
expect(".o_statusbar_status button:disabled").toHaveCount(6); |
| 525 |
expect(rpcCount).toBe(1, { message: "should have done 1 search_read rpc" }); |
| 526 |
await click(".o_field_widget[name='qux'] input"); |
| 527 |
await edit(9.5, { confirm: "enter" }); |
| 528 |
await runAllTimers(); |
| 529 |
await animationFrame(); |
| 530 |
expect(".o_statusbar_status button:disabled").toHaveCount(5); |
| 531 |
expect(rpcCount).toBe(2, { message: "should have done 1 more search_read rpc" }); |
| 532 |
await edit("hey", { confirm: "enter" }); |
| 533 |
await animationFrame(); |
| 534 |
expect(rpcCount).toBe(2, { message: "should not have done 1 more search_read rpc" }); |
| 535 |
}); |
| 536 |
|
| 537 |
test(`statusbar edited by the smart action "Move to stage..."`, async () => { |
| 538 |
await mountView({ |
| 539 |
type: "form", |
| 540 |
resModel: "partner", |
| 541 |
arch: /* xml */ ` |
| 542 |
<form> |
| 543 |
<header> |
| 544 |
<field name="trululu" widget="statusbar" options="{'clickable': '1'}"/> |
| 545 |
</header> |
| 546 |
</form> |
| 547 |
`, |
| 548 |
resId: 1, |
| 549 |
}); |
| 550 |
|
| 551 |
expect(".o_field_widget").toHaveCount(1); |
| 552 |
|
| 553 |
await press(["control", "k"]); |
| 554 |
await animationFrame(); |
| 555 |
await click(`.o_command:contains("Move to Trululu")`); |
| 556 |
await animationFrame(); |
| 557 |
expect(queryAllTexts(".o_command")).toEqual(["first record", "second record", "aaa"]); |
| 558 |
await click("#o_command_2"); |
| 559 |
await animationFrame(); |
| 560 |
}); |
| 561 |
|
| 562 |
test("smart actions are unavailable if readonly", async () => { |
| 563 |
await mountView({ |
| 564 |
type: "form", |
| 565 |
resModel: "partner", |
| 566 |
arch: /* xml */ ` |
| 567 |
<form> |
| 568 |
<header> |
| 569 |
<field name="trululu" widget="statusbar" readonly="1"/> |
| 570 |
</header> |
| 571 |
</form> |
| 572 |
`, |
| 573 |
resId: 1, |
| 574 |
}); |
| 575 |
|
| 576 |
expect(".o_field_widget").toHaveCount(1); |
| 577 |
await press(["control", "k"]); |
| 578 |
await animationFrame(); |
| 579 |
const moveStages = queryAllTexts(".o_command"); |
| 580 |
expect(moveStages).not.toInclude("Move to Trululu\nALT + SHIFT + X"); |
| 581 |
expect(moveStages).not.toInclude("Move to next\nALT + X"); |
| 582 |
}); |
| 583 |
|
| 584 |
test("hotkeys are unavailable if readonly", async () => { |
| 585 |
await mountView({ |
| 586 |
type: "form", |
| 587 |
resModel: "partner", |
| 588 |
arch: /* xml */ ` |
| 589 |
<form> |
| 590 |
<header> |
| 591 |
<field name="trululu" widget="statusbar" readonly="1"/> |
| 592 |
</header> |
| 593 |
</form> |
| 594 |
`, |
| 595 |
resId: 1, |
| 596 |
}); |
| 597 |
|
| 598 |
expect(".o_field_widget").toHaveCount(1); |
| 599 |
await press(["alt", "shift", "x"]); // Move to stage... |
| 600 |
await animationFrame(); |
| 601 |
expect(".modal").toHaveCount(0, { message: "command palette should not open" }); |
| 602 |
|
| 603 |
await press(["alt", "x"]); // Move to next |
| 604 |
await animationFrame(); |
| 605 |
expect(".modal").toHaveCount(0, { message: "command palette should not open" }); |
| 606 |
}); |
| 607 |
|
| 608 |
test("auto save record when field toggled", async () => { |
| 609 |
onRpc("web_save", () => expect.step("web_save")); |
| 610 |
await mountView({ |
| 611 |
type: "form", |
| 612 |
resModel: "partner", |
| 613 |
resId: 1, |
| 614 |
arch: /* xml */ ` |
| 615 |
<form> |
| 616 |
<header> |
| 617 |
<field name="trululu" widget="statusbar" options="{'clickable': 1}" /> |
| 618 |
</header> |
| 619 |
</form> |
| 620 |
`, |
| 621 |
}); |
| 622 |
|
| 623 |
await click( |
| 624 |
".o_statusbar_status button.btn:not(.dropdown-toggle):not(:disabled):not(.o_arrow_button_current):eq(-1)" |
| 625 |
); |
| 626 |
await animationFrame(); |
| 627 |
expect.verifySteps(["web_save"]); |
| 628 |
}); |
| 629 |
|
| 630 |
test("For the same record, a single rpc is done to recover the specialData", async () => { |
| 631 |
Partner._views = { |
| 632 |
"list,3": '<list><field name="display_name"/></list>', |
| 633 |
"search,9": `<search></search>`, |
| 634 |
form: ` |
| 635 |
<form> |
| 636 |
<header> |
| 637 |
<field name="trululu" widget="statusbar" readonly="1"/> |
| 638 |
</header> |
| 639 |
</form> |
| 640 |
`, |
| 641 |
}; |
| 642 |
defineActions([ |
| 643 |
{ |
| 644 |
id: 1, |
| 645 |
name: "Partners", |
| 646 |
res_model: "partner", |
| 647 |
views: [ |
| 648 |
[false, "list"], |
| 649 |
[false, "form"], |
| 650 |
], |
| 651 |
}, |
| 652 |
]); |
| 653 |
onRpc("has_group", () => true); |
| 654 |
onRpc("search_read", () => expect.step("search_read")); |
| 655 |
|
| 656 |
await mountWithCleanup(WebClient); |
| 657 |
await getService("action").doAction(1); |
| 658 |
|
| 659 |
await click(".o_data_row .o_data_cell"); |
| 660 |
await animationFrame(); |
| 661 |
expect.verifySteps(["search_read"]); |
| 662 |
|
| 663 |
await click(".o_back_button"); |
| 664 |
await animationFrame(); |
| 665 |
await click(".o_data_row .o_data_cell"); |
| 666 |
await animationFrame(); |
| 667 |
expect.verifySteps([]); |
| 668 |
}); |
| 669 |
|
| 670 |
test("open form with statusbar, leave and come back to another one with other domain", async () => { |
| 671 |
Partner._views = { |
| 672 |
"list,3": '<list><field name="display_name"/></list>', |
| 673 |
"search,9": `<search/>`, |
| 674 |
form: ` |
| 675 |
<form> |
| 676 |
<header> |
| 677 |
<field name="trululu" widget="statusbar" domain="[['id', '>', id]]" readonly="1"/> |
| 678 |
</header> |
| 679 |
</form> |
| 680 |
`, |
| 681 |
}; |
| 682 |
defineActions([ |
| 683 |
{ |
| 684 |
id: 1, |
| 685 |
name: "Partners", |
| 686 |
res_model: "partner", |
| 687 |
views: [ |
| 688 |
[false, "list"], |
| 689 |
[false, "form"], |
| 690 |
], |
| 691 |
}, |
| 692 |
]); |
| 693 |
onRpc("has_group", () => true); |
| 694 |
onRpc("search_read", () => expect.step("search_read")); |
| 695 |
|
| 696 |
await mountWithCleanup(WebClient); |
| 697 |
await getService("action").doAction(1); |
| 698 |
|
| 699 |
// open first record |
| 700 |
await click(".o_data_row .o_data_cell"); |
| 701 |
await animationFrame(); |
| 702 |
expect.verifySteps(["search_read"]); |
| 703 |
|
| 704 |
// go back and open second record |
| 705 |
await click(".o_back_button"); |
| 706 |
await animationFrame(); |
| 707 |
await click(".o_data_row:eq(1) .o_data_cell"); |
| 708 |
await animationFrame(); |
| 709 |
expect.verifySteps(["search_read"]); |
| 710 |
}); |
| 711 |
|
| 712 |
test.tags("desktop"); |
| 713 |
test("clickable statusbar with readonly modifier set to false is editable on desktop", async () => { |
| 714 |
await mountView({ |
| 715 |
type: "form", |
| 716 |
resModel: "partner", |
| 717 |
resId: 2, |
| 718 |
arch: /* xml */ ` |
| 719 |
<form> |
| 720 |
<header> |
| 721 |
<field name="product_id" widget="statusbar" options="{'clickable': true}" readonly="False"/> |
| 722 |
</header> |
| 723 |
</form> |
| 724 |
`, |
| 725 |
}); |
| 726 |
expect(".o_statusbar_status button:visible").toHaveCount(2); |
| 727 |
expect(".o_statusbar_status button[disabled][aria-checked='false']:visible").toHaveCount(0); |
| 728 |
}); |
| 729 |
|
| 730 |
test.tags("mobile"); |
| 731 |
test("clickable statusbar with readonly modifier set to false is editable on mobile", async () => { |
| 732 |
await mountView({ |
| 733 |
type: "form", |
| 734 |
resModel: "partner", |
| 735 |
resId: 2, |
| 736 |
arch: /* xml */ ` |
| 737 |
<form> |
| 738 |
<header> |
| 739 |
<field name="product_id" widget="statusbar" options="{'clickable': true}" readonly="False"/> |
| 740 |
</header> |
| 741 |
</form> |
| 742 |
`, |
| 743 |
}); |
| 744 |
expect(".o_statusbar_status .dropdown-toggle:visible").toHaveCount(1); |
| 745 |
expect(".o_statusbar_status button[disabled][aria-checked='false']:visible").toHaveCount(0); |
| 746 |
await click(".o_statusbar_status .dropdown-toggle:visible"); |
| 747 |
await animationFrame(); |
| 748 |
expect(".o-dropdown--menu .dropdown-item").toHaveCount(2); |
| 749 |
}); |
| 750 |
|
| 751 |
test.tags("desktop"); |
| 752 |
test("clickable statusbar with readonly modifier set to true is not editable on desktop", async () => { |
| 753 |
await mountView({ |
| 754 |
type: "form", |
| 755 |
resModel: "partner", |
| 756 |
resId: 2, |
| 757 |
arch: /* xml */ ` |
| 758 |
<form> |
| 759 |
<header> |
| 760 |
<field name="product_id" widget="statusbar" options="{'clickable': true}" readonly="True"/> |
| 761 |
</header> |
| 762 |
</form> |
| 763 |
`, |
| 764 |
}); |
| 765 |
expect(".o_statusbar_status button[disabled]:visible").toHaveCount(2); |
| 766 |
}); |
| 767 |
|
| 768 |
test.tags("mobile"); |
| 769 |
test("clickable statusbar with readonly modifier set to true is not editable on mobile", async () => { |
| 770 |
await mountView({ |
| 771 |
type: "form", |
| 772 |
resModel: "partner", |
| 773 |
resId: 2, |
| 774 |
arch: /* xml */ ` |
| 775 |
<form> |
| 776 |
<header> |
| 777 |
<field name="product_id" widget="statusbar" options="{'clickable': true}" readonly="True"/> |
| 778 |
</header> |
| 779 |
</form> |
| 780 |
`, |
| 781 |
}); |
| 782 |
expect(".o_statusbar_status .dropdown-toggle[disabled]:visible").toHaveCount(1); |
| 783 |
}); |
| 784 |
|
| 785 |
test.tags("desktop"); |
| 786 |
test("non-clickable statusbar with readonly modifier set to false is not editable on desktop", async () => { |
| 787 |
await mountView({ |
| 788 |
type: "form", |
| 789 |
resModel: "partner", |
| 790 |
resId: 2, |
| 791 |
arch: /* xml */ ` |
| 792 |
<form> |
| 793 |
<header> |
| 794 |
<field name="product_id" widget="statusbar" options="{'clickable': false}" readonly="False"/> |
| 795 |
</header> |
| 796 |
</form> |
| 797 |
`, |
| 798 |
}); |
| 799 |
expect(".o_statusbar_status button[disabled]:visible").toHaveCount(2); |
| 800 |
}); |
| 801 |
|
| 802 |
test.tags("mobile"); |
| 803 |
test("non-clickable statusbar with readonly modifier set to false is not editable on mobile", async () => { |
| 804 |
await mountView({ |
| 805 |
type: "form", |
| 806 |
resModel: "partner", |
| 807 |
resId: 2, |
| 808 |
arch: /* xml */ ` |
| 809 |
<form> |
| 810 |
<header> |
| 811 |
<field name="product_id" widget="statusbar" options="{'clickable': false}" readonly="False"/> |
| 812 |
</header> |
| 813 |
</form> |
| 814 |
`, |
| 815 |
}); |
| 816 |
expect(".o_statusbar_status .dropdown-toggle[disabled]:visible").toHaveCount(1); |
| 817 |
}); |
| 818 |
|
| 819 |
test.tags("desktop"); |
| 820 |
test("last status bar button have a border radius (no arrow shape) on the right side when a prior folded stage gets selected", async () => { |
| 821 |
class Stage extends models.Model { |
| 822 |
name = fields.Char(); |
| 823 |
folded = fields.Boolean({ default: false }); |
| 824 |
|
| 825 |
_records = [ |
| 826 |
{ id: 1, name: "New" }, |
| 827 |
{ id: 2, name: "In Progress", folded: true }, |
| 828 |
{ id: 3, name: "Done" }, |
| 829 |
]; |
| 830 |
} |
| 831 |
|
| 832 |
class Task extends models.Model { |
| 833 |
status = fields.Many2one({ relation: "stage" }); |
| 834 |
|
| 835 |
_records = [ |
| 836 |
{ id: 1, status: 1 }, |
| 837 |
{ id: 2, status: 2 }, |
| 838 |
{ id: 3, status: 3 }, |
| 839 |
]; |
| 840 |
} |
| 841 |
|
| 842 |
defineModels([Stage, Task]); |
| 843 |
|
| 844 |
await mountView({ |
| 845 |
type: "form", |
| 846 |
resModel: "task", |
| 847 |
resId: 3, |
| 848 |
arch: /* xml */ ` |
| 849 |
<form> |
| 850 |
<header> |
| 851 |
<field name="status" widget="statusbar" options="{'clickable': true, 'fold_field': 'folded'}" /> |
| 852 |
</header> |
| 853 |
</form> |
| 854 |
`, |
| 855 |
}); |
| 856 |
await click(".o_statusbar_status .dropdown-toggle:not(.d-none)"); |
| 857 |
await animationFrame(); |
| 858 |
await click( |
| 859 |
queryFirst(".dropdown-item", { |
| 860 |
root: getDropdownMenu(".o_statusbar_status .dropdown-toggle:not(.d-none)"), |
| 861 |
}) |
| 862 |
); |
| 863 |
await animationFrame(); |
| 864 |
|
| 865 |
expect(".o_statusbar_status button[data-value='3']").not.toHaveStyle({ |
| 866 |
borderTopRightRadius: "0px", |
| 867 |
}); |
| 868 |
expect(".o_statusbar_status button[data-value='3']").toHaveClass("o_first"); |
| 869 |
}); |
| 870 |
|
| 871 |
test.tags("desktop"); |
| 872 |
test("correctly load statusbar when dynamic domain changes", async () => { |
| 873 |
class Stage extends models.Model { |
| 874 |
name = fields.Char(); |
| 875 |
folded = fields.Boolean({ default: false }); |
| 876 |
project_ids = fields.Many2many({ relation: "project" }); |
| 877 |
|
| 878 |
_records = [ |
| 879 |
{ id: 1, name: "Stage Project 1", project_ids: [1] }, |
| 880 |
{ id: 2, name: "Stage Project 2", project_ids: [2] }, |
| 881 |
]; |
| 882 |
} |
| 883 |
|
| 884 |
class Project extends models.Model { |
| 885 |
display_name = fields.Char(); |
| 886 |
|
| 887 |
_records = [ |
| 888 |
{ id: 1, display_name: "Project 1" }, |
| 889 |
{ id: 2, display_name: "Project 2" }, |
| 890 |
]; |
| 891 |
} |
| 892 |
|
| 893 |
class Task extends models.Model { |
| 894 |
status = fields.Many2one({ relation: "stage" }); |
| 895 |
project_id = fields.Many2one({ relation: "project" }); |
| 896 |
|
| 897 |
_records = [{ id: 1, project_id: 1, status: 1 }]; |
| 898 |
} |
| 899 |
Task._onChanges.project_id = (obj) => { |
| 900 |
obj.status = obj.project_id === 1 ? 1 : 2; |
| 901 |
}; |
| 902 |
|
| 903 |
defineModels([Stage, Project, Task]); |
| 904 |
|
| 905 |
onRpc("search_read", ({ kwargs }) => expect.step(kwargs.domain)); |
| 906 |
await mountView({ |
| 907 |
type: "form", |
| 908 |
resModel: "task", |
| 909 |
resId: 1, |
| 910 |
arch: /* xml */ ` |
| 911 |
<form> |
| 912 |
<header> |
| 913 |
<field name="status" widget="statusbar" domain="[('project_ids', 'in', project_id)]" /> |
| 914 |
</header> |
| 915 |
<field name="project_id"/> |
| 916 |
</form> |
| 917 |
`, |
| 918 |
}); |
| 919 |
expect(queryAllTexts(".o_statusbar_status button:not(.d-none)")).toEqual(["Stage Project 1"]); |
| 920 |
expect.verifySteps([["|", ["id", "=", 1], ["project_ids", "in", 1]]]); |
| 921 |
await click(`[name="project_id"] .dropdown input`); |
| 922 |
await animationFrame(); |
| 923 |
await click(`[name="project_id"] .dropdown .dropdown-menu .ui-menu-item:contains("Project 2")`); |
| 924 |
await animationFrame(); |
| 925 |
|
| 926 |
expect(queryAllTexts(".o_statusbar_status button:not(.d-none)")).toEqual(["Stage Project 2"]); |
| 927 |
expect.verifySteps([["|", ["id", "=", 2], ["project_ids", "in", 2]]]); |
| 928 |
await clickSave(); |
| 929 |
expect(queryAllTexts(".o_statusbar_status button:not(.d-none)")).toEqual(["Stage Project 2"]); |
| 930 |
expect.verifySteps([]); |
| 931 |
}); |
| 932 |
|
| 933 |
test.tags("mobile"); |
| 934 |
test("statusbar is rendered correctly on small devices", async () => { |
| 935 |
Partner._records = [ |
| 936 |
{ id: 1, name: "first record", trululu: 4 }, |
| 937 |
{ id: 2, name: "second record", trululu: 1 }, |
| 938 |
{ id: 3, name: "third record" }, |
| 939 |
{ id: 4, name: "aaa" }, |
| 940 |
]; |
| 941 |
await mountView({ |
| 942 |
type: "form", |
| 943 |
resModel: "partner", |
| 944 |
resId: 1, |
| 945 |
arch: /* xml */ ` |
| 946 |
<form> |
| 947 |
<header> |
| 948 |
<field name="trululu" widget="statusbar" options="{'clickable': 1}" /> |
| 949 |
</header> |
| 950 |
<field name="name" /> |
| 951 |
</form> |
| 952 |
`, |
| 953 |
}); |
| 954 |
expect( |
| 955 |
queryAll(".o_statusbar_status .o_arrow_button.dropdown-toggle", { visible: true }) |
| 956 |
).toHaveCount(1); |
| 957 |
expect(".o_statusbar_status .o_arrow_button.o_first:visible").toHaveCount(1); |
| 958 |
expect(".o-dropdown--menu").toHaveCount(0, { message: "dropdown should be hidden" }); |
| 959 |
expect(".o_statusbar_status button.dropdown-toggle:visible").toHaveText("aaa"); |
| 960 |
|
| 961 |
// open the dropdown |
| 962 |
await contains(".o_statusbar_status .dropdown-toggle").click(); |
| 963 |
|
| 964 |
expect(".o-dropdown--menu").toHaveCount(1, { message: "dropdown should be visible" }); |
| 965 |
expect(".o-dropdown--menu .dropdown-item").toHaveCount(4); |
| 966 |
}); |
| 967 |
|
| 968 |
test.tags("mobile"); |
| 969 |
test("statusbar with no status on extra small screens", async () => { |
| 970 |
Partner._records = [ |
| 971 |
{ id: 1, name: "first record", trululu: 4 }, |
| 972 |
{ id: 2, name: "second record", trululu: 1 }, |
| 973 |
{ id: 3, name: "third record" }, |
| 974 |
{ id: 4, name: "aaa" }, |
| 975 |
]; |
| 976 |
await mountView({ |
| 977 |
type: "form", |
| 978 |
resModel: "partner", |
| 979 |
resId: 4, |
| 980 |
arch: /* xml */ ` |
| 981 |
<form> |
| 982 |
<header> |
| 983 |
<field name="trululu" widget="statusbar" /> |
| 984 |
</header> |
| 985 |
</form> |
| 986 |
`, |
| 987 |
}); |
| 988 |
|
| 989 |
expect(".o_field_statusbar").not.toHaveClass("o_field_empty", { |
| 990 |
message: "statusbar widget should have class o_field_empty in edit", |
| 991 |
}); |
| 992 |
expect(".o_statusbar_status button.dropdown-toggle:visible:disabled").toHaveCount(1); |
| 993 |
expect(".o_statusbar_status button.dropdown-toggle:visible:disabled").toHaveText("More"); |
| 994 |
}); |
| 995 |
|
| 996 |
test.tags("mobile"); |
| 997 |
test("clickable statusbar widget on mobile view", async () => { |
| 998 |
Partner._records = [ |
| 999 |
{ id: 1, name: "first record", trululu: 4 }, |
| 1000 |
{ id: 2, name: "second record", trululu: 1 }, |
| 1001 |
{ id: 3, name: "third record" }, |
| 1002 |
{ id: 4, name: "aaa" }, |
| 1003 |
]; |
| 1004 |
await mountView({ |
| 1005 |
type: "form", |
| 1006 |
resModel: "partner", |
| 1007 |
resId: 1, |
| 1008 |
arch: /* xml */ ` |
| 1009 |
<form> |
| 1010 |
<header> |
| 1011 |
<field name="trululu" widget="statusbar" options="{'clickable': '1'}" /> |
| 1012 |
</header> |
| 1013 |
</form> |
| 1014 |
`, |
| 1015 |
}); |
| 1016 |
|
| 1017 |
// Open dropdown |
| 1018 |
click(queryFirst(".o_statusbar_status .dropdown-toggle", { visible: true })); |
| 1019 |
await animationFrame(); |
| 1020 |
|
| 1021 |
expect(".o-dropdown--menu .dropdown-item").toHaveCount(4); |
| 1022 |
|
| 1023 |
click(".o-dropdown--menu .dropdown-item"); |
| 1024 |
await animationFrame(); |
| 1025 |
|
| 1026 |
expect(".o_arrow_button_current").toHaveText("first record"); |
| 1027 |
expect( |
| 1028 |
queryAll(".o_statusbar_status .o_arrow_button.dropdown-toggle", { visible: true }) |
| 1029 |
).toHaveCount(1); |
| 1030 |
|
| 1031 |
// Open second dropdown |
| 1032 |
click(queryFirst(".o_statusbar_status .dropdown-toggle", { visible: true })); |
| 1033 |
await animationFrame(); |
| 1034 |
|
| 1035 |
expect(".o-dropdown--menu .dropdown-item").toHaveCount(4); |
| 1036 |
}); |
| 1037 |
|
| 1038 |
test('"status" with no stages does not crash command palette', async () => { |
| 1039 |
class Stage extends models.Model { |
| 1040 |
name = fields.Char(); |
| 1041 |
_records = []; // no stages |
| 1042 |
} |
| 1043 |
|
| 1044 |
class Task extends models.Model { |
| 1045 |
status = fields.Many2one({ relation: "stage" }); |
| 1046 |
_records = [{ id: 1, status: false }]; |
| 1047 |
} |
| 1048 |
|
| 1049 |
defineModels([Stage, Task]); |
| 1050 |
|
| 1051 |
await mountView({ |
| 1052 |
type: "form", |
| 1053 |
resModel: "task", |
| 1054 |
resId: 1, |
| 1055 |
arch: /* xml */ ` |
| 1056 |
<form> |
| 1057 |
<header> |
| 1058 |
<field name="status" widget="statusbar" options="{'withCommand': true, 'clickable': true}"/> |
| 1059 |
</header> |
| 1060 |
</form> |
| 1061 |
`, |
| 1062 |
}); |
| 1063 |
|
| 1064 |
// Open the command palette (Ctrl+K) |
| 1065 |
await press(["control", "k"]); |
| 1066 |
await animationFrame(); |
| 1067 |
|
| 1068 |
const commands = queryAllTexts(".o_command"); |
| 1069 |
|
| 1070 |
expect(commands).not.toInclude("Move to next Stage"); |
| 1071 |
}); |
| 1072 |
|
| 1073 |
test.tags("desktop"); |
| 1074 |
test("cache: update current status if it changed", async () => { |
| 1075 |
class Stage extends models.Model { |
| 1076 |
name = fields.Char(); |
| 1077 |
_records = [ |
| 1078 |
{ id: 1, name: "Stage 1" }, |
| 1079 |
{ id: 2, name: "Stage 2" }, |
| 1080 |
]; |
| 1081 |
} |
| 1082 |
Partner._fields.stage_id = fields.Many2one({ relation: "stage" }); |
| 1083 |
Partner._records = [ |
| 1084 |
{ |
| 1085 |
id: 1, |
| 1086 |
name: "first record", |
| 1087 |
stage_id: 1, |
| 1088 |
}, |
| 1089 |
{ |
| 1090 |
id: 2, |
| 1091 |
name: "second record", |
| 1092 |
stage_id: 2, |
| 1093 |
}, |
| 1094 |
{ |
| 1095 |
id: 3, |
| 1096 |
name: "third record", |
| 1097 |
stage_id: 2, |
| 1098 |
}, |
| 1099 |
]; |
| 1100 |
defineModels([Stage]); |
| 1101 |
|
| 1102 |
Partner._views = { |
| 1103 |
kanban: ` |
| 1104 |
<kanban default_group_by="stage_id"> |
| 1105 |
<templates> |
| 1106 |
<t t-name="card"> |
| 1107 |
<field name="display_name"/> |
| 1108 |
</t> |
| 1109 |
</templates> |
| 1110 |
</kanban>`, |
| 1111 |
form: ` |
| 1112 |
<form> |
| 1113 |
<header> |
| 1114 |
<field name="stage_id" widget="statusbar" /> |
| 1115 |
</header> |
| 1116 |
</form>`, |
| 1117 |
search: `<search></search>`, |
| 1118 |
}; |
| 1119 |
|
| 1120 |
onRpc("has_group", () => true); |
| 1121 |
let def; |
| 1122 |
onRpc("web_read", () => def); |
| 1123 |
await mountWithCleanup(WebClient); |
| 1124 |
await getService("action").doAction({ |
| 1125 |
id: 1, |
| 1126 |
name: "Partners", |
| 1127 |
res_model: "partner", |
| 1128 |
type: "ir.actions.act_window", |
| 1129 |
cache: true, |
| 1130 |
views: [ |
| 1131 |
[false, "kanban"], |
| 1132 |
[false, "form"], |
| 1133 |
], |
| 1134 |
}); |
| 1135 |
|
| 1136 |
// populate the cache by visiting the 3 records |
| 1137 |
await contains(".o_kanban_record").click(); |
| 1138 |
expect(".o_last_breadcrumb_item").toHaveText("first record"); |
| 1139 |
await pagerNext(); |
| 1140 |
expect(".o_last_breadcrumb_item").toHaveText("second record"); |
| 1141 |
await pagerNext(); |
| 1142 |
expect(".o_last_breadcrumb_item").toHaveText("third record"); |
| 1143 |
|
| 1144 |
// go back to kanban and drag the first record of stage 2 on top of stage 1 column |
| 1145 |
await contains(".o_breadcrumb .o_back_button").click(); |
| 1146 |
const dragActions = await contains(".o_kanban_record:contains(second record)").drag(); |
| 1147 |
await dragActions.moveTo(".o_kanban_record:contains(first record)"); |
| 1148 |
await dragActions.drop(); |
| 1149 |
expect(queryAllTexts(".o_kanban_record")).toEqual([ |
| 1150 |
"second record", |
| 1151 |
"first record", |
| 1152 |
"third record", |
| 1153 |
]); |
| 1154 |
|
| 1155 |
// re-open last record and use to pager to reach the record we just moved |
| 1156 |
await contains(".o_kanban_record:contains(third record)").click(); |
| 1157 |
await pagerPrevious(); |
| 1158 |
def = new Deferred(); |
| 1159 |
await pagerPrevious(); |
| 1160 |
// retrieved from the cache => former value |
| 1161 |
expect(".o_last_breadcrumb_item").toHaveText("second record"); |
| 1162 |
expect('.o_statusbar_status button[data-value="2"]').toHaveClass("o_arrow_button_current"); |
| 1163 |
def.resolve(); |
| 1164 |
await animationFrame(); |
| 1165 |
// updated when the rpc returns |
| 1166 |
expect(".o_last_breadcrumb_item").toHaveText("second record"); |
| 1167 |
expect('.o_statusbar_status button[data-value="1"]').toHaveClass("o_arrow_button_current"); |
| 1168 |
}); |
| 1169 |
|
| 1170 |
test("[adjust] statusbar with a lot of stages, click to change stage", async () => { |
| 1171 |
// force the window width and define long stage names s.t. at most 3 stages can be displayed |
| 1172 |
resize({ width: 800 }); |
| 1173 |
class Stage extends models.Model { |
| 1174 |
name = fields.Char(); |
| 1175 |
_records = Array.from(Array(6).keys()).map((i) => { |
| 1176 |
const id = i + 1; |
| 1177 |
return { id, name: `Stage with very long name ${id}` }; |
| 1178 |
}); |
| 1179 |
} |
| 1180 |
defineModels([Stage]); |
| 1181 |
Partner._fields.stage_id = { type: "many2one", relation: "stage" }; |
| 1182 |
Partner._records[0].stage_id = 3; |
| 1183 |
|
| 1184 |
await mountView({ |
| 1185 |
type: "form", |
| 1186 |
resModel: "partner", |
| 1187 |
resId: 1, |
| 1188 |
arch: /* xml */ ` |
| 1189 |
<form> |
| 1190 |
<header> |
| 1191 |
<field name="stage_id" widget="statusbar" options="{'clickable': 1}" /> |
| 1192 |
</header> |
| 1193 |
</form> |
| 1194 |
`, |
| 1195 |
}); |
| 1196 |
|
| 1197 |
// initial rendering: there should be a dropdown before and a dropdown after |
| 1198 |
expect(".o_statusbar_status button:visible.dropdown-toggle").toHaveCount(2); |
| 1199 |
expect(queryAllTexts(".o_statusbar_status button:visible:not(.dropdown-toggle)")).toEqual([ |
| 1200 |
"Stage with very long name 4", |
| 1201 |
"Stage with very long name 3", |
| 1202 |
"Stage with very long name 2", |
| 1203 |
]); |
| 1204 |
expect(".o_statusbar_status button[data-value='3']").toHaveClass("o_arrow_button_current"); |
| 1205 |
await contains(".o_statusbar_status .o_last").click(); |
| 1206 |
expect(queryAllTexts(".o-dropdown-item")).toEqual(["Stage with very long name 1"]); |
| 1207 |
await contains(".o_statusbar_status .o_first").click(); |
| 1208 |
expect(queryAllTexts(".o-dropdown-item")).toEqual([ |
| 1209 |
"Stage with very long name 5", |
| 1210 |
"Stage with very long name 6", |
| 1211 |
]); |
| 1212 |
|
| 1213 |
// choose the next value: there should still be one dropdown before and one after |
| 1214 |
await contains(".o_statusbar_status button[data-value='4']").click(); |
| 1215 |
expect(".o_statusbar_status button:visible.dropdown-toggle").toHaveCount(2); |
| 1216 |
expect(queryAllTexts(".o_statusbar_status button:visible:not(.dropdown-toggle)")).toEqual([ |
| 1217 |
"Stage with very long name 5", |
| 1218 |
"Stage with very long name 4", |
| 1219 |
"Stage with very long name 3", |
| 1220 |
]); |
| 1221 |
expect(".o_statusbar_status button[data-value='4']").toHaveClass("o_arrow_button_current"); |
| 1222 |
await contains(".o_statusbar_status .o_last").click(); |
| 1223 |
expect(queryAllTexts(".o-dropdown-item")).toEqual([ |
| 1224 |
"Stage with very long name 1", |
| 1225 |
"Stage with very long name 2", |
| 1226 |
]); |
| 1227 |
await contains(".o_statusbar_status .o_first").click(); |
| 1228 |
expect(queryAllTexts(".o-dropdown-item")).toEqual(["Stage with very long name 6"]); |
| 1229 |
|
| 1230 |
// choose the next value: there should only be a dropdown before |
| 1231 |
await contains(".o_statusbar_status button[data-value='5']").click(); |
| 1232 |
expect(".o_statusbar_status button:visible.dropdown-toggle").toHaveCount(1); |
| 1233 |
expect(queryAllTexts(".o_statusbar_status button:visible:not(.dropdown-toggle)")).toEqual([ |
| 1234 |
"Stage with very long name 6", |
| 1235 |
"Stage with very long name 5", |
| 1236 |
"Stage with very long name 4", |
| 1237 |
]); |
| 1238 |
expect(".o_statusbar_status button[data-value='5']").toHaveClass("o_arrow_button_current"); |
| 1239 |
await contains(".o_statusbar_status .o_last").click(); |
| 1240 |
expect(queryAllTexts(".o-dropdown-item")).toEqual([ |
| 1241 |
"Stage with very long name 1", |
| 1242 |
"Stage with very long name 2", |
| 1243 |
"Stage with very long name 3", |
| 1244 |
]); |
| 1245 |
|
| 1246 |
// select the first item from the dropdown before => there should only be a dropdown after |
| 1247 |
await contains(".o-dropdown-item:first").click(); |
| 1248 |
expect(".o_statusbar_status button:visible.dropdown-toggle").toHaveCount(1); |
| 1249 |
expect(queryAllTexts(".o_statusbar_status button:visible:not(.dropdown-toggle)")).toEqual([ |
| 1250 |
"Stage with very long name 3", |
| 1251 |
"Stage with very long name 2", |
| 1252 |
"Stage with very long name 1", |
| 1253 |
]); |
| 1254 |
expect(".o_statusbar_status button[data-value='1']").toHaveClass("o_arrow_button_current"); |
| 1255 |
await contains(".o_statusbar_status .o_first").click(); |
| 1256 |
expect(queryAllTexts(".o-dropdown-item")).toEqual([ |
| 1257 |
"Stage with very long name 4", |
| 1258 |
"Stage with very long name 5", |
| 1259 |
"Stage with very long name 6", |
| 1260 |
]); |
| 1261 |
}); |