| 1 |
import { after, before, expect, test } from "@odoo/hoot"; |
| 2 |
import { |
| 3 |
clear, |
| 4 |
click, |
| 5 |
hover, |
| 6 |
manuallyDispatchProgrammaticEvent, |
| 7 |
middleClick, |
| 8 |
press, |
| 9 |
queryAllAttributes, |
| 10 |
queryAllTexts, |
| 11 |
queryFirst, |
| 12 |
waitFor, |
| 13 |
} from "@odoo/hoot-dom"; |
| 14 |
import { |
| 15 |
animationFrame, |
| 16 |
Deferred, |
| 17 |
mockTimeZone, |
| 18 |
mockTouch, |
| 19 |
runAllTimers, |
| 20 |
tick, |
| 21 |
} from "@odoo/hoot-mock"; |
| 22 |
import { |
| 23 |
Component, |
| 24 |
EventBus, |
| 25 |
onMounted, |
| 26 |
onPatched, |
| 27 |
onWillStart, |
| 28 |
onWillUpdateProps, |
| 29 |
useEffect, |
| 30 |
useRef, |
| 31 |
useState, |
| 32 |
xml, |
| 33 |
} from "@odoo/owl"; |
| 34 |
import { |
| 35 |
clickSave, |
| 36 |
contains, |
| 37 |
defineActions, |
| 38 |
defineMenus, |
| 39 |
defineModels, |
| 40 |
fields, |
| 41 |
findComponent, |
| 42 |
getPagerLimit, |
| 43 |
getPagerValue, |
| 44 |
getService, |
| 45 |
installLanguages, |
| 46 |
makeServerError, |
| 47 |
MockServer, |
| 48 |
mockService, |
| 49 |
models, |
| 50 |
mountView, |
| 51 |
mountViewInDialog, |
| 52 |
mountWithCleanup, |
| 53 |
onRpc, |
| 54 |
patchWithCleanup, |
| 55 |
serverState, |
| 56 |
stepAllNetworkCalls, |
| 57 |
toggleActionMenu, |
| 58 |
toggleMenuItem, |
| 59 |
toggleSearchBarMenu, |
| 60 |
} from "@web/../tests/web_test_helpers"; |
| 61 |
|
| 62 |
import { browser } from "@web/core/browser/browser"; |
| 63 |
import { makeErrorFromResponse } from "@web/core/network/rpc"; |
| 64 |
import { registry } from "@web/core/registry"; |
| 65 |
import { config as transitionConfig } from "@web/core/transition"; |
| 66 |
import { SIZES } from "@web/core/ui/ui_service"; |
| 67 |
import { useBus, useService } from "@web/core/utils/hooks"; |
| 68 |
import { redirect } from "@web/core/utils/urls"; |
| 69 |
import { CharField } from "@web/views/fields/char/char_field"; |
| 70 |
import { DateTimeField } from "@web/views/fields/datetime/datetime_field"; |
| 71 |
import { Field } from "@web/views/fields/field"; |
| 72 |
import { IntegerField } from "@web/views/fields/integer/integer_field"; |
| 73 |
import { useSpecialData } from "@web/views/fields/relational_utils"; |
| 74 |
import { standardFieldProps } from "@web/views/fields/standard_field_props"; |
| 75 |
import { X2ManyField, x2ManyField } from "@web/views/fields/x2many/x2many_field"; |
| 76 |
import { FormController } from "@web/views/form/form_controller"; |
| 77 |
import { AttachDocumentWidget } from "@web/views/widgets/attach_document/attach_document"; |
| 78 |
import { WebClient } from "@web/webclient/webclient"; |
| 79 |
|
| 80 |
const fieldsRegistry = registry.category("fields"); |
| 81 |
const widgetsRegistry = registry.category("view_widgets"); |
| 82 |
|
| 83 |
class Partner extends models.Model { |
| 84 |
name = fields.Char({ translate: true }); |
| 85 |
foo = fields.Char({ default: "My little Foo Value" }); |
| 86 |
bar = fields.Boolean(); |
| 87 |
int_field = fields.Integer(); |
| 88 |
float_field = fields.Float({ aggregator: "sum" }); |
| 89 |
child_ids = fields.One2many({ string: "one2many field", relation: "partner" }); |
| 90 |
parent_id = fields.Many2one({ relation: "partner" }); |
| 91 |
type_ids = fields.Many2many({ relation: "partner.type" }); |
| 92 |
product_id = fields.Many2one({ relation: "product" }); |
| 93 |
product_ids = fields.One2many({ relation: "product" }); |
| 94 |
state = fields.Selection({ |
| 95 |
selection: [ |
| 96 |
["ab", "AB"], |
| 97 |
["cd", "CD"], |
| 98 |
["ef", "EF"], |
| 99 |
], |
| 100 |
}); |
| 101 |
date = fields.Date(); |
| 102 |
datetime = fields.Datetime(); |
| 103 |
reference = fields.Reference({ |
| 104 |
selection: [ |
| 105 |
["product", "Product"], |
| 106 |
["partner_type", "Partner Type"], |
| 107 |
["partner", "Partner"], |
| 108 |
], |
| 109 |
}); |
| 110 |
user_id = fields.Many2one({ relation: "res.users" }); |
| 111 |
|
| 112 |
_records = [ |
| 113 |
{ |
| 114 |
id: 1, |
| 115 |
name: "first record", |
| 116 |
product_id: 37, |
| 117 |
bar: true, |
| 118 |
foo: "yop", |
| 119 |
int_field: 10, |
| 120 |
float_field: 0.44, |
| 121 |
child_ids: [], |
| 122 |
type_ids: [], |
| 123 |
parent_id: 4, |
| 124 |
state: "ab", |
| 125 |
date: "2017-01-25", |
| 126 |
datetime: "2016-12-12 10:55:05", |
| 127 |
}, |
| 128 |
{ |
| 129 |
id: 2, |
| 130 |
name: "second record", |
| 131 |
bar: true, |
| 132 |
foo: "blip", |
| 133 |
int_field: 9, |
| 134 |
float_field: 13, |
| 135 |
child_ids: [], |
| 136 |
type_ids: [], |
| 137 |
parent_id: 1, |
| 138 |
state: "cd", |
| 139 |
}, |
| 140 |
{ |
| 141 |
id: 4, |
| 142 |
name: "aaa", |
| 143 |
state: "ef", |
| 144 |
}, |
| 145 |
{ |
| 146 |
id: 5, |
| 147 |
name: "aaa", |
| 148 |
foo: "", |
| 149 |
bar: false, |
| 150 |
state: "ef", |
| 151 |
}, |
| 152 |
]; |
| 153 |
} |
| 154 |
|
| 155 |
class PartnerType extends models.Model { |
| 156 |
_name = "partner.type"; |
| 157 |
|
| 158 |
name = fields.Char(); |
| 159 |
color = fields.Integer(); |
| 160 |
foo = fields.Char(); |
| 161 |
|
| 162 |
_records = [ |
| 163 |
{ id: 12, name: "gold", color: 2 }, |
| 164 |
{ id: 14, name: "silver", color: 5 }, |
| 165 |
]; |
| 166 |
} |
| 167 |
|
| 168 |
class Product extends models.Model { |
| 169 |
name = fields.Char(); |
| 170 |
partner_type_id = fields.Many2one({ relation: "partner.type" }); |
| 171 |
|
| 172 |
_records = [ |
| 173 |
{ id: 37, name: "xphone" }, |
| 174 |
{ id: 41, name: "xpad" }, |
| 175 |
]; |
| 176 |
} |
| 177 |
|
| 178 |
class ResUsers extends models.Model { |
| 179 |
_name = "res.users"; |
| 180 |
|
| 181 |
name = fields.Char(); |
| 182 |
partner_ids = fields.One2many({ relation: "partner", relation_field: "user_id" }); |
| 183 |
|
| 184 |
_records = [ |
| 185 |
{ id: 17, name: "Aline", partner_ids: [1] }, |
| 186 |
{ id: 19, name: "Christine" }, |
| 187 |
]; |
| 188 |
} |
| 189 |
|
| 190 |
class ResCompany extends models.Model { |
| 191 |
_name = "res.company"; |
| 192 |
name = fields.Char(); |
| 193 |
} |
| 194 |
|
| 195 |
defineModels([Partner, PartnerType, Product, ResUsers, ResCompany]); |
| 196 |
|
| 197 |
onRpc("has_group", () => true); |
| 198 |
|
| 199 |
before(() => { |
| 200 |
patchWithCleanup(EventBus.prototype, { |
| 201 |
addEventListener(...args) { |
| 202 |
super.addEventListener(...args); |
| 203 |
after(() => { |
| 204 |
this.removeEventListener(...args); |
| 205 |
}); |
| 206 |
}, |
| 207 |
}); |
| 208 |
}); |
| 209 |
|
| 210 |
test(`simple form rendering`, async () => { |
| 211 |
await mountView({ |
| 212 |
resModel: "partner", |
| 213 |
type: "form", |
| 214 |
arch: ` |
| 215 |
<form> |
| 216 |
<div class="test" style="opacity: 0.5;">some html<span>aa</span></div> |
| 217 |
<sheet> |
| 218 |
<group> |
| 219 |
<group style="background-color: red"> |
| 220 |
<field name="foo" style="color: blue;"/> |
| 221 |
<field name="bar"/> |
| 222 |
<field name="int_field" string="f3_description"/> |
| 223 |
<field name="float_field"/> |
| 224 |
</group> |
| 225 |
<group> |
| 226 |
<div class="hello"></div> |
| 227 |
</group> |
| 228 |
</group> |
| 229 |
<notebook> |
| 230 |
<page string="Partner Yo"> |
| 231 |
<field name="child_ids"> |
| 232 |
<list> |
| 233 |
<field name="foo"/> |
| 234 |
<field name="bar"/> |
| 235 |
</list> |
| 236 |
</field> |
| 237 |
</page> |
| 238 |
</notebook> |
| 239 |
</sheet> |
| 240 |
</form> |
| 241 |
`, |
| 242 |
resId: 2, |
| 243 |
}); |
| 244 |
expect(`div.test`).toHaveCount(1); |
| 245 |
expect(`div.test`).toHaveStyle({ opacity: "0.5" }); |
| 246 |
expect(`label:contains(Foo)`).toHaveCount(1); |
| 247 |
expect(`.o_field_char input`).toHaveCount(1); |
| 248 |
expect(`.o_field_char input`).toHaveValue("blip"); |
| 249 |
expect(`.o_group .o_inner_group:eq(0)`).toHaveStyle({ backgroundColor: "rgb(255, 0, 0)" }); |
| 250 |
expect(`.o_field_widget[name=foo]`).toHaveStyle({ color: "rgb(0, 0, 255)" }); |
| 251 |
expect(`label:contains(something_id)`).toHaveCount(0); |
| 252 |
expect(`label:contains(f3_description)`).toHaveCount(1); |
| 253 |
expect(`div.o_field_one2many table`).toHaveCount(1); |
| 254 |
expect(`div.o_cell:not(.o_list_record_selector) .o-checkbox input:checked`).toHaveCount(1); |
| 255 |
expect(`label.o_form_label_empty:contains(type_ids)`).toHaveCount(0); |
| 256 |
}); |
| 257 |
|
| 258 |
test(`form rendering with class and style attributes`, async () => { |
| 259 |
await mountView({ |
| 260 |
resModel: "partner", |
| 261 |
type: "form", |
| 262 |
arch: /* xml */ `<form class="myCustomClass" style="border: 1px solid red;"/>`, |
| 263 |
resId: 2, |
| 264 |
}); |
| 265 |
expect( |
| 266 |
`.o_view_controller[style*='border: 1px solid red;'], .o_view_controller [style*='border: 1px solid red;']` |
| 267 |
).toHaveCount(0); |
| 268 |
expect(`.o_view_controller.o_form_view.myCustomClass`).toHaveCount(1); |
| 269 |
expect(`.myCustomClass`).toHaveCount(1); |
| 270 |
}); |
| 271 |
|
| 272 |
test(`generic tags are case insensitive`, async () => { |
| 273 |
await mountView({ |
| 274 |
resModel: "partner", |
| 275 |
type: "form", |
| 276 |
arch: `<form><Div class="test">Hello</Div></form>`, |
| 277 |
}); |
| 278 |
expect(`div.test`).toHaveCount(1); |
| 279 |
}); |
| 280 |
|
| 281 |
test(`form view with a group that contains an invisible group`, async () => { |
| 282 |
await mountView({ |
| 283 |
resModel: "partner", |
| 284 |
type: "form", |
| 285 |
arch: ` |
| 286 |
<form> |
| 287 |
<sheet> |
| 288 |
<group> |
| 289 |
<group invisible="1"> |
| 290 |
<field name="foo"/> |
| 291 |
</group> |
| 292 |
</group> |
| 293 |
</sheet> |
| 294 |
</form> |
| 295 |
`, |
| 296 |
resId: 2, |
| 297 |
}); |
| 298 |
expect(`.o_form_view .o_group`).toHaveCount(1); |
| 299 |
}); |
| 300 |
|
| 301 |
test.tags("mobile"); |
| 302 |
test(`button box rendering on small screen`, async () => { |
| 303 |
await mountView({ |
| 304 |
resModel: "partner", |
| 305 |
type: "form", |
| 306 |
arch: `<form><sheet><div name="button_box"><button id="btn1">MyButton</button><button id="btn2">MyButton2</button><button id="btn3">MyButton3</button><button id="btn4">MyButton4</button></div></sheet></form>`, |
| 307 |
resId: 2, |
| 308 |
}); |
| 309 |
expect(`.o-form-buttonbox > button`).toHaveCount(0); |
| 310 |
expect(`.oe_stat_button .o_button_more`).toHaveCount(1); |
| 311 |
|
| 312 |
await contains(`div.oe_stat_button .o_button_more`).click(); |
| 313 |
expect(`.o-form-buttonbox-small button.oe_stat_button`).toHaveCount(4); |
| 314 |
expect(`.o-dropdown--menu #btn4`).toHaveCount(1); |
| 315 |
}); |
| 316 |
|
| 317 |
test.tags("desktop"); |
| 318 |
test(`button box rendering on big screen`, async () => { |
| 319 |
const bus = new EventBus(); |
| 320 |
mockService("ui", (env) => { |
| 321 |
Object.defineProperty(env, "isSmall", { |
| 322 |
value: false, |
| 323 |
}); |
| 324 |
return { |
| 325 |
bus, |
| 326 |
get size() { |
| 327 |
return SIZES.XXL; |
| 328 |
}, |
| 329 |
get isSmall() { |
| 330 |
return false; |
| 331 |
}, |
| 332 |
}; |
| 333 |
}); |
| 334 |
let btnString = ""; |
| 335 |
for (let i = 0; i < 9; i++) { |
| 336 |
btnString += `<button class="oe_stat_button" id="btn${i}">My Button ${i}</button>`; |
| 337 |
} |
| 338 |
|
| 339 |
await mountView({ |
| 340 |
resModel: "partner", |
| 341 |
type: "form", |
| 342 |
arch: `<form><sheet><div name="button_box">${btnString}</div></sheet></form>`, |
| 343 |
resId: 2, |
| 344 |
}); |
| 345 |
expect(`.o-form-buttonbox > button`).toHaveCount(7); |
| 346 |
expect(`.o-form-buttonbox > .oe_stat_button .o-dropdown`).toHaveCount(1); |
| 347 |
|
| 348 |
const buttonBox = queryFirst(`.o-form-buttonbox`); |
| 349 |
const buttonBoxRect = buttonBox.getBoundingClientRect(); |
| 350 |
// we asserted that we have 7 buttons + 1 dropdown |
| 351 |
for (const btn of buttonBox.children) { |
| 352 |
expect(btn).toHaveRect({ top: buttonBoxRect.top }); |
| 353 |
} |
| 354 |
}); |
| 355 |
|
| 356 |
test(`button box rendering invisible`, async () => { |
| 357 |
await mountView({ |
| 358 |
resModel: "partner", |
| 359 |
type: "form", |
| 360 |
arch: `<form><div name="button_box" invisible="1"><button id="btn1">MyButton</button></div></form>`, |
| 361 |
resId: 2, |
| 362 |
}); |
| 363 |
expect(`.o_control_panel .o_control_panel_actions`).toHaveInnerHTML(""); |
| 364 |
}); |
| 365 |
|
| 366 |
test(`form view gets size class on small and big screens`, async () => { |
| 367 |
let uiSize = SIZES.MD; |
| 368 |
const bus = new EventBus(); |
| 369 |
mockService("ui", (env) => { |
| 370 |
Object.defineProperty(env, "isSmall", { |
| 371 |
value: false, |
| 372 |
}); |
| 373 |
return { |
| 374 |
bus, |
| 375 |
get size() { |
| 376 |
return uiSize; |
| 377 |
}, |
| 378 |
get isSmall() { |
| 379 |
return uiSize <= SIZES.SM; |
| 380 |
}, |
| 381 |
}; |
| 382 |
}); |
| 383 |
|
| 384 |
await mountView({ |
| 385 |
resModel: "partner", |
| 386 |
type: "form", |
| 387 |
arch: `<form><sheet><div></div></sheet></form>`, |
| 388 |
resId: 2, |
| 389 |
}); |
| 390 |
expect(`.o_xxl_form_view, .o_xxs_form_view`).toHaveCount(0); |
| 391 |
|
| 392 |
uiSize = SIZES.XXL; |
| 393 |
bus.trigger("resize"); |
| 394 |
await animationFrame(); |
| 395 |
expect(`.o_xxs_form_view`).toHaveCount(0); |
| 396 |
expect(`.o_xxl_form_view`).toHaveCount(1); |
| 397 |
|
| 398 |
uiSize = SIZES.XS; |
| 399 |
bus.trigger("resize"); |
| 400 |
await animationFrame(); |
| 401 |
expect(`.o_xxl_form_view`).toHaveCount(0); |
| 402 |
expect(`.o_xxs_form_view`).toHaveCount(1); |
| 403 |
}); |
| 404 |
|
| 405 |
test(`duplicate fields rendered properly`, async () => { |
| 406 |
await mountView({ |
| 407 |
resModel: "partner", |
| 408 |
type: "form", |
| 409 |
arch: ` |
| 410 |
<form> |
| 411 |
<group> |
| 412 |
<group> |
| 413 |
<field name="foo" class="foo_1" invisible="not bar"/> |
| 414 |
<field name="foo" class="foo_2" invisible="bar"/> |
| 415 |
<field name="foo" class="foo_3"/> |
| 416 |
<field name="int_field" class="int_field_1" readonly="bar"/> |
| 417 |
<field name="int_field" class="int_field_2" readonly="not bar"/> |
| 418 |
<field name="bar"/> |
| 419 |
</group> |
| 420 |
</group> |
| 421 |
</form> |
| 422 |
`, |
| 423 |
}); |
| 424 |
expect(`.o_field_widget[name=foo].foo_1`).toHaveCount(0); |
| 425 |
expect(`.o_field_widget[name=foo].foo_2`).toHaveCount(1); |
| 426 |
expect(`.o_field_widget[name=foo].foo_3`).toHaveCount(1); |
| 427 |
|
| 428 |
await contains(`.o_field_widget[name=foo].foo_3 input`).edit("hello"); |
| 429 |
expect(`.o_field_widget[name=foo].foo_2 input`).toHaveValue("hello"); |
| 430 |
expect(`.o_field_widget[name=int_field].int_field_1`).not.toHaveClass("o_readonly_modifier"); |
| 431 |
expect(`.o_field_widget[name=int_field].int_field_2`).toHaveClass("o_readonly_modifier"); |
| 432 |
expect(`.int_field_1 input`).toHaveCount(1); |
| 433 |
expect(`.int_field_2 span`).toHaveCount(1); |
| 434 |
|
| 435 |
await contains(`.o_field_widget[name=bar] input`).check(); |
| 436 |
expect(`.o_field_widget[name=int_field].int_field_1`).toHaveClass("o_readonly_modifier"); |
| 437 |
expect(`.o_field_widget[name=int_field].int_field_2`).not.toHaveClass("o_readonly_modifier"); |
| 438 |
expect(`.int_field_1 span`).toHaveCount(1); |
| 439 |
expect(`.int_field_2 input`).toHaveCount(1); |
| 440 |
}); |
| 441 |
|
| 442 |
test(`duplicate fields rendered properly (one2many)`, async () => { |
| 443 |
Partner._records.push({ id: 6, child_ids: [1] }); |
| 444 |
await mountView({ |
| 445 |
resModel: "partner", |
| 446 |
type: "form", |
| 447 |
arch: ` |
| 448 |
<form> |
| 449 |
<field name="child_ids"> |
| 450 |
<list editable="bottom"> |
| 451 |
<field name="foo"/> |
| 452 |
</list> |
| 453 |
<form/> |
| 454 |
</field> |
| 455 |
<field name="child_ids" readonly="True"> |
| 456 |
<list editable="bottom"> |
| 457 |
<field name="foo"/> |
| 458 |
</list> |
| 459 |
<form/> |
| 460 |
</field> |
| 461 |
</form> |
| 462 |
`, |
| 463 |
resId: 6, |
| 464 |
}); |
| 465 |
expect(`.o_field_one2many`).toHaveCount(2); |
| 466 |
expect(`.o_field_one2many:eq(0)`).not.toHaveClass("o_readonly_modifier"); |
| 467 |
expect(`.o_field_one2many:eq(1)`).toHaveClass("o_readonly_modifier"); |
| 468 |
|
| 469 |
await contains(`.o_field_one2many:eq(0) .o_data_cell`).click(); |
| 470 |
expect(`.o_field_one2many`).toHaveCount(2); |
| 471 |
expect(`.o_field_one2many:eq(0) .o_selected_row .o_field_widget[name=foo] input`).toHaveValue( |
| 472 |
"yop" |
| 473 |
); |
| 474 |
expect(`.o_field_one2many:eq(1) .o_data_row:eq(0) .o_data_cell[name=foo]`).toHaveText("yop"); |
| 475 |
|
| 476 |
await contains(`.o_field_one2many:eq(0) .o_selected_row .o_field_widget[name=foo] input`).edit( |
| 477 |
"hello", |
| 478 |
{ confirm: false } |
| 479 |
); |
| 480 |
await click(`.o_content`); // confirm change by focusing out the input. |
| 481 |
await animationFrame(); |
| 482 |
await animationFrame(); |
| 483 |
await animationFrame(); |
| 484 |
await animationFrame(); |
| 485 |
await animationFrame(); |
| 486 |
await animationFrame(); |
| 487 |
expect(`.o_field_one2many:eq(1) .o_data_row:eq(0) .o_data_cell[name=foo]`).toHaveText("hello"); |
| 488 |
|
| 489 |
await contains(`.o_field_one2many:eq(0) .o_field_x2many_list_row_add a`).click(); |
| 490 |
expect(`.o_field_one2many:eq(0) .o_selected_row .o_field_widget[name="foo"] input`).toHaveValue( |
| 491 |
"My little Foo Value" |
| 492 |
); |
| 493 |
expect(`.o_field_one2many:eq(1) .o_data_row:eq(1) .o_data_cell[name=foo]`).toHaveText( |
| 494 |
"My little Foo Value" |
| 495 |
); |
| 496 |
}); |
| 497 |
|
| 498 |
test(`attributes are transferred on async widgets`, async () => { |
| 499 |
const def = new Deferred(); |
| 500 |
class AsyncField extends CharField { |
| 501 |
willStart() { |
| 502 |
return def; |
| 503 |
} |
| 504 |
} |
| 505 |
fieldsRegistry.add("asyncwidget", { component: AsyncField }); |
| 506 |
|
| 507 |
const viewProm = mountView({ |
| 508 |
resModel: "partner", |
| 509 |
type: "form", |
| 510 |
arch: `<form><field name="foo" style="color: blue;" widget="asyncwidget"/></form>`, |
| 511 |
resId: 2, |
| 512 |
}); |
| 513 |
await animationFrame(); |
| 514 |
|
| 515 |
def.resolve(); |
| 516 |
await viewProm; |
| 517 |
expect(`.o_field_widget[name=foo]`).toHaveStyle({ color: "rgb(0, 0, 255)" }); |
| 518 |
}); |
| 519 |
|
| 520 |
test(`placeholder attribute on input`, async () => { |
| 521 |
await mountView({ |
| 522 |
resModel: "partner", |
| 523 |
type: "form", |
| 524 |
arch: `<form><input placeholder="chimay"/></form>`, |
| 525 |
resId: 2, |
| 526 |
}); |
| 527 |
expect(`input[placeholder="chimay"]`).toHaveCount(1); |
| 528 |
}); |
| 529 |
|
| 530 |
test(`decoration works on widgets`, async () => { |
| 531 |
await mountView({ |
| 532 |
resModel: "partner", |
| 533 |
type: "form", |
| 534 |
arch: ` |
| 535 |
<form> |
| 536 |
<field name="int_field"/> |
| 537 |
<field name="display_name" decoration-danger="int_field < 5"/> |
| 538 |
<field name="foo" decoration-danger="int_field > 5"/> |
| 539 |
</form> |
| 540 |
`, |
| 541 |
resId: 2, |
| 542 |
}); |
| 543 |
expect(`.o_field_widget[name="display_name"]`).not.toHaveClass("text-danger"); |
| 544 |
expect(`.o_field_widget[name="foo"]`).toHaveClass("text-danger"); |
| 545 |
}); |
| 546 |
|
| 547 |
test(`form with o2m having a many2many fields using the many2many_tags widget along the color_field option`, async () => { |
| 548 |
// In this scenario, the x2many form view isn't inline, so when we click on the record, |
| 549 |
// it does an independant getView, which doesn't return all fields of the model. In the |
| 550 |
// x2many list view, there's a field with a many2many_tags widget with the color option, |
| 551 |
// and the color field (color) in our case, isn't in the form view. |
| 552 |
// This test ensures that we can open the form view in this situation. |
| 553 |
Partner._records[0].type_ids = [12, 14]; |
| 554 |
Partner._views = { |
| 555 |
form: ` |
| 556 |
<form> |
| 557 |
<field name="display_name"/> |
| 558 |
<field name="type_ids" widget="one2many"> |
| 559 |
<list string="Values"> |
| 560 |
<field name="display_name"/> |
| 561 |
<!-- |
| 562 |
Required to add at least one different field than the fields read |
| 563 |
to display <field name="type_ids" widget="many2many_tags"/> below. |
| 564 |
To force to re-read the record with more fields. |
| 565 |
--> |
| 566 |
<field name="foo"/> |
| 567 |
</list> |
| 568 |
</field> |
| 569 |
</form> |
| 570 |
`, |
| 571 |
}; |
| 572 |
|
| 573 |
await mountView({ |
| 574 |
resModel: "res.users", |
| 575 |
type: "form", |
| 576 |
arch: ` |
| 577 |
<form edit="0"> |
| 578 |
<field name="partner_ids"> |
| 579 |
<list> |
| 580 |
<field name="name"/> |
| 581 |
<field name="type_ids" widget="many2many_tags" options="{'color_field': 'color'}"/> |
| 582 |
</list> |
| 583 |
</field> |
| 584 |
</form> |
| 585 |
`, |
| 586 |
resId: 17, |
| 587 |
}); |
| 588 |
expect(`.o_field_widget[name=type_ids] .o_field_tags`).toHaveCount(1); |
| 589 |
|
| 590 |
await contains(`.o_data_row .o_data_cell`).click(); |
| 591 |
expect(`.modal .o_form_view .o_field_widget[name=type_ids]`).toHaveCount(1); |
| 592 |
}); |
| 593 |
|
| 594 |
test(`form with o2m having a field with fieldDependencies`, async () => { |
| 595 |
// In this scenario, the x2many form view isn't inline, so when we click on the record, |
| 596 |
// it does an independant getView, which doesn't return all fields of the model. In the |
| 597 |
// x2many list view, there's a field with fieldDependencies, and the dependency field |
| 598 |
// (int_field) in our case, isn't in the form view. This test ensures that we can open |
| 599 |
// the form view in this situation. |
| 600 |
class MyField extends CharField {} |
| 601 |
fieldsRegistry.add("my_widget", { |
| 602 |
component: MyField, |
| 603 |
fieldDependencies: [{ name: "int_field", type: "integer" }], |
| 604 |
}); |
| 605 |
|
| 606 |
Partner._records[1].child_ids = [1]; |
| 607 |
|
| 608 |
await mountView({ |
| 609 |
resModel: "partner", |
| 610 |
type: "form", |
| 611 |
arch: ` |
| 612 |
<form> |
| 613 |
<field name="child_ids"> |
| 614 |
<list> |
| 615 |
<field name="foo" widget="my_widget"/> |
| 616 |
</list> |
| 617 |
</field> |
| 618 |
</form> |
| 619 |
`, |
| 620 |
resId: 2, |
| 621 |
}); |
| 622 |
expect(`.o_field_widget[name="child_ids"] .o_data_row`).toHaveCount(1); |
| 623 |
|
| 624 |
await contains(`.o_field_widget[name="child_ids"] .o_data_row .o_data_cell`).click(); |
| 625 |
expect(`.modal .o_form_view .o_field_widget[name="child_ids"]`).toHaveCount(1); |
| 626 |
}); |
| 627 |
|
| 628 |
test(`form with o2m having a selection field with fieldDependencies`, async () => { |
| 629 |
class MyField extends CharField {} |
| 630 |
fieldsRegistry.add("my_widget", { |
| 631 |
component: MyField, |
| 632 |
fieldDependencies: [{ name: "selection", type: "selection" }], |
| 633 |
}); |
| 634 |
|
| 635 |
Partner._fields.o2m = fields.One2many({ relation: "partner.type" }); |
| 636 |
Partner._records[1].o2m = [1]; |
| 637 |
|
| 638 |
PartnerType._fields.selection = fields.Selection({ |
| 639 |
selection: [ |
| 640 |
["a", "A"], |
| 641 |
["b", "B"], |
| 642 |
], |
| 643 |
}); |
| 644 |
PartnerType._records = [ |
| 645 |
{ |
| 646 |
id: 1, |
| 647 |
name: "first partner_type", |
| 648 |
selection: false, |
| 649 |
}, |
| 650 |
]; |
| 651 |
PartnerType._views = { |
| 652 |
form: `<form><field name="display_name" /></form>`, |
| 653 |
}; |
| 654 |
|
| 655 |
await mountView({ |
| 656 |
resModel: "partner", |
| 657 |
type: "form", |
| 658 |
arch: ` |
| 659 |
<form> |
| 660 |
<field name="o2m"> |
| 661 |
<list> |
| 662 |
<field name="display_name" widget="my_widget"/> |
| 663 |
</list> |
| 664 |
</field> |
| 665 |
</form> |
| 666 |
`, |
| 667 |
resId: 2, |
| 668 |
}); |
| 669 |
expect(`.o_field_widget[name=o2m] .o_data_row`).toHaveCount(1); |
| 670 |
|
| 671 |
await contains(`.o_field_widget[name=o2m] .o_field_x2many_list_row_add a`).click(); |
| 672 |
expect(`.modal .o_form_view .o_field_widget[name=display_name]`).toHaveCount(1); |
| 673 |
}); |
| 674 |
|
| 675 |
test(`form view: widget having a o2m field as fieldDependencies`, async () => { |
| 676 |
class MyWidget extends Component { |
| 677 |
static template = xml`<span>My custom widget</span>`; |
| 678 |
static props = ["*"]; |
| 679 |
} |
| 680 |
widgetsRegistry.add("my_widget", { |
| 681 |
component: MyWidget, |
| 682 |
fieldDependencies: [{ name: "child_ids", type: "one2many" }], |
| 683 |
}); |
| 684 |
|
| 685 |
await mountView({ |
| 686 |
resModel: "res.users", |
| 687 |
type: "form", |
| 688 |
arch: ` |
| 689 |
<form> |
| 690 |
<field name="partner_ids" > |
| 691 |
<list> |
| 692 |
<field name="name"/> |
| 693 |
<widget name="my_widget" /> |
| 694 |
</list> |
| 695 |
<form> |
| 696 |
<field name="name"/> |
| 697 |
<widget name="my_widget" /> |
| 698 |
</form> |
| 699 |
</field> |
| 700 |
</form> |
| 701 |
`, |
| 702 |
resId: 17, |
| 703 |
}); |
| 704 |
|
| 705 |
await contains(`.o_list_view .o_field_cell[name="name"]`).click(); |
| 706 |
expect(`.modal .o_form_view .o_widget_my_widget`).toHaveCount(1); |
| 707 |
}); |
| 708 |
|
| 709 |
test(`fieldDependencies are readonly by default`, async () => { |
| 710 |
class MyField extends CharField {} |
| 711 |
fieldsRegistry.add("my_widget", { |
| 712 |
component: MyField, |
| 713 |
fieldDependencies: [ |
| 714 |
{ name: "int_field", type: "integer" }, |
| 715 |
{ name: "bar", type: "boolean" }, |
| 716 |
{ name: "float_field", type: "float", readonly: false }, |
| 717 |
], |
| 718 |
}); |
| 719 |
|
| 720 |
onRpc("web_save", ({ args }) => { |
| 721 |
expect(args[1]).toEqual( |
| 722 |
{ |
| 723 |
name: "plop", |
| 724 |
foo: "My little Foo Value", |
| 725 |
float_field: 0, |
| 726 |
}, |
| 727 |
{ message: "'int_field' and 'bar' shouldn't be present" } |
| 728 |
); |
| 729 |
expect.step("web_save"); |
| 730 |
}); |
| 731 |
await mountView({ |
| 732 |
resModel: "partner", |
| 733 |
type: "form", |
| 734 |
arch: ` |
| 735 |
<form> |
| 736 |
<field name="name"/> |
| 737 |
<field name="foo" widget="my_widget"/> |
| 738 |
<field name="int_field" readonly="1"/> |
| 739 |
</form> |
| 740 |
`, |
| 741 |
}); |
| 742 |
await contains(`[name='name'] input`).edit("plop"); |
| 743 |
await contains(`.o_form_button_save`).click(); |
| 744 |
expect.verifySteps(["web_save"]); |
| 745 |
}); |
| 746 |
|
| 747 |
test(`decoration-bf works on fields`, async () => { |
| 748 |
await mountView({ |
| 749 |
resModel: "partner", |
| 750 |
type: "form", |
| 751 |
arch: ` |
| 752 |
<form> |
| 753 |
<field name="int_field"/> |
| 754 |
<field name="display_name" decoration-bf="int_field < 5"/> |
| 755 |
<field name="foo" decoration-bf="int_field > 5"/> |
| 756 |
</form> |
| 757 |
`, |
| 758 |
resId: 2, |
| 759 |
}); |
| 760 |
expect(`.o_field_widget[name="display_name"]`).not.toHaveClass("fw-bold"); |
| 761 |
expect(`.o_field_widget[name="foo"]`).toHaveClass("fw-bold"); |
| 762 |
}); |
| 763 |
|
| 764 |
test(`decoration-it works on fields`, async () => { |
| 765 |
await mountView({ |
| 766 |
resModel: "partner", |
| 767 |
type: "form", |
| 768 |
arch: ` |
| 769 |
<form> |
| 770 |
<field name="int_field"/> |
| 771 |
<field name="display_name" decoration-it="int_field < 5"/> |
| 772 |
<field name="foo" decoration-it="int_field > 5"/> |
| 773 |
</form> |
| 774 |
`, |
| 775 |
resId: 2, |
| 776 |
}); |
| 777 |
expect(`.o_field_widget[name="display_name"]`).not.toHaveClass("fst-italic"); |
| 778 |
expect(`.o_field_widget[name="foo"]`).toHaveClass("fst-italic"); |
| 779 |
}); |
| 780 |
|
| 781 |
test(`decoration on widgets are reevaluated if necessary`, async () => { |
| 782 |
await mountView({ |
| 783 |
resModel: "partner", |
| 784 |
type: "form", |
| 785 |
arch: ` |
| 786 |
<form> |
| 787 |
<field name="int_field"/> |
| 788 |
<field name="display_name" decoration-danger="int_field < 5"/> |
| 789 |
</form> |
| 790 |
`, |
| 791 |
resId: 2, |
| 792 |
}); |
| 793 |
expect(`.o_field_widget[name="display_name"]`).not.toHaveClass("text-danger"); |
| 794 |
await contains(`.o_field_widget[name=int_field] input`).edit("3"); |
| 795 |
expect(`.o_field_widget[name="display_name"]`).toHaveClass("text-danger"); |
| 796 |
}); |
| 797 |
|
| 798 |
test(`decoration on widgets works on same widget`, async () => { |
| 799 |
await mountView({ |
| 800 |
resModel: "partner", |
| 801 |
type: "form", |
| 802 |
arch: `<form><field name="int_field" decoration-danger="int_field < 5"/></form>`, |
| 803 |
resId: 2, |
| 804 |
}); |
| 805 |
expect(`.o_field_widget[name="int_field"]`).not.toHaveClass("text-danger"); |
| 806 |
await contains(`.o_field_widget[name=int_field] input`).edit("3"); |
| 807 |
expect(`.o_field_widget[name="int_field"]`).toHaveClass("text-danger"); |
| 808 |
}); |
| 809 |
|
| 810 |
test(`only necessary fields are fetched with correct context`, async () => { |
| 811 |
onRpc("web_read", ({ kwargs }) => { |
| 812 |
expect.step("web_read"); |
| 813 |
expect(kwargs.specification).toEqual( |
| 814 |
{ foo: {}, display_name: {} }, |
| 815 |
{ message: "should only fetch requested fields" } |
| 816 |
); |
| 817 |
expect(kwargs.context.bin_size).toBe(true, { |
| 818 |
message: "bin_size should always be in the context", |
| 819 |
}); |
| 820 |
}); |
| 821 |
await mountView({ |
| 822 |
resModel: "partner", |
| 823 |
type: "form", |
| 824 |
arch: `<form><field name="foo"/></form>`, |
| 825 |
resId: 1, |
| 826 |
}); |
| 827 |
expect.verifySteps(["web_read"]); |
| 828 |
}); |
| 829 |
|
| 830 |
test(`group rendering`, async () => { |
| 831 |
await mountView({ |
| 832 |
resModel: "partner", |
| 833 |
type: "form", |
| 834 |
arch: ` |
| 835 |
<form> |
| 836 |
<sheet> |
| 837 |
<group> |
| 838 |
<field name="foo"/> |
| 839 |
</group> |
| 840 |
</sheet> |
| 841 |
</form> |
| 842 |
`, |
| 843 |
resId: 1, |
| 844 |
}); |
| 845 |
expect(`div.o_inner_group`).toHaveCount(1); |
| 846 |
}); |
| 847 |
|
| 848 |
test(`group with formLabel`, async () => { |
| 849 |
await mountView({ |
| 850 |
resModel: "partner", |
| 851 |
type: "form", |
| 852 |
arch: ` |
| 853 |
<form> |
| 854 |
<sheet> |
| 855 |
<group> |
| 856 |
<!-- OuterGroup --> |
| 857 |
<field name="foo"/> |
| 858 |
<label for="foo" class="plop plop2"/> |
| 859 |
<group> |
| 860 |
<!-- InnerGroup --> |
| 861 |
<field name="display_name"/> |
| 862 |
</group> |
| 863 |
</group> |
| 864 |
</sheet> |
| 865 |
</form> |
| 866 |
`, |
| 867 |
resId: 1, |
| 868 |
}); |
| 869 |
expect(`.o_field_widget[name=foo]`).toHaveClass(["o_field_char", "col-lg-6"]); |
| 870 |
expect(`.o_form_label[for=foo_0]`).toHaveClass(["plop", "plop2", "col-lg-6"]); |
| 871 |
}); |
| 872 |
|
| 873 |
test(`group containing both a field and a group`, async () => { |
| 874 |
// The purpose of this test is to check that classnames defined in a |
| 875 |
// field widget and those added by the form renderer are correctly |
| 876 |
// combined. For instance, the renderer adds className 'o_group_col_x' |
| 877 |
// on outer group's children (an outer group being a group that contains |
| 878 |
// at least a group). |
| 879 |
await mountView({ |
| 880 |
resModel: "partner", |
| 881 |
type: "form", |
| 882 |
arch: ` |
| 883 |
<form> |
| 884 |
<group> |
| 885 |
<field name="foo"/> |
| 886 |
<group> |
| 887 |
<field name="int_field"/> |
| 888 |
</group> |
| 889 |
</group> |
| 890 |
</form> |
| 891 |
`, |
| 892 |
resId: 1, |
| 893 |
}); |
| 894 |
expect(`.o_group .o_field_widget[name=foo]`).toHaveCount(1); |
| 895 |
expect(`.o_group .o_inner_group .o_field_widget[name=int_field]`).toHaveCount(1); |
| 896 |
expect(`.o_field_widget[name=foo]`).toHaveClass(["o_field_char", "col-lg-6"]); |
| 897 |
}); |
| 898 |
|
| 899 |
test(`field ids are unique (same field name in 2 form views)`, async () => { |
| 900 |
await mountView({ |
| 901 |
resModel: "partner", |
| 902 |
type: "form", |
| 903 |
arch: ` |
| 904 |
<form> |
| 905 |
<sheet> |
| 906 |
<group> |
| 907 |
<field name="foo"/> |
| 908 |
</group> |
| 909 |
<field name="child_ids"> |
| 910 |
<form> |
| 911 |
<sheet> |
| 912 |
<group> |
| 913 |
<field name="bar"/> |
| 914 |
<field name="foo"/> |
| 915 |
</group> |
| 916 |
</sheet> |
| 917 |
</form> |
| 918 |
<list> |
| 919 |
<field name="foo"/> |
| 920 |
</list> |
| 921 |
</field> |
| 922 |
</sheet> |
| 923 |
</form>`, |
| 924 |
resId: 1, |
| 925 |
}); |
| 926 |
|
| 927 |
expect(".o_field_widget input#foo_0").toHaveCount(1); |
| 928 |
|
| 929 |
await contains(".o_field_x2many_list_row_add a").click(); |
| 930 |
expect(".modal .o_form_view").toHaveCount(1); |
| 931 |
expect(".o_field_widget input#foo_0").toHaveCount(1); |
| 932 |
expect(".modal .o_field_widget input#foo_0").toHaveCount(1); |
| 933 |
expect(".modal .o_field_widget input#bar_0").toHaveCount(1); |
| 934 |
}); |
| 935 |
|
| 936 |
test(`Form and subview with _view_ref contexts`, async () => { |
| 937 |
Product._fields.type_ids = fields.One2many({ relation: "partner.type" }); |
| 938 |
Product._records = [{ id: 1, name: "Tromblon", type_ids: [12, 14] }]; |
| 939 |
Partner._records[0].product_id = 1; |
| 940 |
|
| 941 |
// This is an old test, written before "get_views" (formerly "load_views") automatically |
| 942 |
// inlines x2many subviews. As the purpose of this test is to assert that the js fetches |
| 943 |
// the correct sub view when it is not inline (which can still happen in nested form views), |
| 944 |
// we bypass the inline mecanism of "get_views" by setting widget="one2many" on the field. |
| 945 |
Partner._views = { |
| 946 |
form: ` |
| 947 |
<form> |
| 948 |
<field name="name"/> |
| 949 |
<field name="product_id" context="{'list_view_ref': 'some_tree_view'}"/> |
| 950 |
</form> |
| 951 |
`, |
| 952 |
}; |
| 953 |
PartnerType._views = { |
| 954 |
list: `<list><field name="color"/></list>`, |
| 955 |
kanban: ` |
| 956 |
<kanban> |
| 957 |
<templates> |
| 958 |
<t t-name="card"> |
| 959 |
<field name="color"/> |
| 960 |
</t> |
| 961 |
</templates> |
| 962 |
</kanban> |
| 963 |
`, |
| 964 |
}; |
| 965 |
Product._views = { |
| 966 |
form: ` |
| 967 |
<form> |
| 968 |
<field name="name"/> |
| 969 |
<field name="type_ids" widget="one2many" context="{'list_view_ref': 'some_other_tree_view'}"/> |
| 970 |
</form> |
| 971 |
`, |
| 972 |
}; |
| 973 |
|
| 974 |
onRpc("product", "get_views", ({ kwargs }) => { |
| 975 |
const { context } = kwargs; |
| 976 |
expect.step("product get_views"); |
| 977 |
expect(context.list_view_ref).toBe("some_tree_view"); |
| 978 |
// "The correct _view_ref should have been sent to the server, first time" |
| 979 |
}); |
| 980 |
onRpc("partner.type", "get_views", ({ kwargs }) => { |
| 981 |
const { context } = kwargs; |
| 982 |
expect.step("partner.type get_views"); |
| 983 |
expect(context.list_view_ref).toBe("some_other_tree_view"); |
| 984 |
// "The correct _view_ref should have been sent to the server for the subview" |
| 985 |
}); |
| 986 |
onRpc("get_formview_action", ({ model, kwargs }) => { |
| 987 |
expect.step("get_formview_action"); |
| 988 |
return { |
| 989 |
res_id: 1, |
| 990 |
type: "ir.actions.act_window", |
| 991 |
target: "current", |
| 992 |
res_model: model, |
| 993 |
context: kwargs.context, |
| 994 |
view_mode: "form", |
| 995 |
views: [[false, "form"]], |
| 996 |
}; |
| 997 |
}); |
| 998 |
|
| 999 |
await mountWithCleanup(WebClient); |
| 1000 |
await getService("action").doAction({ |
| 1001 |
res_id: 1, |
| 1002 |
type: "ir.actions.act_window", |
| 1003 |
target: "current", |
| 1004 |
res_model: "partner", |
| 1005 |
view_mode: "form", |
| 1006 |
views: [[false, "form"]], |
| 1007 |
}); |
| 1008 |
await contains(`.o_field_widget[name="product_id"] .o_external_button`, { |
| 1009 |
visible: false, |
| 1010 |
}).click(); |
| 1011 |
expect.verifySteps(["get_formview_action", "product get_views", "partner.type get_views"]); |
| 1012 |
}); |
| 1013 |
|
| 1014 |
test(`Form and subsubview with only _view_ref contexts`, async () => { |
| 1015 |
PartnerType._fields.company_ids = fields.One2many({ relation: "res.company" }); |
| 1016 |
ResCompany._views = { |
| 1017 |
list: `<list><field name="name"/></list>`, |
| 1018 |
kanban: ` |
| 1019 |
<kanban> |
| 1020 |
<templates> |
| 1021 |
<t t-name="card"> |
| 1022 |
<field name="name"/> |
| 1023 |
</t> |
| 1024 |
</templates> |
| 1025 |
</kanban> |
| 1026 |
`, |
| 1027 |
"form,2": `<form><field name="name"/></form>`, |
| 1028 |
}; |
| 1029 |
PartnerType._views = { |
| 1030 |
list: `<list><field name="name"/></list>`, |
| 1031 |
kanban: ` |
| 1032 |
<kanban> |
| 1033 |
<templates> |
| 1034 |
<t t-name="card"> |
| 1035 |
<field name="name"/> |
| 1036 |
</t> |
| 1037 |
</templates> |
| 1038 |
</kanban> |
| 1039 |
`, |
| 1040 |
"form,foo.partner_type_form_view": ` |
| 1041 |
<form> |
| 1042 |
<field name="color"/> |
| 1043 |
<field name="company_ids" context="{ |
| 1044 |
'default_color': 2, |
| 1045 |
'form_view_ref': 'bar.rescompany_form_view', |
| 1046 |
}"/> |
| 1047 |
</form> |
| 1048 |
`, |
| 1049 |
}; |
| 1050 |
|
| 1051 |
const userContext = { |
| 1052 |
lang: "en", |
| 1053 |
tz: "taht", |
| 1054 |
uid: 7, |
| 1055 |
allowed_company_ids: [1], |
| 1056 |
}; |
| 1057 |
const expectedContexts = new Map(); |
| 1058 |
expectedContexts.set("view:partner", { ...userContext }); |
| 1059 |
expectedContexts.set("onchange:partner", { ...userContext }); |
| 1060 |
expectedContexts.set("view:partner.type", { |
| 1061 |
...userContext, |
| 1062 |
form_view_ref: "foo.partner_type_form_view", |
| 1063 |
}); |
| 1064 |
expectedContexts.set("onchange:partner.type", { |
| 1065 |
...userContext, |
| 1066 |
form_view_ref: "foo.partner_type_form_view", |
| 1067 |
}); |
| 1068 |
|
| 1069 |
onRpc("get_views", ({ model, kwargs }) => { |
| 1070 |
const { context } = kwargs; |
| 1071 |
expect.step(`get_views (${model})`); |
| 1072 |
expect(context).toEqual(expectedContexts.get(`view:${model}`)); |
| 1073 |
}); |
| 1074 |
onRpc("onchange", ({ model, kwargs }) => { |
| 1075 |
const { context } = kwargs; |
| 1076 |
expect.step(`onchange (${model})`); |
| 1077 |
expect(context).toEqual(expectedContexts.get(`onchange:${model}`)); |
| 1078 |
}); |
| 1079 |
await mountView({ |
| 1080 |
resModel: "partner", |
| 1081 |
type: "form", |
| 1082 |
arch: ` |
| 1083 |
<form> |
| 1084 |
<field string="Partner Types" name="type_ids" widget="one2many" context="{ |
| 1085 |
'default_partner_id': id, |
| 1086 |
'form_view_ref': 'foo.partner_type_form_view' |
| 1087 |
}"/> |
| 1088 |
</form> |
| 1089 |
`, |
| 1090 |
resId: 2, |
| 1091 |
}); |
| 1092 |
expect.verifySteps(["get_views (partner)", "get_views (partner.type)"]); |
| 1093 |
|
| 1094 |
// Add a line in the x2many type_ids field |
| 1095 |
expectedContexts.clear(); |
| 1096 |
expectedContexts.set("view:partner.type", { |
| 1097 |
...userContext, |
| 1098 |
form_view_ref: "foo.partner_type_form_view", |
| 1099 |
}); |
| 1100 |
expectedContexts.set("onchange:partner.type", { |
| 1101 |
...userContext, |
| 1102 |
default_partner_id: 2, |
| 1103 |
form_view_ref: "foo.partner_type_form_view", |
| 1104 |
}); |
| 1105 |
|
| 1106 |
await contains( |
| 1107 |
`[name=type_ids] .o_field_x2many_list_row_add a, [name=type_ids] .o-kanban-button-new` |
| 1108 |
).click(); |
| 1109 |
expect.verifySteps(["get_views (partner.type)"]); |
| 1110 |
|
| 1111 |
// Create a new type_ids |
| 1112 |
await contains(`.modal .o_create_button`).click(); |
| 1113 |
expect.verifySteps(["get_views (partner.type)", "onchange (partner.type)"]); |
| 1114 |
|
| 1115 |
// Create a new company |
| 1116 |
expectedContexts.clear(); |
| 1117 |
expectedContexts.set("view:res.company", { |
| 1118 |
...userContext, |
| 1119 |
form_view_ref: "bar.rescompany_form_view", |
| 1120 |
}); |
| 1121 |
expectedContexts.set("onchange:res.company", { |
| 1122 |
...userContext, |
| 1123 |
default_color: 2, |
| 1124 |
form_view_ref: "bar.rescompany_form_view", |
| 1125 |
}); |
| 1126 |
|
| 1127 |
await contains(`.modal [name=company_ids] .o_field_x2many_list_row_add a`).click(); |
| 1128 |
expect.verifySteps(["get_views (res.company)", "onchange (res.company)"]); |
| 1129 |
}); |
| 1130 |
|
| 1131 |
test(`x2many form_view_ref with defined list`, async () => { |
| 1132 |
Partner._records = [{ id: 1, type_ids: [1] }]; |
| 1133 |
|
| 1134 |
PartnerType._records = [{ id: 1, name: "Timmy 1" }]; |
| 1135 |
PartnerType._views = { |
| 1136 |
"form,foo.partner_type_form_view": ` |
| 1137 |
<form> |
| 1138 |
<div class="form_view_ref_partner_type"> |
| 1139 |
<field name="display_name" /> |
| 1140 |
</div> |
| 1141 |
</form> |
| 1142 |
`, |
| 1143 |
}; |
| 1144 |
|
| 1145 |
const expectedContexts = new Map(); |
| 1146 |
const userContext = { |
| 1147 |
lang: "en", |
| 1148 |
tz: "taht", |
| 1149 |
uid: 7, |
| 1150 |
allowed_company_ids: [1], |
| 1151 |
}; |
| 1152 |
|
| 1153 |
expectedContexts.set("partner", { ...userContext }); |
| 1154 |
expectedContexts.set("partner.type", { |
| 1155 |
...userContext, |
| 1156 |
form_view_ref: "foo.partner_type_form_view", |
| 1157 |
}); |
| 1158 |
|
| 1159 |
onRpc("get_views", ({ model, kwargs }) => { |
| 1160 |
expect.step(`get_views (${model})`); |
| 1161 |
expect(kwargs.context).toEqual(expectedContexts.get(model)); |
| 1162 |
}); |
| 1163 |
|
| 1164 |
await mountView({ |
| 1165 |
resModel: "partner", |
| 1166 |
type: "form", |
| 1167 |
arch: ` |
| 1168 |
<form> |
| 1169 |
<field name="type_ids" invisible="1" /> |
| 1170 |
<field string="Partner Types" name="type_ids" context="{ |
| 1171 |
'default_partner_id': id, |
| 1172 |
'form_view_ref': 'foo.partner_type_form_view' |
| 1173 |
}"> |
| 1174 |
<list> |
| 1175 |
<field name="display_name" /> |
| 1176 |
</list> |
| 1177 |
</field> |
| 1178 |
</form> |
| 1179 |
`, |
| 1180 |
resId: 1, |
| 1181 |
}); |
| 1182 |
expect.verifySteps(["get_views (partner)"]); |
| 1183 |
|
| 1184 |
await contains(`.o_field_widget[name='type_ids'] .o_field_cell`).click(); |
| 1185 |
expect.verifySteps(["get_views (partner.type)"]); |
| 1186 |
}); |
| 1187 |
|
| 1188 |
test(`invisible fields are properly hidden`, async () => { |
| 1189 |
await mountView({ |
| 1190 |
resModel: "partner", |
| 1191 |
type: "form", |
| 1192 |
// the arch contains an x2many field without inline view: as it is always invisible, |
| 1193 |
// the view should not be fetched. we don't specify any view in this test, so if it |
| 1194 |
// ever tries to fetch it, it will crash, indicating that this is wrong. |
| 1195 |
arch: ` |
| 1196 |
<form> |
| 1197 |
<sheet> |
| 1198 |
<group> |
| 1199 |
<field name="foo" invisible="1"/> |
| 1200 |
<field name="bar"/> |
| 1201 |
</group> |
| 1202 |
<field name="float_field" invisible="1"/> |
| 1203 |
<field name="child_ids" invisible="True"/> |
| 1204 |
</sheet> |
| 1205 |
</form> |
| 1206 |
`, |
| 1207 |
resId: 1, |
| 1208 |
}); |
| 1209 |
expect(`label:contains(Foo)`).toHaveCount(0); |
| 1210 |
expect(`.o_field_widget[name=foo]`).toHaveCount(0); |
| 1211 |
expect(`.o_field_widget[name=float_field]`).toHaveCount(0); |
| 1212 |
expect(`.o_field_widget[name="child_ids"]`).toHaveCount(0); |
| 1213 |
}); |
| 1214 |
|
| 1215 |
test(`correctly copy attributes to compiled labels`, async () => { |
| 1216 |
await mountView({ |
| 1217 |
resModel: "partner", |
| 1218 |
type: "form", |
| 1219 |
arch: ` |
| 1220 |
<form> |
| 1221 |
<label string="Apply after" for="bar" class="a"/> |
| 1222 |
<field name="bar" class="b"/> |
| 1223 |
<label string="hours" for="bar" class="c"/> |
| 1224 |
</form> |
| 1225 |
`, |
| 1226 |
}); |
| 1227 |
expect(`.o_form_label:eq(0)`).toHaveClass("a"); |
| 1228 |
expect(`.o_field_widget.o_field_boolean`).toHaveClass("b"); |
| 1229 |
expect(`.o_form_label:eq(1)`).toHaveClass("c"); |
| 1230 |
}); |
| 1231 |
|
| 1232 |
test(`invisible fields are not used for the label generation`, async () => { |
| 1233 |
await mountView({ |
| 1234 |
resModel: "partner", |
| 1235 |
type: "form", |
| 1236 |
arch: ` |
| 1237 |
<form> |
| 1238 |
<sheet> |
| 1239 |
<field name="float_field" invisible="1"/> |
| 1240 |
<label for="float_field"/> |
| 1241 |
<field name="float_field"/> |
| 1242 |
</sheet> |
| 1243 |
</form> |
| 1244 |
`, |
| 1245 |
resId: 1, |
| 1246 |
}); |
| 1247 |
expect(`label:contains(Float field)`).toHaveCount(1); |
| 1248 |
}); |
| 1249 |
|
| 1250 |
test(`invisible elements are properly hidden`, async () => { |
| 1251 |
await mountView({ |
| 1252 |
resModel: "partner", |
| 1253 |
type: "form", |
| 1254 |
arch: ` |
| 1255 |
<form> |
| 1256 |
<header invisible="1"> |
| 1257 |
<button name="myaction" string="coucou"/> |
| 1258 |
</header> |
| 1259 |
<sheet> |
| 1260 |
<group> |
| 1261 |
<group string="invgroup" invisible="1"> |
| 1262 |
<field name="foo"/> |
| 1263 |
</group> |
| 1264 |
<group string="visgroup"> |
| 1265 |
<field name="bar"/> |
| 1266 |
</group> |
| 1267 |
</group> |
| 1268 |
<notebook> |
| 1269 |
<page string="visible"/> |
| 1270 |
<page string="invisible" invisible="1"/> |
| 1271 |
</notebook> |
| 1272 |
</sheet> |
| 1273 |
</form> |
| 1274 |
`, |
| 1275 |
resId: 1, |
| 1276 |
}); |
| 1277 |
expect(`.o_form_statusbar button:contains(coucou)`).toHaveCount(0); |
| 1278 |
expect(`.o_notebook li a:contains(visible)`).toHaveCount(1); |
| 1279 |
expect(`.o_notebook li a:contains(invisible)`).toHaveCount(0); |
| 1280 |
expect(`div.o_inner_group:contains(visgroup)`).toHaveCount(1); |
| 1281 |
expect(`div.o_inner_group:contains(invgroup)`).toHaveCount(0); |
| 1282 |
}); |
| 1283 |
|
| 1284 |
test(`invisible attrs on fields are re-evaluated on field change`, async () => { |
| 1285 |
// we set the value bar to simulate a falsy boolean value. |
| 1286 |
Partner._records[0].bar = false; |
| 1287 |
|
| 1288 |
await mountView({ |
| 1289 |
resModel: "partner", |
| 1290 |
type: "form", |
| 1291 |
arch: ` |
| 1292 |
<form> |
| 1293 |
<sheet> |
| 1294 |
<group> |
| 1295 |
<field name="int_field"/> |
| 1296 |
<field name="type_ids" invisible="1"/> |
| 1297 |
<field name="foo" invisible="int_field == 10"/> |
| 1298 |
<field name="bar" invisible="not bar and not type_ids"/> |
| 1299 |
</group> |
| 1300 |
</sheet> |
| 1301 |
</form> |
| 1302 |
`, |
| 1303 |
resId: 1, |
| 1304 |
}); |
| 1305 |
expect(`.o_field_widget[name=int_field]`).toHaveCount(1); |
| 1306 |
expect(`.o_field_widget[name=type_ids]`).toHaveCount(0); |
| 1307 |
expect(`.o_field_widget[name=foo]`).toHaveCount(0); |
| 1308 |
expect(`.o_field_widget[name=bar]`).toHaveCount(0); |
| 1309 |
|
| 1310 |
await contains(`.o_field_widget[name=int_field] input`).edit("44"); |
| 1311 |
expect(`.o_field_widget[name=int_field]`).toHaveCount(1); |
| 1312 |
expect(`.o_field_widget[name=type_ids]`).toHaveCount(0); |
| 1313 |
expect(`.o_field_widget[name=foo]`).toHaveCount(1); |
| 1314 |
expect(`.o_field_widget[name=bar]`).toHaveCount(0); |
| 1315 |
}); |
| 1316 |
|
| 1317 |
test(`invisible attrs char fields`, async () => { |
| 1318 |
// For a char/text field, the server can return false or "" (empty string), |
| 1319 |
// depending if the field isn't set in db (NULL) or set to the empty string. |
| 1320 |
// This makes no difference in the UI, but it matters when evaluating modifiers. |
| 1321 |
Partner._records[0].name = false; |
| 1322 |
Partner._records[0].foo = ""; |
| 1323 |
|
| 1324 |
await mountView({ |
| 1325 |
resModel: "partner", |
| 1326 |
type: "form", |
| 1327 |
arch: ` |
| 1328 |
<form> |
| 1329 |
<div class="a" invisible="foo == False">b</div> |
| 1330 |
<div class="b" invisible="foo == ''">b</div> |
| 1331 |
<div class="c" invisible="not name">c</div> |
| 1332 |
<div class="d" invisible="name == ''">d</div> |
| 1333 |
<div class="e" invisible="not foo">e</div> |
| 1334 |
<div class="f" invisible="name == False">f</div> |
| 1335 |
<field name="name" invisible="1"/> |
| 1336 |
<field name="foo" invisible="1"/> |
| 1337 |
</form> |
| 1338 |
`, |
| 1339 |
resId: 1, |
| 1340 |
}); |
| 1341 |
expect(`div.a`).toHaveCount(1); |
| 1342 |
expect(`div.b`).toHaveCount(0); |
| 1343 |
expect(`div.c`).toHaveCount(0); |
| 1344 |
expect(`div.d`).toHaveCount(1); |
| 1345 |
expect(`div.e`).toHaveCount(0); |
| 1346 |
expect(`div.f`).toHaveCount(0); |
| 1347 |
}); |
| 1348 |
|
| 1349 |
test(`properly handle modifiers and attributes on notebook tags`, async () => { |
| 1350 |
await mountView({ |
| 1351 |
resModel: "partner", |
| 1352 |
type: "form", |
| 1353 |
arch: ` |
| 1354 |
<form> |
| 1355 |
<sheet> |
| 1356 |
<field name="int_field"/> |
| 1357 |
<notebook name="test_name" class="new_class" invisible="int_field == 10"> |
| 1358 |
<page string="Foo"> |
| 1359 |
<field name="foo"/> |
| 1360 |
</page> |
| 1361 |
</notebook> |
| 1362 |
</sheet> |
| 1363 |
</form> |
| 1364 |
`, |
| 1365 |
resId: 1, |
| 1366 |
}); |
| 1367 |
expect(`.o_notebook`).toHaveCount(0); |
| 1368 |
|
| 1369 |
await contains(`.o_field_widget[name=int_field] input`).edit("44"); |
| 1370 |
expect(`.o_notebook`).toHaveCount(1); |
| 1371 |
expect(`.o_notebook`).toHaveClass("new_class"); |
| 1372 |
}); |
| 1373 |
|
| 1374 |
test(`empty notebook`, async () => { |
| 1375 |
await mountView({ |
| 1376 |
resModel: "partner", |
| 1377 |
type: "form", |
| 1378 |
arch: ` |
| 1379 |
<form> |
| 1380 |
<sheet> |
| 1381 |
<notebook/> |
| 1382 |
</sheet> |
| 1383 |
</form> |
| 1384 |
`, |
| 1385 |
resId: 1, |
| 1386 |
}); |
| 1387 |
expect(`:scope .o_notebook .nav`).toHaveCount(0); |
| 1388 |
}); |
| 1389 |
|
| 1390 |
test(`notebook page name and class transferred to DOM`, async () => { |
| 1391 |
await mountView({ |
| 1392 |
resModel: "partner", |
| 1393 |
type: "form", |
| 1394 |
arch: ` |
| 1395 |
<form> |
| 1396 |
<sheet> |
| 1397 |
<notebook> |
| 1398 |
<page name="choucroute" string="Choucroute" class="sauerKraut"> |
| 1399 |
<field name="foo"/> |
| 1400 |
</page> |
| 1401 |
</notebook> |
| 1402 |
</sheet> |
| 1403 |
</form> |
| 1404 |
`, |
| 1405 |
resId: 1, |
| 1406 |
}); |
| 1407 |
expect(`.o_notebook .nav .nav-link[name='choucroute']`).toHaveClass(["active", "sauerKraut"]); |
| 1408 |
}); |
| 1409 |
|
| 1410 |
test(`no visible page`, async () => { |
| 1411 |
await mountView({ |
| 1412 |
resModel: "partner", |
| 1413 |
type: "form", |
| 1414 |
arch: ` |
| 1415 |
<form> |
| 1416 |
<sheet> |
| 1417 |
<notebook> |
| 1418 |
<page string="Foo" invisible="1"> |
| 1419 |
<field name="foo"/> |
| 1420 |
</page> |
| 1421 |
<page string="Bar" invisible="1"> |
| 1422 |
<field name="bar"/> |
| 1423 |
</page> |
| 1424 |
</notebook> |
| 1425 |
</sheet> |
| 1426 |
</form> |
| 1427 |
`, |
| 1428 |
resId: 1, |
| 1429 |
}); |
| 1430 |
expect(`.o_notebook_headers .nav-item`).toHaveCount(0); |
| 1431 |
expect(`.tab-content .tab-pane`).toHaveCount(0); |
| 1432 |
}); |
| 1433 |
|
| 1434 |
test(`notebook: pages with invisible modifiers`, async () => { |
| 1435 |
await mountView({ |
| 1436 |
resModel: "partner", |
| 1437 |
type: "form", |
| 1438 |
arch: ` |
| 1439 |
<form> |
| 1440 |
<sheet> |
| 1441 |
<field name="bar"/> |
| 1442 |
<notebook> |
| 1443 |
<page string="A" invisible='not bar'> |
| 1444 |
<field name="foo"/> |
| 1445 |
</page> |
| 1446 |
<page string="B" invisible='bar'> |
| 1447 |
<field name="int_field"/> |
| 1448 |
</page> |
| 1449 |
<page string="C"> |
| 1450 |
<field name="float_field"/> |
| 1451 |
</page> |
| 1452 |
</notebook> |
| 1453 |
</sheet> |
| 1454 |
</form> |
| 1455 |
`, |
| 1456 |
resId: 1, |
| 1457 |
}); |
| 1458 |
expect(`.o_notebook .nav-link`).toHaveCount(2); |
| 1459 |
expect(`.o_notebook .nav .nav-link.active`).toHaveCount(1); |
| 1460 |
expect(`.o_notebook .nav .nav-link:eq(0)`).toHaveClass("active"); |
| 1461 |
expect(`.o_notebook .nav-link.active`).toHaveText("A"); |
| 1462 |
|
| 1463 |
await contains(`.o_field_widget[name=bar] input`).click(); |
| 1464 |
expect(`.o_notebook .nav-link`).toHaveCount(2); |
| 1465 |
expect(`.o_notebook .nav .nav-link.active`).toHaveCount(1); |
| 1466 |
expect(`.o_notebook .nav .nav-link:eq(0)`).toHaveClass("active"); |
| 1467 |
expect(`.o_notebook .nav-link.active`).toHaveText("B"); |
| 1468 |
}); |
| 1469 |
|
| 1470 |
test(`invisible attrs on first notebook page`, async () => { |
| 1471 |
await mountView({ |
| 1472 |
resModel: "partner", |
| 1473 |
type: "form", |
| 1474 |
arch: ` |
| 1475 |
<form> |
| 1476 |
<sheet> |
| 1477 |
<field name="int_field"/> |
| 1478 |
<notebook> |
| 1479 |
<page string="Foo" invisible='int_field == 44'> |
| 1480 |
<field name="foo"/> |
| 1481 |
</page> |
| 1482 |
<page string="Bar"> |
| 1483 |
<field name="bar"/> |
| 1484 |
</page> |
| 1485 |
</notebook> |
| 1486 |
</sheet> |
| 1487 |
</form> |
| 1488 |
`, |
| 1489 |
resId: 1, |
| 1490 |
}); |
| 1491 |
expect(`.o_notebook .nav .nav-link`).toHaveCount(2); |
| 1492 |
expect(`.o_notebook .nav .nav-link:eq(0)`).toHaveClass("active"); |
| 1493 |
expect(`.o_notebook .tab-content .tab-pane:eq(0)`).toHaveClass("active"); |
| 1494 |
|
| 1495 |
await contains(`.o_field_widget[name=int_field] input`).edit("44"); |
| 1496 |
expect(`.o_notebook .nav .nav-link`).toHaveCount(1); |
| 1497 |
expect(`.o_notebook .tab-content .tab-pane`).toHaveCount(1); |
| 1498 |
expect(`.o_notebook .nav .nav-link`).toHaveClass("active"); |
| 1499 |
expect(`.o_notebook .tab-content .tab-pane`).toHaveClass("active"); |
| 1500 |
}); |
| 1501 |
|
| 1502 |
test(`invisible attrs on notebook page which has only one page`, async () => { |
| 1503 |
await mountView({ |
| 1504 |
resModel: "partner", |
| 1505 |
type: "form", |
| 1506 |
arch: ` |
| 1507 |
<form> |
| 1508 |
<sheet> |
| 1509 |
<field name="bar"/> |
| 1510 |
<notebook> |
| 1511 |
<page string="Foo" invisible='bar'> |
| 1512 |
<field name="foo"/> |
| 1513 |
</page> |
| 1514 |
</notebook> |
| 1515 |
</sheet> |
| 1516 |
</form> |
| 1517 |
`, |
| 1518 |
resId: 1, |
| 1519 |
}); |
| 1520 |
expect(`.o_notebook`).toHaveCount(0); |
| 1521 |
|
| 1522 |
// enable checkbox |
| 1523 |
await contains(`.o_field_boolean input`).click(); |
| 1524 |
expect(`.o_notebook .nav .nav-link`).toHaveCount(1); |
| 1525 |
expect(`.o_notebook .tab-content .tab-pane`).toHaveCount(1); |
| 1526 |
expect(`.o_notebook .nav .nav-link`).toHaveClass("active"); |
| 1527 |
expect(`.o_notebook .tab-content .tab-pane`).toHaveClass("active"); |
| 1528 |
}); |
| 1529 |
|
| 1530 |
test(`first notebook page invisible`, async () => { |
| 1531 |
await mountView({ |
| 1532 |
resModel: "partner", |
| 1533 |
type: "form", |
| 1534 |
arch: ` |
| 1535 |
<form> |
| 1536 |
<sheet> |
| 1537 |
<field name="product_id"/> |
| 1538 |
<notebook> |
| 1539 |
<page string="Foo" invisible="1"> |
| 1540 |
<field name="foo"/> |
| 1541 |
</page> |
| 1542 |
<page string="Bar"> |
| 1543 |
<field name="bar"/> |
| 1544 |
</page> |
| 1545 |
</notebook> |
| 1546 |
</sheet> |
| 1547 |
</form> |
| 1548 |
`, |
| 1549 |
resId: 1, |
| 1550 |
}); |
| 1551 |
expect(`.o_notebook .nav .nav-link`).toHaveCount(1); |
| 1552 |
expect(`.o_notebook .nav .nav-link`).toHaveClass("active"); |
| 1553 |
}); |
| 1554 |
|
| 1555 |
test(`hide notebook element if all pages hidden`, async () => { |
| 1556 |
await mountView({ |
| 1557 |
resModel: "partner", |
| 1558 |
type: "form", |
| 1559 |
arch: ` |
| 1560 |
<form> |
| 1561 |
<sheet> |
| 1562 |
<field name="bar"/> |
| 1563 |
<notebook class="new_class"> |
| 1564 |
<page string="Foo" invisible="bar"> |
| 1565 |
<field name="foo"/> |
| 1566 |
</page> |
| 1567 |
<page string="float_field" invisible="1"> |
| 1568 |
<field name="float_field"/> |
| 1569 |
</page> |
| 1570 |
<page string="IntField" invisible="bar"> |
| 1571 |
<field name="int_field"/> |
| 1572 |
</page> |
| 1573 |
</notebook> |
| 1574 |
</sheet> |
| 1575 |
</form> |
| 1576 |
`, |
| 1577 |
}); |
| 1578 |
expect(`.o_notebook .nav .nav-link`).toHaveCount(2); |
| 1579 |
|
| 1580 |
await contains(`.o_field_boolean input`).click(); |
| 1581 |
expect(`.o_notebook`).toHaveCount(0); |
| 1582 |
}); |
| 1583 |
|
| 1584 |
test(`autofocus on second notebook page`, async () => { |
| 1585 |
await mountView({ |
| 1586 |
resModel: "partner", |
| 1587 |
type: "form", |
| 1588 |
arch: ` |
| 1589 |
<form> |
| 1590 |
<sheet> |
| 1591 |
<field name="product_id"/> |
| 1592 |
<notebook> |
| 1593 |
<page string="Choucroute"> |
| 1594 |
<field name="foo"/> |
| 1595 |
</page> |
| 1596 |
<page string="Cassoulet" autofocus="autofocus"> |
| 1597 |
<field name="bar"/> |
| 1598 |
</page> |
| 1599 |
</notebook> |
| 1600 |
</sheet> |
| 1601 |
</form> |
| 1602 |
`, |
| 1603 |
resId: 1, |
| 1604 |
}); |
| 1605 |
expect(`.o_notebook .nav .nav-item:eq(0) .nav-link`).not.toHaveClass("active"); |
| 1606 |
expect(`.o_notebook .nav .nav-item:eq(1) .nav-link`).toHaveClass("active"); |
| 1607 |
}); |
| 1608 |
|
| 1609 |
test(`invisible attrs on group are re-evaluated on field change`, async () => { |
| 1610 |
await mountView({ |
| 1611 |
resModel: "partner", |
| 1612 |
type: "form", |
| 1613 |
arch: ` |
| 1614 |
<form> |
| 1615 |
<sheet> |
| 1616 |
<field name="bar"/> |
| 1617 |
<group invisible='not bar'> |
| 1618 |
<group> |
| 1619 |
<field name="foo"/> |
| 1620 |
</group> |
| 1621 |
</group> |
| 1622 |
</sheet> |
| 1623 |
</form> |
| 1624 |
`, |
| 1625 |
resId: 1, |
| 1626 |
}); |
| 1627 |
expect(`div.o_group`).toHaveCount(1); |
| 1628 |
|
| 1629 |
await contains(`.o_field_boolean input`).click(); |
| 1630 |
expect(`div.o_group`).toHaveCount(0); |
| 1631 |
}); |
| 1632 |
|
| 1633 |
test(`invisible attrs with zero value in expression and unset value in data`, async () => { |
| 1634 |
await mountView({ |
| 1635 |
resModel: "partner", |
| 1636 |
type: "form", |
| 1637 |
arch: ` |
| 1638 |
<form> |
| 1639 |
<sheet> |
| 1640 |
<field name="foo"/> |
| 1641 |
<group invisible='float_field == 0.0'> |
| 1642 |
<div class="hello">this should be invisible</div> |
| 1643 |
<field name="float_field"/> |
| 1644 |
</group> |
| 1645 |
</sheet> |
| 1646 |
</form> |
| 1647 |
`, |
| 1648 |
}); |
| 1649 |
expect(`div.hello`).toHaveCount(0); |
| 1650 |
}); |
| 1651 |
|
| 1652 |
test(`reset local state when switching to another view`, async () => { |
| 1653 |
Partner._views = { |
| 1654 |
form: ` |
| 1655 |
<form> |
| 1656 |
<sheet> |
| 1657 |
<field name="product_id"/> |
| 1658 |
<notebook> |
| 1659 |
<page string="Foo"> |
| 1660 |
<field name="foo"/> |
| 1661 |
</page> |
| 1662 |
<page string="Bar"> |
| 1663 |
<field name="bar"/> |
| 1664 |
</page> |
| 1665 |
</notebook> |
| 1666 |
</sheet> |
| 1667 |
</form> |
| 1668 |
`, |
| 1669 |
list: `<list><field name="foo"/></list>`, |
| 1670 |
}; |
| 1671 |
|
| 1672 |
defineActions([ |
| 1673 |
{ |
| 1674 |
id: 1, |
| 1675 |
name: "Partner", |
| 1676 |
res_model: "partner", |
| 1677 |
views: [ |
| 1678 |
[false, "list"], |
| 1679 |
[false, "form"], |
| 1680 |
], |
| 1681 |
}, |
| 1682 |
]); |
| 1683 |
|
| 1684 |
await mountWithCleanup(WebClient); |
| 1685 |
await getService("action").doAction(1); |
| 1686 |
|
| 1687 |
await contains(`.o_control_panel_main_buttons button.o_list_button_add`).click(); |
| 1688 |
expect(`.o_form_view`).toHaveCount(1); |
| 1689 |
// sanity check: notebook active page is first page |
| 1690 |
expect(`.o_notebook .nav-link:eq(0)`).toHaveClass("active"); |
| 1691 |
|
| 1692 |
// click on second page tab |
| 1693 |
await contains(`.o_notebook .nav-link:eq(1)`).click(); |
| 1694 |
expect(`.o_notebook .nav-link:eq(1)`).toHaveClass("active"); |
| 1695 |
|
| 1696 |
await contains(`.o_control_panel .o_form_button_cancel`).click(); |
| 1697 |
expect(`.o_form_view`).toHaveCount(0); |
| 1698 |
|
| 1699 |
await contains(`.o_control_panel_main_buttons button.o_list_button_add`).click(); |
| 1700 |
expect(`.o_form_view`).toHaveCount(1); |
| 1701 |
// check notebook active page is first page again |
| 1702 |
expect(`.o_notebook .nav-link:eq(0)`).toHaveClass("active"); |
| 1703 |
}); |
| 1704 |
|
| 1705 |
test.tags("desktop"); |
| 1706 |
test(`trying to leave an invalid form view should not change the navbar`, async () => { |
| 1707 |
defineMenus([ |
| 1708 |
{ id: 1, name: "App0", actionID: 1 }, |
| 1709 |
{ id: 2, name: "App1", actionID: 2 }, |
| 1710 |
]); |
| 1711 |
|
| 1712 |
defineActions([ |
| 1713 |
{ |
| 1714 |
id: 1, |
| 1715 |
name: "Partner", |
| 1716 |
res_model: "partner", |
| 1717 |
views: [[false, "form"]], |
| 1718 |
}, |
| 1719 |
{ |
| 1720 |
id: 2, |
| 1721 |
name: "Product", |
| 1722 |
res_model: "product", |
| 1723 |
views: [[false, "list"]], |
| 1724 |
}, |
| 1725 |
]); |
| 1726 |
|
| 1727 |
Partner._views = { |
| 1728 |
form: ` |
| 1729 |
<form> |
| 1730 |
<sheet> |
| 1731 |
<field name="name" required="1"/> |
| 1732 |
<field name="foo"/> |
| 1733 |
</sheet> |
| 1734 |
</form> |
| 1735 |
`, |
| 1736 |
}; |
| 1737 |
Product._views = { |
| 1738 |
list: `<list><field name="name"/></list>`, |
| 1739 |
}; |
| 1740 |
|
| 1741 |
await mountWithCleanup(WebClient); |
| 1742 |
await animationFrame(); |
| 1743 |
await getService("action").doAction(1); |
| 1744 |
expect(`.o_main_navbar .o_menu_brand`).toHaveText("App0"); |
| 1745 |
|
| 1746 |
await contains(`[name='foo'] input`).edit("blop"); |
| 1747 |
await contains(`.o_navbar_apps_menu button`).click(); |
| 1748 |
await contains(`.o-dropdown--menu .dropdown-item[data-section='2']`).click(); |
| 1749 |
await animationFrame(); |
| 1750 |
expect(`.o_main_navbar .o_menu_brand`).toHaveText("App0"); |
| 1751 |
|
| 1752 |
await contains(`[name='name'] input`).edit("blop"); |
| 1753 |
await contains(`.o_navbar_apps_menu button`).click(); |
| 1754 |
await contains(`.o-dropdown--menu .dropdown-item[data-section='2']`).click(); |
| 1755 |
await animationFrame(); |
| 1756 |
expect(`.o_main_navbar .o_menu_brand`).toHaveText("App1"); |
| 1757 |
}); |
| 1758 |
|
| 1759 |
test.tags("desktop"); |
| 1760 |
test(`rendering stat buttons with action on desktop`, async () => { |
| 1761 |
mockService("action", { |
| 1762 |
doActionButton(params) { |
| 1763 |
expect.step("doActionButton"); |
| 1764 |
expect(params.name).toBe("someaction"); |
| 1765 |
expect(params.type).toBe("action"); |
| 1766 |
}, |
| 1767 |
}); |
| 1768 |
|
| 1769 |
await mountView({ |
| 1770 |
resModel: "partner", |
| 1771 |
type: "form", |
| 1772 |
arch: ` |
| 1773 |
<form> |
| 1774 |
<sheet> |
| 1775 |
<div name="button_box" class="oe_button_box"> |
| 1776 |
<button class="oe_stat_button" type="action" name="someaction"> |
| 1777 |
<field name="int_field"/> |
| 1778 |
</button> |
| 1779 |
<button class="oe_stat_button" name="some_action" type="action" invisible='bar'> |
| 1780 |
<field name="bar"/> |
| 1781 |
</button> |
| 1782 |
</div> |
| 1783 |
<group> |
| 1784 |
<field name="foo"/> |
| 1785 |
</group> |
| 1786 |
</sheet> |
| 1787 |
</form> |
| 1788 |
`, |
| 1789 |
resId: 2, |
| 1790 |
}); |
| 1791 |
expect(`button.oe_stat_button`).toHaveCount(1); |
| 1792 |
|
| 1793 |
await contains(`button.oe_stat_button`).click(); |
| 1794 |
expect.verifySteps(["doActionButton"]); |
| 1795 |
}); |
| 1796 |
|
| 1797 |
test.tags("mobile"); |
| 1798 |
test(`rendering stat buttons with action on mobile`, async () => { |
| 1799 |
mockService("action", { |
| 1800 |
doActionButton(params) { |
| 1801 |
expect.step("doActionButton"); |
| 1802 |
expect(params.name).toBe("someaction"); |
| 1803 |
expect(params.type).toBe("action"); |
| 1804 |
}, |
| 1805 |
}); |
| 1806 |
|
| 1807 |
await mountView({ |
| 1808 |
resModel: "partner", |
| 1809 |
type: "form", |
| 1810 |
arch: ` |
| 1811 |
<form> |
| 1812 |
<sheet> |
| 1813 |
<div name="button_box" class="oe_button_box"> |
| 1814 |
<button class="oe_stat_button" type="action" name="someaction"> |
| 1815 |
<field name="int_field"/> |
| 1816 |
</button> |
| 1817 |
<button class="oe_stat_button" name="some_action" type="action" invisible='bar'> |
| 1818 |
<field name="bar"/> |
| 1819 |
</button> |
| 1820 |
</div> |
| 1821 |
<group> |
| 1822 |
<field name="foo"/> |
| 1823 |
</group> |
| 1824 |
</sheet> |
| 1825 |
</form> |
| 1826 |
`, |
| 1827 |
resId: 2, |
| 1828 |
}); |
| 1829 |
await contains(".o-form-buttonbox .o_button_more").click(); |
| 1830 |
expect(`button.oe_stat_button`).toHaveCount(1); |
| 1831 |
|
| 1832 |
await contains(`button.oe_stat_button`).click(); |
| 1833 |
expect.verifySteps(["doActionButton"]); |
| 1834 |
}); |
| 1835 |
|
| 1836 |
test.tags("desktop"); |
| 1837 |
test(`rendering stat buttons without class on desktop`, async () => { |
| 1838 |
await mountView({ |
| 1839 |
resModel: "partner", |
| 1840 |
type: "form", |
| 1841 |
arch: ` |
| 1842 |
<form> |
| 1843 |
<sheet> |
| 1844 |
<div name="button_box" class="oe_button_box"> |
| 1845 |
<button> |
| 1846 |
<field name="int_field"/> |
| 1847 |
</button> |
| 1848 |
</div> |
| 1849 |
<group> |
| 1850 |
<field name="foo"/> |
| 1851 |
</group> |
| 1852 |
</sheet> |
| 1853 |
</form> |
| 1854 |
`, |
| 1855 |
resId: 2, |
| 1856 |
}); |
| 1857 |
expect(`button.oe_stat_button`).toHaveCount(1); |
| 1858 |
}); |
| 1859 |
|
| 1860 |
test.tags("mobile"); |
| 1861 |
test(`rendering stat buttons without class on mobile`, async () => { |
| 1862 |
await mountView({ |
| 1863 |
resModel: "partner", |
| 1864 |
type: "form", |
| 1865 |
arch: ` |
| 1866 |
<form> |
| 1867 |
<sheet> |
| 1868 |
<div name="button_box" class="oe_button_box"> |
| 1869 |
<button> |
| 1870 |
<field name="int_field"/> |
| 1871 |
</button> |
| 1872 |
</div> |
| 1873 |
<group> |
| 1874 |
<field name="foo"/> |
| 1875 |
</group> |
| 1876 |
</sheet> |
| 1877 |
</form> |
| 1878 |
`, |
| 1879 |
resId: 2, |
| 1880 |
}); |
| 1881 |
await contains(".o-form-buttonbox .o_button_more").click(); |
| 1882 |
expect(`button.oe_stat_button`).toHaveCount(1); |
| 1883 |
}); |
| 1884 |
|
| 1885 |
test.tags("desktop"); |
| 1886 |
test(`rendering stat buttons without action on desktop`, async () => { |
| 1887 |
await mountView({ |
| 1888 |
resModel: "partner", |
| 1889 |
type: "form", |
| 1890 |
arch: ` |
| 1891 |
<form> |
| 1892 |
<sheet> |
| 1893 |
<div name="button_box" class="oe_button_box"> |
| 1894 |
<button class="oe_stat_button"> |
| 1895 |
<field name="int_field"/> |
| 1896 |
</button> |
| 1897 |
<button class="oe_stat_button" name="some_action" type="action" invisible='bar'> |
| 1898 |
<field name="bar"/> |
| 1899 |
</button> |
| 1900 |
</div> |
| 1901 |
<group> |
| 1902 |
<field name="foo"/> |
| 1903 |
</group> |
| 1904 |
</sheet> |
| 1905 |
</form> |
| 1906 |
`, |
| 1907 |
resId: 2, |
| 1908 |
}); |
| 1909 |
expect(`button.oe_stat_button[disabled]`).toHaveCount(1); |
| 1910 |
}); |
| 1911 |
|
| 1912 |
test.tags("mobile"); |
| 1913 |
test(`rendering stat buttons without action on mobile`, async () => { |
| 1914 |
await mountView({ |
| 1915 |
resModel: "partner", |
| 1916 |
type: "form", |
| 1917 |
arch: ` |
| 1918 |
<form> |
| 1919 |
<sheet> |
| 1920 |
<div name="button_box" class="oe_button_box"> |
| 1921 |
<button class="oe_stat_button"> |
| 1922 |
<field name="int_field"/> |
| 1923 |
</button> |
| 1924 |
<button class="oe_stat_button" name="some_action" type="action" invisible='bar'> |
| 1925 |
<field name="bar"/> |
| 1926 |
</button> |
| 1927 |
</div> |
| 1928 |
<group> |
| 1929 |
<field name="foo"/> |
| 1930 |
</group> |
| 1931 |
</sheet> |
| 1932 |
</form> |
| 1933 |
`, |
| 1934 |
resId: 2, |
| 1935 |
}); |
| 1936 |
await contains(".o-form-buttonbox .o_button_more").click(); |
| 1937 |
expect(`button.oe_stat_button[disabled]`).toHaveCount(1); |
| 1938 |
}); |
| 1939 |
|
| 1940 |
test.tags("desktop"); |
| 1941 |
test(`readonly stat buttons stays disabled on desktop`, async () => { |
| 1942 |
mockService("action", { |
| 1943 |
async doActionButton(params) { |
| 1944 |
if (params.name == "action_to_perform") { |
| 1945 |
expect.step("action_to_perform"); |
| 1946 |
expect(`button.oe_stat_button[disabled]`).toHaveCount(2, { |
| 1947 |
message: "While performing the action, both buttons should be disabled.", |
| 1948 |
}); |
| 1949 |
} |
| 1950 |
}, |
| 1951 |
}); |
| 1952 |
|
| 1953 |
await mountView({ |
| 1954 |
resModel: "partner", |
| 1955 |
type: "form", |
| 1956 |
arch: ` |
| 1957 |
<form> |
| 1958 |
<sheet> |
| 1959 |
<div name="button_box" class="oe_button_box"> |
| 1960 |
<button class="oe_stat_button"> |
| 1961 |
<field name="int_field"/> |
| 1962 |
</button> |
| 1963 |
<button class="oe_stat_button" type="action" name="some_action"> |
| 1964 |
<field name="bar"/> |
| 1965 |
</button> |
| 1966 |
</div> |
| 1967 |
<group> |
| 1968 |
<button type="action" name="action_to_perform">Run an action</button> |
| 1969 |
</group> |
| 1970 |
</sheet> |
| 1971 |
</form> |
| 1972 |
`, |
| 1973 |
resId: 2, |
| 1974 |
}); |
| 1975 |
expect(`button.oe_stat_button`).toHaveCount(2); |
| 1976 |
expect(`button.oe_stat_button[disabled]`).toHaveCount(1); |
| 1977 |
|
| 1978 |
await contains(`button[name=action_to_perform]`).click(); |
| 1979 |
expect(`button.oe_stat_button[disabled]`).toHaveCount(1, { |
| 1980 |
message: "After performing the action, only one button should be disabled.", |
| 1981 |
}); |
| 1982 |
expect.verifySteps(["action_to_perform"]); |
| 1983 |
}); |
| 1984 |
|
| 1985 |
test.tags("mobile"); |
| 1986 |
test(`readonly stat buttons stays disabled on mobile`, async () => { |
| 1987 |
mockService("action", { |
| 1988 |
async doActionButton(params) { |
| 1989 |
if (params.name == "action_to_perform") { |
| 1990 |
expect.step("action_to_perform"); |
| 1991 |
} |
| 1992 |
}, |
| 1993 |
}); |
| 1994 |
|
| 1995 |
await mountView({ |
| 1996 |
resModel: "partner", |
| 1997 |
type: "form", |
| 1998 |
arch: ` |
| 1999 |
<form> |
| 2000 |
<sheet> |
| 2001 |
<div name="button_box" class="oe_button_box"> |
| 2002 |
<button class="oe_stat_button"> |
| 2003 |
<field name="int_field"/> |
| 2004 |
</button> |
| 2005 |
<button class="oe_stat_button" type="action" name="some_action"> |
| 2006 |
<field name="bar"/> |
| 2007 |
</button> |
| 2008 |
</div> |
| 2009 |
<group> |
| 2010 |
<button type="action" name="action_to_perform">Run an action</button> |
| 2011 |
</group> |
| 2012 |
</sheet> |
| 2013 |
</form> |
| 2014 |
`, |
| 2015 |
resId: 2, |
| 2016 |
}); |
| 2017 |
await contains(".o-form-buttonbox .o_button_more").click(); |
| 2018 |
expect(`button.oe_stat_button`).toHaveCount(2); |
| 2019 |
expect(`button.oe_stat_button[disabled]`).toHaveCount(1); |
| 2020 |
|
| 2021 |
await contains(`button[name=action_to_perform]`).click(); |
| 2022 |
await contains(".o_bottom_sheet_backdrop").click(); |
| 2023 |
await contains(".o-form-buttonbox .o_button_more").click(); |
| 2024 |
expect(`button.oe_stat_button[disabled]`).toHaveCount(1, { |
| 2025 |
message: "After performing the action, only one button should be disabled.", |
| 2026 |
}); |
| 2027 |
expect.verifySteps(["action_to_perform"]); |
| 2028 |
}); |
| 2029 |
|
| 2030 |
test(`label with no string attribute gets the default label for the corresponding field`, async () => { |
| 2031 |
await mountView({ |
| 2032 |
resModel: "partner", |
| 2033 |
type: "form", |
| 2034 |
arch: ` |
| 2035 |
<form> |
| 2036 |
<sheet> |
| 2037 |
<group> |
| 2038 |
<label for="bar"/> |
| 2039 |
<div> |
| 2040 |
<field name="bar"/> |
| 2041 |
</div> |
| 2042 |
</group> |
| 2043 |
</sheet> |
| 2044 |
</form> |
| 2045 |
`, |
| 2046 |
resId: 2, |
| 2047 |
}); |
| 2048 |
expect(`label.o_form_label`).toHaveCount(1); |
| 2049 |
expect(`label.o_form_label`).toHaveText("Bar"); |
| 2050 |
}); |
| 2051 |
|
| 2052 |
test(`label uses the string attribute when present`, async () => { |
| 2053 |
await mountView({ |
| 2054 |
resModel: "partner", |
| 2055 |
type: "form", |
| 2056 |
arch: ` |
| 2057 |
<form> |
| 2058 |
<sheet> |
| 2059 |
<group> |
| 2060 |
<label for="bar" string="customstring"/> |
| 2061 |
<div> |
| 2062 |
<field name="bar"/> |
| 2063 |
</div> |
| 2064 |
</group> |
| 2065 |
</sheet> |
| 2066 |
</form> |
| 2067 |
`, |
| 2068 |
resId: 2, |
| 2069 |
}); |
| 2070 |
expect(`label.o_form_label`).toHaveCount(1); |
| 2071 |
expect(`label.o_form_label`).toHaveText("customstring"); |
| 2072 |
}); |
| 2073 |
|
| 2074 |
test(`label ignores the content of the label when present`, async () => { |
| 2075 |
await mountView({ |
| 2076 |
resModel: "partner", |
| 2077 |
type: "form", |
| 2078 |
arch: ` |
| 2079 |
<form> |
| 2080 |
<sheet> |
| 2081 |
<group> |
| 2082 |
<label for="bar">customstring</label> |
| 2083 |
<div> |
| 2084 |
<field name="bar"/> |
| 2085 |
</div> |
| 2086 |
</group> |
| 2087 |
</sheet> |
| 2088 |
</form> |
| 2089 |
`, |
| 2090 |
resId: 2, |
| 2091 |
}); |
| 2092 |
expect(`label.o_form_label`).toHaveCount(1); |
| 2093 |
expect(`label.o_form_label`).toHaveText("Bar"); |
| 2094 |
}); |
| 2095 |
|
| 2096 |
test(`label with empty string attribute renders to an empty label`, async () => { |
| 2097 |
await mountView({ |
| 2098 |
resModel: "partner", |
| 2099 |
type: "form", |
| 2100 |
arch: ` |
| 2101 |
<form> |
| 2102 |
<sheet> |
| 2103 |
<group> |
| 2104 |
<label for="bar" string=""/> |
| 2105 |
<div> |
| 2106 |
<field name="bar"/> |
| 2107 |
</div> |
| 2108 |
</group> |
| 2109 |
</sheet> |
| 2110 |
</form> |
| 2111 |
`, |
| 2112 |
resId: 2, |
| 2113 |
}); |
| 2114 |
expect(`label.o_form_label`).toHaveCount(1); |
| 2115 |
expect(`label.o_form_label`).toHaveText(""); |
| 2116 |
}); |
| 2117 |
|
| 2118 |
test(`two mutually exclusive labels with a dynamic invisible attribute`, async () => { |
| 2119 |
await mountView({ |
| 2120 |
resModel: "partner", |
| 2121 |
type: "form", |
| 2122 |
arch: ` |
| 2123 |
<form> |
| 2124 |
<sheet> |
| 2125 |
<group> |
| 2126 |
<label for="bar" string="label1" invisible='bar'/> |
| 2127 |
<label for="bar" string="label2" invisible='not bar'/> |
| 2128 |
<field name="bar" nolabel="1"/> |
| 2129 |
</group> |
| 2130 |
</sheet> |
| 2131 |
</form> |
| 2132 |
`, |
| 2133 |
resId: 2, |
| 2134 |
}); |
| 2135 |
expect(`label.o_form_label`).toHaveCount(1); |
| 2136 |
expect(`label.o_form_label`).toHaveText("label2"); |
| 2137 |
expect(`.o_cell`).toHaveCount(2); |
| 2138 |
}); |
| 2139 |
|
| 2140 |
test(`label is not rendered when invisible and not at top-level in a group`, async () => { |
| 2141 |
await mountView({ |
| 2142 |
resModel: "partner", |
| 2143 |
type: "form", |
| 2144 |
arch: ` |
| 2145 |
<form> |
| 2146 |
<sheet> |
| 2147 |
<group> |
| 2148 |
<div> |
| 2149 |
<label for="bar" invisible='bar'/> |
| 2150 |
<field name="bar" /> |
| 2151 |
</div> |
| 2152 |
</group> |
| 2153 |
</sheet> |
| 2154 |
</form> |
| 2155 |
`, |
| 2156 |
resId: 2, |
| 2157 |
}); |
| 2158 |
expect(`label.o_form_label`).toHaveCount(0); |
| 2159 |
}); |
| 2160 |
|
| 2161 |
test(`input ids for multiple occurrences of fields in form view`, async () => { |
| 2162 |
// A same field can occur several times in the view, but its id must be |
| 2163 |
// unique by occurrence, otherwise there is a warning in the console (in |
| 2164 |
// edit mode) as we get several inputs with the same "id" attribute, and |
| 2165 |
// several labels the same "for" attribute. |
| 2166 |
await mountView({ |
| 2167 |
resModel: "partner", |
| 2168 |
type: "form", |
| 2169 |
arch: ` |
| 2170 |
<form> |
| 2171 |
<group> |
| 2172 |
<field name="foo"/> |
| 2173 |
<label for="float_field"/> |
| 2174 |
<div><field name="float_field"/></div> |
| 2175 |
</group> |
| 2176 |
<group> |
| 2177 |
<field name="foo"/> |
| 2178 |
<label for="float_field2"/> |
| 2179 |
<div><field name="float_field" id="float_field2"/></div> |
| 2180 |
</group> |
| 2181 |
</form> |
| 2182 |
`, |
| 2183 |
}); |
| 2184 |
const fieldIdAttrs = queryAllAttributes(`.o_field_widget input`, "id"); |
| 2185 |
const labelForAttrs = queryAllAttributes(`.o_form_label`, "for"); |
| 2186 |
expect(new Set(fieldIdAttrs)).toHaveLength(4); |
| 2187 |
expect(fieldIdAttrs).toEqual(labelForAttrs); |
| 2188 |
}); |
| 2189 |
|
| 2190 |
test(`input ids for multiple occurrences of fields in sub form view (inline)`, async () => { |
| 2191 |
// A same field can occur several times in the view, but its id must be |
| 2192 |
// unique by occurrence, otherwise there is a warning in the console (in |
| 2193 |
// edit mode) as we get several inputs with the same "id" attribute, and |
| 2194 |
// several labels the same "for" attribute. |
| 2195 |
await mountView({ |
| 2196 |
resModel: "partner", |
| 2197 |
type: "form", |
| 2198 |
arch: ` |
| 2199 |
<form> |
| 2200 |
<field name="child_ids"> |
| 2201 |
<list><field name="foo"/></list> |
| 2202 |
<form> |
| 2203 |
<group> |
| 2204 |
<field name="foo"/> |
| 2205 |
<label for="float_field"/> |
| 2206 |
<div><field name="float_field"/></div> |
| 2207 |
</group> |
| 2208 |
<group> |
| 2209 |
<field name="foo"/> |
| 2210 |
<label for="float_field2"/> |
| 2211 |
<div><field name="float_field" id="float_field2"/></div> |
| 2212 |
</group> |
| 2213 |
</form> |
| 2214 |
</field> |
| 2215 |
</form> |
| 2216 |
`, |
| 2217 |
}); |
| 2218 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 2219 |
const fieldIdAttrs = queryAllAttributes(`.modal .o_form_view .o_field_widget input`, "id"); |
| 2220 |
const labelForAttrs = queryAllAttributes(`.modal .o_form_view .o_form_label`, "for"); |
| 2221 |
expect(new Set(fieldIdAttrs)).toHaveLength(4); |
| 2222 |
expect(fieldIdAttrs).toEqual(labelForAttrs); |
| 2223 |
}); |
| 2224 |
|
| 2225 |
test.tags("desktop"); |
| 2226 |
test(`input ids for multiple occurrences of fields in sub form view (not inline)`, async () => { |
| 2227 |
// A same field can occur several times in the view, but its id must be |
| 2228 |
// unique by occurrence, otherwise there is a warning in the console (in |
| 2229 |
// edit mode) as we get several inputs with the same "id" attribute, and |
| 2230 |
// several labels the same "for" attribute. |
| 2231 |
Partner._views = { |
| 2232 |
list: `<list><field name="foo"/></list>`, |
| 2233 |
form: ` |
| 2234 |
<form> |
| 2235 |
<group> |
| 2236 |
<field name="foo"/> |
| 2237 |
<label for="float_field"/> |
| 2238 |
<div><field name="float_field"/></div> |
| 2239 |
</group> |
| 2240 |
<group> |
| 2241 |
<field name="foo"/> |
| 2242 |
<label for="float_field2"/> |
| 2243 |
<div><field name="float_field" id="float_field2"/></div> |
| 2244 |
</group> |
| 2245 |
</form> |
| 2246 |
`, |
| 2247 |
}; |
| 2248 |
|
| 2249 |
await mountView({ |
| 2250 |
resModel: "partner", |
| 2251 |
type: "form", |
| 2252 |
arch: `<form><field name="child_ids" widget="one2many"/></form>`, |
| 2253 |
}); |
| 2254 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 2255 |
const fieldIdAttrs = queryAllAttributes(`.modal .o_form_view .o_field_widget input`, "id"); |
| 2256 |
const labelForAttrs = queryAllAttributes(`.modal .o_form_view .o_form_label`, "for"); |
| 2257 |
expect(new Set(fieldIdAttrs)).toHaveLength(4); |
| 2258 |
expect(fieldIdAttrs).toEqual(labelForAttrs); |
| 2259 |
}); |
| 2260 |
|
| 2261 |
test(`two occurrences of invalid field in form view`, async () => { |
| 2262 |
Partner._fields.parent_id = fields.Many2one({ relation: "partner", required: true }); |
| 2263 |
|
| 2264 |
await mountView({ |
| 2265 |
resModel: "partner", |
| 2266 |
type: "form", |
| 2267 |
arch: ` |
| 2268 |
<form> |
| 2269 |
<group> |
| 2270 |
<field name="parent_id"/> |
| 2271 |
<field name="parent_id"/> |
| 2272 |
</group> |
| 2273 |
</form> |
| 2274 |
`, |
| 2275 |
}); |
| 2276 |
await contains(`.o_form_button_save`).click(); |
| 2277 |
expect(`.o_form_label.o_field_invalid`).toHaveCount(2); |
| 2278 |
expect(`.o_field_many2one.o_field_invalid`).toHaveCount(2); |
| 2279 |
}); |
| 2280 |
|
| 2281 |
test(`two occurrences of invalid integer fields in form view`, async () => { |
| 2282 |
Partner._fields.parent_id = fields.Many2one({ relation: "partner", required: true }); |
| 2283 |
|
| 2284 |
await mountView({ |
| 2285 |
resModel: "partner", |
| 2286 |
type: "form", |
| 2287 |
arch: ` |
| 2288 |
<form> |
| 2289 |
<group> |
| 2290 |
<field name="int_field" class="a"/> |
| 2291 |
<field name="int_field" class="b"/> |
| 2292 |
</group> |
| 2293 |
</form> |
| 2294 |
`, |
| 2295 |
}); |
| 2296 |
await contains(`.a input`).edit("abc"); |
| 2297 |
expect(`.o_form_label.o_field_invalid`).toHaveCount(2); |
| 2298 |
expect(`.o_field_integer.o_field_invalid`).toHaveCount(2); |
| 2299 |
|
| 2300 |
await contains(`.b input`).edit("10"); |
| 2301 |
expect(`.o_form_label.o_field_invalid`).toHaveCount(0); |
| 2302 |
expect(`.o_field_integer.o_field_invalid`).toHaveCount(0); |
| 2303 |
}); |
| 2304 |
|
| 2305 |
test(`mutually exclusive required fields in form view`, async () => { |
| 2306 |
delete Partner._fields.foo.default; |
| 2307 |
|
| 2308 |
onRpc("web_save", () => expect.step("saved")); |
| 2309 |
await mountView({ |
| 2310 |
resModel: "partner", |
| 2311 |
type: "form", |
| 2312 |
arch: ` |
| 2313 |
<form> |
| 2314 |
<group> |
| 2315 |
<field name="foo" required="not name"/> |
| 2316 |
<field name="name" required="not foo"/> |
| 2317 |
</group> |
| 2318 |
</form> |
| 2319 |
`, |
| 2320 |
resId: 1, |
| 2321 |
}); |
| 2322 |
|
| 2323 |
await contains(".o_field_widget[name=foo] input").edit(""); |
| 2324 |
await contains(".o_field_widget[name=name] input").edit(""); |
| 2325 |
|
| 2326 |
await contains(`.o_form_button_save`).click(); |
| 2327 |
expect(`.o_field_widget.o_field_invalid`).toHaveCount(2); |
| 2328 |
expect(`.o_form_button_save`).toHaveAttribute("disabled"); |
| 2329 |
|
| 2330 |
await contains(`.o_field_widget[name=foo] input`).edit("some value"); |
| 2331 |
expect(`.o_field_widget.o_field_invalid`).toHaveCount(0); |
| 2332 |
expect(`.o_form_button_save`).not.toHaveAttribute("disabled"); |
| 2333 |
|
| 2334 |
await contains(`.o_form_button_save`).click(); |
| 2335 |
expect.verifySteps(["saved"]); |
| 2336 |
}); |
| 2337 |
|
| 2338 |
test(`twice same field with different required attributes`, async () => { |
| 2339 |
Partner._fields.foo = fields.Char(); |
| 2340 |
|
| 2341 |
onRpc(({ method }) => expect.step(method)); |
| 2342 |
await mountView({ |
| 2343 |
resModel: "partner", |
| 2344 |
type: "form", |
| 2345 |
arch: ` |
| 2346 |
<form> |
| 2347 |
<group> |
| 2348 |
<field name="bar"/> |
| 2349 |
<field name="int_field"/> |
| 2350 |
<field name="foo" required="not bar"/> |
| 2351 |
<field name="foo" required="int_field == 44"/> |
| 2352 |
</group> |
| 2353 |
</form> |
| 2354 |
`, |
| 2355 |
}); |
| 2356 |
expect(`.o_field_widget[name=foo]:eq(0)`).toHaveClass("o_required_modifier"); |
| 2357 |
expect(`.o_field_widget[name=foo]:eq(1)`).not.toHaveClass("o_required_modifier"); |
| 2358 |
|
| 2359 |
await contains(`.o_field_widget[name=bar] input`).click(); |
| 2360 |
expect(`.o_field_widget[name=foo]:eq(0)`).not.toHaveClass("o_required_modifier"); |
| 2361 |
expect(`.o_field_widget[name=foo]:eq(1)`).not.toHaveClass("o_required_modifier"); |
| 2362 |
|
| 2363 |
await contains(`.o_field_widget[name=int_field] input`).edit("44"); |
| 2364 |
expect(`.o_field_widget[name=foo]:eq(0)`).not.toHaveClass("o_required_modifier"); |
| 2365 |
expect(`.o_field_widget[name=foo]:eq(1)`).toHaveClass("o_required_modifier"); |
| 2366 |
|
| 2367 |
await contains(`.o_form_button_save`).click(); |
| 2368 |
expect(`.o_form_label.o_field_invalid`).toHaveCount(2); |
| 2369 |
expect(`.o_field_widget.o_field_invalid`).toHaveCount(2); |
| 2370 |
expect.verifySteps(["get_views", "onchange"]); |
| 2371 |
}); |
| 2372 |
|
| 2373 |
test(`twice same field with different readonly attributes`, async () => { |
| 2374 |
Partner._fields.foo = fields.Char(); |
| 2375 |
|
| 2376 |
onRpc("web_save", ({ args }) => { |
| 2377 |
expect.step("web_save"); |
| 2378 |
expect(args[1]).toEqual({ |
| 2379 |
bar: true, |
| 2380 |
int_field: 0, |
| 2381 |
foo: "some value", |
| 2382 |
}); |
| 2383 |
}); |
| 2384 |
await mountView({ |
| 2385 |
resModel: "partner", |
| 2386 |
type: "form", |
| 2387 |
arch: ` |
| 2388 |
<form> |
| 2389 |
<group> |
| 2390 |
<field name="bar"/> |
| 2391 |
<field name="int_field"/> |
| 2392 |
<field name="foo" readonly="not bar"/> |
| 2393 |
<field name="foo" readonly="int_field == 0"/> |
| 2394 |
</group> |
| 2395 |
</form> |
| 2396 |
`, |
| 2397 |
}); |
| 2398 |
expect(`.o_field_widget[name=foo]:eq(0)`).toHaveClass("o_readonly_modifier"); |
| 2399 |
expect(`.o_field_widget[name=foo]:eq(1)`).toHaveClass("o_readonly_modifier"); |
| 2400 |
|
| 2401 |
await contains(`.o_field_widget[name=bar] input`).click(); |
| 2402 |
expect(`.o_field_widget[name=foo]:eq(0)`).not.toHaveClass("o_readonly_modifier"); |
| 2403 |
expect(`.o_field_widget[name=foo]:eq(1)`).toHaveClass("o_readonly_modifier"); |
| 2404 |
|
| 2405 |
await contains(`.o_field_widget[name=foo] input`).edit("some value"); |
| 2406 |
await contains(`.o_form_button_save`).click(); |
| 2407 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("some value"); |
| 2408 |
expect.verifySteps(["web_save"]); |
| 2409 |
}); |
| 2410 |
|
| 2411 |
test(`twice same field with different invisible attributes`, async () => { |
| 2412 |
Partner._fields.foo = fields.Char(); |
| 2413 |
|
| 2414 |
onRpc(({ method }) => expect.step(method)); |
| 2415 |
await mountView({ |
| 2416 |
resModel: "partner", |
| 2417 |
type: "form", |
| 2418 |
arch: ` |
| 2419 |
<form> |
| 2420 |
<group> |
| 2421 |
<field name="bar"/> |
| 2422 |
<field name="int_field"/> |
| 2423 |
<field name="foo" required="1" invisible="not bar"/> |
| 2424 |
<field name="foo" invisible="int_field == 0"/> |
| 2425 |
</group> |
| 2426 |
</form> |
| 2427 |
`, |
| 2428 |
}); |
| 2429 |
expect(`.o_field_widget[name=foo]`).toHaveCount(0); |
| 2430 |
|
| 2431 |
await contains(`.o_field_widget[name=bar] input`).click(); |
| 2432 |
expect(`.o_field_widget[name=foo]`).toHaveCount(1); |
| 2433 |
|
| 2434 |
// foo is required, and as it isn't invisible (at least for one occurrence), it shouldn't |
| 2435 |
// allow to save as it is not set |
| 2436 |
await contains(`.o_form_button_save`).click(); |
| 2437 |
expect(".o_field_widget[name=foo]").toHaveClass("o_field_invalid"); |
| 2438 |
expect.verifySteps(["get_views", "onchange"]); |
| 2439 |
}); |
| 2440 |
|
| 2441 |
test(`required field computed by another field in a form view`, async () => { |
| 2442 |
Partner._fields.foo = fields.Char({ |
| 2443 |
onChange(record) { |
| 2444 |
if (record.foo) { |
| 2445 |
record.name = "plop"; |
| 2446 |
} |
| 2447 |
}, |
| 2448 |
}); |
| 2449 |
|
| 2450 |
await mountView({ |
| 2451 |
resModel: "partner", |
| 2452 |
type: "form", |
| 2453 |
arch: ` |
| 2454 |
<form> |
| 2455 |
<field name="name" required="1"/> |
| 2456 |
<field name="foo"/> |
| 2457 |
</form> |
| 2458 |
`, |
| 2459 |
}); |
| 2460 |
await contains(`.o_form_button_save`).click(); |
| 2461 |
expect(`.o_form_editable`).toHaveCount(1); |
| 2462 |
expect(`.o_field_invalid`).toHaveCount(1); |
| 2463 |
|
| 2464 |
await contains(`[name='foo'] input`).edit("hello"); |
| 2465 |
expect(`.o_form_editable`).toHaveCount(1); |
| 2466 |
expect(`.o_field_invalid`).toHaveCount(0); |
| 2467 |
}); |
| 2468 |
|
| 2469 |
test(`required field computed by another field in a x2m`, async () => { |
| 2470 |
Partner._fields.foo = fields.Char({ |
| 2471 |
default: false, |
| 2472 |
onChange(record) { |
| 2473 |
if (record.foo) { |
| 2474 |
record.name = "plop"; |
| 2475 |
} |
| 2476 |
}, |
| 2477 |
}); |
| 2478 |
|
| 2479 |
await mountView({ |
| 2480 |
resModel: "partner", |
| 2481 |
type: "form", |
| 2482 |
arch: ` |
| 2483 |
<form> |
| 2484 |
<field name="child_ids"> |
| 2485 |
<list editable="bottom"> |
| 2486 |
<field name="foo"/> |
| 2487 |
<field name="int_field"/> |
| 2488 |
<field name="name" required="1"/> |
| 2489 |
</list> |
| 2490 |
</field> |
| 2491 |
</form> |
| 2492 |
`, |
| 2493 |
}); |
| 2494 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 2495 |
await contains(`.o_data_row [name='int_field'] input`).edit("1"); |
| 2496 |
await contains(".o_form_view").click(); |
| 2497 |
expect(`.o_form_editable`).toHaveCount(1); |
| 2498 |
expect(`.o_selected_row`).toHaveCount(1); |
| 2499 |
expect(`.o_field_invalid`).toHaveCount(1); |
| 2500 |
|
| 2501 |
await contains(`.o_data_row [name='foo'] input`).edit("hello"); |
| 2502 |
await contains(".o_form_view").click(); |
| 2503 |
expect(`.o_form_editable`).toHaveCount(1); |
| 2504 |
expect(`.o_selected_row`).toHaveCount(0); |
| 2505 |
expect(`.o_field_invalid`).toHaveCount(0); |
| 2506 |
}); |
| 2507 |
|
| 2508 |
test.tags("desktop"); |
| 2509 |
test(`tooltips on multiple occurrences of fields and labels`, async () => { |
| 2510 |
Partner._fields.foo = fields.Char({ help: "foo tooltip" }); |
| 2511 |
Partner._fields.bar = fields.Boolean({ help: "bar tooltip" }); |
| 2512 |
|
| 2513 |
await mountView({ |
| 2514 |
resModel: "partner", |
| 2515 |
type: "form", |
| 2516 |
arch: ` |
| 2517 |
<form> |
| 2518 |
<group> |
| 2519 |
<field name="foo"/> |
| 2520 |
<label for="bar"/> |
| 2521 |
<div><field name="bar"/></div> |
| 2522 |
</group> |
| 2523 |
<group> |
| 2524 |
<field name="foo"/> |
| 2525 |
<label for="bar2"/> |
| 2526 |
<div><field name="bar" id="bar2"/></div> |
| 2527 |
</group> |
| 2528 |
</form> |
| 2529 |
`, |
| 2530 |
}); |
| 2531 |
await hover(".o_form_label[for=foo_0] sup"); |
| 2532 |
await runAllTimers(); |
| 2533 |
await animationFrame(); |
| 2534 |
expect(".o-tooltip .o-tooltip--help").toHaveText("foo tooltip"); |
| 2535 |
|
| 2536 |
await hover(".o_form_label[for=bar_0] sup"); |
| 2537 |
await runAllTimers(); |
| 2538 |
await animationFrame(); |
| 2539 |
expect(".o-tooltip .o-tooltip--help").toHaveText("bar tooltip"); |
| 2540 |
|
| 2541 |
await hover(".o_form_label[for=foo_1] sup"); |
| 2542 |
await runAllTimers(); |
| 2543 |
await animationFrame(); |
| 2544 |
expect(".o-tooltip .o-tooltip--help").toHaveText("foo tooltip"); |
| 2545 |
|
| 2546 |
await hover(".o_form_label[for=bar_1] sup"); |
| 2547 |
await runAllTimers(); |
| 2548 |
await animationFrame(); |
| 2549 |
expect(".o-tooltip .o-tooltip--help").toHaveText("bar tooltip"); |
| 2550 |
}); |
| 2551 |
|
| 2552 |
test(`readonly attrs on fields are re-evaluated on field change`, async () => { |
| 2553 |
await mountView({ |
| 2554 |
resModel: "partner", |
| 2555 |
type: "form", |
| 2556 |
arch: ` |
| 2557 |
<form> |
| 2558 |
<sheet> |
| 2559 |
<group> |
| 2560 |
<field name="foo" readonly="bar"/> |
| 2561 |
<field name="bar"/> |
| 2562 |
</group> |
| 2563 |
</sheet> |
| 2564 |
</form> |
| 2565 |
`, |
| 2566 |
resId: 1, |
| 2567 |
}); |
| 2568 |
expect(`.o_field_widget[name="foo"]`).toHaveClass("o_readonly_modifier"); |
| 2569 |
|
| 2570 |
await contains(`.o_field_boolean input`).click(); |
| 2571 |
expect(`.o_field_widget[name="foo"]`).not.toHaveClass("o_readonly_modifier"); |
| 2572 |
|
| 2573 |
await contains(`.o_field_boolean input`).click(); |
| 2574 |
expect(`.o_field_widget[name="foo"]`).toHaveClass("o_readonly_modifier"); |
| 2575 |
|
| 2576 |
await contains(`.o_field_boolean input`).click(); |
| 2577 |
expect(`.o_field_widget[name="foo"]`).not.toHaveClass("o_readonly_modifier"); |
| 2578 |
}); |
| 2579 |
|
| 2580 |
test(`field with readonly modifier depending on id`, async () => { |
| 2581 |
await mountView({ |
| 2582 |
resModel: "partner", |
| 2583 |
type: "form", |
| 2584 |
arch: `<form><field name="int_field" readonly="id"/></form>`, |
| 2585 |
}); |
| 2586 |
expect(`.o_form_editable`).toHaveCount(1); |
| 2587 |
expect(`.o_field_widget[name=int_field] input`).toHaveCount(1); |
| 2588 |
expect(`.o_field_widget[name=int_field]`).not.toHaveClass("o_readonly_modifier"); |
| 2589 |
|
| 2590 |
await contains(`.o_field_widget[name=int_field] input`).edit("34"); |
| 2591 |
await contains(`.o_form_button_save`).click(); |
| 2592 |
expect(`.o_field_widget[name=int_field]`).toHaveText("34"); |
| 2593 |
|
| 2594 |
expect(`.o_form_editable`).toHaveCount(1); |
| 2595 |
expect(`.o_field_widget[name=int_field] input`).toHaveCount(0); |
| 2596 |
expect(`.o_field_widget[name=int_field]`).toHaveClass("o_readonly_modifier"); |
| 2597 |
}); |
| 2598 |
|
| 2599 |
test.tags("desktop"); |
| 2600 |
test(`readonly attrs on lines are re-evaluated on field change 2`, async () => { |
| 2601 |
Partner._records[0].product_ids = [37]; |
| 2602 |
Partner._records[0].parent_id = false; |
| 2603 |
|
| 2604 |
let onchangeApplied = false; |
| 2605 |
Partner._fields.parent_id = fields.Many2one({ |
| 2606 |
relation: "partner", |
| 2607 |
onChange(record) { |
| 2608 |
// when parent_id changes, push another record in product_ids. |
| 2609 |
// only push a second record once. |
| 2610 |
if (!onchangeApplied) { |
| 2611 |
record.product_ids = [[37, 41]]; |
| 2612 |
onchangeApplied = true; |
| 2613 |
} |
| 2614 |
}, |
| 2615 |
}); |
| 2616 |
|
| 2617 |
Product._records[0].name = "test"; |
| 2618 |
// This one is necessary to have a valid, rendered widget |
| 2619 |
Product._fields.int_field = fields.Integer(); |
| 2620 |
|
| 2621 |
await mountView({ |
| 2622 |
resModel: "partner", |
| 2623 |
type: "form", |
| 2624 |
arch: ` |
| 2625 |
<form> |
| 2626 |
<field name="parent_id"/> |
| 2627 |
<field name="product_ids" readonly="not parent_id"> |
| 2628 |
<list editable="top"><field name="int_field" widget="handle"/><field name="name"/></list> |
| 2629 |
</field> |
| 2630 |
</form> |
| 2631 |
`, |
| 2632 |
resId: 1, |
| 2633 |
}); |
| 2634 |
await contains(`.o_field_many2one[name="parent_id"] input`).click(); |
| 2635 |
await contains(`.dropdown .dropdown-item:contains(first record)`).click(); |
| 2636 |
expect(`.o_field_one2many[name="product_ids"]`).not.toHaveClass("o_readonly_modifier"); |
| 2637 |
|
| 2638 |
await clear(); |
| 2639 |
await click(`.o_content`); // blur input to trigger change |
| 2640 |
await animationFrame(); |
| 2641 |
expect(`.o_field_one2many[name="product_ids"]`).toHaveClass("o_readonly_modifier"); |
| 2642 |
|
| 2643 |
await contains(`.o_field_many2one[name="parent_id"] input`).click(); |
| 2644 |
await contains(`.dropdown .dropdown-item:contains(second record)`).click(); |
| 2645 |
expect(`.o_field_one2many[name="product_ids"]`).not.toHaveClass("o_readonly_modifier"); |
| 2646 |
|
| 2647 |
await clear(); |
| 2648 |
await click(`.o_content`); // blur input to trigger change |
| 2649 |
await animationFrame(); |
| 2650 |
expect(`.o_field_one2many[name="product_ids"]`).toHaveClass("o_readonly_modifier"); |
| 2651 |
}); |
| 2652 |
|
| 2653 |
test(`empty fields have o_form_empty class in readonly mode`, async () => { |
| 2654 |
Partner._records[1].foo = false; // 1 is record with id=2 |
| 2655 |
Partner._records[1].parent_id = false; // 1 is record with id=2 |
| 2656 |
Partner._fields.foo = fields.Char({ |
| 2657 |
onChange(record) { |
| 2658 |
if (record.foo === "hello") { |
| 2659 |
record.int_field = false; |
| 2660 |
} |
| 2661 |
}, |
| 2662 |
}); |
| 2663 |
Partner._fields.int_field = fields.Integer({ readonly: true }); |
| 2664 |
|
| 2665 |
await mountView({ |
| 2666 |
resModel: "partner", |
| 2667 |
type: "form", |
| 2668 |
arch: ` |
| 2669 |
<form> |
| 2670 |
<sheet> |
| 2671 |
<group> |
| 2672 |
<field name="foo"/> |
| 2673 |
<field name="parent_id" readonly="not foo"/> |
| 2674 |
<field name="int_field"/> |
| 2675 |
</group> |
| 2676 |
</sheet> |
| 2677 |
</form> |
| 2678 |
`, |
| 2679 |
resId: 2, |
| 2680 |
}); |
| 2681 |
expect(`.o_field_empty`).toHaveCount(1); |
| 2682 |
expect(`.o_form_label_empty`).toHaveCount(1); |
| 2683 |
|
| 2684 |
await contains(`.o_field_widget[name=foo] input`).edit("test"); |
| 2685 |
expect(`.o_field_empty`).toHaveCount(0); |
| 2686 |
expect(`.o_form_label_empty`).toHaveCount(0); |
| 2687 |
|
| 2688 |
await contains(`.o_field_widget[name=foo] input`).edit("hello"); |
| 2689 |
expect(`.o_field_empty`).toHaveCount(1); |
| 2690 |
expect(`.o_form_label_empty`).toHaveCount(1); |
| 2691 |
}); |
| 2692 |
|
| 2693 |
test(`empty fields' labels still get the empty class after widget rerender`, async () => { |
| 2694 |
Partner._fields.foo = fields.Char(); |
| 2695 |
Partner._records[1].foo = false; // 1 is record with id=2 |
| 2696 |
Partner._records[1].name = false; // 1 is record with id=2 |
| 2697 |
|
| 2698 |
await mountView({ |
| 2699 |
resModel: "partner", |
| 2700 |
type: "form", |
| 2701 |
arch: ` |
| 2702 |
<form> |
| 2703 |
<group> |
| 2704 |
<field name="foo"/> |
| 2705 |
<field name="name" readonly="foo == 'readonly'"/> |
| 2706 |
</group> |
| 2707 |
</form> |
| 2708 |
`, |
| 2709 |
resId: 2, |
| 2710 |
}); |
| 2711 |
expect(`.o_field_empty`).toHaveCount(0); |
| 2712 |
expect(`.o_form_label_empty`).toHaveCount(0); |
| 2713 |
|
| 2714 |
await contains(`.o_field_widget[name=foo] input`).edit("readonly"); |
| 2715 |
await contains(`.o_field_widget[name=foo] input`).edit("edit"); |
| 2716 |
await contains(`.o_field_widget[name=name] input`).edit("some name"); |
| 2717 |
await contains(`.o_field_widget[name=foo] input`).edit("readonly"); |
| 2718 |
expect(`.o_field_empty`).toHaveCount(0); |
| 2719 |
expect(`.o_form_label_empty`).toHaveCount(0); |
| 2720 |
}); |
| 2721 |
|
| 2722 |
test(`empty inner readonly fields don't have o_form_empty class in "create" mode`, async () => { |
| 2723 |
Partner._fields.product_id = fields.Many2one({ relation: "product", readonly: true }); |
| 2724 |
await mountView({ |
| 2725 |
resModel: "partner", |
| 2726 |
type: "form", |
| 2727 |
arch: ` |
| 2728 |
<form> |
| 2729 |
<sheet> |
| 2730 |
<group> |
| 2731 |
<group> |
| 2732 |
<field name="product_id"/> |
| 2733 |
</group> |
| 2734 |
</group> |
| 2735 |
</sheet> |
| 2736 |
</form> |
| 2737 |
`, |
| 2738 |
}); |
| 2739 |
expect(`.o_form_label_empty`).toHaveCount(0); |
| 2740 |
expect(`.o_field_empty`).toHaveCount(0); |
| 2741 |
}); |
| 2742 |
|
| 2743 |
test(`label tag added for fields have o_form_empty class in readonly mode if field is empty`, async () => { |
| 2744 |
Partner._fields.foo = fields.Char({ |
| 2745 |
onChange(record) { |
| 2746 |
if (record.foo === "hello") { |
| 2747 |
record.int_field = false; |
| 2748 |
} |
| 2749 |
}, |
| 2750 |
}); |
| 2751 |
Partner._fields.int_field = fields.Integer({ readonly: true }); |
| 2752 |
Partner._records[1].foo = false; // 1 is record with id=2 |
| 2753 |
Partner._records[1].parent_id = false; // 1 is record with id=2 |
| 2754 |
|
| 2755 |
await mountView({ |
| 2756 |
resModel: "partner", |
| 2757 |
type: "form", |
| 2758 |
arch: ` |
| 2759 |
<form> |
| 2760 |
<sheet> |
| 2761 |
<label for="foo" string="Foo"/> |
| 2762 |
<field name="foo"/> |
| 2763 |
<label for="parent_id" string="parent_id" readonly="not foo"/> |
| 2764 |
<field name="parent_id" readonly="not foo"/> |
| 2765 |
<label for="int_field" string="IntField" readonly="not int_field"/> |
| 2766 |
<field name="int_field"/> |
| 2767 |
</sheet> |
| 2768 |
</form> |
| 2769 |
`, |
| 2770 |
resId: 2, |
| 2771 |
}); |
| 2772 |
expect(".o_field_empty").toHaveCount(1); |
| 2773 |
expect(".o_form_label_empty").toHaveCount(1); |
| 2774 |
|
| 2775 |
await contains(`div[name=foo] input`).edit("test"); |
| 2776 |
expect(`.o_field_empty`).toHaveCount(0); |
| 2777 |
expect(`.o_form_label_empty`).toHaveCount(0); |
| 2778 |
|
| 2779 |
await contains(`div[name=foo] input`).edit("hello"); |
| 2780 |
expect(`.o_field_empty`).toHaveCount(1); |
| 2781 |
expect(`.o_form_label_empty`).toHaveCount(1); |
| 2782 |
}); |
| 2783 |
|
| 2784 |
test(`required attrs on fields are re-evaluated on field change`, async () => { |
| 2785 |
await mountView({ |
| 2786 |
resModel: "partner", |
| 2787 |
type: "form", |
| 2788 |
arch: ` |
| 2789 |
<form> |
| 2790 |
<sheet> |
| 2791 |
<group> |
| 2792 |
<field name="foo" required="bar"/> |
| 2793 |
<field name="bar"/> |
| 2794 |
</group> |
| 2795 |
</sheet> |
| 2796 |
</form> |
| 2797 |
`, |
| 2798 |
resId: 1, |
| 2799 |
}); |
| 2800 |
expect(`.o_field_widget[name="foo"]`).toHaveClass("o_required_modifier"); |
| 2801 |
|
| 2802 |
await contains(`.o_field_boolean input`).uncheck(); |
| 2803 |
expect(`.o_field_widget[name="foo"]`).not.toHaveClass("o_required_modifier"); |
| 2804 |
|
| 2805 |
await contains(`.o_field_boolean input`).check(); |
| 2806 |
expect(`.o_field_widget[name="foo"]`).toHaveClass("o_required_modifier"); |
| 2807 |
}); |
| 2808 |
|
| 2809 |
test(`required fields should have o_required_modifier`, async () => { |
| 2810 |
Partner._fields.foo = fields.Char({ required: true }); |
| 2811 |
|
| 2812 |
await mountView({ |
| 2813 |
resModel: "partner", |
| 2814 |
type: "form", |
| 2815 |
arch: ` |
| 2816 |
<form> |
| 2817 |
<sheet> |
| 2818 |
<group> |
| 2819 |
<field name="foo"/> |
| 2820 |
</group> |
| 2821 |
</sheet> |
| 2822 |
</form> |
| 2823 |
`, |
| 2824 |
resId: 1, |
| 2825 |
}); |
| 2826 |
expect(`.o_field_widget`).toHaveClass("o_required_modifier"); |
| 2827 |
}); |
| 2828 |
|
| 2829 |
test(`required float fields works as expected`, async () => { |
| 2830 |
Partner._fields.float_field = fields.Float({ required: true }); |
| 2831 |
|
| 2832 |
onRpc(({ method }) => expect.step(method)); |
| 2833 |
await mountView({ |
| 2834 |
resModel: "partner", |
| 2835 |
type: "form", |
| 2836 |
arch: ` |
| 2837 |
<form> |
| 2838 |
<sheet> |
| 2839 |
<group> |
| 2840 |
<field name="float_field"/> |
| 2841 |
</group> |
| 2842 |
</sheet> |
| 2843 |
</form> |
| 2844 |
`, |
| 2845 |
}); |
| 2846 |
expect(`.o_field_widget[name="float_field"]`).toHaveClass("o_required_modifier"); |
| 2847 |
expect(`.o_field_widget[name="float_field"] input`).toHaveValue("0.00"); |
| 2848 |
|
| 2849 |
await contains(`.o_form_button_save`).click(); |
| 2850 |
await contains(`.o_field_widget[name="float_field"] input`).edit("1"); |
| 2851 |
await contains(`.o_form_button_save`).click(); |
| 2852 |
expect(`.o_field_widget[name="float_field"] input`).toHaveValue("1.00"); |
| 2853 |
expect.verifySteps(["get_views", "onchange", "web_save", "web_save"]); |
| 2854 |
}); |
| 2855 |
|
| 2856 |
test(`separators`, async () => { |
| 2857 |
await mountView({ |
| 2858 |
resModel: "partner", |
| 2859 |
type: "form", |
| 2860 |
arch: ` |
| 2861 |
<form> |
| 2862 |
<sheet> |
| 2863 |
<group> |
| 2864 |
<separator string="Geolocation"/> |
| 2865 |
<field name="foo"/> |
| 2866 |
</group> |
| 2867 |
</sheet> |
| 2868 |
</form> |
| 2869 |
`, |
| 2870 |
resId: 1, |
| 2871 |
}); |
| 2872 |
expect(`div.o_horizontal_separator`).toHaveCount(1); |
| 2873 |
}); |
| 2874 |
|
| 2875 |
test(`invisible attrs on separators`, async () => { |
| 2876 |
await mountView({ |
| 2877 |
resModel: "partner", |
| 2878 |
type: "form", |
| 2879 |
arch: ` |
| 2880 |
<form> |
| 2881 |
<sheet> |
| 2882 |
<group> |
| 2883 |
<separator string="Geolocation" invisible="bar"/> |
| 2884 |
<field name="bar"/> |
| 2885 |
</group> |
| 2886 |
</sheet> |
| 2887 |
</form> |
| 2888 |
`, |
| 2889 |
resId: 1, |
| 2890 |
}); |
| 2891 |
expect(`div.o_horizontal_separator`).toHaveCount(0); |
| 2892 |
}); |
| 2893 |
|
| 2894 |
test(`form views in dialogs do not have a control panel`, async () => { |
| 2895 |
Partner._views = { |
| 2896 |
form: `<form><field name="foo"/></form>`, |
| 2897 |
}; |
| 2898 |
|
| 2899 |
defineActions([ |
| 2900 |
{ |
| 2901 |
id: 1, |
| 2902 |
name: "Partner", |
| 2903 |
res_model: "partner", |
| 2904 |
views: [[false, "form"]], |
| 2905 |
target: "new", |
| 2906 |
}, |
| 2907 |
]); |
| 2908 |
|
| 2909 |
await mountWithCleanup(WebClient); |
| 2910 |
await getService("action").doAction(1); |
| 2911 |
expect(`.o_dialog .o_form_view`).toHaveCount(1); |
| 2912 |
expect(`.o_dialog .o_form_view .o_control_panel`).toHaveCount(0); |
| 2913 |
}); |
| 2914 |
|
| 2915 |
test(`form views in dialogs do not add display_name field`, async () => { |
| 2916 |
Partner._views = { |
| 2917 |
form: `<form><field name="foo"/></form>`, |
| 2918 |
}; |
| 2919 |
|
| 2920 |
defineActions([ |
| 2921 |
{ |
| 2922 |
id: 1, |
| 2923 |
name: "Partner", |
| 2924 |
res_model: "partner", |
| 2925 |
views: [[false, "form"]], |
| 2926 |
target: "new", |
| 2927 |
}, |
| 2928 |
]); |
| 2929 |
|
| 2930 |
onRpc("onchange", ({ args }) => { |
| 2931 |
expect.step("onchange"); |
| 2932 |
expect(args[3]).toEqual({ foo: {} }); |
| 2933 |
}); |
| 2934 |
await mountWithCleanup(WebClient); |
| 2935 |
await getService("action").doAction(1); |
| 2936 |
expect(`.o_dialog .o_form_view`).toHaveCount(1); |
| 2937 |
expect(`.o_dialog .o_form_view .o_control_panel`).toHaveCount(0); |
| 2938 |
expect.verifySteps(["onchange"]); |
| 2939 |
}); |
| 2940 |
|
| 2941 |
test(`form views in dialogs closes on save`, async () => { |
| 2942 |
Partner._fields.foo = fields.Char(); |
| 2943 |
Partner._records[0].foo = undefined; |
| 2944 |
Partner._views = { |
| 2945 |
form: `<form><field name="foo" required="1"/></form>`, |
| 2946 |
}; |
| 2947 |
|
| 2948 |
defineActions([ |
| 2949 |
{ |
| 2950 |
id: 1, |
| 2951 |
name: "Partner", |
| 2952 |
res_model: "partner", |
| 2953 |
views: [[false, "form"]], |
| 2954 |
target: "new", |
| 2955 |
}, |
| 2956 |
]); |
| 2957 |
|
| 2958 |
await mountWithCleanup(WebClient); |
| 2959 |
await getService("action").doAction(1); |
| 2960 |
expect(`.o_dialog .o_form_view`).toHaveCount(1); |
| 2961 |
|
| 2962 |
await contains(`.o_dialog .o_form_button_save`).click(); |
| 2963 |
expect(`.o_dialog .o_form_view`).toHaveCount(1); |
| 2964 |
|
| 2965 |
await contains(`[name="foo"] input`).edit("Gizmo"); |
| 2966 |
await contains(`.o_dialog .o_form_button_save`).click(); |
| 2967 |
expect(`.o_dialog .o_form_view`).toHaveCount(0); |
| 2968 |
}); |
| 2969 |
|
| 2970 |
test(`form views in dialogs closes on discard on existing record`, async () => { |
| 2971 |
Partner._fields.foo = fields.Char(); |
| 2972 |
Partner._records[0].foo = undefined; |
| 2973 |
Partner._views = { |
| 2974 |
form: `<form><field name="foo" required="1"/></form>`, |
| 2975 |
}; |
| 2976 |
|
| 2977 |
defineActions([ |
| 2978 |
{ |
| 2979 |
id: 1, |
| 2980 |
name: "Partner", |
| 2981 |
res_model: "partner", |
| 2982 |
views: [[false, "form"]], |
| 2983 |
target: "new", |
| 2984 |
res_id: 1, |
| 2985 |
}, |
| 2986 |
]); |
| 2987 |
|
| 2988 |
await mountWithCleanup(WebClient); |
| 2989 |
await getService("action").doAction(1); |
| 2990 |
expect(`.o_dialog .o_form_view`).toHaveCount(1); |
| 2991 |
|
| 2992 |
await contains(`.o_dialog .o_form_button_cancel`).click(); |
| 2993 |
expect(`.o_dialog .o_form_view`).toHaveCount(0); |
| 2994 |
}); |
| 2995 |
|
| 2996 |
test(`form views in dialogs do not have class o_xxl_form_view`, async () => { |
| 2997 |
const bus = new EventBus(); |
| 2998 |
mockService("ui", (env) => { |
| 2999 |
Object.defineProperty(env, "isSmall", { |
| 3000 |
value: false, |
| 3001 |
}); |
| 3002 |
return { |
| 3003 |
activateElement() {}, |
| 3004 |
deactivateElement() {}, |
| 3005 |
bus, |
| 3006 |
size: SIZES.XXL, |
| 3007 |
isSmall: false, |
| 3008 |
}; |
| 3009 |
}); |
| 3010 |
|
| 3011 |
Partner._views = { |
| 3012 |
form: `<form><field name="foo"/></form>`, |
| 3013 |
}; |
| 3014 |
|
| 3015 |
defineActions([ |
| 3016 |
{ |
| 3017 |
id: 1, |
| 3018 |
name: "Partner", |
| 3019 |
res_model: "partner", |
| 3020 |
views: [[false, "form"]], |
| 3021 |
target: "new", |
| 3022 |
}, |
| 3023 |
]); |
| 3024 |
|
| 3025 |
await mountWithCleanup(WebClient); |
| 3026 |
await getService("action").doAction(1); |
| 3027 |
expect(`.o_dialog .o_form_view`).toHaveCount(1); |
| 3028 |
expect(`.o_dialog .o_form_view`).not.toHaveClass("o_xxl_form_view"); |
| 3029 |
}); |
| 3030 |
|
| 3031 |
test(`form with custom cog action that has a confirmation target="new" action`, async () => { |
| 3032 |
PartnerType._views = { |
| 3033 |
form: ` |
| 3034 |
<form> |
| 3035 |
Are you sure blablabla |
| 3036 |
<footer> |
| 3037 |
<button name="my_action" type="action" string="Do it"/> |
| 3038 |
</footer> |
| 3039 |
</form>`, |
| 3040 |
}; |
| 3041 |
const contextualAction = { |
| 3042 |
id: 80, |
| 3043 |
name: "Sort of confirmation dialog", |
| 3044 |
res_model: "partner.type", |
| 3045 |
context: "{}", |
| 3046 |
views: [[false, "form"]], |
| 3047 |
type: "ir.actions.act_window", |
| 3048 |
target: "new", |
| 3049 |
}; |
| 3050 |
Partner._toolbar = { |
| 3051 |
action: [contextualAction], |
| 3052 |
print: [], |
| 3053 |
}; |
| 3054 |
Partner._views = { |
| 3055 |
form: `<form><field name="foo"/></form>`, |
| 3056 |
list: `<list><field name="foo"/></list>`, |
| 3057 |
search: `<search/>`, |
| 3058 |
}; |
| 3059 |
defineActions([ |
| 3060 |
{ |
| 3061 |
id: 1, |
| 3062 |
name: "Partner", |
| 3063 |
res_model: "partner", |
| 3064 |
views: [[false, "form"]], |
| 3065 |
res_id: 1, |
| 3066 |
}, |
| 3067 |
{ |
| 3068 |
id: 2, |
| 3069 |
name: "Partner", |
| 3070 |
res_model: "partner", |
| 3071 |
views: [[false, "list"]], |
| 3072 |
xml_id: "my_action", |
| 3073 |
}, |
| 3074 |
contextualAction, |
| 3075 |
]); |
| 3076 |
|
| 3077 |
stepAllNetworkCalls(); |
| 3078 |
await mountWithCleanup(WebClient); |
| 3079 |
await getService("action").doAction(1); |
| 3080 |
expect(".o_form_view").toHaveCount(1); |
| 3081 |
|
| 3082 |
await contains(`.o_cp_action_menus button:has(.fa-cog)`).click(); |
| 3083 |
await contains(`.o-dropdown-item:contains(Sort of confirmation dialog)`).click(); |
| 3084 |
expect(".o_dialog").toHaveCount(1); |
| 3085 |
|
| 3086 |
await contains(".o_dialog footer button:contains(Do it)").click(); |
| 3087 |
expect(".o_dialog").toHaveCount(0); |
| 3088 |
expect(".o_list_view").toHaveCount(1); |
| 3089 |
|
| 3090 |
// should not reload the first form view when confirming with Do it |
| 3091 |
expect.verifySteps([ |
| 3092 |
"/web/webclient/translations", |
| 3093 |
"/web/webclient/load_menus", |
| 3094 |
"/web/action/load", |
| 3095 |
"get_views", |
| 3096 |
"web_read", |
| 3097 |
"/web/action/load", |
| 3098 |
"get_views", |
| 3099 |
"onchange", |
| 3100 |
"web_save", |
| 3101 |
"/web/action/load", |
| 3102 |
"get_views", |
| 3103 |
"web_search_read", |
| 3104 |
"has_group", |
| 3105 |
]); |
| 3106 |
}); |
| 3107 |
|
| 3108 |
test.tags("desktop"); |
| 3109 |
test(`buttons in form view`, async () => { |
| 3110 |
expect.errors(1); |
| 3111 |
|
| 3112 |
mockService("action", { |
| 3113 |
doActionButton(params) { |
| 3114 |
expect.step(params.name); |
| 3115 |
if (params.name === "post") { |
| 3116 |
expect(params.resId).toBe(2); |
| 3117 |
params.onClose(); |
| 3118 |
} else { |
| 3119 |
throw makeServerError({ message: "doActionButton error" }); |
| 3120 |
} |
| 3121 |
}, |
| 3122 |
}); |
| 3123 |
|
| 3124 |
onRpc(({ method }) => expect.step(method)); |
| 3125 |
await mountView({ |
| 3126 |
resModel: "partner", |
| 3127 |
type: "form", |
| 3128 |
arch: ` |
| 3129 |
<form> |
| 3130 |
<field name="state" invisible="1"/> |
| 3131 |
<header> |
| 3132 |
<button name="post" class="child_ids" string="Confirm" type="object"/> |
| 3133 |
<button name="some_method" class="s" string="Do it" type="object"/> |
| 3134 |
<button name="some_other_method" invisible="state not in ['ab', 'ef']" string="Do not" type="object"/> |
| 3135 |
</header> |
| 3136 |
<sheet> |
| 3137 |
<group> |
| 3138 |
<button string="Geolocate" name="geo_localize" icon="fa-check" type="object"/> |
| 3139 |
</group> |
| 3140 |
</sheet> |
| 3141 |
</form> |
| 3142 |
`, |
| 3143 |
resId: 2, |
| 3144 |
}); |
| 3145 |
expect(`button.btn i.fa.fa-check`).toHaveCount(1); |
| 3146 |
expect(`.o_form_statusbar button`).toHaveCount(2); |
| 3147 |
expect(`button.child_ids[name="post"]:contains(Confirm)`).toHaveCount(1); |
| 3148 |
|
| 3149 |
// click on p (will succeed and reload) |
| 3150 |
await contains(`.o_form_statusbar button.child_ids`).click(); |
| 3151 |
expect.verifyErrors([]); |
| 3152 |
|
| 3153 |
// click on s (will fail) |
| 3154 |
await contains(`.o_form_statusbar button.s`).click(); |
| 3155 |
expect.verifySteps([ |
| 3156 |
"get_views", |
| 3157 |
"web_read", // initial read |
| 3158 |
"post", |
| 3159 |
"web_read", // reload (successfully clicked on p) |
| 3160 |
"some_method", |
| 3161 |
]); |
| 3162 |
expect.verifyErrors(["doActionButton error"]); |
| 3163 |
}); |
| 3164 |
|
| 3165 |
test.tags("desktop"); |
| 3166 |
test(`buttons classes in form view`, async () => { |
| 3167 |
await mountView({ |
| 3168 |
resModel: "partner", |
| 3169 |
type: "form", |
| 3170 |
arch: ` |
| 3171 |
<form> |
| 3172 |
<header> |
| 3173 |
<button name="0"/> |
| 3174 |
<button name="1" class="btn-primary"/> |
| 3175 |
<button name="2" class="oe_highlight"/> |
| 3176 |
<button name="3" class="btn-secondary"/> |
| 3177 |
<button name="4" class="btn-link"/> |
| 3178 |
<button name="5" class="oe_link"/> |
| 3179 |
<button name="6" class="btn-success"/> |
| 3180 |
<button name="7" class="o_this_is_a_button"/> |
| 3181 |
</header> |
| 3182 |
<sheet> |
| 3183 |
<button name="8"/> |
| 3184 |
<button name="9" class="btn-primary"/> |
| 3185 |
<button name="10" class="oe_highlight"/> |
| 3186 |
<button name="11" class="btn-secondary"/> |
| 3187 |
<button name="12" class="btn-link"/> |
| 3188 |
<button name="13" class="oe_link"/> |
| 3189 |
<button name="14" class="btn-success"/> |
| 3190 |
<button name="15" class="o_this_is_a_button"/> |
| 3191 |
</sheet> |
| 3192 |
</form> |
| 3193 |
`, |
| 3194 |
resId: 2, |
| 3195 |
}); |
| 3196 |
expect(`button[name="0"]`).toHaveClass("btn btn-secondary"); |
| 3197 |
expect(`button[name="1"]`).toHaveClass("btn btn-primary"); |
| 3198 |
expect(`button[name="2"]`).toHaveClass("btn btn-primary"); |
| 3199 |
expect(`button[name="3"]`).toHaveClass("btn btn-secondary"); |
| 3200 |
expect(`button[name="4"]`).toHaveClass("btn btn-link"); |
| 3201 |
expect(`button[name="5"]`).toHaveClass("btn btn-link"); |
| 3202 |
expect(`button[name="6"]`).toHaveClass("btn btn-success"); |
| 3203 |
expect(`button[name="7"]`).toHaveClass("btn o_this_is_a_button btn-secondary"); |
| 3204 |
expect(`button[name="8"]`).toHaveClass("btn btn-secondary"); |
| 3205 |
expect(`button[name="9"]`).toHaveClass("btn btn-primary"); |
| 3206 |
expect(`button[name="10"]`).toHaveClass("btn btn-primary"); |
| 3207 |
expect(`button[name="11"]`).toHaveClass("btn btn-secondary"); |
| 3208 |
expect(`button[name="12"]`).toHaveClass("btn btn-link"); |
| 3209 |
expect(`button[name="13"]`).toHaveClass("btn btn-link"); |
| 3210 |
expect(`button[name="14"]`).toHaveClass("btn btn-success"); |
| 3211 |
expect(`button[name="15"]`).toHaveClass("btn o_this_is_a_button"); |
| 3212 |
}); |
| 3213 |
|
| 3214 |
test.tags("desktop"); |
| 3215 |
test(`buttons should be in .o_statusbar_buttons in form view header on desktop`, async () => { |
| 3216 |
await mountView({ |
| 3217 |
resModel: "partner", |
| 3218 |
type: "form", |
| 3219 |
arch: ` |
| 3220 |
<form> |
| 3221 |
<header> |
| 3222 |
<button name="0"/> |
| 3223 |
<field name="foo" widget="url" class="btn btn-secondary" text="My Button" readonly="1"/> |
| 3224 |
</header> |
| 3225 |
</form> |
| 3226 |
`, |
| 3227 |
resId: 2, |
| 3228 |
}); |
| 3229 |
expect(`.o_statusbar_buttons > button:eq(0)`).toHaveAttribute("name", "0"); |
| 3230 |
expect(`.o_statusbar_buttons > div:eq(0)`).toHaveAttribute("name", "foo"); |
| 3231 |
}); |
| 3232 |
|
| 3233 |
test.tags("mobile"); |
| 3234 |
test(`buttons should be in .o_statusbar_buttons in form view header on mobile`, async () => { |
| 3235 |
await mountView({ |
| 3236 |
resModel: "partner", |
| 3237 |
type: "form", |
| 3238 |
arch: ` |
| 3239 |
<form> |
| 3240 |
<header> |
| 3241 |
<button name="0"/> |
| 3242 |
<field name="foo" widget="url" class="btn btn-secondary" text="My Button" readonly="1"/> |
| 3243 |
</header> |
| 3244 |
</form> |
| 3245 |
`, |
| 3246 |
resId: 2, |
| 3247 |
}); |
| 3248 |
|
| 3249 |
expect(`.o_statusbar_buttons > button:eq(0)`).toHaveAttribute("name", "0"); |
| 3250 |
await contains(".o_statusbar_buttons .dropdown-toggle:has(.oi-ellipsis-v)").click(); |
| 3251 |
expect(`.o-dropdown--menu div.o_field_widget`).toHaveAttribute("name", "foo"); |
| 3252 |
}); |
| 3253 |
|
| 3254 |
test(`button in form view and long willStart`, async () => { |
| 3255 |
mockService("action", { |
| 3256 |
doActionButton(params) { |
| 3257 |
params.onClose(); |
| 3258 |
}, |
| 3259 |
}); |
| 3260 |
|
| 3261 |
let rpcCount = 0; |
| 3262 |
class AsyncField extends CharField { |
| 3263 |
setup() { |
| 3264 |
onWillStart(async () => { |
| 3265 |
expect.step("willStart"); |
| 3266 |
}); |
| 3267 |
onWillUpdateProps(async () => { |
| 3268 |
expect.step("willUpdateProps"); |
| 3269 |
if (rpcCount === 1) { |
| 3270 |
return new Promise(() => {}); |
| 3271 |
} |
| 3272 |
}); |
| 3273 |
} |
| 3274 |
} |
| 3275 |
fieldsRegistry.add("asyncwidget", { component: AsyncField }); |
| 3276 |
|
| 3277 |
onRpc("web_read", () => { |
| 3278 |
rpcCount++; |
| 3279 |
expect.step(`web_read${rpcCount}`); |
| 3280 |
}); |
| 3281 |
await mountView({ |
| 3282 |
resModel: "partner", |
| 3283 |
type: "form", |
| 3284 |
arch: ` |
| 3285 |
<form> |
| 3286 |
<field name="state" invisible="1"/> |
| 3287 |
<header> |
| 3288 |
<button name="post" class="child_ids" string="Confirm" type="object"/> |
| 3289 |
</header> |
| 3290 |
<sheet> |
| 3291 |
<group> |
| 3292 |
<field name="foo" widget="asyncwidget"/> |
| 3293 |
</group> |
| 3294 |
</sheet> |
| 3295 |
</form> |
| 3296 |
`, |
| 3297 |
resId: 2, |
| 3298 |
}); |
| 3299 |
expect.verifySteps(["web_read1", "willStart"]); |
| 3300 |
|
| 3301 |
await contains(`.o_form_statusbar button.child_ids`).click(); |
| 3302 |
expect.verifySteps(["web_read2", "willUpdateProps"]); |
| 3303 |
|
| 3304 |
await contains(`.o_form_statusbar button.child_ids`).click(); |
| 3305 |
expect.verifySteps(["web_read3", "willUpdateProps"]); |
| 3306 |
}); |
| 3307 |
|
| 3308 |
test.tags("desktop"); |
| 3309 |
test(`buttons in form view, new record`, async () => { |
| 3310 |
// this test simulates a situation similar to the settings forms. |
| 3311 |
|
| 3312 |
let resId = null; |
| 3313 |
mockService("action", { |
| 3314 |
doActionButton(params) { |
| 3315 |
expect.step("execute_action"); |
| 3316 |
expect(params.resId).toBe(resId); |
| 3317 |
params.onClose(); |
| 3318 |
}, |
| 3319 |
}); |
| 3320 |
|
| 3321 |
onRpc("web_save", ({ parent }) => { |
| 3322 |
const result = parent(); |
| 3323 |
resId = result[0].id; |
| 3324 |
return result; |
| 3325 |
}); |
| 3326 |
onRpc(({ method }) => expect.step(method)); |
| 3327 |
await mountView({ |
| 3328 |
resModel: "partner", |
| 3329 |
type: "form", |
| 3330 |
arch: ` |
| 3331 |
<form> |
| 3332 |
<header> |
| 3333 |
<button name="post" class="child_ids" string="Confirm" type="object"/> |
| 3334 |
<button name="some_method" class="s" string="Do it" type="object"/> |
| 3335 |
</header> |
| 3336 |
<sheet> |
| 3337 |
<group> |
| 3338 |
<button string="Geolocate" name="geo_localize" icon="fa-check" type="object"/> |
| 3339 |
</group> |
| 3340 |
</sheet> |
| 3341 |
</form> |
| 3342 |
`, |
| 3343 |
}); |
| 3344 |
expect.verifySteps(["get_views", "onchange"]); |
| 3345 |
|
| 3346 |
await contains(`.o_form_statusbar button.child_ids`).click(); |
| 3347 |
expect.verifySteps(["web_save", "execute_action", "web_read"]); |
| 3348 |
}); |
| 3349 |
|
| 3350 |
test(`buttons in form view, new record, with field id in view`, async () => { |
| 3351 |
// buttons in form view are one of the rare example of situation when we |
| 3352 |
// save a record without reloading it immediately, because we only care |
| 3353 |
// about its id for the next step. But at some point, if the field id |
| 3354 |
// is in the view, it was registered in the changes, and caused invalid |
| 3355 |
// values in the record (data.id was set to null) |
| 3356 |
|
| 3357 |
let resId = null; |
| 3358 |
mockService("action", { |
| 3359 |
doActionButton(params) { |
| 3360 |
expect.step("execute_action"); |
| 3361 |
expect(params.resId).toBe(resId); |
| 3362 |
params.onClose(); |
| 3363 |
}, |
| 3364 |
}); |
| 3365 |
|
| 3366 |
onRpc("web_save", ({ parent }) => { |
| 3367 |
const result = parent(); |
| 3368 |
resId = result[0].id; |
| 3369 |
return result; |
| 3370 |
}); |
| 3371 |
onRpc(({ method }) => expect.step(method)); |
| 3372 |
await mountView({ |
| 3373 |
resModel: "partner", |
| 3374 |
type: "form", |
| 3375 |
arch: ` |
| 3376 |
<form> |
| 3377 |
<header> |
| 3378 |
<button name="post" class="child_ids" string="Confirm" type="object"/> |
| 3379 |
</header> |
| 3380 |
<sheet> |
| 3381 |
<group> |
| 3382 |
<field name="id" invisible="1"/> |
| 3383 |
<field name="foo"/> |
| 3384 |
</group> |
| 3385 |
</sheet> |
| 3386 |
</form> |
| 3387 |
`, |
| 3388 |
}); |
| 3389 |
await contains(`.o_form_statusbar button.child_ids`).click(); |
| 3390 |
expect.verifySteps(["get_views", "onchange", "web_save", "execute_action", "web_read"]); |
| 3391 |
}); |
| 3392 |
|
| 3393 |
test(`buttons with data-hotkey attribute`, async () => { |
| 3394 |
mockService("action", { |
| 3395 |
doActionButton(params) { |
| 3396 |
expect.step(params.name); |
| 3397 |
}, |
| 3398 |
}); |
| 3399 |
|
| 3400 |
await mountView({ |
| 3401 |
resModel: "partner", |
| 3402 |
type: "form", |
| 3403 |
arch: ` |
| 3404 |
<form> |
| 3405 |
<button name="validate" string="Validate" type="object" data-hotkey="v"/> |
| 3406 |
</form> |
| 3407 |
`, |
| 3408 |
resId: 2, |
| 3409 |
}); |
| 3410 |
expect(`.o_form_view button[data-hotkey=v]`).toHaveCount(1); |
| 3411 |
|
| 3412 |
await press(["alt", "v"]); |
| 3413 |
await animationFrame(); |
| 3414 |
expect.verifySteps(["validate"]); |
| 3415 |
}); |
| 3416 |
|
| 3417 |
test(`change and save char`, async () => { |
| 3418 |
onRpc("web_save", ({ args }) => { |
| 3419 |
expect.step("web_save"); |
| 3420 |
expect(args[1].foo).toBe("tralala"); |
| 3421 |
}); |
| 3422 |
await mountView({ |
| 3423 |
resModel: "partner", |
| 3424 |
type: "form", |
| 3425 |
arch: `<form><group><field name="foo"/></group></form>`, |
| 3426 |
resId: 2, |
| 3427 |
}); |
| 3428 |
expect(`.o_form_editable`).toHaveCount(1); |
| 3429 |
|
| 3430 |
await contains(`.o_field_widget[name=foo] input`).edit("tralala"); |
| 3431 |
await contains(`.o_form_button_save`).click(); |
| 3432 |
expect.verifySteps(["web_save"]); |
| 3433 |
}); |
| 3434 |
|
| 3435 |
test(`properly reload data from server`, async () => { |
| 3436 |
onRpc("web_save", ({ args }) => { |
| 3437 |
args[1].foo = "apple"; |
| 3438 |
}); |
| 3439 |
await mountView({ |
| 3440 |
resModel: "partner", |
| 3441 |
type: "form", |
| 3442 |
arch: `<form><group><field name="foo"/></group></form>`, |
| 3443 |
resId: 2, |
| 3444 |
}); |
| 3445 |
await contains(`.o_field_widget[name=foo] input`).edit("tralala"); |
| 3446 |
await contains(`.o_form_button_save`).click(); |
| 3447 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("apple"); |
| 3448 |
}); |
| 3449 |
|
| 3450 |
test(`disable buttons until reload data from server`, async () => { |
| 3451 |
let def = null; |
| 3452 |
onRpc("web_save", async ({ args }) => { |
| 3453 |
args[1].foo = "apple"; |
| 3454 |
await def; |
| 3455 |
}); |
| 3456 |
await mountView({ |
| 3457 |
resModel: "partner", |
| 3458 |
type: "form", |
| 3459 |
arch: `<form><group><field name="foo"/></group></form>`, |
| 3460 |
resId: 2, |
| 3461 |
}); |
| 3462 |
|
| 3463 |
def = new Deferred(); |
| 3464 |
await contains(`.o_field_widget[name=foo] input`).edit("tralala"); |
| 3465 |
await contains(`.o_form_button_save`).click(); |
| 3466 |
|
| 3467 |
expect(`.o_form_button_save`).not.toBeEnabled(); |
| 3468 |
expect(`.o_form_button_cancel`).not.toBeEnabled(); |
| 3469 |
|
| 3470 |
def.resolve(); |
| 3471 |
await animationFrame(); |
| 3472 |
expect(`.o_form_button_save`).toBeEnabled(); |
| 3473 |
expect(`.o_form_button_cancel`).toBeEnabled(); |
| 3474 |
}); |
| 3475 |
|
| 3476 |
test(`properly apply onchange in simple case`, async () => { |
| 3477 |
Partner._onChanges = { |
| 3478 |
foo(record) { |
| 3479 |
record.int_field = record.foo.length + 1000; |
| 3480 |
}, |
| 3481 |
}; |
| 3482 |
await mountView({ |
| 3483 |
resModel: "partner", |
| 3484 |
type: "form", |
| 3485 |
arch: `<form><field name="foo"/><field name="int_field"/></form>`, |
| 3486 |
resId: 2, |
| 3487 |
}); |
| 3488 |
expect(`.o_field_widget[name=int_field] input`).toHaveValue("9"); |
| 3489 |
|
| 3490 |
await contains(`.o_field_widget[name=foo] input`).edit("tralala"); |
| 3491 |
expect(`.o_field_widget[name=int_field] input`).toHaveValue("1,007"); |
| 3492 |
}); |
| 3493 |
|
| 3494 |
test(`properly apply onchange when changed field is active field`, async () => { |
| 3495 |
Partner._onChanges = { |
| 3496 |
int_field(record) { |
| 3497 |
record.int_field = 14; |
| 3498 |
}, |
| 3499 |
}; |
| 3500 |
await mountView({ |
| 3501 |
resModel: "partner", |
| 3502 |
type: "form", |
| 3503 |
arch: `<form><field name="int_field"/></form>`, |
| 3504 |
resId: 2, |
| 3505 |
}); |
| 3506 |
expect(`.o_field_widget[name=int_field] input`).toHaveValue("9"); |
| 3507 |
|
| 3508 |
await contains(`.o_field_widget[name=int_field] input`).edit("666"); |
| 3509 |
expect(`.o_field_widget[name=int_field] input`).toHaveValue("14"); |
| 3510 |
|
| 3511 |
await contains(`.o_form_button_save`).click(); |
| 3512 |
expect(`.o_field_widget[name=int_field] input`).toHaveValue("14"); |
| 3513 |
}); |
| 3514 |
|
| 3515 |
test(`onchange send only the present fields to the server`, async () => { |
| 3516 |
Partner._records[0].product_id = false; |
| 3517 |
Partner._onChanges = { |
| 3518 |
foo(record) { |
| 3519 |
record.foo = record.foo + " alligator"; |
| 3520 |
}, |
| 3521 |
}; |
| 3522 |
PartnerType._views = { |
| 3523 |
list: `<list><field name="name"/></list>`, |
| 3524 |
}; |
| 3525 |
|
| 3526 |
onRpc("onchange", ({ args }) => { |
| 3527 |
expect.step("onchange"); |
| 3528 |
expect(args[3]).toEqual({ |
| 3529 |
display_name: {}, |
| 3530 |
foo: {}, |
| 3531 |
child_ids: { |
| 3532 |
fields: { |
| 3533 |
bar: {}, |
| 3534 |
product_id: { |
| 3535 |
fields: { |
| 3536 |
display_name: {}, |
| 3537 |
}, |
| 3538 |
}, |
| 3539 |
}, |
| 3540 |
limit: 40, |
| 3541 |
}, |
| 3542 |
type_ids: { |
| 3543 |
fields: { |
| 3544 |
name: {}, |
| 3545 |
}, |
| 3546 |
limit: 40, |
| 3547 |
}, |
| 3548 |
}); |
| 3549 |
}); |
| 3550 |
await mountView({ |
| 3551 |
resModel: "partner", |
| 3552 |
type: "form", |
| 3553 |
arch: ` |
| 3554 |
<form> |
| 3555 |
<field name="foo"/> |
| 3556 |
<field name="child_ids" widget="one2many"> |
| 3557 |
<list> |
| 3558 |
<field name="bar"/> |
| 3559 |
<field name="product_id"/> |
| 3560 |
</list> |
| 3561 |
</field> |
| 3562 |
<field name="type_ids"/> |
| 3563 |
</form> |
| 3564 |
`, |
| 3565 |
resId: 1, |
| 3566 |
}); |
| 3567 |
await contains(`.o_field_widget[name=foo] input`).edit("tralala"); |
| 3568 |
expect.verifySteps(["onchange"]); |
| 3569 |
}); |
| 3570 |
|
| 3571 |
test(`onchange only send present fields value`, async () => { |
| 3572 |
Partner._onChanges = { |
| 3573 |
foo: () => {}, |
| 3574 |
}; |
| 3575 |
|
| 3576 |
let checkOnchange = false; |
| 3577 |
onRpc("onchange", ({ args }) => { |
| 3578 |
if (!checkOnchange) { |
| 3579 |
return; |
| 3580 |
} |
| 3581 |
expect.step("onchange"); |
| 3582 |
expect(args[1]).toEqual({ |
| 3583 |
foo: "tralala", |
| 3584 |
child_ids: [[0, args[1].child_ids[0][1], { name: "valid line", float_field: 12.4 }]], |
| 3585 |
}); |
| 3586 |
}); |
| 3587 |
await mountView({ |
| 3588 |
resModel: "partner", |
| 3589 |
type: "form", |
| 3590 |
arch: ` |
| 3591 |
<form> |
| 3592 |
<field name="name"/> |
| 3593 |
<field name="foo"/> |
| 3594 |
<field name="child_ids"> |
| 3595 |
<list editable="top"> |
| 3596 |
<field name="name"/> |
| 3597 |
<field name="float_field"/> |
| 3598 |
</list> |
| 3599 |
</field> |
| 3600 |
</form> |
| 3601 |
`, |
| 3602 |
resId: 1, |
| 3603 |
}); |
| 3604 |
|
| 3605 |
// add a o2m row |
| 3606 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 3607 |
await contains(`.o_field_one2many .o_field_widget[name=name] input`).edit("valid line", { |
| 3608 |
confirm: false, |
| 3609 |
}); |
| 3610 |
await contains(`.o_field_one2many .o_field_widget[name=float_field] input`).edit("12.4", { |
| 3611 |
confirm: false, |
| 3612 |
}); |
| 3613 |
expect.verifySteps([]); |
| 3614 |
|
| 3615 |
// trigger an onchange by modifying foo |
| 3616 |
checkOnchange = true; |
| 3617 |
await contains(`.o_field_widget[name=foo] input`).edit("tralala"); |
| 3618 |
expect.verifySteps(["onchange"]); |
| 3619 |
}); |
| 3620 |
|
| 3621 |
test(`onchange send relation parent field values (including readonly)`, async () => { |
| 3622 |
ResUsers._fields.login = fields.Char(); |
| 3623 |
ResUsers._onChanges = { |
| 3624 |
name: (obj) => { |
| 3625 |
// like computed field that depends on "name" field |
| 3626 |
obj.login = obj.name.toLowerCase() + "@example.org"; |
| 3627 |
}, |
| 3628 |
}; |
| 3629 |
Partner._onChanges = { |
| 3630 |
float_field: () => {}, |
| 3631 |
}; |
| 3632 |
|
| 3633 |
let checkOnchange = false; |
| 3634 |
onRpc("onchange", ({ args, kwargs }) => { |
| 3635 |
if (!checkOnchange) { |
| 3636 |
return; |
| 3637 |
} |
| 3638 |
expect(args[1]).toEqual({ |
| 3639 |
float_field: 12.4, |
| 3640 |
user_id: { |
| 3641 |
id: 17, |
| 3642 |
name: "Test", |
| 3643 |
login: "[email protected]", |
| 3644 |
partner_ids: [[0, args[1].user_id.partner_ids[0][1], { float_field: 0 }]], |
| 3645 |
}, |
| 3646 |
}); |
| 3647 |
expect.step("onchange"); |
| 3648 |
}); |
| 3649 |
|
| 3650 |
await mountView({ |
| 3651 |
resModel: "res.users", |
| 3652 |
type: "form", |
| 3653 |
arch: ` |
| 3654 |
<form> |
| 3655 |
<field name="name"/> |
| 3656 |
<field name="login" readonly="True"/> |
| 3657 |
<field name="partner_ids"> |
| 3658 |
<list editable="top"> |
| 3659 |
<field name="float_field"/> |
| 3660 |
</list> |
| 3661 |
</field> |
| 3662 |
</form> |
| 3663 |
`, |
| 3664 |
resId: 17, |
| 3665 |
}); |
| 3666 |
|
| 3667 |
// trigger an onchange that update a readonly field by modifying user name |
| 3668 |
await contains(`.o_field_widget[name=name] input`).edit("Test"); |
| 3669 |
|
| 3670 |
// add a o2m row |
| 3671 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 3672 |
expect.verifySteps([]); |
| 3673 |
|
| 3674 |
// trigger an onchange by modifying float_field |
| 3675 |
// confirm with blur s.t. it doesn't create a new line which would call another onchange and |
| 3676 |
// pollute our assertions |
| 3677 |
checkOnchange = true; |
| 3678 |
await contains(`.o_field_one2many .o_field_widget[name=float_field] input`).edit("12.4", { |
| 3679 |
confirm: "blur", |
| 3680 |
}); |
| 3681 |
expect.verifySteps(["onchange"]); |
| 3682 |
}); |
| 3683 |
|
| 3684 |
test(`evaluate in python field options`, async () => { |
| 3685 |
class MyField extends Component { |
| 3686 |
static props = ["*"]; |
| 3687 |
static template = xml`<div>ok</div>`; |
| 3688 |
setup() { |
| 3689 |
expect.step("setup"); |
| 3690 |
expect(this.props.horizontal).toBe(true); |
| 3691 |
} |
| 3692 |
} |
| 3693 |
fieldsRegistry.add("my_field", { |
| 3694 |
component: MyField, |
| 3695 |
extractProps({ options }) { |
| 3696 |
expect.step("extractProps"); |
| 3697 |
expect(options).toEqual({ horizontal: true }); |
| 3698 |
return { horizontal: options.horizontal }; |
| 3699 |
}, |
| 3700 |
}); |
| 3701 |
|
| 3702 |
await mountView({ |
| 3703 |
resModel: "partner", |
| 3704 |
type: "form", |
| 3705 |
arch: ` |
| 3706 |
<form> |
| 3707 |
<field name="foo" widget="my_field" options="{'horizontal': True}"/> |
| 3708 |
</form> |
| 3709 |
`, |
| 3710 |
resId: 2, |
| 3711 |
}); |
| 3712 |
expect(`.o_field_widget`).toHaveText("ok"); |
| 3713 |
expect.verifySteps(["extractProps", "setup"]); |
| 3714 |
}); |
| 3715 |
|
| 3716 |
test(`can create a record with default values`, async () => { |
| 3717 |
onRpc("web_save", ({ kwargs }) => { |
| 3718 |
expect.step("web_save"); |
| 3719 |
expect(kwargs.context.active_field).toBe(2); |
| 3720 |
}); |
| 3721 |
await mountView({ |
| 3722 |
resModel: "partner", |
| 3723 |
type: "form", |
| 3724 |
arch: ` |
| 3725 |
<form> |
| 3726 |
<field name="foo"/> |
| 3727 |
<field name="bar"/> |
| 3728 |
</form> |
| 3729 |
`, |
| 3730 |
resId: 1, |
| 3731 |
context: { active_field: 2 }, |
| 3732 |
}); |
| 3733 |
|
| 3734 |
const n = MockServer.env["partner"].length; |
| 3735 |
|
| 3736 |
await contains(`.o_form_button_create`).click(); |
| 3737 |
expect(`.o_form_editable`).toHaveCount(1); |
| 3738 |
expect(`.o_field_char input`).toHaveValue("My little Foo Value"); |
| 3739 |
|
| 3740 |
await contains(`.o_form_button_save`).click(); |
| 3741 |
expect.verifySteps(["web_save"]); |
| 3742 |
expect(`.o_form_editable`).toHaveCount(1); |
| 3743 |
expect(MockServer.env["partner"]).toHaveLength(n + 1); |
| 3744 |
}); |
| 3745 |
|
| 3746 |
test(`default record with a one2many and an onchange on sub field`, async () => { |
| 3747 |
Partner._onChanges = { |
| 3748 |
foo: () => {}, |
| 3749 |
}; |
| 3750 |
|
| 3751 |
onRpc("onchange", ({ args }) => { |
| 3752 |
expect.step("onchange"); |
| 3753 |
expect(args[3]).toEqual({ |
| 3754 |
display_name: {}, |
| 3755 |
child_ids: { |
| 3756 |
fields: { |
| 3757 |
foo: {}, |
| 3758 |
}, |
| 3759 |
limit: 40, |
| 3760 |
}, |
| 3761 |
}); |
| 3762 |
}); |
| 3763 |
await mountView({ |
| 3764 |
resModel: "partner", |
| 3765 |
type: "form", |
| 3766 |
arch: ` |
| 3767 |
<form> |
| 3768 |
<field name="child_ids" widget="one2many"> |
| 3769 |
<list><field name="foo"/></list> |
| 3770 |
</field> |
| 3771 |
</form> |
| 3772 |
`, |
| 3773 |
}); |
| 3774 |
expect.verifySteps(["onchange"]); |
| 3775 |
}); |
| 3776 |
|
| 3777 |
test(`remove default value in subviews`, async () => { |
| 3778 |
Product._onchanges = { |
| 3779 |
name: () => {}, |
| 3780 |
}; |
| 3781 |
|
| 3782 |
const defaultContext = { |
| 3783 |
lang: "en", |
| 3784 |
tz: "taht", |
| 3785 |
uid: 7, |
| 3786 |
allowed_company_ids: [1], |
| 3787 |
}; |
| 3788 |
|
| 3789 |
onRpc("partner", "onchange", ({ kwargs }) => { |
| 3790 |
expect.step(`onchange:partner`); |
| 3791 |
expect(kwargs.context).toEqual({ ...defaultContext, default_state: "ab" }); |
| 3792 |
}); |
| 3793 |
onRpc("product", "onchange", ({ kwargs }) => { |
| 3794 |
expect.step(`onchange:product`); |
| 3795 |
expect(kwargs.context).toEqual({ ...defaultContext, default_product_uom_qty: 68 }); |
| 3796 |
}); |
| 3797 |
await mountView({ |
| 3798 |
resModel: "partner", |
| 3799 |
type: "form", |
| 3800 |
arch: ` |
| 3801 |
<form> |
| 3802 |
<field name="product_ids" context="{'default_product_uom_qty': 68}"> |
| 3803 |
<list editable="top"> |
| 3804 |
<field name="name"/> |
| 3805 |
</list> |
| 3806 |
</field> |
| 3807 |
</form> |
| 3808 |
`, |
| 3809 |
context: { default_state: "ab" }, |
| 3810 |
}); |
| 3811 |
expect.verifySteps(["onchange:partner"]); |
| 3812 |
|
| 3813 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 3814 |
expect.verifySteps(["onchange:product"]); |
| 3815 |
}); |
| 3816 |
|
| 3817 |
test(`form with one2many with dynamic context`, async () => { |
| 3818 |
onRpc("web_read", ({ kwargs }) => { |
| 3819 |
expect.step("web_read"); |
| 3820 |
expect(kwargs.specification).toEqual({ |
| 3821 |
display_name: {}, |
| 3822 |
int_field: {}, |
| 3823 |
child_ids: { |
| 3824 |
fields: { |
| 3825 |
foo: {}, |
| 3826 |
}, |
| 3827 |
context: { static: 4 }, |
| 3828 |
limit: 40, |
| 3829 |
}, |
| 3830 |
}); |
| 3831 |
}); |
| 3832 |
onRpc("onchange", ({ kwargs }) => { |
| 3833 |
expect.step("onchange"); |
| 3834 |
expect(kwargs.context).toEqual({ |
| 3835 |
dynamic: 20, |
| 3836 |
lang: "en", |
| 3837 |
static: 4, |
| 3838 |
tz: "taht", |
| 3839 |
uid: 7, |
| 3840 |
allowed_company_ids: [1], |
| 3841 |
}); |
| 3842 |
}); |
| 3843 |
await mountView({ |
| 3844 |
resModel: "partner", |
| 3845 |
type: "form", |
| 3846 |
arch: ` |
| 3847 |
<form> |
| 3848 |
<field name="int_field"/> |
| 3849 |
<field name="child_ids" editable="bottom" context="{'static': 4, 'dynamic': int_field * 2}"> |
| 3850 |
<list> |
| 3851 |
<field name="foo"/> |
| 3852 |
</list> |
| 3853 |
</field> |
| 3854 |
</form> |
| 3855 |
`, |
| 3856 |
resId: 1, |
| 3857 |
}); |
| 3858 |
expect.verifySteps(["web_read"]); |
| 3859 |
|
| 3860 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 3861 |
expect.verifySteps(["onchange"]); |
| 3862 |
}); |
| 3863 |
|
| 3864 |
test(`reference field in one2many list`, async () => { |
| 3865 |
Partner._records[0].reference = "partner,2"; |
| 3866 |
Partner._views = { |
| 3867 |
form: `<form><field name="name"/></form>`, |
| 3868 |
}; |
| 3869 |
|
| 3870 |
onRpc("get_formview_id", () => false); |
| 3871 |
await mountViewInDialog({ |
| 3872 |
resModel: "res.users", |
| 3873 |
type: "form", |
| 3874 |
arch: ` |
| 3875 |
<form> |
| 3876 |
<field name="name"/> |
| 3877 |
<field name="partner_ids"> |
| 3878 |
<list editable="bottom"> |
| 3879 |
<field name="name"/> |
| 3880 |
<field name="reference"/> |
| 3881 |
</list> |
| 3882 |
</field> |
| 3883 |
</form> |
| 3884 |
`, |
| 3885 |
resId: 17, |
| 3886 |
}); |
| 3887 |
await contains(`table td[data-tooltip="first record"]`).click(); |
| 3888 |
await contains(`table td button.o_external_button`, { visible: false }).click(); |
| 3889 |
await contains(`.o_dialog:not(.o_inactive_modal) .o_field_widget[name="name"] input`).edit( |
| 3890 |
"New name" |
| 3891 |
); |
| 3892 |
await contains(`.o_dialog:not(.o_inactive_modal) footer .o_form_button_save`).click(); |
| 3893 |
expect(`.o_field_cell[data-tooltip="New name"]`).toHaveCount(1); |
| 3894 |
}); |
| 3895 |
|
| 3896 |
test(`there is an Actions menu when creating a new record`, async () => { |
| 3897 |
await mountView({ |
| 3898 |
resModel: "partner", |
| 3899 |
type: "form", |
| 3900 |
arch: `<form><field name="foo"/></form>`, |
| 3901 |
actionMenus: {}, |
| 3902 |
resId: 1, |
| 3903 |
}); |
| 3904 |
expect(`.o_cp_action_menus`).toHaveCount(1); |
| 3905 |
|
| 3906 |
await contains(`.o_form_button_create`).click(); |
| 3907 |
expect(`.o_cp_action_menus`).toHaveCount(1); |
| 3908 |
|
| 3909 |
await contains(`.o_form_button_save`).click(); |
| 3910 |
expect(`.o_cp_action_menus`).toHaveCount(1); |
| 3911 |
}); |
| 3912 |
|
| 3913 |
test(`basic default record`, async () => { |
| 3914 |
Partner._fields.foo = fields.Char({ default: "default foo value" }); |
| 3915 |
|
| 3916 |
onRpc(({ method }) => expect.step(method)); |
| 3917 |
await mountView({ |
| 3918 |
resModel: "partner", |
| 3919 |
type: "form", |
| 3920 |
arch: `<form><field name="foo"/></form>`, |
| 3921 |
}); |
| 3922 |
expect(`input`).toHaveValue("default foo value"); |
| 3923 |
expect.verifySteps(["get_views", "onchange"]); |
| 3924 |
}); |
| 3925 |
|
| 3926 |
test(`make default record with non empty one2many`, async () => { |
| 3927 |
Partner._fields.child_ids = fields.One2many({ |
| 3928 |
relation: "partner", |
| 3929 |
default: [ |
| 3930 |
[6, 0, []], // replace with zero ids |
| 3931 |
[0, 0, { foo: "new foo1", product_id: 41, child_ids: [] }], // create a new value |
| 3932 |
[0, 0, { foo: "new foo2", product_id: 37, child_ids: [] }], // create a new value |
| 3933 |
], |
| 3934 |
}); |
| 3935 |
|
| 3936 |
onRpc("read", ({ args }) => { |
| 3937 |
if (args[1].length === 1 && args[1][0] === "display_name") { |
| 3938 |
expect.step("read display_name"); |
| 3939 |
} |
| 3940 |
}); |
| 3941 |
await mountView({ |
| 3942 |
resModel: "partner", |
| 3943 |
type: "form", |
| 3944 |
arch: ` |
| 3945 |
<form> |
| 3946 |
<field name="child_ids"> |
| 3947 |
<list> |
| 3948 |
<field name="foo"/> |
| 3949 |
<field name="product_id"/> |
| 3950 |
</list> |
| 3951 |
</field> |
| 3952 |
</form> |
| 3953 |
`, |
| 3954 |
}); |
| 3955 |
expect(`td:contains(new foo1)`).toHaveCount(1); |
| 3956 |
expect(`td:contains(new foo2)`).toHaveCount(1); |
| 3957 |
expect(`td:contains(xphone)`).toHaveCount(1); |
| 3958 |
expect.verifySteps([]); |
| 3959 |
}); |
| 3960 |
|
| 3961 |
test(`make default record with non empty many2one`, async () => { |
| 3962 |
Partner._fields.parent_id = fields.Many2one({ relation: "partner", default: 4 }); |
| 3963 |
|
| 3964 |
onRpc("read", ({ args }) => { |
| 3965 |
if (args[1].length === 1 && args[1][0] === "display_name") { |
| 3966 |
throw new Error("Should not call display_name read"); |
| 3967 |
} |
| 3968 |
}); |
| 3969 |
await mountView({ |
| 3970 |
resModel: "partner", |
| 3971 |
type: "form", |
| 3972 |
arch: `<form><field name="parent_id"/></form>`, |
| 3973 |
}); |
| 3974 |
expect(`.o_field_widget[name="parent_id"] input`).toHaveValue("aaa"); |
| 3975 |
expect.verifySteps([]); |
| 3976 |
}); |
| 3977 |
|
| 3978 |
test(`form view properly change its title`, async () => { |
| 3979 |
Partner._views = { |
| 3980 |
form: `<form><field name="foo"/></form>`, |
| 3981 |
}; |
| 3982 |
|
| 3983 |
defineActions([ |
| 3984 |
{ |
| 3985 |
id: 1, |
| 3986 |
name: "Partner", |
| 3987 |
res_model: "partner", |
| 3988 |
views: [[false, "form"]], |
| 3989 |
res_id: 1, |
| 3990 |
}, |
| 3991 |
]); |
| 3992 |
|
| 3993 |
await mountWithCleanup(WebClient); |
| 3994 |
await getService("action").doAction(1); |
| 3995 |
expect(`.o_breadcrumb`).toHaveText("first record"); |
| 3996 |
|
| 3997 |
await contains(`.o_form_button_create`).click(); |
| 3998 |
expect(`.o_breadcrumb`).toHaveText("New"); |
| 3999 |
}); |
| 4000 |
|
| 4001 |
test(`archive/unarchive a record`, async () => { |
| 4002 |
// add active field on partner model to have archive option |
| 4003 |
Partner._fields.active = fields.Boolean(); |
| 4004 |
|
| 4005 |
onRpc(({ method }) => expect.step(method)); |
| 4006 |
await mountView({ |
| 4007 |
resModel: "partner", |
| 4008 |
type: "form", |
| 4009 |
arch: `<form><field name="active"/><field name="foo"/></form>`, |
| 4010 |
resId: 1, |
| 4011 |
actionMenus: {}, |
| 4012 |
}); |
| 4013 |
expect(`.o_cp_action_menus`).toHaveCount(1); |
| 4014 |
|
| 4015 |
await toggleActionMenu(); |
| 4016 |
expect(`.o-dropdown--menu span:contains(Archive)`).toHaveCount(1); |
| 4017 |
|
| 4018 |
await toggleMenuItem("Archive"); |
| 4019 |
expect(`.modal`).toHaveCount(1); |
| 4020 |
|
| 4021 |
await contains(`.modal-footer .btn-primary`).click(); |
| 4022 |
await toggleActionMenu(); |
| 4023 |
expect(`.o-dropdown--menu span:contains(Unarchive)`).toHaveCount(1); |
| 4024 |
|
| 4025 |
await toggleMenuItem("UnArchive"); |
| 4026 |
await toggleActionMenu(); |
| 4027 |
expect(`.o-dropdown--menu span:contains(Archive)`).toHaveCount(1); |
| 4028 |
expect.verifySteps([ |
| 4029 |
"get_views", |
| 4030 |
"web_read", |
| 4031 |
"action_archive", |
| 4032 |
"web_read", |
| 4033 |
"action_unarchive", |
| 4034 |
"web_read", |
| 4035 |
]); |
| 4036 |
}); |
| 4037 |
|
| 4038 |
test(`apply custom standard action menu (archive)`, async () => { |
| 4039 |
// add active field on partner model to have archive option |
| 4040 |
Partner._fields.active = fields.Boolean(); |
| 4041 |
|
| 4042 |
const formView = registry.category("views").get("form"); |
| 4043 |
class CustomFormController extends formView.Controller { |
| 4044 |
getStaticActionMenuItems() { |
| 4045 |
const menuItems = super.getStaticActionMenuItems(); |
| 4046 |
menuItems.archive.callback = () => { |
| 4047 |
expect.step("customArchive"); |
| 4048 |
}; |
| 4049 |
return menuItems; |
| 4050 |
} |
| 4051 |
} |
| 4052 |
registry.category("views").add("custom_form", { |
| 4053 |
...formView, |
| 4054 |
Controller: CustomFormController, |
| 4055 |
}); |
| 4056 |
after(() => { |
| 4057 |
registry.category("views").remove("custom_form"); |
| 4058 |
}); |
| 4059 |
|
| 4060 |
await mountView({ |
| 4061 |
resModel: "partner", |
| 4062 |
type: "form", |
| 4063 |
arch: ` |
| 4064 |
<form js_class="custom_form"> |
| 4065 |
<field name="active"/> |
| 4066 |
<field name="foo"/> |
| 4067 |
</form> |
| 4068 |
`, |
| 4069 |
resId: 1, |
| 4070 |
actionMenus: {}, |
| 4071 |
}); |
| 4072 |
expect(`.o_cp_action_menus`).toHaveCount(1); |
| 4073 |
|
| 4074 |
await toggleActionMenu(); |
| 4075 |
expect(`.o-dropdown--menu span:contains(Archive)`).toHaveCount(1); |
| 4076 |
|
| 4077 |
await toggleMenuItem("Archive"); |
| 4078 |
expect.verifySteps(["customArchive"]); |
| 4079 |
}); |
| 4080 |
|
| 4081 |
test(`add custom static action menu`, async () => { |
| 4082 |
const formView = registry.category("views").get("form"); |
| 4083 |
class CustomFormController extends formView.Controller { |
| 4084 |
getStaticActionMenuItems() { |
| 4085 |
const menuItems = super.getStaticActionMenuItems(); |
| 4086 |
menuItems.customAvailable = { |
| 4087 |
isAvailable: () => true, |
| 4088 |
description: "Custom Available", |
| 4089 |
sequence: 35, |
| 4090 |
callback: () => { |
| 4091 |
expect.step("Custom Available"); |
| 4092 |
}, |
| 4093 |
}; |
| 4094 |
menuItems.customNotAvailable = { |
| 4095 |
isAvailable: () => false, |
| 4096 |
description: "Custom Not Available", |
| 4097 |
callback: () => { |
| 4098 |
expect.step("Custom Not Available"); |
| 4099 |
}, |
| 4100 |
}; |
| 4101 |
menuItems.customDefaultAvailable = { |
| 4102 |
description: "Custom Default Available", |
| 4103 |
callback: () => { |
| 4104 |
expect.step("Custom Default Available"); |
| 4105 |
}, |
| 4106 |
}; |
| 4107 |
return menuItems; |
| 4108 |
} |
| 4109 |
} |
| 4110 |
registry.category("views").add("custom_form", { |
| 4111 |
...formView, |
| 4112 |
Controller: CustomFormController, |
| 4113 |
}); |
| 4114 |
after(() => { |
| 4115 |
registry.category("views").remove("custom_form"); |
| 4116 |
}); |
| 4117 |
|
| 4118 |
await mountView({ |
| 4119 |
resModel: "partner", |
| 4120 |
type: "form", |
| 4121 |
arch: ` |
| 4122 |
<form js_class="custom_form"> |
| 4123 |
<field name="foo"/> |
| 4124 |
</form> |
| 4125 |
`, |
| 4126 |
resId: 1, |
| 4127 |
actionMenus: {}, |
| 4128 |
}); |
| 4129 |
expect(`.o_cp_action_menus`).toHaveCount(1); |
| 4130 |
|
| 4131 |
await toggleActionMenu(); |
| 4132 |
expect(queryAllTexts`.o-dropdown--menu .dropdown-item`).toEqual([ |
| 4133 |
"Custom Default Available", |
| 4134 |
"Duplicate", |
| 4135 |
"Custom Available", |
| 4136 |
"Delete", |
| 4137 |
]); |
| 4138 |
|
| 4139 |
await toggleMenuItem("Custom Available"); |
| 4140 |
expect.verifySteps(["Custom Available"]); |
| 4141 |
|
| 4142 |
await toggleActionMenu(); |
| 4143 |
await toggleMenuItem("Custom Default Available"); |
| 4144 |
expect.verifySteps(["Custom Default Available"]); |
| 4145 |
}); |
| 4146 |
|
| 4147 |
test(`archive a record with intermediary action`, async () => { |
| 4148 |
// add active field on partner model to have archive option |
| 4149 |
Partner._fields.active = fields.Boolean(); |
| 4150 |
Partner._fields.archived = fields.Char({ default: "false" }); |
| 4151 |
Partner._views = { |
| 4152 |
form: /* xml */ ` |
| 4153 |
<form> |
| 4154 |
<field name="active" /> |
| 4155 |
<field name="archived" /> |
| 4156 |
<field name="foo" /> |
| 4157 |
</form>`, |
| 4158 |
}; |
| 4159 |
Product._views = { |
| 4160 |
form: /* xml */ ` |
| 4161 |
<form> |
| 4162 |
<field name="display_name" /> |
| 4163 |
<footer> |
| 4164 |
<button type="object" name="do_archive" class="myButton" /> |
| 4165 |
</footer> |
| 4166 |
</form> |
| 4167 |
`, |
| 4168 |
}; |
| 4169 |
|
| 4170 |
let readPartner = 0; |
| 4171 |
onRpc("do_archive", () => false); |
| 4172 |
onRpc("action_archive", () => ({ |
| 4173 |
type: "ir.actions.act_window", |
| 4174 |
res_model: "product", |
| 4175 |
target: "new", |
| 4176 |
views: [[false, "form"]], |
| 4177 |
})); |
| 4178 |
onRpc("partner", "web_read", () => { |
| 4179 |
if (readPartner === 1) { |
| 4180 |
return [{ id: 1, archived: "true" }]; |
| 4181 |
} |
| 4182 |
readPartner++; |
| 4183 |
}); |
| 4184 |
onRpc(({ model, method, route }) => |
| 4185 |
expect.step(`${method || route}${method ? ": " + model : ""}`) |
| 4186 |
); |
| 4187 |
await mountWithCleanup(WebClient); |
| 4188 |
await getService("action").doAction({ |
| 4189 |
res_model: "partner", |
| 4190 |
res_id: 1, |
| 4191 |
type: "ir.actions.act_window", |
| 4192 |
views: [[false, "form"]], |
| 4193 |
}); |
| 4194 |
expect(`[name='archived'] input`).toHaveValue("false"); |
| 4195 |
expect.verifySteps(["get_views: partner", "web_read: partner"]); |
| 4196 |
|
| 4197 |
await toggleActionMenu(); |
| 4198 |
expect(`.o-dropdown--menu .o-dropdown-item:contains(Archive)`).toHaveCount(1); |
| 4199 |
|
| 4200 |
await toggleMenuItem("Archive"); |
| 4201 |
expect(`.modal`).toHaveCount(1); |
| 4202 |
expect.verifySteps([]); |
| 4203 |
|
| 4204 |
await contains(`.modal-footer .btn-primary`).click(); |
| 4205 |
expect.verifySteps(["action_archive: partner", "get_views: product", "onchange: product"]); |
| 4206 |
|
| 4207 |
await contains(`.modal footer .myButton`).click(); |
| 4208 |
expect.verifySteps(["web_save: product", "do_archive: product", "web_read: partner"]); |
| 4209 |
expect(`.modal`).toHaveCount(0); |
| 4210 |
expect(`[name='archived'] input`).toHaveValue("true"); |
| 4211 |
}); |
| 4212 |
|
| 4213 |
test(`archive action with active field not in view`, async () => { |
| 4214 |
// add active field on partner model, but do not put it in the view |
| 4215 |
Partner._fields.active = fields.Boolean(); |
| 4216 |
|
| 4217 |
await mountView({ |
| 4218 |
resModel: "partner", |
| 4219 |
type: "form", |
| 4220 |
arch: `<form><field name="foo"/></form>`, |
| 4221 |
resId: 1, |
| 4222 |
actionMenus: {}, |
| 4223 |
}); |
| 4224 |
expect(`.o_cp_action_menus`).toHaveCount(1); |
| 4225 |
|
| 4226 |
await toggleActionMenu(); |
| 4227 |
expect(`.o_cp_action_menus span:contains(Archive)`).toHaveCount(0); |
| 4228 |
expect(`.o_cp_action_menus span:contains(Unarchive)`).toHaveCount(0); |
| 4229 |
}); |
| 4230 |
|
| 4231 |
test(`archive action not shown with readonly active field`, async () => { |
| 4232 |
// add active field on partner model in readonly mode to do not have Archive option |
| 4233 |
Partner._fields.active = fields.Boolean({ readonly: true }); |
| 4234 |
|
| 4235 |
await mountView({ |
| 4236 |
resModel: "partner", |
| 4237 |
type: "form", |
| 4238 |
arch: `<form><field name="active"/><field name="foo"/></form>`, |
| 4239 |
resId: 1, |
| 4240 |
actionMenus: {}, |
| 4241 |
}); |
| 4242 |
await contains(`.o_cp_action_menus .dropdown-toggle`).click(); |
| 4243 |
expect(queryAllTexts`.o_menu_item`).toEqual(["Duplicate", "Delete"]); |
| 4244 |
}); |
| 4245 |
|
| 4246 |
test(`can duplicate a record`, async () => { |
| 4247 |
onRpc("copy", ({ args, model }) => { |
| 4248 |
if (model === "partner") { |
| 4249 |
expect(args).toEqual([[1]]); |
| 4250 |
expect.step("copy"); |
| 4251 |
} |
| 4252 |
}); |
| 4253 |
await mountView({ |
| 4254 |
resModel: "partner", |
| 4255 |
type: "form", |
| 4256 |
arch: `<form><field name="foo"/></form>`, |
| 4257 |
resId: 1, |
| 4258 |
actionMenus: {}, |
| 4259 |
}); |
| 4260 |
expect(`.o_breadcrumb`).toHaveText("first record"); |
| 4261 |
|
| 4262 |
await toggleActionMenu(); |
| 4263 |
await toggleMenuItem("Duplicate"); |
| 4264 |
expect.verifySteps(["copy"]); |
| 4265 |
expect(`.o_breadcrumb`).toHaveText("first record (copy)"); |
| 4266 |
expect(`.o_form_editable`).toHaveCount(1); |
| 4267 |
}); |
| 4268 |
|
| 4269 |
test(`duplicating a record preserves the context`, async () => { |
| 4270 |
onRpc("web_read", ({ kwargs }) => expect.step(kwargs.context.hey)); |
| 4271 |
await mountView({ |
| 4272 |
resModel: "partner", |
| 4273 |
type: "form", |
| 4274 |
arch: `<form><field name="foo"/></form>`, |
| 4275 |
resId: 1, |
| 4276 |
actionMenus: {}, |
| 4277 |
context: { hey: "hoy" }, |
| 4278 |
}); |
| 4279 |
expect.verifySteps(["hoy"]); |
| 4280 |
|
| 4281 |
await toggleActionMenu(); |
| 4282 |
await toggleMenuItem("Duplicate"); |
| 4283 |
expect.verifySteps(["hoy"]); |
| 4284 |
}); |
| 4285 |
|
| 4286 |
test(`cannot duplicate a record`, async () => { |
| 4287 |
await mountView({ |
| 4288 |
resModel: "partner", |
| 4289 |
type: "form", |
| 4290 |
arch: `<form duplicate="false"><field name="foo"/></form>`, |
| 4291 |
resId: 1, |
| 4292 |
actionMenus: {}, |
| 4293 |
}); |
| 4294 |
expect(`.o_breadcrumb`).toHaveText("first record"); |
| 4295 |
expect(`.o_cp_action_menus`).toHaveCount(1); |
| 4296 |
|
| 4297 |
await toggleActionMenu(); |
| 4298 |
expect(`.o_cp_action_menus span:contains(Duplicate)`).toHaveCount(0); |
| 4299 |
}); |
| 4300 |
|
| 4301 |
test(`don't duplicate if save fail`, async () => { |
| 4302 |
onRpc("web_save", () => { |
| 4303 |
expect.step("web_save"); |
| 4304 |
throw new Error("Cannot save"); |
| 4305 |
}); |
| 4306 |
onRpc("copy", () => expect.step("copy")); |
| 4307 |
await mountView({ |
| 4308 |
resModel: "partner", |
| 4309 |
type: "form", |
| 4310 |
arch: `<form><field name="foo"/></form>`, |
| 4311 |
actionMenus: {}, |
| 4312 |
}); |
| 4313 |
await contains(`[name=foo] input`).edit("new value"); |
| 4314 |
await toggleActionMenu(); |
| 4315 |
await toggleMenuItem("Duplicate"); |
| 4316 |
expect(`.modal .o_error_dialog`).toHaveCount(1); |
| 4317 |
|
| 4318 |
// Discard changes don't trigger Duplicate action |
| 4319 |
await contains(`.modal .btn-secondary`).click(); |
| 4320 |
expect.verifySteps(["web_save"]); |
| 4321 |
}); |
| 4322 |
|
| 4323 |
test(`editing a translatable field in a duplicate record overrides translations`, async () => { |
| 4324 |
onRpc("web_save", () => expect.step("web_save")); |
| 4325 |
onRpc("web_override_translations", ({ args }) => { |
| 4326 |
expect.step("web_override_translations"); |
| 4327 |
expect(args[1]).toEqual({ name: "first record (test)" }); |
| 4328 |
return true; |
| 4329 |
}); |
| 4330 |
await mountView({ |
| 4331 |
resModel: "partner", |
| 4332 |
type: "form", |
| 4333 |
arch: `<form><field name="name"/></form>`, |
| 4334 |
resId: 1, |
| 4335 |
actionMenus: {}, |
| 4336 |
}); |
| 4337 |
expect(`.o_breadcrumb`).toHaveText("first record"); |
| 4338 |
|
| 4339 |
await toggleActionMenu(); |
| 4340 |
await toggleMenuItem("Duplicate"); |
| 4341 |
expect(`.o_breadcrumb`).toHaveText("first record (copy)"); |
| 4342 |
expect(`.o_form_editable`).toHaveCount(1); |
| 4343 |
|
| 4344 |
await contains(`.o_field_char input`).edit("first record (test)"); |
| 4345 |
await contains(`.o_form_button_save`).click(); |
| 4346 |
expect.verifySteps(["web_save", "web_override_translations"]); |
| 4347 |
}); |
| 4348 |
|
| 4349 |
test.tags("desktop"); |
| 4350 |
test(`clicking on stat buttons in edit mode on desktop`, async () => { |
| 4351 |
mockService("action", { |
| 4352 |
doActionButton() { |
| 4353 |
expect.step("doActionButton"); |
| 4354 |
}, |
| 4355 |
}); |
| 4356 |
|
| 4357 |
onRpc("web_save", ({ args }) => { |
| 4358 |
expect(args[1].foo).toBe("tralala"); |
| 4359 |
}); |
| 4360 |
onRpc(({ method }) => expect.step(method)); |
| 4361 |
await mountView({ |
| 4362 |
resModel: "partner", |
| 4363 |
type: "form", |
| 4364 |
arch: ` |
| 4365 |
<form> |
| 4366 |
<sheet> |
| 4367 |
<div name="button_box"> |
| 4368 |
<button class="oe_stat_button" name="some_action" type="action"> |
| 4369 |
<field name="bar"/> |
| 4370 |
</button> |
| 4371 |
</div> |
| 4372 |
<group> |
| 4373 |
<field name="foo"/> |
| 4374 |
</group> |
| 4375 |
</sheet> |
| 4376 |
</form> |
| 4377 |
`, |
| 4378 |
resId: 2, |
| 4379 |
}); |
| 4380 |
expect.verifySteps(["get_views", "web_read"]); |
| 4381 |
|
| 4382 |
await contains(`.oe_stat_button`).click(); |
| 4383 |
expect.verifySteps(["doActionButton"]); |
| 4384 |
expect(`.o_form_editable`).toHaveCount(1); |
| 4385 |
|
| 4386 |
await contains(`.o_field_widget[name=foo] input`).edit("tralala"); |
| 4387 |
await contains(`.oe_stat_button`).click(); |
| 4388 |
expect(`.o_form_editable`).toHaveCount(1); |
| 4389 |
expect.verifySteps(["web_save", "doActionButton"]); |
| 4390 |
}); |
| 4391 |
|
| 4392 |
test.tags("mobile"); |
| 4393 |
test(`clicking on stat buttons in edit mode on mobile`, async () => { |
| 4394 |
mockService("action", { |
| 4395 |
doActionButton() { |
| 4396 |
expect.step("doActionButton"); |
| 4397 |
}, |
| 4398 |
}); |
| 4399 |
|
| 4400 |
onRpc("web_save", ({ args }) => { |
| 4401 |
expect(args[1].foo).toBe("tralala"); |
| 4402 |
}); |
| 4403 |
onRpc(({ method }) => expect.step(method)); |
| 4404 |
await mountView({ |
| 4405 |
resModel: "partner", |
| 4406 |
type: "form", |
| 4407 |
arch: ` |
| 4408 |
<form> |
| 4409 |
<sheet> |
| 4410 |
<div name="button_box"> |
| 4411 |
<button class="oe_stat_button" name="some_action" type="action"> |
| 4412 |
<field name="bar"/> |
| 4413 |
</button> |
| 4414 |
</div> |
| 4415 |
<group> |
| 4416 |
<field name="foo"/> |
| 4417 |
</group> |
| 4418 |
</sheet> |
| 4419 |
</form> |
| 4420 |
`, |
| 4421 |
resId: 2, |
| 4422 |
}); |
| 4423 |
expect.verifySteps(["get_views", "web_read"]); |
| 4424 |
|
| 4425 |
await contains(".o-form-buttonbox .o_button_more").click(); |
| 4426 |
await contains(`button.oe_stat_button`).click(); |
| 4427 |
expect.verifySteps(["doActionButton"]); |
| 4428 |
expect(`.o_form_editable`).toHaveCount(1); |
| 4429 |
|
| 4430 |
await contains(`.o_field_widget[name=foo] input`).edit("tralala"); |
| 4431 |
await contains(".o-form-buttonbox .o_button_more").click(); |
| 4432 |
await contains(`button.oe_stat_button`).click(); |
| 4433 |
expect(`.o_form_editable`).toHaveCount(1); |
| 4434 |
expect.verifySteps(["web_save", "doActionButton"]); |
| 4435 |
}); |
| 4436 |
|
| 4437 |
test.tags("desktop"); |
| 4438 |
test(`clicking on stat buttons save and reload in edit mode on desktop`, async () => { |
| 4439 |
mockService("action", { |
| 4440 |
doActionButton() {}, |
| 4441 |
}); |
| 4442 |
|
| 4443 |
onRpc("web_save", ({ args }) => { |
| 4444 |
// simulate an override of the model... |
| 4445 |
args[1].name = "GOLDORAK"; |
| 4446 |
}); |
| 4447 |
|
| 4448 |
await mountView({ |
| 4449 |
resModel: "partner", |
| 4450 |
type: "form", |
| 4451 |
arch: ` |
| 4452 |
<form> |
| 4453 |
<sheet> |
| 4454 |
<div name="button_box"> |
| 4455 |
<button class="oe_stat_button" type="action"> |
| 4456 |
<field name="int_field" widget="statinfo" string="Some number"/> |
| 4457 |
</button> |
| 4458 |
</div> |
| 4459 |
<group> |
| 4460 |
<field name="name"/> |
| 4461 |
</group> |
| 4462 |
</sheet> |
| 4463 |
</form> |
| 4464 |
`, |
| 4465 |
resId: 2, |
| 4466 |
}); |
| 4467 |
expect(`.o_control_panel .o_breadcrumb`).toHaveText("second record"); |
| 4468 |
|
| 4469 |
await contains(`.o_field_widget[name=name] input`).edit("some other name"); |
| 4470 |
await contains(`button.oe_stat_button`).click(); |
| 4471 |
expect(`.o_control_panel .o_breadcrumb`).toHaveText("GOLDORAK"); |
| 4472 |
}); |
| 4473 |
|
| 4474 |
test.tags("mobile"); |
| 4475 |
test(`clicking on stat buttons save and reload in edit mode on mobile`, async () => { |
| 4476 |
mockService("action", { |
| 4477 |
doActionButton() {}, |
| 4478 |
}); |
| 4479 |
|
| 4480 |
onRpc("web_save", ({ args }) => { |
| 4481 |
// simulate an override of the model... |
| 4482 |
args[1].name = "GOLDORAK"; |
| 4483 |
}); |
| 4484 |
|
| 4485 |
await mountView({ |
| 4486 |
resModel: "partner", |
| 4487 |
type: "form", |
| 4488 |
arch: ` |
| 4489 |
<form> |
| 4490 |
<sheet> |
| 4491 |
<div name="button_box"> |
| 4492 |
<button class="oe_stat_button" type="action"> |
| 4493 |
<field name="int_field" widget="statinfo" string="Some number"/> |
| 4494 |
</button> |
| 4495 |
</div> |
| 4496 |
<group> |
| 4497 |
<field name="name"/> |
| 4498 |
</group> |
| 4499 |
</sheet> |
| 4500 |
</form> |
| 4501 |
`, |
| 4502 |
resId: 2, |
| 4503 |
}); |
| 4504 |
expect(`.o_breadcrumb`).toHaveText("second record"); |
| 4505 |
|
| 4506 |
await contains(`.o_field_widget[name=name] input`).edit("some other name"); |
| 4507 |
await contains(".o-form-buttonbox .o_button_more").click(); |
| 4508 |
await contains(`button.oe_stat_button`).click(); |
| 4509 |
expect(`.o_breadcrumb`).toHaveText("GOLDORAK"); |
| 4510 |
}); |
| 4511 |
|
| 4512 |
test(`buttons with attr "special" do not trigger a save`, async () => { |
| 4513 |
mockService("action", { |
| 4514 |
doActionButton() { |
| 4515 |
expect.step("doActionButton"); |
| 4516 |
}, |
| 4517 |
}); |
| 4518 |
|
| 4519 |
onRpc("web_save", () => expect.step("web_save")); |
| 4520 |
await mountView({ |
| 4521 |
resModel: "partner", |
| 4522 |
type: "form", |
| 4523 |
arch: ` |
| 4524 |
<form> |
| 4525 |
<field name="foo"/> |
| 4526 |
<button string="Do something" class="btn-primary" name="abc" type="object"/> |
| 4527 |
<button string="Or discard" class="btn-secondary" special="cancel"/> |
| 4528 |
</form> |
| 4529 |
`, |
| 4530 |
resId: 1, |
| 4531 |
}); |
| 4532 |
await contains(`.o_field_widget[name=foo] input`).edit("tralala"); |
| 4533 |
await contains(`.o_content button.btn-primary`).click(); |
| 4534 |
expect.verifySteps(["web_save", "doActionButton"]); |
| 4535 |
|
| 4536 |
await contains(`.o_field_widget[name=foo] input`).edit("abcdef"); |
| 4537 |
await contains(`.o_content button.btn-secondary`).click(); |
| 4538 |
expect.verifySteps(["doActionButton"]); |
| 4539 |
}); |
| 4540 |
|
| 4541 |
test(`buttons with attr "special=save" save`, async () => { |
| 4542 |
mockService("action", { |
| 4543 |
doActionButton() { |
| 4544 |
expect.step("execute_action"); |
| 4545 |
}, |
| 4546 |
}); |
| 4547 |
|
| 4548 |
onRpc(({ method }) => expect.step(method)); |
| 4549 |
await mountView({ |
| 4550 |
resModel: "partner", |
| 4551 |
type: "form", |
| 4552 |
arch: ` |
| 4553 |
<form> |
| 4554 |
<field name="foo"/> |
| 4555 |
<button string="Save" class="btn-primary" special="save"/> |
| 4556 |
</form> |
| 4557 |
`, |
| 4558 |
resId: 1, |
| 4559 |
}); |
| 4560 |
expect.verifySteps(["get_views", "web_read"]); |
| 4561 |
|
| 4562 |
await contains(`.o_field_widget[name=foo] input`).edit("tralala"); |
| 4563 |
await contains(`.o_content button.btn-primary`).click(); |
| 4564 |
expect.verifySteps(["web_save", "execute_action"]); |
| 4565 |
}); |
| 4566 |
|
| 4567 |
test.tags("desktop"); |
| 4568 |
test(`buttons with attr "special" in dialog close the dialog`, async () => { |
| 4569 |
Product._views = { |
| 4570 |
form: ` |
| 4571 |
<form> |
| 4572 |
<sheet> |
| 4573 |
<field name="name" /> |
| 4574 |
</sheet> |
| 4575 |
<footer> |
| 4576 |
<button class="btn btn-primary" special="save" data-hotkey="s">Special button save</button> |
| 4577 |
<button class="btn btn-secondary" special="cancel" data-hotkey="j">Special button cancel</button> |
| 4578 |
</footer> |
| 4579 |
</form> |
| 4580 |
`, |
| 4581 |
}; |
| 4582 |
|
| 4583 |
onRpc("get_formview_id", () => false); |
| 4584 |
onRpc("web_save", ({ model }) => expect.step(`${model}.web_save`)); |
| 4585 |
await mountView({ |
| 4586 |
resModel: "partner", |
| 4587 |
type: "form", |
| 4588 |
arch: ` |
| 4589 |
<form> |
| 4590 |
<sheet> |
| 4591 |
<group> |
| 4592 |
<field name="product_id"/> |
| 4593 |
</group> |
| 4594 |
</sheet> |
| 4595 |
</form> |
| 4596 |
`, |
| 4597 |
resId: 2, |
| 4598 |
}); |
| 4599 |
await contains(`[name="product_id"] input`).edit("ABC", { confirm: false }); |
| 4600 |
await runAllTimers(); // skip debounce |
| 4601 |
await contains(`.o_m2o_dropdown_option_create_edit`).click(); |
| 4602 |
expect(`.o_dialog`).toHaveCount(1); |
| 4603 |
|
| 4604 |
await contains(`.o_field_widget[name=name] input`).edit("ABCDE"); |
| 4605 |
await contains(`button[special=save]`).click(); |
| 4606 |
expect(`.o_dialog`).toHaveCount(0); |
| 4607 |
expect.verifySteps(["product.web_save"]); |
| 4608 |
expect(`[name="product_id"] input`).toHaveValue("ABCDE"); |
| 4609 |
expect(`.o_form_status_indicator_buttons:not(.invisible)`).toHaveCount(1); |
| 4610 |
|
| 4611 |
await contains(`.o_form_button_save`).click(); |
| 4612 |
expect.verifySteps(["partner.web_save"]); |
| 4613 |
|
| 4614 |
await contains(`[name="product_id"] input`).edit("XYZ", { confirm: false }); |
| 4615 |
await runAllTimers(); // skip debounce |
| 4616 |
await contains(`.o_m2o_dropdown_option_create_edit`).click(); |
| 4617 |
await contains(`button[special=cancel]`).click(); |
| 4618 |
expect(`.o_dialog`).toHaveCount(0); |
| 4619 |
expect.verifySteps([]); |
| 4620 |
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(1); |
| 4621 |
}); |
| 4622 |
|
| 4623 |
test.tags("desktop"); |
| 4624 |
test(`Add custom buttons to default buttons (replace="0")`, async () => { |
| 4625 |
Product._views = { |
| 4626 |
form: ` |
| 4627 |
<form> |
| 4628 |
<sheet> |
| 4629 |
<field name="name" /> |
| 4630 |
</sheet> |
| 4631 |
<footer replace="0"> |
| 4632 |
<button class="btn btn-primary">Custom 1</button> |
| 4633 |
<button class="btn btn-secondary">Custom 2</button> |
| 4634 |
</footer> |
| 4635 |
</form> |
| 4636 |
`, |
| 4637 |
}; |
| 4638 |
await mountView({ |
| 4639 |
resModel: "partner", |
| 4640 |
type: "form", |
| 4641 |
arch: ` |
| 4642 |
<form> |
| 4643 |
<sheet> |
| 4644 |
<group> |
| 4645 |
<field name="product_id"/> |
| 4646 |
</group> |
| 4647 |
</sheet> |
| 4648 |
</form> |
| 4649 |
`, |
| 4650 |
resId: 2, |
| 4651 |
}); |
| 4652 |
await contains(`[name="product_id"] input`).edit("ABC", { confirm: false }); |
| 4653 |
await runAllTimers(); // skip debounce |
| 4654 |
await contains(`.o_m2o_dropdown_option_create_edit`).click(); |
| 4655 |
|
| 4656 |
expect(".o_dialog .o_form_button_save").toHaveCount(1); |
| 4657 |
expect(".o_dialog .o_form_button_cancel").toHaveCount(1); |
| 4658 |
expect(".o_dialog button:contains(Custom 1)").toHaveCount(1); |
| 4659 |
expect(".o_dialog button:contains(Custom 2)").toHaveCount(1); |
| 4660 |
}); |
| 4661 |
|
| 4662 |
test(`missing widgets do not crash`, async () => { |
| 4663 |
Partner._fields.foo = fields.Generic({ type: "new field type without widget" }); |
| 4664 |
|
| 4665 |
await mountView({ |
| 4666 |
resModel: "partner", |
| 4667 |
type: "form", |
| 4668 |
arch: `<form><field name="foo"/></form>`, |
| 4669 |
resId: 1, |
| 4670 |
}); |
| 4671 |
expect(`.o_field_widget`).toHaveCount(1); |
| 4672 |
}); |
| 4673 |
|
| 4674 |
test(`nolabel`, async () => { |
| 4675 |
await mountView({ |
| 4676 |
resModel: "partner", |
| 4677 |
type: "form", |
| 4678 |
arch: ` |
| 4679 |
<form> |
| 4680 |
<sheet> |
| 4681 |
<group> |
| 4682 |
<group class="firstgroup"> |
| 4683 |
<field name="foo" nolabel="1"/> |
| 4684 |
</group> |
| 4685 |
<group class="secondgroup"> |
| 4686 |
<field name="product_id"/> |
| 4687 |
<field name="int_field" nolabel="1"/><field name="float_field" nolabel="1"/> |
| 4688 |
</group> |
| 4689 |
<group> |
| 4690 |
<field name="bar"/> |
| 4691 |
</group> |
| 4692 |
</group> |
| 4693 |
</sheet> |
| 4694 |
</form> |
| 4695 |
`, |
| 4696 |
resId: 1, |
| 4697 |
}); |
| 4698 |
expect(`label.o_form_label`).toHaveCount(2); |
| 4699 |
expect(`label.o_form_label:eq(0)`).toHaveText("Product"); |
| 4700 |
expect(`label.o_form_label:eq(1)`).toHaveText("Bar"); |
| 4701 |
expect(`.firstgroup div`).toHaveStyle(""); |
| 4702 |
expect(`.secondgroup div.o_wrap_label`).toHaveCount(1); |
| 4703 |
expect(`.secondgroup div.o_wrap_input`).toHaveCount(1); |
| 4704 |
expect(`.secondgroup div.o_cell`).toHaveCount(4); |
| 4705 |
}); |
| 4706 |
|
| 4707 |
test(`many2one in a one2many`, async () => { |
| 4708 |
Partner._records[0].child_ids = [2]; |
| 4709 |
Partner._records[1].product_id = 37; |
| 4710 |
|
| 4711 |
await mountView({ |
| 4712 |
resModel: "partner", |
| 4713 |
type: "form", |
| 4714 |
arch: ` |
| 4715 |
<form> |
| 4716 |
<field name="child_ids"> |
| 4717 |
<list> |
| 4718 |
<field name="product_id"/> |
| 4719 |
</list> |
| 4720 |
</field> |
| 4721 |
</form> |
| 4722 |
`, |
| 4723 |
resId: 1, |
| 4724 |
}); |
| 4725 |
expect(`td:contains(xphone)`).toHaveCount(1); |
| 4726 |
}); |
| 4727 |
|
| 4728 |
test(`circular many2many's`, async () => { |
| 4729 |
Partner._records[0].type_ids = [12]; |
| 4730 |
PartnerType._fields.partner_ids = fields.Many2many({ relation: "partner" }); |
| 4731 |
PartnerType._records[0].partner_ids = [1]; |
| 4732 |
|
| 4733 |
await mountView({ |
| 4734 |
resModel: "partner", |
| 4735 |
type: "form", |
| 4736 |
arch: ` |
| 4737 |
<form> |
| 4738 |
<field name="type_ids"> |
| 4739 |
<list><field name="display_name"/></list> |
| 4740 |
<form> |
| 4741 |
<field name="partner_ids"> |
| 4742 |
<list><field name="display_name"/></list> |
| 4743 |
<form><field name="display_name"/></form> |
| 4744 |
</field> |
| 4745 |
</form> |
| 4746 |
</field> |
| 4747 |
</form> |
| 4748 |
`, |
| 4749 |
resId: 1, |
| 4750 |
}); |
| 4751 |
expect(`td:contains(gold)`).toHaveCount(1); |
| 4752 |
|
| 4753 |
await contains(`.o_data_cell`).click(); |
| 4754 |
expect(`.modal`).toHaveCount(1); |
| 4755 |
expect(`.modal td:contains(first record)`).toHaveCount(1); |
| 4756 |
|
| 4757 |
await contains(`.modal .o_data_cell`).click(); |
| 4758 |
expect(`.modal`).toHaveCount(2); |
| 4759 |
}); |
| 4760 |
|
| 4761 |
test(`discard changes on a non dirty form view`, async () => { |
| 4762 |
onRpc("write", () => expect.step("write")); |
| 4763 |
await mountView({ |
| 4764 |
resModel: "partner", |
| 4765 |
type: "form", |
| 4766 |
arch: `<form><field name="foo"></field></form>`, |
| 4767 |
resId: 1, |
| 4768 |
}); |
| 4769 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("yop"); |
| 4770 |
|
| 4771 |
await contains(`.o_form_button_cancel`, { visible: false }).click(); |
| 4772 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("yop"); |
| 4773 |
expect.verifySteps([]); |
| 4774 |
}); |
| 4775 |
|
| 4776 |
test(`discard changes on a dirty form view`, async () => { |
| 4777 |
onRpc("write", () => expect.step("write")); |
| 4778 |
await mountView({ |
| 4779 |
resModel: "partner", |
| 4780 |
type: "form", |
| 4781 |
arch: `<form><field name="foo"></field></form>`, |
| 4782 |
resId: 1, |
| 4783 |
}); |
| 4784 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("yop"); |
| 4785 |
|
| 4786 |
await contains(`.o_field_widget[name=foo] input`).edit("new value"); |
| 4787 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("new value"); |
| 4788 |
|
| 4789 |
await contains(`.o_form_button_cancel`).click(); |
| 4790 |
expect(`.o_field_widget input`).toHaveValue("yop"); |
| 4791 |
expect.verifySteps([]); |
| 4792 |
}); |
| 4793 |
|
| 4794 |
test(`discard changes on a dirty form view (for date field)`, async () => { |
| 4795 |
// this test checks that the relational model properly handles date object |
| 4796 |
// when they are discarded and saved. This may be an issue because |
| 4797 |
// dates are saved as luxon instances, and were at one point stringified, |
| 4798 |
// then parsed into string, which is wrong. |
| 4799 |
Partner._fields.date = fields.Date({ default: "2017-01-25" }); |
| 4800 |
|
| 4801 |
await mountView({ |
| 4802 |
type: "form", |
| 4803 |
resModel: "partner", |
| 4804 |
arch: `<form><field name="date"></field></form>`, |
| 4805 |
}); |
| 4806 |
|
| 4807 |
// also focus the buttons before clicking on them to precisely reproduce what |
| 4808 |
// really happens (mostly because the datepicker lib need that focus |
| 4809 |
// event to properly focusout the input, otherwise it crashes later on |
| 4810 |
// when the 'blur' event is triggered by the re-rendering) |
| 4811 |
await contains(`.o_form_button_cancel`).click(); |
| 4812 |
|
| 4813 |
await contains(`.o_form_button_save`).click(); |
| 4814 |
expect(`.o_field_widget button`).toHaveValue("01/25/2017"); |
| 4815 |
}); |
| 4816 |
|
| 4817 |
test.tags("desktop"); |
| 4818 |
test(`discard changes on relational data on new record`, async () => { |
| 4819 |
await mountView({ |
| 4820 |
resModel: "partner", |
| 4821 |
type: "form", |
| 4822 |
arch: ` |
| 4823 |
<form> |
| 4824 |
<field name="child_ids"> |
| 4825 |
<list editable="top"> |
| 4826 |
<field name="product_id"/> |
| 4827 |
</list> |
| 4828 |
</field> |
| 4829 |
</form> |
| 4830 |
`, |
| 4831 |
}); |
| 4832 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 4833 |
await contains(`.o_input_dropdown input`).click(); |
| 4834 |
await contains(`.dropdown-item:contains(xphone)`).click(); |
| 4835 |
expect(`.o_field_widget[name="product_id"] input`).toHaveValue("xphone"); |
| 4836 |
|
| 4837 |
await contains(`.o_form_button_cancel`).click(); |
| 4838 |
expect(`.o_data_row`).toHaveCount(0); |
| 4839 |
}); |
| 4840 |
|
| 4841 |
test("discard changes on relational data on existing record", async () => { |
| 4842 |
Partner._records[0].product_ids = [37]; |
| 4843 |
Partner._records[0].bar = false; |
| 4844 |
Partner._onChanges = { |
| 4845 |
bar(record) { |
| 4846 |
// when bar changes, push another record in product_ids. |
| 4847 |
record.product_ids = [[4, 41]]; |
| 4848 |
}, |
| 4849 |
}; |
| 4850 |
await mountView({ |
| 4851 |
type: "form", |
| 4852 |
resModel: "partner", |
| 4853 |
resId: 1, |
| 4854 |
arch: ` |
| 4855 |
<form> |
| 4856 |
<field name="bar"/> |
| 4857 |
<field name="product_ids" widget="one2many"> |
| 4858 |
<list> |
| 4859 |
<field name="display_name"/> |
| 4860 |
</list> |
| 4861 |
</field> |
| 4862 |
</form>`, |
| 4863 |
}); |
| 4864 |
|
| 4865 |
expect(queryAllTexts`.o_data_cell`).toEqual(["xphone"]); |
| 4866 |
expect(`.o_field_widget[name=bar] input:checked`).toHaveCount(0); |
| 4867 |
|
| 4868 |
// Click on bar |
| 4869 |
await contains(`.o_field_widget[name=bar] input`).click(); |
| 4870 |
expect(`.o_field_widget[name=bar] input:checked`).toHaveCount(1); |
| 4871 |
expect(queryAllTexts`.o_data_cell`).toEqual(["xphone", "xpad"]); |
| 4872 |
|
| 4873 |
// click on discard |
| 4874 |
await contains(`.o_form_button_cancel`).click(); |
| 4875 |
expect(queryAllTexts`.o_data_cell`).toEqual(["xphone"]); |
| 4876 |
expect(`.o_field_widget[name=bar] input:checked`).toHaveCount(0); |
| 4877 |
}); |
| 4878 |
|
| 4879 |
test("discard changes on relational data on new record (1)", async () => { |
| 4880 |
// When bar is changed, it pushes a record in product_ids |
| 4881 |
// After discarding, product_ids should be empty |
| 4882 |
Partner._onChanges = { |
| 4883 |
bar(record) { |
| 4884 |
if (record.bar) { |
| 4885 |
// when bar changes, push another record in product_ids. |
| 4886 |
record.product_ids = [[4, 41]]; |
| 4887 |
} |
| 4888 |
}, |
| 4889 |
}; |
| 4890 |
await mountView({ |
| 4891 |
type: "form", |
| 4892 |
resModel: "partner", |
| 4893 |
arch: ` |
| 4894 |
<form> |
| 4895 |
<field name="bar"/> |
| 4896 |
<field name="product_ids" widget="one2many"> |
| 4897 |
<list> |
| 4898 |
<field name="display_name"/> |
| 4899 |
</list> |
| 4900 |
</field> |
| 4901 |
</form>`, |
| 4902 |
}); |
| 4903 |
|
| 4904 |
expect(queryAllTexts`.o_data_cell`).toEqual([]); |
| 4905 |
expect(`.o_field_widget[name=bar] input:checked`).toHaveCount(0); |
| 4906 |
|
| 4907 |
// Click on bar |
| 4908 |
await contains(`.o_field_widget[name=bar] input`).click(); |
| 4909 |
expect(`.o_field_widget[name=bar] input:checked`).toHaveCount(1); |
| 4910 |
expect(queryAllTexts`.o_data_cell`).toEqual(["xpad"]); |
| 4911 |
|
| 4912 |
// click on discard |
| 4913 |
await contains(`.o_form_button_cancel`).click(); |
| 4914 |
expect(queryAllTexts`.o_data_cell`).toEqual([]); |
| 4915 |
expect(`.o_field_widget[name=bar] input:checked`).toHaveCount(0); |
| 4916 |
}); |
| 4917 |
|
| 4918 |
test("discard changes on relational data on new record (2)", async () => { |
| 4919 |
// An initial onChange push a record in product_ids |
| 4920 |
// When bar is changed, it pushes a second record in product_ids |
| 4921 |
// After discarding, product_ids should contain the inital record pushed by the inital onChange |
| 4922 |
Partner._onChanges = { |
| 4923 |
product_ids(record) { |
| 4924 |
record.product_ids = [[4, 41]]; |
| 4925 |
}, |
| 4926 |
bar(record) { |
| 4927 |
if (record.bar) { |
| 4928 |
// when bar changes, push another record in product_ids. |
| 4929 |
record.product_ids = [[4, 37]]; |
| 4930 |
} |
| 4931 |
}, |
| 4932 |
}; |
| 4933 |
await mountView({ |
| 4934 |
type: "form", |
| 4935 |
resModel: "partner", |
| 4936 |
arch: ` |
| 4937 |
<form> |
| 4938 |
<field name="bar"/> |
| 4939 |
<field name="product_ids" widget="one2many"> |
| 4940 |
<list> |
| 4941 |
<field name="display_name"/> |
| 4942 |
</list> |
| 4943 |
</field> |
| 4944 |
</form>`, |
| 4945 |
}); |
| 4946 |
|
| 4947 |
expect(queryAllTexts`.o_data_cell`).toEqual(["xpad"]); |
| 4948 |
expect(`.o_field_widget[name=bar] input:checked`).toHaveCount(0); |
| 4949 |
|
| 4950 |
// Click on bar |
| 4951 |
await contains(`.o_field_widget[name=bar] input`).click(); |
| 4952 |
expect(`.o_field_widget[name=bar] input:checked`).toHaveCount(1); |
| 4953 |
expect(queryAllTexts`.o_data_cell`).toEqual(["xpad", "xphone"]); |
| 4954 |
|
| 4955 |
// click on discard |
| 4956 |
await contains(`.o_form_button_cancel`).click(); |
| 4957 |
expect(queryAllTexts`.o_data_cell`).toEqual(["xpad"]); |
| 4958 |
expect(`.o_field_widget[name=bar] input:checked`).toHaveCount(0); |
| 4959 |
}); |
| 4960 |
|
| 4961 |
test(`discard changes on a new (non dirty, except for defaults) form view`, async () => { |
| 4962 |
Partner._fields.foo = fields.Char({ default: "ABC" }); |
| 4963 |
|
| 4964 |
await mountView({ |
| 4965 |
resModel: "partner", |
| 4966 |
type: "form", |
| 4967 |
arch: `<form><field name="foo"></field></form>`, |
| 4968 |
config: { |
| 4969 |
historyBack() { |
| 4970 |
expect.step("history-back"); |
| 4971 |
}, |
| 4972 |
}, |
| 4973 |
}); |
| 4974 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("ABC"); |
| 4975 |
|
| 4976 |
await contains(`.o_form_button_cancel`).click(); |
| 4977 |
expect.verifySteps(["history-back"]); |
| 4978 |
}); |
| 4979 |
|
| 4980 |
test(`discard changes on a new (dirty) form view`, async () => { |
| 4981 |
Partner._fields.foo = fields.Char({ default: "ABC" }); |
| 4982 |
|
| 4983 |
await mountView({ |
| 4984 |
resModel: "partner", |
| 4985 |
type: "form", |
| 4986 |
arch: `<form><field name="foo"></field></form>`, |
| 4987 |
config: { |
| 4988 |
historyBack() { |
| 4989 |
expect.step("history-back"); |
| 4990 |
}, |
| 4991 |
}, |
| 4992 |
}); |
| 4993 |
expect(`.o_form_editable`).not.toHaveClass(["o_form_saved", "o_form_dirty"]); |
| 4994 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("ABC"); |
| 4995 |
|
| 4996 |
await contains(`.o_field_widget[name=foo] input`).edit("DEF"); |
| 4997 |
expect(`.o_form_editable`).toHaveClass("o_form_dirty"); |
| 4998 |
expect(`.o_form_editable`).not.toHaveClass("o_form_saved"); |
| 4999 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("DEF"); |
| 5000 |
|
| 5001 |
await contains(`.o_form_button_cancel`).click(); |
| 5002 |
expect(`.o_form_editable`).not.toHaveClass(["o_form_saved", "o_form_dirty"]); |
| 5003 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("ABC"); |
| 5004 |
expect.verifySteps(["history-back"]); |
| 5005 |
|
| 5006 |
await contains(`.o_field_widget[name=foo] input`).edit("GHI"); |
| 5007 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("GHI"); |
| 5008 |
|
| 5009 |
await contains(`.o_form_button_cancel`).click(); |
| 5010 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("ABC"); |
| 5011 |
expect.verifySteps(["history-back"]); |
| 5012 |
}); |
| 5013 |
|
| 5014 |
test(`discard has to wait for changes in each field`, async () => { |
| 5015 |
const def = new Deferred(); |
| 5016 |
class CustomField extends Component { |
| 5017 |
static template = xml`<input t-ref="input" t-att-value="value" t-on-blur="onBlur" t-on-input="onInput" />`; |
| 5018 |
static props = { |
| 5019 |
...standardFieldProps, |
| 5020 |
}; |
| 5021 |
|
| 5022 |
setup() { |
| 5023 |
this.input = useRef("input"); |
| 5024 |
useBus(this.props.record.model.bus, "NEED_LOCAL_CHANGES", ({ detail }) => |
| 5025 |
detail.proms.push(this.updateValue()) |
| 5026 |
); |
| 5027 |
} |
| 5028 |
|
| 5029 |
get value() { |
| 5030 |
return this.props.record.data[this.props.name]; |
| 5031 |
} |
| 5032 |
|
| 5033 |
async updateValue() { |
| 5034 |
const value = this.input.el.value; |
| 5035 |
await def; |
| 5036 |
await this.props.record.update({ [this.props.name]: `update value: ${value}` }); |
| 5037 |
} |
| 5038 |
|
| 5039 |
onBlur() { |
| 5040 |
return this.updateValue(); |
| 5041 |
} |
| 5042 |
|
| 5043 |
onInput() { |
| 5044 |
this.props.record.model.bus.trigger("FIELD_IS_DIRTY", true); |
| 5045 |
} |
| 5046 |
} |
| 5047 |
fieldsRegistry.add("custom", { component: CustomField }); |
| 5048 |
|
| 5049 |
await mountView({ |
| 5050 |
resModel: "partner", |
| 5051 |
type: "form", |
| 5052 |
arch: `<form><field name="foo" widget="custom"/></form>`, |
| 5053 |
resId: 2, |
| 5054 |
}); |
| 5055 |
|
| 5056 |
expect(`[name="foo"] input`).toHaveValue("blip"); |
| 5057 |
|
| 5058 |
await contains(`[name="foo"] input`).edit("test"); |
| 5059 |
expect(`[name="foo"] input`).toHaveValue("test"); |
| 5060 |
|
| 5061 |
// should never display 'update value' |
| 5062 |
await contains(`.o_form_button_cancel`).click(); |
| 5063 |
expect(`[name="foo"] input`).toHaveValue("test"); |
| 5064 |
|
| 5065 |
def.resolve(); |
| 5066 |
await animationFrame(); |
| 5067 |
expect(`[name="foo"] input`).toHaveValue("blip"); |
| 5068 |
}); |
| 5069 |
|
| 5070 |
test(`save a new dirty record`, async () => { |
| 5071 |
await mountView({ |
| 5072 |
resModel: "partner", |
| 5073 |
type: "form", |
| 5074 |
arch: `<form><field name="foo"></field></form>`, |
| 5075 |
}); |
| 5076 |
expect(`.o_form_editable`).not.toHaveClass("o_form_saved o_form_dirty"); |
| 5077 |
|
| 5078 |
await contains(`.o_field_widget[name=foo] input`).edit("DEF"); |
| 5079 |
await contains(`.o_form_button_save`).click(); |
| 5080 |
expect(`.o_form_editable`).toHaveClass("o_form_saved"); |
| 5081 |
expect(`.o_form_editable`).not.toHaveClass("o_form_dirty"); |
| 5082 |
}); |
| 5083 |
|
| 5084 |
test(`discard changes on a duplicated record`, async () => { |
| 5085 |
await mountView({ |
| 5086 |
resModel: "partner", |
| 5087 |
type: "form", |
| 5088 |
arch: `<form><field name="foo"></field></form>`, |
| 5089 |
resId: 1, |
| 5090 |
actionMenus: {}, |
| 5091 |
}); |
| 5092 |
await contains(`.o_field_widget[name=foo] input`).edit("tralala"); |
| 5093 |
await contains(`.o_form_button_save`).click(); |
| 5094 |
await toggleActionMenu(); |
| 5095 |
await toggleMenuItem("Duplicate"); |
| 5096 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("tralala"); |
| 5097 |
|
| 5098 |
await contains(`.o_form_button_cancel`, { visible: false }).click(); |
| 5099 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("tralala"); |
| 5100 |
}); |
| 5101 |
|
| 5102 |
test(`discard invalid value`, async () => { |
| 5103 |
await mountView({ |
| 5104 |
resModel: "partner", |
| 5105 |
type: "form", |
| 5106 |
arch: `<form><field name="int_field"></field></form>`, |
| 5107 |
resId: 1, |
| 5108 |
}); |
| 5109 |
await contains(`.o_field_widget[name=int_field] input`).edit("tralala"); |
| 5110 |
expect(`.o_field_invalid`).toHaveCount(1); |
| 5111 |
expect(`.o_field_widget[name=int_field] input`).toHaveValue("tralala"); |
| 5112 |
|
| 5113 |
await contains(`.o_form_button_cancel`).click(); |
| 5114 |
expect(`.o_field_invalid`).toHaveCount(0); |
| 5115 |
expect(`.o_field_widget[name=int_field] input`).toHaveValue("10"); |
| 5116 |
}); |
| 5117 |
|
| 5118 |
test(`Domain: allow empty domain on fieldInfo`, async () => { |
| 5119 |
Partner._fields.product_id = fields.Many2one({ |
| 5120 |
relation: "product", |
| 5121 |
domain: `[("display_name", "=", name)]`, |
| 5122 |
}); |
| 5123 |
|
| 5124 |
onRpc("search_read", ({ kwargs }) => { |
| 5125 |
expect.step("search_read"); |
| 5126 |
expect(JSON.stringify(kwargs.domain)).toBe("[]"); |
| 5127 |
}); |
| 5128 |
await mountView({ |
| 5129 |
resModel: "partner", |
| 5130 |
type: "form", |
| 5131 |
arch: ` |
| 5132 |
<form> |
| 5133 |
<header> |
| 5134 |
<field name="product_id" widget="statusbar" domain="[]"></field> |
| 5135 |
</header> |
| 5136 |
<sheet> |
| 5137 |
<group> |
| 5138 |
<field name="name"></field> |
| 5139 |
</group> |
| 5140 |
</sheet> |
| 5141 |
</form> |
| 5142 |
`, |
| 5143 |
resId: 1, |
| 5144 |
}); |
| 5145 |
expect.verifySteps(["search_read"]); |
| 5146 |
}); |
| 5147 |
|
| 5148 |
test.tags("desktop"); |
| 5149 |
test(`discard form with specialdata on desktop`, async () => { |
| 5150 |
await mountView({ |
| 5151 |
resModel: "partner", |
| 5152 |
type: "form", |
| 5153 |
arch: ` |
| 5154 |
<form> |
| 5155 |
<header> |
| 5156 |
<field name="product_id" domain="[('name', '=', name)]" widget="statusbar"/> |
| 5157 |
</header> |
| 5158 |
<sheet> |
| 5159 |
<group> |
| 5160 |
<field name="name"></field> |
| 5161 |
</group> |
| 5162 |
</sheet> |
| 5163 |
</form> |
| 5164 |
`, |
| 5165 |
resId: 1, |
| 5166 |
}); |
| 5167 |
expect(`.o_statusbar_status button:not(.d-none)`).toHaveCount(1); |
| 5168 |
|
| 5169 |
await contains(`.o_field_widget[name=name] input`).edit("xpad"); |
| 5170 |
expect(`.o_statusbar_status button:not(.d-none)`).toHaveCount(2); |
| 5171 |
|
| 5172 |
await animationFrame(); // @todo remove |
| 5173 |
await contains(`.o_form_button_cancel`).click(); |
| 5174 |
expect(`.o_statusbar_status button:not(.d-none)`).toHaveCount(1); |
| 5175 |
expect(`.o_statusbar_status button:not(.d-none)`).toHaveText("xphone"); |
| 5176 |
}); |
| 5177 |
|
| 5178 |
test.tags("mobile"); |
| 5179 |
test(`discard form with specialdata on mobile`, async () => { |
| 5180 |
await mountView({ |
| 5181 |
resModel: "partner", |
| 5182 |
type: "form", |
| 5183 |
arch: ` |
| 5184 |
<form> |
| 5185 |
<header> |
| 5186 |
<field name="product_id" domain="[('name', '=', name)]" widget="statusbar"/> |
| 5187 |
</header> |
| 5188 |
<sheet> |
| 5189 |
<group> |
| 5190 |
<field name="name"></field> |
| 5191 |
</group> |
| 5192 |
</sheet> |
| 5193 |
</form> |
| 5194 |
`, |
| 5195 |
resId: 1, |
| 5196 |
}); |
| 5197 |
expect(`.o_statusbar_status .dropdown-toggle:visible`).toHaveCount(1); |
| 5198 |
|
| 5199 |
await contains(`.o_field_widget[name=name] input`).edit("xpad"); |
| 5200 |
expect(`.o_statusbar_status .dropdown-toggle:visible`).toHaveCount(1); |
| 5201 |
|
| 5202 |
await contains(`.o_form_button_cancel`).click(); |
| 5203 |
expect(`.o_statusbar_status .dropdown-toggle:visible`).toHaveCount(1); |
| 5204 |
expect(`.o_statusbar_status .dropdown-toggle:visible`).toHaveText("xphone"); |
| 5205 |
}); |
| 5206 |
|
| 5207 |
test(`switching to another record from a dirty one`, async () => { |
| 5208 |
onRpc("web_save", () => expect.step("web_save")); |
| 5209 |
await mountView({ |
| 5210 |
resModel: "partner", |
| 5211 |
type: "form", |
| 5212 |
arch: `<form><field name="foo"></field></form>`, |
| 5213 |
resIds: [1, 2], |
| 5214 |
resId: 1, |
| 5215 |
}); |
| 5216 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("yop"); |
| 5217 |
|
| 5218 |
await contains(`.o_field_widget[name=foo] input`).edit("new value"); |
| 5219 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("new value"); |
| 5220 |
|
| 5221 |
await contains(`.o_pager_next`).click(); |
| 5222 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("blip"); |
| 5223 |
expect.verifySteps(["web_save"]); |
| 5224 |
|
| 5225 |
await contains(`.o_pager_previous`).click(); |
| 5226 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("new value"); |
| 5227 |
expect.verifySteps([]); |
| 5228 |
}); |
| 5229 |
|
| 5230 |
test.tags("desktop"); |
| 5231 |
test(`switching to another record from a dirty one on desktop`, async () => { |
| 5232 |
await mountView({ |
| 5233 |
resModel: "partner", |
| 5234 |
type: "form", |
| 5235 |
arch: `<form><field name="foo"></field></form>`, |
| 5236 |
resIds: [1, 2], |
| 5237 |
resId: 1, |
| 5238 |
}); |
| 5239 |
expect(getPagerValue()).toEqual([1]); |
| 5240 |
expect(getPagerLimit()).toBe(2); |
| 5241 |
|
| 5242 |
await contains(`.o_field_widget[name=foo] input`).edit("new value"); |
| 5243 |
await contains(`.o_pager_next`).click(); |
| 5244 |
expect(getPagerValue()).toEqual([2]); |
| 5245 |
|
| 5246 |
await contains(`.o_pager_previous`).click(); |
| 5247 |
expect(getPagerValue()).toEqual([1]); |
| 5248 |
}); |
| 5249 |
|
| 5250 |
test.tags("desktop"); |
| 5251 |
test("Save record, no changes but dirty (add and remove tag)", async () => { |
| 5252 |
onRpc("web_save", () => expect.step("ERROR: web_save should not be called")); |
| 5253 |
onRpc("web_read", () => expect.step("web_read")); |
| 5254 |
await mountView({ |
| 5255 |
type: "form", |
| 5256 |
resModel: "partner", |
| 5257 |
arch: `<form> |
| 5258 |
<field name="type_ids" widget="many2many_tags"/> |
| 5259 |
</form>`, |
| 5260 |
resId: 1, |
| 5261 |
}); |
| 5262 |
|
| 5263 |
expect(`.o_field_widget[name=type_ids] .o_tag`).toHaveCount(0); |
| 5264 |
|
| 5265 |
// add a tag |
| 5266 |
await contains(`.o_input_dropdown input`).click(); |
| 5267 |
await contains(`.dropdown-item:contains(gold)`).click(); |
| 5268 |
|
| 5269 |
expect(`.o_field_widget[name=type_ids] .o_tag`).toHaveCount(1); |
| 5270 |
|
| 5271 |
// remove tag |
| 5272 |
await contains(`.o_field_widget[name=type_ids] .o_tag .o_delete`).click(); |
| 5273 |
expect(`.o_field_widget[name=type_ids] .o_tag`).toHaveCount(0); |
| 5274 |
expect.verifySteps(["web_read", "web_read"]); |
| 5275 |
|
| 5276 |
// click on save |
| 5277 |
await contains(`.o_form_button_save`).click(); |
| 5278 |
// The `web_save` RPC should not be called as there are no changes. |
| 5279 |
// The record must be marked as not dirty. |
| 5280 |
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(1); |
| 5281 |
expect.verifySteps([]); // avoid doint an extra web_read |
| 5282 |
}); |
| 5283 |
|
| 5284 |
test.tags("desktop"); |
| 5285 |
test("switching to another record from a dirty record but wo changes (add and remove tag)", async () => { |
| 5286 |
onRpc("web_save", () => expect.step("ERROR: web_save should not be called")); |
| 5287 |
onRpc("web_read", () => expect.step("web_read")); |
| 5288 |
await mountView({ |
| 5289 |
type: "form", |
| 5290 |
resModel: "partner", |
| 5291 |
arch: `<form> |
| 5292 |
<field name="type_ids" widget="many2many_tags"/> |
| 5293 |
</form>`, |
| 5294 |
resIds: [1, 2], |
| 5295 |
resId: 1, |
| 5296 |
}); |
| 5297 |
|
| 5298 |
expect(getPagerValue()).toEqual([1]); |
| 5299 |
expect(getPagerLimit()).toBe(2); |
| 5300 |
|
| 5301 |
expect(`.o_field_widget[name=type_ids] .o_tag`).toHaveCount(0); |
| 5302 |
expect(`.o_breadcrumb`).toHaveText("first record"); |
| 5303 |
|
| 5304 |
// add a tag |
| 5305 |
await contains(`.o_input_dropdown input`).click(); |
| 5306 |
await contains(`.dropdown-item:contains(gold)`).click(); |
| 5307 |
|
| 5308 |
expect(`.o_field_widget[name=type_ids] .o_tag`).toHaveCount(1); |
| 5309 |
|
| 5310 |
// remove tag |
| 5311 |
await contains(`.o_field_widget[name=type_ids] .o_tag .o_delete`).click(); |
| 5312 |
expect(`.o_field_widget[name=type_ids] .o_tag`).toHaveCount(0); |
| 5313 |
expect.verifySteps(["web_read", "web_read"]); |
| 5314 |
|
| 5315 |
// click on the pager to switch to the next record |
| 5316 |
// The `web_save` RPC should not be called as there are no changes. |
| 5317 |
// The next record should be load correctly. |
| 5318 |
await contains(`.o_pager_next`).click(); |
| 5319 |
expect(`.modal`).toHaveCount(0); |
| 5320 |
expect(getPagerValue()).toEqual([2]); |
| 5321 |
expect(`.o_breadcrumb`).toHaveText("second record"); |
| 5322 |
expect.verifySteps(["web_read"]); |
| 5323 |
}); |
| 5324 |
|
| 5325 |
test(`do not reload after save when using pager`, async () => { |
| 5326 |
onRpc(({ method }) => expect.step(method)); |
| 5327 |
await mountView({ |
| 5328 |
resModel: "partner", |
| 5329 |
type: "form", |
| 5330 |
arch: `<form><field name="foo"></field></form>`, |
| 5331 |
resIds: [1, 2], |
| 5332 |
resId: 1, |
| 5333 |
}); |
| 5334 |
expect.verifySteps(["get_views", "web_read"]); |
| 5335 |
expect(`.o_input`).toHaveValue("yop"); |
| 5336 |
|
| 5337 |
await contains(`.o_field_widget[name=foo] input`).edit("new value"); |
| 5338 |
await contains(`.o_pager_next`).click(); |
| 5339 |
expect(`.o_input`).toHaveValue("blip"); |
| 5340 |
expect.verifySteps(["web_save"]); |
| 5341 |
}); |
| 5342 |
|
| 5343 |
test.tags("desktop"); |
| 5344 |
test(`do not reload after save when using pager on desktop`, async () => { |
| 5345 |
await mountView({ |
| 5346 |
resModel: "partner", |
| 5347 |
type: "form", |
| 5348 |
arch: `<form><field name="foo"></field></form>`, |
| 5349 |
resIds: [1, 2], |
| 5350 |
resId: 1, |
| 5351 |
}); |
| 5352 |
expect(getPagerValue()).toEqual([1]); |
| 5353 |
expect(getPagerLimit()).toBe(2); |
| 5354 |
|
| 5355 |
await contains(`.o_field_widget[name=foo] input`).edit("new value"); |
| 5356 |
await contains(`.o_pager_next`).click(); |
| 5357 |
expect(getPagerValue()).toEqual([2]); |
| 5358 |
}); |
| 5359 |
|
| 5360 |
test(`switching to another record from an invalid one`, async () => { |
| 5361 |
onRpc("web_save", () => expect.step("web_save")); |
| 5362 |
await mountView({ |
| 5363 |
resModel: "partner", |
| 5364 |
type: "form", |
| 5365 |
arch: `<form><field name="foo" required="1"/></form>`, |
| 5366 |
resIds: [1, 2], |
| 5367 |
resId: 1, |
| 5368 |
}); |
| 5369 |
expect(`.o_breadcrumb`).toHaveText("first record"); |
| 5370 |
expect(`.o_field_widget[name=foo]`).toHaveClass("o_required_modifier"); |
| 5371 |
|
| 5372 |
await contains(`.o_field_widget[name=foo] input`).edit(""); |
| 5373 |
await contains(`.o_pager_next`).click(); |
| 5374 |
expect(`.o_breadcrumb`).toHaveText("first record"); |
| 5375 |
expect(`.o_form_status_indicator .text-danger`).toHaveAttribute( |
| 5376 |
"data-tooltip", |
| 5377 |
"Unable to save. Correct the issue or discard all changes" |
| 5378 |
); |
| 5379 |
expect(`.o_field_widget[name=foo]`).toHaveClass("o_field_invalid"); |
| 5380 |
expect(`.o_notification_manager .o_notification`).toHaveCount(1); |
| 5381 |
expect.verifySteps([]); |
| 5382 |
}); |
| 5383 |
|
| 5384 |
test.tags("desktop"); |
| 5385 |
test(`switching to another record from an invalid one on desktop`, async () => { |
| 5386 |
await mountView({ |
| 5387 |
resModel: "partner", |
| 5388 |
type: "form", |
| 5389 |
arch: `<form><field name="foo" required="1"/></form>`, |
| 5390 |
resIds: [1, 2], |
| 5391 |
resId: 1, |
| 5392 |
}); |
| 5393 |
expect(getPagerValue()).toEqual([1]); |
| 5394 |
expect(getPagerLimit()).toBe(2); |
| 5395 |
|
| 5396 |
await contains(`.o_field_widget[name=foo] input`).edit(""); |
| 5397 |
await contains(`.o_pager_next`).click(); |
| 5398 |
expect(getPagerValue()).toEqual([1]); |
| 5399 |
expect(getPagerLimit()).toBe(2); |
| 5400 |
}); |
| 5401 |
|
| 5402 |
test(`keynav: switching to another record from an invalid one`, async () => { |
| 5403 |
onRpc("web_save", () => expect.step("web_save")); |
| 5404 |
await mountView({ |
| 5405 |
resModel: "partner", |
| 5406 |
type: "form", |
| 5407 |
arch: `<form><field name="foo" required="1"/></form>`, |
| 5408 |
resIds: [1, 2], |
| 5409 |
resId: 1, |
| 5410 |
}); |
| 5411 |
expect(`.o_breadcrumb`).toHaveText("first record"); |
| 5412 |
expect(`.o_field_widget[name=foo]`).toHaveClass("o_required_modifier"); |
| 5413 |
|
| 5414 |
await contains(`.o_field_widget[name=foo] input`).edit(""); |
| 5415 |
await press(["alt", "n"]); |
| 5416 |
await tick(); |
| 5417 |
await animationFrame(); |
| 5418 |
expect(`.o_breadcrumb`).toHaveText("first record"); |
| 5419 |
expect(`.o_form_status_indicator .text-danger`).toHaveAttribute( |
| 5420 |
"data-tooltip", |
| 5421 |
"Unable to save. Correct the issue or discard all changes" |
| 5422 |
); |
| 5423 |
expect(`.o_field_widget[name=foo]`).toHaveClass("o_field_invalid"); |
| 5424 |
expect(`.o_notification_manager .o_notification`).toHaveCount(1); |
| 5425 |
expect.verifySteps([]); |
| 5426 |
}); |
| 5427 |
|
| 5428 |
test.tags("desktop"); |
| 5429 |
test(`keynav: switching to another record from an invalid one on desktop`, async () => { |
| 5430 |
onRpc("web_save", () => expect.step("web_save")); |
| 5431 |
await mountView({ |
| 5432 |
resModel: "partner", |
| 5433 |
type: "form", |
| 5434 |
arch: `<form><field name="foo" required="1"/></form>`, |
| 5435 |
resIds: [1, 2], |
| 5436 |
resId: 1, |
| 5437 |
}); |
| 5438 |
expect(`.o_pager_counter`).toHaveText("1 / 2"); |
| 5439 |
|
| 5440 |
await contains(`.o_field_widget[name=foo] input`).edit(""); |
| 5441 |
await press(["alt", "n"]); |
| 5442 |
await tick(); |
| 5443 |
await animationFrame(); |
| 5444 |
expect(`.o_pager_counter`).toHaveText("1 / 2"); |
| 5445 |
}); |
| 5446 |
|
| 5447 |
test(`switching to another record from an invalid one (2)`, async () => { |
| 5448 |
// in this scenario, the record is already invalid in db, so we should be allowed to |
| 5449 |
// leave it |
| 5450 |
Partner._records[0].foo = false; |
| 5451 |
|
| 5452 |
await mountView({ |
| 5453 |
resModel: "partner", |
| 5454 |
type: "form", |
| 5455 |
arch: `<form><field name="foo" required="1"/></form>`, |
| 5456 |
resIds: [1, 2], |
| 5457 |
resId: 1, |
| 5458 |
}); |
| 5459 |
expect(`.o_breadcrumb`).toHaveText("first record"); |
| 5460 |
expect(`.o_field_widget[name=foo]`).toHaveClass("o_required_modifier"); |
| 5461 |
|
| 5462 |
await contains(`.o_pager_next`).click(); |
| 5463 |
expect(`.o_breadcrumb`).toHaveText("second record"); |
| 5464 |
|
| 5465 |
await contains(`.o_pager_previous`).click(); |
| 5466 |
expect(`.o_breadcrumb`).toHaveText("first record"); |
| 5467 |
expect(`.o_field_widget[name=foo]`).toHaveClass("o_required_modifier"); |
| 5468 |
}); |
| 5469 |
|
| 5470 |
test("open a new record from an invalid one", async () => { |
| 5471 |
// in this scenario, the record is already invalid in db, so we should be allowed to |
| 5472 |
// leave it |
| 5473 |
Partner._records[0].foo = false; |
| 5474 |
|
| 5475 |
await mountView({ |
| 5476 |
resModel: "partner", |
| 5477 |
type: "form", |
| 5478 |
arch: `<form><field name="foo" required="1"/></form>`, |
| 5479 |
resIds: [1], |
| 5480 |
resId: 1, |
| 5481 |
}); |
| 5482 |
|
| 5483 |
expect(`.o_breadcrumb`).toHaveText("first record"); |
| 5484 |
expect(`.o_field_widget[name=foo]`).toHaveClass("o_required_modifier"); |
| 5485 |
|
| 5486 |
await contains(".o_control_panel_main_buttons .o_form_button_create").click(); |
| 5487 |
expect(`.o_breadcrumb`).toHaveText("New"); |
| 5488 |
}); |
| 5489 |
|
| 5490 |
test.tags("desktop"); |
| 5491 |
test(`switching to another record from an invalid one (2) on desktop`, async () => { |
| 5492 |
// in this scenario, the record is already invalid in db, so we should be allowed to |
| 5493 |
// leave it |
| 5494 |
Partner._records[0].foo = false; |
| 5495 |
|
| 5496 |
await mountView({ |
| 5497 |
resModel: "partner", |
| 5498 |
type: "form", |
| 5499 |
arch: `<form><field name="foo" required="1"/></form>`, |
| 5500 |
resIds: [1, 2], |
| 5501 |
resId: 1, |
| 5502 |
}); |
| 5503 |
expect(`.o_pager_counter`).toHaveText("1 / 2"); |
| 5504 |
|
| 5505 |
await contains(`.o_pager_next`).click(); |
| 5506 |
expect(`.o_pager_counter`).toHaveText("2 / 2"); |
| 5507 |
|
| 5508 |
await contains(`.o_pager_previous`).click(); |
| 5509 |
expect(`.o_pager_counter`).toHaveText("1 / 2"); |
| 5510 |
}); |
| 5511 |
|
| 5512 |
test(`keynav: switching to another record from a dirty one`, async () => { |
| 5513 |
onRpc("web_save", () => expect.step("web_save")); |
| 5514 |
await mountView({ |
| 5515 |
resModel: "partner", |
| 5516 |
type: "form", |
| 5517 |
arch: `<form><field name="foo"></field></form>`, |
| 5518 |
resIds: [1, 2], |
| 5519 |
resId: 1, |
| 5520 |
}); |
| 5521 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("yop"); |
| 5522 |
|
| 5523 |
await contains(`.o_field_widget[name=foo] input`).edit("new value", { confirm: false }); |
| 5524 |
await press(["alt", "n"]); |
| 5525 |
await tick(); |
| 5526 |
await animationFrame(); |
| 5527 |
expect.verifySteps(["web_save"]); |
| 5528 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("blip"); |
| 5529 |
|
| 5530 |
await press(["alt", "p"]); |
| 5531 |
await tick(); |
| 5532 |
await animationFrame(); |
| 5533 |
expect.verifySteps([]); |
| 5534 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("new value"); |
| 5535 |
}); |
| 5536 |
|
| 5537 |
test.tags("desktop"); |
| 5538 |
test(`keynav: switching to another record from a dirty one on desktop`, async () => { |
| 5539 |
await mountView({ |
| 5540 |
resModel: "partner", |
| 5541 |
type: "form", |
| 5542 |
arch: `<form><field name="foo"></field></form>`, |
| 5543 |
resIds: [1, 2], |
| 5544 |
resId: 1, |
| 5545 |
}); |
| 5546 |
expect(getPagerValue()).toEqual([1]); |
| 5547 |
expect(getPagerLimit()).toBe(2); |
| 5548 |
|
| 5549 |
await contains(`.o_field_widget[name=foo] input`).edit("new value", { confirm: false }); |
| 5550 |
await press(["alt", "n"]); |
| 5551 |
await tick(); |
| 5552 |
await animationFrame(); |
| 5553 |
expect(`.o_pager_counter`).toHaveText("2 / 2"); |
| 5554 |
|
| 5555 |
await press(["alt", "p"]); |
| 5556 |
await tick(); |
| 5557 |
await animationFrame(); |
| 5558 |
expect(`.o_pager_counter`).toHaveText("1 / 2"); |
| 5559 |
}); |
| 5560 |
|
| 5561 |
test(`handling dirty state: switching to another record`, async () => { |
| 5562 |
Partner._fields.priority = fields.Selection({ |
| 5563 |
default: 1, |
| 5564 |
selection: [ |
| 5565 |
[1, "Low"], |
| 5566 |
[2, "Medium"], |
| 5567 |
[3, "High"], |
| 5568 |
], |
| 5569 |
}); |
| 5570 |
|
| 5571 |
await mountView({ |
| 5572 |
resModel: "partner", |
| 5573 |
type: "form", |
| 5574 |
arch: ` |
| 5575 |
<form> |
| 5576 |
<field name="foo"></field> |
| 5577 |
<field name="priority" widget="priority"></field> |
| 5578 |
</form> |
| 5579 |
`, |
| 5580 |
resIds: [1, 2], |
| 5581 |
resId: 1, |
| 5582 |
}); |
| 5583 |
expect(`.o_breadcrumb`).toHaveText("first record"); |
| 5584 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("yop"); |
| 5585 |
|
| 5586 |
await contains(`.o_field_widget[name=foo] input`).edit("new value"); |
| 5587 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("new value"); |
| 5588 |
|
| 5589 |
await contains(`.o_form_button_save`).click(); |
| 5590 |
await contains(`.o_pager_next`).click(); |
| 5591 |
expect(`.o_breadcrumb`).toHaveText("second record"); |
| 5592 |
expect(`.o_priority .fa-star-o`).toHaveCount(2); |
| 5593 |
|
| 5594 |
await contains(`.o_priority .fa-star-o`).click(); |
| 5595 |
expect(`.o_priority .fa-star`).toHaveCount(1); |
| 5596 |
|
| 5597 |
await contains(`.o_pager_next`).click(); |
| 5598 |
expect(`.o_breadcrumb`).toHaveText("first record"); |
| 5599 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("new value"); |
| 5600 |
|
| 5601 |
await contains(`.o_field_widget[name=foo] input`).edit("wrong value"); |
| 5602 |
await contains(`.o_form_button_cancel`).click(); |
| 5603 |
await contains(`.o_pager_next`).click(); |
| 5604 |
expect(`.o_breadcrumb`).toHaveText("second record"); |
| 5605 |
}); |
| 5606 |
|
| 5607 |
test.tags("desktop"); |
| 5608 |
test(`handling dirty state: switching to another record on desktop`, async () => { |
| 5609 |
Partner._fields.priority = fields.Selection({ |
| 5610 |
default: 1, |
| 5611 |
selection: [ |
| 5612 |
[1, "Low"], |
| 5613 |
[2, "Medium"], |
| 5614 |
[3, "High"], |
| 5615 |
], |
| 5616 |
}); |
| 5617 |
|
| 5618 |
await mountView({ |
| 5619 |
resModel: "partner", |
| 5620 |
type: "form", |
| 5621 |
arch: ` |
| 5622 |
<form> |
| 5623 |
<field name="foo"></field> |
| 5624 |
<field name="priority" widget="priority"></field> |
| 5625 |
</form> |
| 5626 |
`, |
| 5627 |
resIds: [1, 2], |
| 5628 |
resId: 1, |
| 5629 |
}); |
| 5630 |
expect(`.o_pager_counter`).toHaveText("1 / 2"); |
| 5631 |
|
| 5632 |
await contains(`.o_field_widget[name=foo] input`).edit("new value"); |
| 5633 |
|
| 5634 |
await contains(`.o_form_button_save`).click(); |
| 5635 |
await contains(`.o_pager_next`).click(); |
| 5636 |
expect(`.o_pager_counter`).toHaveText("2 / 2"); |
| 5637 |
|
| 5638 |
await contains(`.o_priority .fa-star-o`).click(); |
| 5639 |
|
| 5640 |
await contains(`.o_pager_next`).click(); |
| 5641 |
expect(`.o_pager_counter`).toHaveText("1 / 2"); |
| 5642 |
|
| 5643 |
await contains(`.o_field_widget[name=foo] input`).edit("wrong value"); |
| 5644 |
await contains(`.o_form_button_cancel`).click(); |
| 5645 |
await contains(`.o_pager_next`).click(); |
| 5646 |
expect(getPagerValue()).toEqual([2]); |
| 5647 |
}); |
| 5648 |
|
| 5649 |
test(`restore local state when switching to another record`, async () => { |
| 5650 |
await mountView({ |
| 5651 |
resModel: "partner", |
| 5652 |
type: "form", |
| 5653 |
arch: ` |
| 5654 |
<form> |
| 5655 |
<notebook> |
| 5656 |
<page string="First Page" name="first"> |
| 5657 |
<field name="foo"/> |
| 5658 |
</page> |
| 5659 |
<page string="Second page" name="second"> |
| 5660 |
<field name="bar"/> |
| 5661 |
</page> |
| 5662 |
</notebook> |
| 5663 |
</form> |
| 5664 |
`, |
| 5665 |
resIds: [1, 2], |
| 5666 |
resId: 1, |
| 5667 |
}); |
| 5668 |
await contains(`.o_notebook .nav-link:eq(1)`).click(); |
| 5669 |
expect(`.o_notebook .nav-link:eq(0)`).not.toHaveClass("active"); |
| 5670 |
expect(`.o_notebook .nav-link:eq(1)`).toHaveClass("active"); |
| 5671 |
|
| 5672 |
await contains(`.o_pager_next`).click(); |
| 5673 |
expect(`.o_notebook .nav-link:eq(0)`).not.toHaveClass("active"); |
| 5674 |
expect(`.o_notebook .nav-link:eq(1)`).toHaveClass("active"); |
| 5675 |
}); |
| 5676 |
|
| 5677 |
test(`restore the open notebook page when switching to another view`, async () => { |
| 5678 |
Partner._views = { |
| 5679 |
list: `<list><field name="foo"/></list>`, |
| 5680 |
form: ` |
| 5681 |
<form> |
| 5682 |
<notebook> |
| 5683 |
<page string="First Page" name="first"> |
| 5684 |
<field name="foo"/> |
| 5685 |
</page> |
| 5686 |
<page string="Second page" name="second"> |
| 5687 |
<field name="bar"/> |
| 5688 |
</page> |
| 5689 |
</notebook> |
| 5690 |
<notebook> |
| 5691 |
<page string="Page1" name="p1"> |
| 5692 |
<field name="foo"/> |
| 5693 |
</page> |
| 5694 |
<page string="Page2" name="p2" autofocus="autofocus"> |
| 5695 |
<field name="bar"/> |
| 5696 |
</page> |
| 5697 |
<page string="Page3" name="p3"> |
| 5698 |
<field name="bar"/> |
| 5699 |
</page> |
| 5700 |
</notebook> |
| 5701 |
</form> |
| 5702 |
`, |
| 5703 |
}; |
| 5704 |
|
| 5705 |
defineActions([ |
| 5706 |
{ |
| 5707 |
id: 1, |
| 5708 |
name: "test", |
| 5709 |
res_model: "partner", |
| 5710 |
views: [[false, "list"]], |
| 5711 |
}, |
| 5712 |
{ |
| 5713 |
id: 2, |
| 5714 |
name: "test2", |
| 5715 |
res_model: "partner", |
| 5716 |
res_id: 1, |
| 5717 |
views: [[false, "form"]], |
| 5718 |
}, |
| 5719 |
]); |
| 5720 |
|
| 5721 |
await mountWithCleanup(WebClient); |
| 5722 |
await getService("action").doAction(2); |
| 5723 |
|
| 5724 |
expect(`.o_notebook:eq(0) .nav-link:eq(0)`).toHaveClass("active"); |
| 5725 |
expect(`.o_notebook:eq(0) .nav-link:eq(1)`).not.toHaveClass("active"); |
| 5726 |
expect(`.o_notebook:eq(1) .nav-link:eq(0)`).not.toHaveClass("active"); |
| 5727 |
expect(`.o_notebook:eq(1) .nav-link:eq(1)`).toHaveClass("active"); |
| 5728 |
expect(`.o_notebook:eq(1) .nav-link:eq(2)`).not.toHaveClass("active"); |
| 5729 |
|
| 5730 |
// click on second page tab of the first notebook |
| 5731 |
await contains(`.o_notebook:eq(0) .nav-link:eq(1)`).click(); |
| 5732 |
// click on third page tab of the second notebook |
| 5733 |
await contains(`.o_notebook:eq(1) .nav-link:eq(2)`).click(); |
| 5734 |
expect(`.o_notebook:eq(0) .nav-link:eq(0)`).not.toHaveClass("active"); |
| 5735 |
expect(`.o_notebook:eq(0) .nav-link:eq(1)`).toHaveClass("active"); |
| 5736 |
expect(`.o_notebook:eq(1) .nav-link:eq(0)`).not.toHaveClass("active"); |
| 5737 |
expect(`.o_notebook:eq(1) .nav-link:eq(1)`).not.toHaveClass("active"); |
| 5738 |
expect(`.o_notebook:eq(1) .nav-link:eq(2)`).toHaveClass("active"); |
| 5739 |
|
| 5740 |
// switch to a list view |
| 5741 |
await getService("action").doAction(1); |
| 5742 |
|
| 5743 |
// back to the form view |
| 5744 |
await contains(`.o_back_button`).click(); |
| 5745 |
expect(`.o_notebook:eq(0) .nav-link:eq(0)`).not.toHaveClass("active"); |
| 5746 |
expect(`.o_notebook:eq(0) .nav-link:eq(1)`).toHaveClass("active"); |
| 5747 |
expect(`.o_notebook:eq(1) .nav-link:eq(0)`).not.toHaveClass("active"); |
| 5748 |
expect(`.o_notebook:eq(1) .nav-link:eq(1)`).not.toHaveClass("active"); |
| 5749 |
expect(`.o_notebook:eq(1) .nav-link:eq(2)`).toHaveClass("active"); |
| 5750 |
}); |
| 5751 |
|
| 5752 |
test.tags("desktop"); |
| 5753 |
test(`don't restore the open notebook page when we create a new record`, async () => { |
| 5754 |
Partner._views = { |
| 5755 |
list: `<list><field name="foo"/></list>`, |
| 5756 |
form: ` |
| 5757 |
<form> |
| 5758 |
<notebook> |
| 5759 |
<page string="First Page" name="first"> |
| 5760 |
<field name="foo"/> |
| 5761 |
</page> |
| 5762 |
<page string="Second page" name="second"> |
| 5763 |
<field name="bar"/> |
| 5764 |
</page> |
| 5765 |
</notebook> |
| 5766 |
<notebook> |
| 5767 |
<page string="Page1" name="p1"> |
| 5768 |
<field name="foo"/> |
| 5769 |
</page> |
| 5770 |
<page string="Page2" name="p2" autofocus="autofocus"> |
| 5771 |
<field name="bar"/> |
| 5772 |
</page> |
| 5773 |
<page string="Page3" name="p3"> |
| 5774 |
<field name="bar"/> |
| 5775 |
</page> |
| 5776 |
</notebook> |
| 5777 |
</form> |
| 5778 |
`, |
| 5779 |
}; |
| 5780 |
|
| 5781 |
defineActions([ |
| 5782 |
{ |
| 5783 |
id: 1, |
| 5784 |
name: "test", |
| 5785 |
res_model: "partner", |
| 5786 |
views: [ |
| 5787 |
[false, "list"], |
| 5788 |
[false, "form"], |
| 5789 |
], |
| 5790 |
}, |
| 5791 |
]); |
| 5792 |
|
| 5793 |
await mountWithCleanup(WebClient); |
| 5794 |
await getService("action").doAction(1); |
| 5795 |
await contains(`.o_data_cell`).click(); |
| 5796 |
expect(`.o_notebook:eq(0) .nav-link:eq(0)`).toHaveClass("active"); |
| 5797 |
expect(`.o_notebook:eq(0) .nav-link:eq(1)`).not.toHaveClass("active"); |
| 5798 |
expect(`.o_notebook:eq(1) .nav-link:eq(0)`).not.toHaveClass("active"); |
| 5799 |
expect(`.o_notebook:eq(1) .nav-link:eq(1)`).toHaveClass("active"); |
| 5800 |
expect(`.o_notebook:eq(1) .nav-link:eq(2)`).not.toHaveClass("active"); |
| 5801 |
|
| 5802 |
// click on second page tab of the first notebook |
| 5803 |
await contains(`.o_notebook:eq(0) .nav-link:eq(1)`).click(); |
| 5804 |
// click on third page tab of the second notebook |
| 5805 |
await contains(`.o_notebook:eq(1) .nav-link:eq(2)`).click(); |
| 5806 |
expect(`.o_notebook:eq(0) .nav-link:eq(0)`).not.toHaveClass("active"); |
| 5807 |
expect(`.o_notebook:eq(0) .nav-link:eq(1)`).toHaveClass("active"); |
| 5808 |
expect(`.o_notebook:eq(1) .nav-link:eq(0)`).not.toHaveClass("active"); |
| 5809 |
expect(`.o_notebook:eq(1) .nav-link:eq(1)`).not.toHaveClass("active"); |
| 5810 |
expect(`.o_notebook:eq(1) .nav-link:eq(2)`).toHaveClass("active"); |
| 5811 |
|
| 5812 |
// back to the list view |
| 5813 |
await contains(`.o_back_button`).click(); |
| 5814 |
// Create a new record |
| 5815 |
await contains(`.o_control_panel_main_buttons button.o_list_button_add`).click(); |
| 5816 |
expect(`.o_notebook:eq(0) .nav-link:eq(0)`).toHaveClass("active"); |
| 5817 |
expect(`.o_notebook:eq(0) .nav-link:eq(1)`).not.toHaveClass("active"); |
| 5818 |
expect(`.o_notebook:eq(1) .nav-link:eq(0)`).not.toHaveClass("active"); |
| 5819 |
expect(`.o_notebook:eq(1) .nav-link:eq(1)`).toHaveClass("active"); |
| 5820 |
expect(`.o_notebook:eq(1) .nav-link:eq(2)`).not.toHaveClass("active"); |
| 5821 |
}); |
| 5822 |
|
| 5823 |
test(`pager is hidden in create mode`, async () => { |
| 5824 |
await mountView({ |
| 5825 |
resModel: "partner", |
| 5826 |
type: "form", |
| 5827 |
arch: `<form><field name="foo"/></form>`, |
| 5828 |
resId: 1, |
| 5829 |
resIds: [1, 2], |
| 5830 |
}); |
| 5831 |
expect(`.o_pager`).toHaveCount(1); |
| 5832 |
|
| 5833 |
await contains(`.o_form_button_create`).click(); |
| 5834 |
expect(`.o_pager`).toHaveCount(0); |
| 5835 |
|
| 5836 |
await contains(`.o_form_button_save`).click(); |
| 5837 |
expect(`.o_pager`).toHaveCount(1); |
| 5838 |
}); |
| 5839 |
|
| 5840 |
test.tags("desktop"); |
| 5841 |
test(`pager is hidden in create mode on desktop`, async () => { |
| 5842 |
await mountView({ |
| 5843 |
resModel: "partner", |
| 5844 |
type: "form", |
| 5845 |
arch: `<form><field name="foo"/></form>`, |
| 5846 |
resId: 1, |
| 5847 |
resIds: [1, 2], |
| 5848 |
}); |
| 5849 |
expect(getPagerValue()).toEqual([1]); |
| 5850 |
expect(getPagerLimit()).toBe(2); |
| 5851 |
|
| 5852 |
await contains(`.o_form_button_create`).click(); |
| 5853 |
expect(`.o_pager`).toHaveCount(0); |
| 5854 |
|
| 5855 |
await contains(`.o_form_button_save`).click(); |
| 5856 |
expect(getPagerValue()).toEqual([3]); |
| 5857 |
expect(getPagerLimit()).toBe(3); |
| 5858 |
}); |
| 5859 |
|
| 5860 |
test(`switching to another record`, async () => { |
| 5861 |
await mountView({ |
| 5862 |
resModel: "partner", |
| 5863 |
type: "form", |
| 5864 |
arch: `<form><field name="foo"></field></form>`, |
| 5865 |
resId: 1, |
| 5866 |
resIds: [1, 2], |
| 5867 |
}); |
| 5868 |
expect(`.o_breadcrumb`).toHaveText("first record"); |
| 5869 |
|
| 5870 |
await contains(`.o_pager_next`).click(); |
| 5871 |
expect(`.o_breadcrumb`).toHaveText("second record"); |
| 5872 |
}); |
| 5873 |
|
| 5874 |
test.tags("desktop"); |
| 5875 |
test(`switching to another record on desktop`, async () => { |
| 5876 |
await mountView({ |
| 5877 |
resModel: "partner", |
| 5878 |
type: "form", |
| 5879 |
arch: `<form><field name="foo"></field></form>`, |
| 5880 |
resId: 1, |
| 5881 |
resIds: [1, 2], |
| 5882 |
}); |
| 5883 |
expect(getPagerValue()).toEqual([1]); |
| 5884 |
|
| 5885 |
await contains(`.o_pager_next`).click(); |
| 5886 |
expect(getPagerValue()).toEqual([2]); |
| 5887 |
}); |
| 5888 |
|
| 5889 |
test(`switching to non-existing record`, async () => { |
| 5890 |
expect.errors(1); |
| 5891 |
|
| 5892 |
await mountView({ |
| 5893 |
resModel: "partner", |
| 5894 |
type: "form", |
| 5895 |
arch: `<form><field name="foo"></field></form>`, |
| 5896 |
resId: 1, |
| 5897 |
resIds: [1, 999, 2], |
| 5898 |
}); |
| 5899 |
expect(`.o_breadcrumb`).toHaveText("first record"); |
| 5900 |
|
| 5901 |
await contains(`.o_pager_next`).click(); |
| 5902 |
expect(`.o_breadcrumb`).toHaveText("first record"); |
| 5903 |
|
| 5904 |
await animationFrame(); |
| 5905 |
expect(`.o_notification_body`).toHaveCount(1); |
| 5906 |
expect.verifyErrors([ |
| 5907 |
"It seems the records with IDs 999 cannot be found. They might have been deleted.", |
| 5908 |
]); |
| 5909 |
|
| 5910 |
await contains(`.o_pager_next`).click(); |
| 5911 |
expect(`.o_breadcrumb`).toHaveText("second record"); |
| 5912 |
expect(`.o_notification_body`).toHaveCount(1); |
| 5913 |
}); |
| 5914 |
|
| 5915 |
test.tags("desktop"); |
| 5916 |
test(`switching to non-existing record on desktop`, async () => { |
| 5917 |
await mountView({ |
| 5918 |
resModel: "partner", |
| 5919 |
type: "form", |
| 5920 |
arch: `<form><field name="foo"></field></form>`, |
| 5921 |
resId: 1, |
| 5922 |
resIds: [1, 999, 2], |
| 5923 |
}); |
| 5924 |
expect(getPagerValue()).toEqual([1]); |
| 5925 |
expect(getPagerLimit()).toBe(3); |
| 5926 |
|
| 5927 |
expect.errors(1); |
| 5928 |
await contains(`.o_pager_next`).click(); |
| 5929 |
expect.verifyErrors([Error]); |
| 5930 |
expect(getPagerValue()).toEqual([1]); |
| 5931 |
expect(getPagerLimit()).toBe(2); |
| 5932 |
|
| 5933 |
await animationFrame(); |
| 5934 |
|
| 5935 |
await contains(`.o_pager_next`).click(); |
| 5936 |
expect(getPagerValue()).toEqual([2]); |
| 5937 |
expect(getPagerLimit()).toBe(2); |
| 5938 |
}); |
| 5939 |
|
| 5940 |
test(`modifiers are reevaluated when creating new record`, async () => { |
| 5941 |
await mountView({ |
| 5942 |
resModel: "partner", |
| 5943 |
type: "form", |
| 5944 |
arch: ` |
| 5945 |
<form> |
| 5946 |
<sheet> |
| 5947 |
<group> |
| 5948 |
<field name="foo" class="foo_field" invisible='bar'/> |
| 5949 |
<field name="bar"/> |
| 5950 |
</group> |
| 5951 |
</sheet> |
| 5952 |
</form> |
| 5953 |
`, |
| 5954 |
resId: 1, |
| 5955 |
}); |
| 5956 |
expect(`.foo_field`).toHaveCount(0); |
| 5957 |
|
| 5958 |
await contains(`.o_form_button_create`).click(); |
| 5959 |
expect(`.foo_field`).toHaveCount(1); |
| 5960 |
}); |
| 5961 |
|
| 5962 |
test(`empty readonly fields are visible on new records`, async () => { |
| 5963 |
Partner._fields.foo = fields.Char({ readonly: true }); |
| 5964 |
Partner._records[0].foo = undefined; |
| 5965 |
|
| 5966 |
await mountView({ |
| 5967 |
resModel: "partner", |
| 5968 |
type: "form", |
| 5969 |
arch: ` |
| 5970 |
<form> |
| 5971 |
<sheet> |
| 5972 |
<group> |
| 5973 |
<field name="foo"/> |
| 5974 |
</group> |
| 5975 |
</sheet> |
| 5976 |
</form> |
| 5977 |
`, |
| 5978 |
resId: 1, |
| 5979 |
}); |
| 5980 |
expect(`.o_field_empty`).toHaveCount(1); |
| 5981 |
|
| 5982 |
await contains(`.o_form_button_create`).click(); |
| 5983 |
expect(`.o_field_empty`).toHaveCount(0); |
| 5984 |
}); |
| 5985 |
|
| 5986 |
test(`all group children have correct layout classname`, async () => { |
| 5987 |
await mountView({ |
| 5988 |
resModel: "partner", |
| 5989 |
type: "form", |
| 5990 |
arch: ` |
| 5991 |
<form> |
| 5992 |
<sheet> |
| 5993 |
<group> |
| 5994 |
<group class="inner_group"> |
| 5995 |
<field name="name"/> |
| 5996 |
</group> |
| 5997 |
<div class="inner_div"> |
| 5998 |
<field name="foo"/> |
| 5999 |
</div> |
| 6000 |
</group> |
| 6001 |
</sheet> |
| 6002 |
</form> |
| 6003 |
`, |
| 6004 |
resId: 1, |
| 6005 |
}); |
| 6006 |
expect(`.inner_group`).toHaveClass("col-lg-6"); |
| 6007 |
expect(`.inner_div`).toHaveClass("col-lg-6"); |
| 6008 |
}); |
| 6009 |
|
| 6010 |
test(`deleting a record`, async () => { |
| 6011 |
await mountView({ |
| 6012 |
resModel: "partner", |
| 6013 |
type: "form", |
| 6014 |
arch: `<form><field name="foo"></field></form>`, |
| 6015 |
actionMenus: {}, |
| 6016 |
resIds: [1, 2, 4], |
| 6017 |
resId: 1, |
| 6018 |
}); |
| 6019 |
expect(`.o_breadcrumb`).toHaveText("first record"); |
| 6020 |
|
| 6021 |
// open action menu and delete |
| 6022 |
await toggleActionMenu(); |
| 6023 |
await toggleMenuItem("Delete"); |
| 6024 |
expect(`.modal`).toHaveCount(1); |
| 6025 |
|
| 6026 |
await contains(`.modal-footer button.btn-primary`).click(); |
| 6027 |
expect(`.o_breadcrumb`).toHaveText("second record"); |
| 6028 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("blip"); |
| 6029 |
}); |
| 6030 |
|
| 6031 |
test.tags("desktop"); |
| 6032 |
test(`deleting a record on desktop`, async () => { |
| 6033 |
await mountView({ |
| 6034 |
resModel: "partner", |
| 6035 |
type: "form", |
| 6036 |
arch: `<form><field name="foo"></field></form>`, |
| 6037 |
actionMenus: {}, |
| 6038 |
resIds: [1, 2, 4], |
| 6039 |
resId: 1, |
| 6040 |
}); |
| 6041 |
expect(getPagerValue()).toEqual([1]); |
| 6042 |
expect(getPagerLimit()).toBe(3); |
| 6043 |
|
| 6044 |
// open action menu and delete |
| 6045 |
await toggleActionMenu(); |
| 6046 |
await toggleMenuItem("Delete"); |
| 6047 |
|
| 6048 |
await contains(`.modal-footer button.btn-primary`).click(); |
| 6049 |
expect(getPagerValue()).toEqual([1]); |
| 6050 |
expect(getPagerLimit()).toBe(2); |
| 6051 |
}); |
| 6052 |
|
| 6053 |
test(`deleting the last record`, async () => { |
| 6054 |
onRpc(({ method }) => expect.step(method)); |
| 6055 |
await mountView({ |
| 6056 |
resModel: "partner", |
| 6057 |
type: "form", |
| 6058 |
arch: `<form><field name="foo"></field></form>`, |
| 6059 |
resIds: [1], |
| 6060 |
resId: 1, |
| 6061 |
actionMenus: {}, |
| 6062 |
config: { |
| 6063 |
historyBack() { |
| 6064 |
expect.step("history-back"); |
| 6065 |
}, |
| 6066 |
}, |
| 6067 |
}); |
| 6068 |
expect.verifySteps(["get_views", "web_read"]); |
| 6069 |
await toggleActionMenu(); |
| 6070 |
await toggleMenuItem("Delete"); |
| 6071 |
expect(`.modal`).toHaveCount(1); |
| 6072 |
expect.verifySteps([]); |
| 6073 |
|
| 6074 |
await contains(`.modal-footer button.btn-primary`).click(); |
| 6075 |
expect(`.modal`).toHaveCount(0); |
| 6076 |
expect.verifySteps(["unlink", "history-back"]); |
| 6077 |
}); |
| 6078 |
|
| 6079 |
test("delete the last record (without previous action)", async () => { |
| 6080 |
Partner._views = { |
| 6081 |
form: ` |
| 6082 |
<form> |
| 6083 |
<field name="display_name"/> |
| 6084 |
</form>`, |
| 6085 |
}; |
| 6086 |
|
| 6087 |
redirect("/odoo/m-partner/1"); |
| 6088 |
patchWithCleanup(WebClient.prototype, { |
| 6089 |
_loadDefaultApp() { |
| 6090 |
expect.step("__DEFAULT_ACTION__ called"); |
| 6091 |
}, |
| 6092 |
}); |
| 6093 |
await mountWithCleanup(WebClient); |
| 6094 |
await toggleActionMenu(); |
| 6095 |
await toggleMenuItem("Delete"); |
| 6096 |
await contains(`.modal-footer button.btn-primary`).click(); |
| 6097 |
expect.verifySteps(["__DEFAULT_ACTION__ called"]); |
| 6098 |
}); |
| 6099 |
|
| 6100 |
test(`empty required fields cannot be saved`, async () => { |
| 6101 |
Partner._fields.foo = fields.Char({ required: true }); |
| 6102 |
|
| 6103 |
await mountView({ |
| 6104 |
resModel: "partner", |
| 6105 |
type: "form", |
| 6106 |
arch: `<form><group><field name="foo"/></group></form>`, |
| 6107 |
}); |
| 6108 |
await contains(`.o_form_button_save`).click(); |
| 6109 |
expect(`label.o_form_label`).toHaveClass("o_field_invalid"); |
| 6110 |
expect(`.o_field_widget[name=foo]`).toHaveClass("o_field_invalid"); |
| 6111 |
expect(`.o_notification`).toHaveCount(1); |
| 6112 |
expect(`.o_notification_content`).toHaveText("Missing required fields"); |
| 6113 |
expect(`.o_notification_bar`).toHaveClass("bg-danger"); |
| 6114 |
|
| 6115 |
await contains(`.o_field_widget[name=foo] input`).edit("tralala"); |
| 6116 |
expect(`.o_field_invalid`).toHaveCount(0); |
| 6117 |
}); |
| 6118 |
|
| 6119 |
test("empty required fields in an existing record are highlighted", async () => { |
| 6120 |
Partner._fields.foo = fields.Char({ required: true }); |
| 6121 |
Partner._records[0].foo = false; |
| 6122 |
|
| 6123 |
await mountView({ |
| 6124 |
resModel: "partner", |
| 6125 |
type: "form", |
| 6126 |
arch: ` |
| 6127 |
<form> |
| 6128 |
<group> |
| 6129 |
<field name="foo"/> |
| 6130 |
<field name="int_field"/> |
| 6131 |
<field name="child_ids"> |
| 6132 |
<list> |
| 6133 |
<field name="name"/> |
| 6134 |
<field name="foo" column_invisible="parent.int_field < 20"/> |
| 6135 |
</list> |
| 6136 |
</field> |
| 6137 |
</group> |
| 6138 |
</form> |
| 6139 |
`, |
| 6140 |
resId: 1, |
| 6141 |
}); |
| 6142 |
|
| 6143 |
expect(".o_field_widget[name=foo]").toHaveClass("o_field_invalid"); |
| 6144 |
expect(".o_form_status_indicator_buttons").toHaveClass("invisible"); |
| 6145 |
expect(queryAllTexts`.o_column_sortable div span`).toEqual(["Name"]); |
| 6146 |
|
| 6147 |
await contains(".o_field_widget[name=int_field] input").edit("25", { confirm: false }); |
| 6148 |
expect(".o_form_status_indicator_buttons").not.toHaveClass("invisible"); |
| 6149 |
expect(".o_form_status_indicator_buttons .o_form_button_save").toHaveAttribute("disabled"); |
| 6150 |
expect(".o_form_status_indicator span.text-danger").toHaveCount(1); |
| 6151 |
|
| 6152 |
await contains(".o_control_panel").click(); // blur the input |
| 6153 |
expect(".o_form_status_indicator_buttons").not.toHaveClass("invisible"); |
| 6154 |
expect(".o_form_status_indicator_buttons .o_form_button_save").toHaveAttribute("disabled"); |
| 6155 |
expect(".o_form_status_indicator span.text-danger").toHaveCount(1); |
| 6156 |
expect(queryAllTexts`.o_column_sortable div span`).toEqual(["Name", "Foo"]); |
| 6157 |
|
| 6158 |
await contains(".o_form_button_cancel").click(); |
| 6159 |
expect(".o_field_widget[name=foo]").toHaveClass("o_field_invalid"); |
| 6160 |
expect(".o_form_status_indicator_buttons").toHaveClass("invisible"); |
| 6161 |
|
| 6162 |
await contains(".o_form_button_create").click(); |
| 6163 |
expect(".o_field_widget[name=foo]").not.toHaveClass("o_field_invalid"); |
| 6164 |
expect(".o_form_status_indicator_buttons").not.toHaveClass("invisible"); |
| 6165 |
expect(queryAllTexts`.o_column_sortable div span`).toEqual(["Name"]); |
| 6166 |
}); |
| 6167 |
|
| 6168 |
test(`display a dialog if onchange result is a warning`, async () => { |
| 6169 |
Partner._onChanges = { foo: true }; |
| 6170 |
|
| 6171 |
onRpc("onchange", () => ({ |
| 6172 |
value: { int_field: 10 }, |
| 6173 |
warning: { |
| 6174 |
title: "Warning", |
| 6175 |
message: "You must first select a partner", |
| 6176 |
type: "dialog", |
| 6177 |
}, |
| 6178 |
})); |
| 6179 |
await mountView({ |
| 6180 |
resModel: "partner", |
| 6181 |
type: "form", |
| 6182 |
arch: `<form><field name="foo"/><field name="int_field"/></form>`, |
| 6183 |
resId: 2, |
| 6184 |
}); |
| 6185 |
expect(`.o_field_widget[name=int_field] input`).toHaveValue("9"); |
| 6186 |
|
| 6187 |
await contains(`.o_field_widget[name=foo] input`).edit("tralala"); |
| 6188 |
expect(`.o_field_widget[name=int_field] input`).toHaveValue("10"); |
| 6189 |
expect(`.modal`).toHaveCount(1); |
| 6190 |
expect(`.modal-title`).toHaveText("Warning"); |
| 6191 |
expect(`.modal-body`).toHaveText("You must first select a partner"); |
| 6192 |
}); |
| 6193 |
|
| 6194 |
test(`display a notificaton if onchange result is a warning with type notification`, async () => { |
| 6195 |
Partner._onChanges = { foo: true }; |
| 6196 |
|
| 6197 |
onRpc("onchange", () => ({ |
| 6198 |
value: { int_field: 10 }, |
| 6199 |
warning: { |
| 6200 |
message: "You must first select a partner", |
| 6201 |
type: "notification", |
| 6202 |
className: "abc", |
| 6203 |
sticky: true, |
| 6204 |
}, |
| 6205 |
})); |
| 6206 |
await mountView({ |
| 6207 |
resModel: "partner", |
| 6208 |
type: "form", |
| 6209 |
arch: `<form><field name="foo"/><field name="int_field"/></form>`, |
| 6210 |
resId: 2, |
| 6211 |
}); |
| 6212 |
expect(`.o_field_widget[name=int_field] input`).toHaveValue("9"); |
| 6213 |
|
| 6214 |
await contains(`.o_field_widget[name=foo] input`).edit("tralala"); |
| 6215 |
expect(`.o_field_widget[name=int_field] input`).toHaveValue("10"); |
| 6216 |
expect(`.o_notification`).toHaveCount(1); |
| 6217 |
expect(`.o_notification`).toHaveClass("abc"); |
| 6218 |
expect(`.o_notification_content`).toHaveText("You must first select a partner"); |
| 6219 |
}); |
| 6220 |
|
| 6221 |
test(`can create record even if onchange returns a warning`, async () => { |
| 6222 |
Partner._onChanges = { foo: true }; |
| 6223 |
|
| 6224 |
onRpc("onchange", () => ({ |
| 6225 |
value: { int_field: 10 }, |
| 6226 |
warning: { |
| 6227 |
message: "You must first select a partner", |
| 6228 |
}, |
| 6229 |
})); |
| 6230 |
await mountView({ |
| 6231 |
resModel: "partner", |
| 6232 |
type: "form", |
| 6233 |
arch: `<form><field name="foo"/><field name="int_field"/></form>`, |
| 6234 |
}); |
| 6235 |
expect(`.o_field_widget[name="int_field"] input`).toHaveValue("10"); |
| 6236 |
expect(`.o_notification`).toHaveCount(1); |
| 6237 |
}); |
| 6238 |
|
| 6239 |
test(`onchange returns an error`, async () => { |
| 6240 |
expect.errors(1); |
| 6241 |
Partner._onChanges = { int_field: () => {} }; |
| 6242 |
|
| 6243 |
onRpc("onchange", ({ args }) => { |
| 6244 |
if (args[1].int_field === 64) { |
| 6245 |
throw makeServerError({ message: "Some business message" }); |
| 6246 |
} |
| 6247 |
}); |
| 6248 |
await mountView({ |
| 6249 |
resModel: "partner", |
| 6250 |
type: "form", |
| 6251 |
arch: `<form><field name="int_field"/></form>`, |
| 6252 |
resId: 2, |
| 6253 |
}); |
| 6254 |
expect(`.o_field_widget[name=int_field] input`).toHaveValue("9"); |
| 6255 |
|
| 6256 |
await contains(`.o_field_widget[name=int_field] input`).edit("64"); |
| 6257 |
expect.verifyErrors(["Some business message"]); |
| 6258 |
await waitFor(`.modal`); |
| 6259 |
expect(`.modal-body`).toHaveText(/Some business message/); |
| 6260 |
expect(`.o_field_widget[name="int_field"] input`).toHaveValue("9"); |
| 6261 |
|
| 6262 |
await contains(`.modal .btn-primary`).click(); |
| 6263 |
expect(`.modal`).toHaveCount(0); |
| 6264 |
|
| 6265 |
await contains(`.o_field_widget[name=int_field] input`).edit("32"); |
| 6266 |
expect(`.modal`).toHaveCount(0); |
| 6267 |
expect(`.o_field_invalid`).toHaveCount(0); |
| 6268 |
}); |
| 6269 |
|
| 6270 |
test(`button box is rendered in create mode`, async () => { |
| 6271 |
await mountView({ |
| 6272 |
resModel: "partner", |
| 6273 |
type: "form", |
| 6274 |
arch: ` |
| 6275 |
<form> |
| 6276 |
<div name="button_box" class="oe_button_box"> |
| 6277 |
<button type="object" class="oe_stat_button" icon="fa-check-square"> |
| 6278 |
<field name="bar"/> |
| 6279 |
</button> |
| 6280 |
</div> |
| 6281 |
</form> |
| 6282 |
`, |
| 6283 |
resId: 2, |
| 6284 |
}); |
| 6285 |
expect(`.oe_stat_button`).toHaveCount(1); |
| 6286 |
|
| 6287 |
await contains(`.o_form_button_cancel`, { visible: false }).click(); |
| 6288 |
await contains(`.o_form_button_create`).click(); |
| 6289 |
expect(`.oe_stat_button`).toHaveCount(1); |
| 6290 |
}); |
| 6291 |
|
| 6292 |
test(`button box is not rendered in form views in dialogs`, async () => { |
| 6293 |
await mountViewInDialog({ |
| 6294 |
resModel: "partner", |
| 6295 |
type: "form", |
| 6296 |
arch: ` |
| 6297 |
<form> |
| 6298 |
<div name="button_box" class="oe_button_box"> |
| 6299 |
<button type="object" class="oe_stat_button" icon="fa-check-square"> |
| 6300 |
<field name="bar"/> |
| 6301 |
</button> |
| 6302 |
</div> |
| 6303 |
</form> |
| 6304 |
`, |
| 6305 |
resId: 2, |
| 6306 |
}); |
| 6307 |
expect(`.o_dialog`).toHaveCount(1); |
| 6308 |
expect(`.oe_stat_button`).toHaveCount(0); |
| 6309 |
}); |
| 6310 |
|
| 6311 |
test(`properly apply onchange on one2many fields`, async () => { |
| 6312 |
Partner._records[0].child_ids = [4]; |
| 6313 |
Partner._onChanges = { |
| 6314 |
foo(record) { |
| 6315 |
record.child_ids = [ |
| 6316 |
[5], |
| 6317 |
[1, 4, { name: "updated record" }], |
| 6318 |
[0, null, { name: "created record" }], |
| 6319 |
]; |
| 6320 |
}, |
| 6321 |
}; |
| 6322 |
await mountView({ |
| 6323 |
resModel: "partner", |
| 6324 |
type: "form", |
| 6325 |
arch: ` |
| 6326 |
<form> |
| 6327 |
<group><field name="foo"/></group> |
| 6328 |
<field name="child_ids"> |
| 6329 |
<list><field name="name"/></list> |
| 6330 |
</field> |
| 6331 |
</form> |
| 6332 |
`, |
| 6333 |
resId: 1, |
| 6334 |
}); |
| 6335 |
expect(`.o_field_one2many .o_data_row`).toHaveCount(1); |
| 6336 |
expect(`.o_field_one2many .o_data_row .o_data_cell`).toHaveText("aaa"); |
| 6337 |
|
| 6338 |
await contains(`.o_field_widget[name=foo] input`).edit("let us trigger an onchange"); |
| 6339 |
expect(`.o_data_row`).toHaveCount(2); |
| 6340 |
expect(`.o_data_row:eq(0) .o_data_cell`).toHaveText("updated record"); |
| 6341 |
expect(`.o_data_row:eq(1) .o_data_cell`).toHaveText("created record"); |
| 6342 |
}); |
| 6343 |
|
| 6344 |
test(`properly apply onchange on one2many fields direct click`, async () => { |
| 6345 |
Partner._records[0].child_ids = [2, 4]; |
| 6346 |
Partner._onChanges = { |
| 6347 |
int_field(record) { |
| 6348 |
record.child_ids = [ |
| 6349 |
[1, 2, { name: "updated record 1", int_field: record.int_field }], |
| 6350 |
[1, 4, { name: "updated record 2", int_field: record.int_field * 2 }], |
| 6351 |
]; |
| 6352 |
}, |
| 6353 |
}; |
| 6354 |
Partner._views = { |
| 6355 |
form: ` |
| 6356 |
<form> |
| 6357 |
<field name="name"/> |
| 6358 |
<field name="int_field"/> |
| 6359 |
</form> |
| 6360 |
`, |
| 6361 |
}; |
| 6362 |
|
| 6363 |
const deferred = new Deferred(); |
| 6364 |
onRpc("onchange", () => deferred); |
| 6365 |
await mountView({ |
| 6366 |
resModel: "partner", |
| 6367 |
type: "form", |
| 6368 |
arch: ` |
| 6369 |
<form> |
| 6370 |
<field name="foo"/> |
| 6371 |
<field name="int_field"/> |
| 6372 |
<field name="child_ids"> |
| 6373 |
<list> |
| 6374 |
<field name="display_name"/> |
| 6375 |
<field name="int_field"/> |
| 6376 |
</list> |
| 6377 |
</field> |
| 6378 |
</form> |
| 6379 |
`, |
| 6380 |
resId: 1, |
| 6381 |
}); |
| 6382 |
await contains(`.o_field_widget[name=int_field] input`).edit("2"); |
| 6383 |
await contains(`.o_data_row .o_data_cell`).click(); |
| 6384 |
expect(`.modal`).toHaveCount(0); |
| 6385 |
|
| 6386 |
deferred.resolve(); |
| 6387 |
await animationFrame(); |
| 6388 |
expect(`.modal`).toHaveCount(1); |
| 6389 |
expect(`.modal .o_field_widget[name=int_field] input`).toHaveValue("2"); |
| 6390 |
}); |
| 6391 |
|
| 6392 |
test(`update many2many value in one2many after onchange`, async () => { |
| 6393 |
Partner._records[1].child_ids = [4]; |
| 6394 |
Partner._onChanges = { |
| 6395 |
foo(record) { |
| 6396 |
record.child_ids = [[5], [1, 4, { name: "gold", type_ids: [[5]] }]]; |
| 6397 |
}, |
| 6398 |
}; |
| 6399 |
|
| 6400 |
await mountView({ |
| 6401 |
resModel: "partner", |
| 6402 |
type: "form", |
| 6403 |
arch: ` |
| 6404 |
<form> |
| 6405 |
<field name="foo"/> |
| 6406 |
<field name="child_ids"> |
| 6407 |
<list editable="top"> |
| 6408 |
<field name="name" readonly="not type_ids"/> |
| 6409 |
<field name="type_ids"/> |
| 6410 |
</list> |
| 6411 |
</field> |
| 6412 |
</form> |
| 6413 |
`, |
| 6414 |
resId: 2, |
| 6415 |
}); |
| 6416 |
expect(queryAllTexts`.o_data_cell`).toEqual(["aaa", "No records"]); |
| 6417 |
|
| 6418 |
await contains(`.o_field_widget[name=foo] input`).edit("tralala"); |
| 6419 |
expect(queryAllTexts`.o_data_cell`).toEqual(["gold", "No records"]); |
| 6420 |
}); |
| 6421 |
|
| 6422 |
test(`delete a line in a one2many while editing another line`, async () => { |
| 6423 |
Partner._records[0].child_ids = [1, 2]; |
| 6424 |
|
| 6425 |
await mountView({ |
| 6426 |
resModel: "partner", |
| 6427 |
type: "form", |
| 6428 |
arch: ` |
| 6429 |
<form> |
| 6430 |
<field name="child_ids"> |
| 6431 |
<list editable="bottom"> |
| 6432 |
<field name="name" required="True"/> |
| 6433 |
</list> |
| 6434 |
</field> |
| 6435 |
</form> |
| 6436 |
`, |
| 6437 |
resId: 1, |
| 6438 |
}); |
| 6439 |
await contains(`.o_data_cell:eq(0)`).click(); |
| 6440 |
await contains(`.o_field_widget[name=name] input`).clear(); |
| 6441 |
await contains(`.fa-trash-o:eq(1)`).click(); |
| 6442 |
expect(`.o_data_row`).toHaveCount(2); |
| 6443 |
expect(`.o_data_cell:eq(0)`).toHaveClass(["o_invalid_cell"]); |
| 6444 |
}); |
| 6445 |
|
| 6446 |
test(`properly apply onchange on many2many fields`, async () => { |
| 6447 |
Partner._onChanges = { |
| 6448 |
foo(record) { |
| 6449 |
record.type_ids = [ |
| 6450 |
[4, 12], |
| 6451 |
[4, 14], |
| 6452 |
]; |
| 6453 |
}, |
| 6454 |
}; |
| 6455 |
|
| 6456 |
onRpc(({ method }) => expect.step(method)); |
| 6457 |
onRpc("web_save", ({ args }) => { |
| 6458 |
expect(args[1].type_ids).toEqual([ |
| 6459 |
[4, 12], |
| 6460 |
[4, 14], |
| 6461 |
]); |
| 6462 |
}); |
| 6463 |
await mountView({ |
| 6464 |
resModel: "partner", |
| 6465 |
type: "form", |
| 6466 |
arch: ` |
| 6467 |
<form> |
| 6468 |
<field name="foo"/> |
| 6469 |
<field name="type_ids"> |
| 6470 |
<list><field name="display_name"/></list> |
| 6471 |
</field> |
| 6472 |
</form> |
| 6473 |
`, |
| 6474 |
resId: 2, |
| 6475 |
}); |
| 6476 |
expect.verifySteps(["get_views", "web_read"]); |
| 6477 |
expect(`.o_field_many2many .o_data_row`).toHaveCount(0); |
| 6478 |
|
| 6479 |
await contains(`.o_field_widget[name=foo] input`).edit("let us trigger an onchange"); |
| 6480 |
expect.verifySteps(["onchange"]); |
| 6481 |
expect(`.o_data_row`).toHaveCount(2); |
| 6482 |
expect(`.o_data_row .o_data_cell:eq(0)`).toHaveText("gold"); |
| 6483 |
expect(`.o_data_row .o_data_cell:eq(1)`).toHaveText("silver"); |
| 6484 |
|
| 6485 |
await contains(`.o_form_button_save`).click(); |
| 6486 |
expect.verifySteps(["web_save"]); |
| 6487 |
}); |
| 6488 |
|
| 6489 |
test(`form with domain widget: opening a many2many form and save should not crash`, async () => { |
| 6490 |
// We just test that there is no crash in this situation |
| 6491 |
Partner._records[0].type_ids = [12]; |
| 6492 |
await mountView({ |
| 6493 |
resModel: "partner", |
| 6494 |
type: "form", |
| 6495 |
arch: ` |
| 6496 |
<form> |
| 6497 |
<group> |
| 6498 |
<field name="foo" widget="domain"/> |
| 6499 |
</group> |
| 6500 |
<field name="type_ids"> |
| 6501 |
<list> |
| 6502 |
<field name="display_name"/> |
| 6503 |
</list> |
| 6504 |
<form> |
| 6505 |
<field name="name"/> |
| 6506 |
<field name="color"/> |
| 6507 |
</form> |
| 6508 |
</field> |
| 6509 |
</form> |
| 6510 |
`, |
| 6511 |
resId: 1, |
| 6512 |
}); |
| 6513 |
|
| 6514 |
// open a form view and save many2many record |
| 6515 |
await contains(`.o_data_row .o_data_cell`).click(); |
| 6516 |
await contains(`.modal-dialog footer .btn-primary`).click(); |
| 6517 |
expect.verifyErrors([]); |
| 6518 |
}); |
| 6519 |
|
| 6520 |
test(`display_name not sent for onchanges if not in view`, async () => { |
| 6521 |
Partner._records[0].type_ids = [12]; |
| 6522 |
Partner._onChanges = { foo() {} }; |
| 6523 |
PartnerType._onChanges = { name() {} }; |
| 6524 |
|
| 6525 |
onRpc("partner", "web_read", ({ kwargs }) => { |
| 6526 |
expect.step(`partner.web_read`); |
| 6527 |
expect(kwargs.specification).toEqual({ |
| 6528 |
display_name: {}, |
| 6529 |
foo: {}, |
| 6530 |
type_ids: { |
| 6531 |
fields: { |
| 6532 |
name: {}, |
| 6533 |
color: {}, |
| 6534 |
}, |
| 6535 |
limit: 40, |
| 6536 |
}, |
| 6537 |
}); |
| 6538 |
}); |
| 6539 |
onRpc("partner.type", "web_read", ({ kwargs }) => { |
| 6540 |
expect.step(`partner.type.web_read`); |
| 6541 |
expect(kwargs.specification).toEqual({ |
| 6542 |
color: {}, |
| 6543 |
name: {}, |
| 6544 |
}); |
| 6545 |
}); |
| 6546 |
|
| 6547 |
onRpc("partner", "onchange", ({ args }) => { |
| 6548 |
expect.step(`partner.onchange`); |
| 6549 |
expect(args[1]).toEqual({ foo: "coucou" }); |
| 6550 |
expect(args[3]).toEqual({ |
| 6551 |
display_name: {}, |
| 6552 |
foo: {}, |
| 6553 |
type_ids: { |
| 6554 |
fields: { |
| 6555 |
name: {}, |
| 6556 |
color: {}, |
| 6557 |
}, |
| 6558 |
limit: 40, |
| 6559 |
}, |
| 6560 |
}); |
| 6561 |
}); |
| 6562 |
onRpc("partner.type", "onchange", ({ args }) => { |
| 6563 |
expect.step(`partner.type.onchange`); |
| 6564 |
expect(args[1]).toEqual({ name: "new name" }); |
| 6565 |
expect(args[3]).toEqual({ |
| 6566 |
name: {}, |
| 6567 |
color: {}, |
| 6568 |
}); |
| 6569 |
}); |
| 6570 |
|
| 6571 |
await mountView({ |
| 6572 |
resModel: "partner", |
| 6573 |
type: "form", |
| 6574 |
arch: ` |
| 6575 |
<form> |
| 6576 |
<group> |
| 6577 |
<field name="foo"/> |
| 6578 |
<field name="type_ids"> |
| 6579 |
<list><field name="name"/></list> |
| 6580 |
<form> |
| 6581 |
<field name="name"/> |
| 6582 |
<field name="color"/> |
| 6583 |
</form> |
| 6584 |
</field> |
| 6585 |
</group> |
| 6586 |
</form> |
| 6587 |
`, |
| 6588 |
resId: 1, |
| 6589 |
}); |
| 6590 |
expect.verifySteps(["partner.web_read"]); |
| 6591 |
|
| 6592 |
// trigger the onchange |
| 6593 |
await contains(`.o_field_widget[name=foo] input`).edit("coucou"); |
| 6594 |
expect.verifySteps(["partner.onchange"]); |
| 6595 |
|
| 6596 |
// open a subrecord and trigger an onchange |
| 6597 |
await contains(`.o_data_row .o_data_cell`).click(); |
| 6598 |
expect.verifySteps(["partner.type.web_read"]); |
| 6599 |
|
| 6600 |
await contains(`.modal .o_field_widget[name=name] input`).edit("new name"); |
| 6601 |
expect.verifySteps(["partner.type.onchange"]); |
| 6602 |
}); |
| 6603 |
|
| 6604 |
test(`onchanges on date(time) fields`, async () => { |
| 6605 |
mockTimeZone(2); |
| 6606 |
|
| 6607 |
Partner._onChanges = { |
| 6608 |
foo(record) { |
| 6609 |
record.date = "2021-12-12"; |
| 6610 |
record.datetime = "2021-12-12 10:55:05"; |
| 6611 |
}, |
| 6612 |
}; |
| 6613 |
|
| 6614 |
await mountView({ |
| 6615 |
resModel: "partner", |
| 6616 |
type: "form", |
| 6617 |
arch: ` |
| 6618 |
<form> |
| 6619 |
<field name="foo"/> |
| 6620 |
<field name="date"/> |
| 6621 |
<field name="datetime"/> |
| 6622 |
</form> |
| 6623 |
`, |
| 6624 |
resId: 1, |
| 6625 |
}); |
| 6626 |
expect(`.o_field_widget[name=date] button`).toHaveValue("01/25/2017"); |
| 6627 |
expect(`.o_field_widget[name=datetime] button`).toHaveValue("12/12/2016 12:55:05"); |
| 6628 |
|
| 6629 |
// trigger the onchange |
| 6630 |
await contains(`.o_field_widget[name="foo"] input`).edit("coucou"); |
| 6631 |
expect(`.o_field_widget[name=date] button`).toHaveValue("12/12/2021"); |
| 6632 |
expect(`.o_field_widget[name=datetime] button`).toHaveValue("12/12/2021 12:55:05"); |
| 6633 |
}); |
| 6634 |
|
| 6635 |
test(`onchanges are not sent for invalid values`, async () => { |
| 6636 |
Partner._onChanges = { |
| 6637 |
int_field(record) { |
| 6638 |
record.foo = String(record.int_field); |
| 6639 |
}, |
| 6640 |
}; |
| 6641 |
|
| 6642 |
onRpc(({ method }) => expect.step(method)); |
| 6643 |
await mountView({ |
| 6644 |
resModel: "partner", |
| 6645 |
type: "form", |
| 6646 |
arch: `<form><field name="foo"/><field name="int_field"/></form>`, |
| 6647 |
resId: 2, |
| 6648 |
}); |
| 6649 |
expect.verifySteps(["get_views", "web_read"]); |
| 6650 |
|
| 6651 |
// edit int_field, and check that an onchange has been applied |
| 6652 |
await contains(`.o_field_widget[name="int_field"] input`).edit("123"); |
| 6653 |
expect(`.o_field_widget[name="foo"] input`).toHaveValue("123"); |
| 6654 |
|
| 6655 |
// enter an invalid value in a float, and check that no onchange has |
| 6656 |
// been applied |
| 6657 |
await contains(`.o_field_widget[name="int_field"] input`).edit("123a"); |
| 6658 |
expect(`.o_field_widget[name="foo"] input`).toHaveValue("123"); |
| 6659 |
expect.verifySteps(["onchange"]); |
| 6660 |
|
| 6661 |
// save, and check that the int_field input is marked as invalid |
| 6662 |
await contains(`.o_form_button_save`).click(); |
| 6663 |
expect(`.o_field_widget[name="int_field"]`).toHaveClass("o_field_invalid"); |
| 6664 |
expect.verifySteps([]); |
| 6665 |
}); |
| 6666 |
|
| 6667 |
test(`rpc complete after destroying parent`, async () => { |
| 6668 |
Partner._views = { |
| 6669 |
form: ` |
| 6670 |
<form> |
| 6671 |
<button name="update_module" type="object" class="o_form_button_update"/> |
| 6672 |
</form> |
| 6673 |
`, |
| 6674 |
list: `<list><field name="display_name"/></list>`, |
| 6675 |
}; |
| 6676 |
|
| 6677 |
defineActions([ |
| 6678 |
{ |
| 6679 |
id: 1, |
| 6680 |
name: "Partner", |
| 6681 |
res_model: "partner", |
| 6682 |
res_id: 1, |
| 6683 |
views: [[false, "form"]], |
| 6684 |
target: "new", |
| 6685 |
}, |
| 6686 |
{ |
| 6687 |
id: 2, |
| 6688 |
name: "Partner 2", |
| 6689 |
res_model: "partner", |
| 6690 |
views: [[false, "list"]], |
| 6691 |
}, |
| 6692 |
]); |
| 6693 |
|
| 6694 |
const deferred = new Deferred(); |
| 6695 |
onRpc("update_module", async () => { |
| 6696 |
await deferred; |
| 6697 |
return { type: "ir.actions.act_window_close" }; |
| 6698 |
}); |
| 6699 |
await mountWithCleanup(WebClient); |
| 6700 |
await getService("action").doAction(1); |
| 6701 |
expect(`.o_form_view`).toHaveCount(1); |
| 6702 |
|
| 6703 |
// should not crash when the call to "update_module" returns, as we should not |
| 6704 |
// try to reload the form view, which will no longer be in the DOM |
| 6705 |
await contains(`.o_form_button_update`).click(); |
| 6706 |
|
| 6707 |
// simulate that we executed another action before update_module returns |
| 6708 |
await getService("action").doAction(2); |
| 6709 |
expect(`.o_list_view`).toHaveCount(1); |
| 6710 |
|
| 6711 |
deferred.resolve(); // call to update_module finally returns |
| 6712 |
await animationFrame(); |
| 6713 |
expect(`.o_list_view`).toHaveCount(1); |
| 6714 |
}); |
| 6715 |
|
| 6716 |
test(`onchanges that complete after discarding`, async () => { |
| 6717 |
Partner._onChanges = { |
| 6718 |
foo(record) { |
| 6719 |
record.int_field = record.foo.length + 1000; |
| 6720 |
}, |
| 6721 |
}; |
| 6722 |
|
| 6723 |
const deferred = new Deferred(); |
| 6724 |
onRpc("onchange", async () => { |
| 6725 |
await deferred; |
| 6726 |
expect.step("onchange is done"); |
| 6727 |
}); |
| 6728 |
await mountView({ |
| 6729 |
resModel: "partner", |
| 6730 |
type: "form", |
| 6731 |
arch: `<form><field name="foo"/><field name="int_field"/></form>`, |
| 6732 |
resId: 2, |
| 6733 |
}); |
| 6734 |
expect(`.o_field_widget[name="foo"] input`).toHaveValue("blip"); |
| 6735 |
|
| 6736 |
// edit a field and discard |
| 6737 |
await contains(`.o_field_widget[name=foo] input`).edit("1234"); |
| 6738 |
await contains(`.o_form_button_cancel`).click(); |
| 6739 |
expect(`.modal`).toHaveCount(0); |
| 6740 |
expect(`.o_field_widget[name="foo"] input`).toHaveValue("1234"); |
| 6741 |
expect.verifySteps([]); |
| 6742 |
|
| 6743 |
// complete the onchange |
| 6744 |
deferred.resolve(); |
| 6745 |
await animationFrame(); |
| 6746 |
expect(`.o_field_widget[name="foo"] input`).toHaveValue("blip"); |
| 6747 |
expect.verifySteps(["onchange is done"]); |
| 6748 |
}); |
| 6749 |
|
| 6750 |
test(`discarding before save returns`, async () => { |
| 6751 |
const deferred = new Deferred(); |
| 6752 |
onRpc("web_save", async () => { |
| 6753 |
await deferred; |
| 6754 |
}); |
| 6755 |
const view = await mountView({ |
| 6756 |
resModel: "partner", |
| 6757 |
type: "form", |
| 6758 |
arch: `<form><field name="foo"/></form>`, |
| 6759 |
resId: 2, |
| 6760 |
}); |
| 6761 |
const form = findComponent(view, (c) => c instanceof FormController); |
| 6762 |
|
| 6763 |
expect(`.o_form_view .o_form_editable`).toHaveCount(1); |
| 6764 |
await contains(`.o_field_widget[name=foo] input`).edit("1234"); |
| 6765 |
|
| 6766 |
// save the value and discard directly |
| 6767 |
await contains(`.o_form_button_save`).click(); |
| 6768 |
expect(`.o_form_button_cancel`).not.toBeEnabled(); |
| 6769 |
// with form view extensions, it may happen that someone tries to discard |
| 6770 |
// while there is a pending save, so we simulate this here |
| 6771 |
form.discard(); |
| 6772 |
await animationFrame(); |
| 6773 |
expect(`.o_form_view .o_form_editable`).toHaveCount(1); |
| 6774 |
expect(`.o_field_widget[name="foo"] input`).toHaveValue("1234"); |
| 6775 |
expect(`.modal`).toHaveCount(0); |
| 6776 |
|
| 6777 |
// complete the write |
| 6778 |
deferred.resolve(); |
| 6779 |
await animationFrame(); |
| 6780 |
expect(`.modal`).toHaveCount(0); |
| 6781 |
expect(`.o_field_widget[name="foo"] input`).toHaveValue("1234"); |
| 6782 |
}); |
| 6783 |
|
| 6784 |
test(`unchanged relational data is not sent for onchanges`, async () => { |
| 6785 |
Partner._records[1].child_ids = [4]; |
| 6786 |
Partner._onChanges = { |
| 6787 |
foo(record) { |
| 6788 |
record.int_field = record.foo.length + 1000; |
| 6789 |
}, |
| 6790 |
}; |
| 6791 |
|
| 6792 |
onRpc("onchange", ({ args }) => { |
| 6793 |
expect.step("onchange"); |
| 6794 |
expect(args[1]).toEqual({ foo: "trigger an onchange" }); |
| 6795 |
}); |
| 6796 |
await mountView({ |
| 6797 |
resModel: "partner", |
| 6798 |
type: "form", |
| 6799 |
arch: ` |
| 6800 |
<form> |
| 6801 |
<field name="foo"/> |
| 6802 |
<field name="int_field"/> |
| 6803 |
<field name="child_ids"> |
| 6804 |
<list> |
| 6805 |
<field name="foo"/> |
| 6806 |
<field name="bar"/> |
| 6807 |
</list> |
| 6808 |
</field> |
| 6809 |
</form> |
| 6810 |
`, |
| 6811 |
resId: 2, |
| 6812 |
}); |
| 6813 |
await contains(`.o_field_widget[name=foo] input`).edit("trigger an onchange"); |
| 6814 |
expect.verifySteps(["onchange"]); |
| 6815 |
}); |
| 6816 |
|
| 6817 |
test(`onchange value are not discarded on o2m edition`, async () => { |
| 6818 |
Partner._records[1].child_ids = [4]; |
| 6819 |
Partner._onChanges = { |
| 6820 |
foo() {}, |
| 6821 |
}; |
| 6822 |
|
| 6823 |
onRpc("onchange", () => ({ |
| 6824 |
value: { |
| 6825 |
child_ids: [[1, 4, { foo: "foo changed" }]], |
| 6826 |
}, |
| 6827 |
})); |
| 6828 |
onRpc("web_save", ({ args }) => { |
| 6829 |
expect.step("web_save"); |
| 6830 |
expect(args[1].child_ids).toEqual([[1, 4, { foo: "foo changed" }]]); |
| 6831 |
}); |
| 6832 |
|
| 6833 |
await mountView({ |
| 6834 |
resModel: "partner", |
| 6835 |
type: "form", |
| 6836 |
arch: ` |
| 6837 |
<form> |
| 6838 |
<field name="foo"/> |
| 6839 |
<field name="int_field"/> |
| 6840 |
<field name="child_ids"> |
| 6841 |
<list> |
| 6842 |
<field name="foo"/> |
| 6843 |
<field name="bar"/> |
| 6844 |
</list> |
| 6845 |
<form> |
| 6846 |
<field name="foo"/> |
| 6847 |
<field name="product_id"/> |
| 6848 |
</form> |
| 6849 |
</field> |
| 6850 |
</form> |
| 6851 |
`, |
| 6852 |
resId: 2, |
| 6853 |
}); |
| 6854 |
expect(`.o_data_row .o_data_cell[name=foo]`).toHaveText("My little Foo Value"); |
| 6855 |
|
| 6856 |
await contains(`.o_field_widget[name=foo] input`).edit("trigger an onchange"); |
| 6857 |
expect(`.o_data_row .o_data_cell[name=foo]`).toHaveText("foo changed"); |
| 6858 |
|
| 6859 |
await contains(`.o_data_row .o_data_cell`).click(); |
| 6860 |
expect(`.modal .modal-title`).toHaveText("Open: one2many field"); |
| 6861 |
expect(`.modal .o_field_widget[name=foo] input`).toHaveValue("foo changed"); |
| 6862 |
}); |
| 6863 |
|
| 6864 |
test(`args of onchanges in o2m fields are correct (inline edition)`, async () => { |
| 6865 |
Partner._fields.int_field = fields.Integer({ default: 14 }); |
| 6866 |
Partner._onChanges = { |
| 6867 |
int_field(record) { |
| 6868 |
record.foo = "[blip] " + record.int_field; |
| 6869 |
}, |
| 6870 |
}; |
| 6871 |
Partner._records[1].child_ids = [4]; |
| 6872 |
|
| 6873 |
await mountView({ |
| 6874 |
resModel: "partner", |
| 6875 |
type: "form", |
| 6876 |
arch: ` |
| 6877 |
<form> |
| 6878 |
<field name="foo"/> |
| 6879 |
<field name="child_ids"> |
| 6880 |
<list editable="top"> |
| 6881 |
<field name="foo"/> |
| 6882 |
<field name="int_field"/> |
| 6883 |
</list> |
| 6884 |
</field> |
| 6885 |
</form> |
| 6886 |
`, |
| 6887 |
resId: 2, |
| 6888 |
}); |
| 6889 |
expect(`.o_data_row td[name=foo]`).toHaveText("My little Foo Value"); |
| 6890 |
|
| 6891 |
await contains(`.o_data_row td:eq(1)`).click(); |
| 6892 |
await contains(`.o_field_widget[name=int_field] input`).edit("77", { confirm: false }); |
| 6893 |
await contains(`.o_content`).click(); |
| 6894 |
expect(`.o_data_row td[name=foo]`).toHaveText("[blip] 77"); |
| 6895 |
|
| 6896 |
// create a new o2m record |
| 6897 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 6898 |
expect(`.o_data_row input:eq(0)`).toHaveValue("[blip] 14"); |
| 6899 |
}); |
| 6900 |
|
| 6901 |
test(`args of onchanges in o2m fields are correct (dialog edition)`, async () => { |
| 6902 |
Partner._fields.int_field = fields.Integer({ default: 14 }); |
| 6903 |
Partner._onChanges = { |
| 6904 |
int_field(record) { |
| 6905 |
record.foo = "[blip] " + record.int_field; |
| 6906 |
}, |
| 6907 |
}; |
| 6908 |
Partner._records[1].child_ids = [4]; |
| 6909 |
|
| 6910 |
await mountView({ |
| 6911 |
resModel: "partner", |
| 6912 |
type: "form", |
| 6913 |
arch: ` |
| 6914 |
<form> |
| 6915 |
<field name="foo"/> |
| 6916 |
<field name="child_ids" string="custom label"> |
| 6917 |
<list> |
| 6918 |
<field name="foo"/> |
| 6919 |
</list> |
| 6920 |
<form> |
| 6921 |
<field name="foo"/> |
| 6922 |
<field name="int_field"/> |
| 6923 |
</form> |
| 6924 |
</field> |
| 6925 |
</form> |
| 6926 |
`, |
| 6927 |
resId: 2, |
| 6928 |
}); |
| 6929 |
expect(`.o_data_row .o_data_cell`).toHaveText("My little Foo Value"); |
| 6930 |
|
| 6931 |
await contains(`.o_data_row td`).click(); |
| 6932 |
await contains(`.modal .o_field_widget[name=int_field] input`).edit("77"); |
| 6933 |
expect(`.modal .o_field_widget[name=foo] input`).toHaveValue("[blip] 77"); |
| 6934 |
|
| 6935 |
await contains(`.modal-footer .btn-primary`).click(); |
| 6936 |
expect(`.o_data_row .o_data_cell`).toHaveText("[blip] 77"); |
| 6937 |
|
| 6938 |
// create a new o2m record |
| 6939 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 6940 |
expect(`.modal .modal-title`).toHaveText("Create custom label"); |
| 6941 |
expect(`.modal .o_field_widget[name=foo] input`).toHaveValue("[blip] 14"); |
| 6942 |
await contains(`.modal-footer .btn-primary`).click(); |
| 6943 |
expect(`.o_data_row:eq(1) .o_data_cell`).toHaveText("[blip] 14"); |
| 6944 |
}); |
| 6945 |
|
| 6946 |
test(`context of onchanges contains the context of changed fields`, async () => { |
| 6947 |
Partner._onChanges = { |
| 6948 |
foo() {}, |
| 6949 |
}; |
| 6950 |
|
| 6951 |
onRpc("onchange", ({ kwargs }) => { |
| 6952 |
expect.step("onchange"); |
| 6953 |
expect(kwargs.context.test).toBe(1); |
| 6954 |
expect(kwargs.context.int_ctx).toBeEmpty(); |
| 6955 |
}); |
| 6956 |
await mountView({ |
| 6957 |
resModel: "partner", |
| 6958 |
type: "form", |
| 6959 |
arch: ` |
| 6960 |
<form> |
| 6961 |
<field name="foo" context="{'test': 1}"/> |
| 6962 |
<field name="int_field" context="{'int_ctx': 1}"/> |
| 6963 |
</form> |
| 6964 |
`, |
| 6965 |
resId: 2, |
| 6966 |
}); |
| 6967 |
await contains(`.o_field_widget[name=foo] input`).edit("coucou"); |
| 6968 |
expect.verifySteps(["onchange"]); |
| 6969 |
}); |
| 6970 |
|
| 6971 |
test.tags("desktop"); |
| 6972 |
test(`clicking on a stat button with a context on desktop`, async () => { |
| 6973 |
mockService("action", { |
| 6974 |
doActionButton({ buttonContext }) { |
| 6975 |
// button context should have been evaluated and given to the |
| 6976 |
// action, with magic keys but without previous context |
| 6977 |
expect(buttonContext).toEqual({ test: 2 }); |
| 6978 |
expect.step("doActionButton"); |
| 6979 |
}, |
| 6980 |
}); |
| 6981 |
|
| 6982 |
await mountView({ |
| 6983 |
resModel: "partner", |
| 6984 |
type: "form", |
| 6985 |
arch: ` |
| 6986 |
<form> |
| 6987 |
<sheet> |
| 6988 |
<div class="oe_button_box" name="button_box"> |
| 6989 |
<button class="oe_stat_button" type="action" name="1" context="{'test': id}"> |
| 6990 |
<field name="float_field" widget="statinfo"/> |
| 6991 |
</button> |
| 6992 |
</div> |
| 6993 |
</sheet> |
| 6994 |
</form>`, |
| 6995 |
resId: 2, |
| 6996 |
context: { some_context: true }, |
| 6997 |
}); |
| 6998 |
await contains(`button.oe_stat_button`).click(); |
| 6999 |
expect.verifySteps(["doActionButton"]); |
| 7000 |
}); |
| 7001 |
|
| 7002 |
test.tags("mobile"); |
| 7003 |
test(`clicking on a stat button with a context on mobile`, async () => { |
| 7004 |
mockService("action", { |
| 7005 |
doActionButton({ buttonContext }) { |
| 7006 |
// button context should have been evaluated and given to the |
| 7007 |
// action, with magic keys but without previous context |
| 7008 |
expect(buttonContext).toEqual({ test: 2 }); |
| 7009 |
expect.step("doActionButton"); |
| 7010 |
}, |
| 7011 |
}); |
| 7012 |
|
| 7013 |
await mountView({ |
| 7014 |
resModel: "partner", |
| 7015 |
type: "form", |
| 7016 |
arch: ` |
| 7017 |
<form> |
| 7018 |
<sheet> |
| 7019 |
<div class="oe_button_box" name="button_box"> |
| 7020 |
<button class="oe_stat_button" type="action" name="1" context="{'test': id}"> |
| 7021 |
<field name="float_field" widget="statinfo"/> |
| 7022 |
</button> |
| 7023 |
</div> |
| 7024 |
</sheet> |
| 7025 |
</form>`, |
| 7026 |
resId: 2, |
| 7027 |
context: { some_context: true }, |
| 7028 |
}); |
| 7029 |
await contains(".o-form-buttonbox .o_button_more").click(); |
| 7030 |
await contains(`button.oe_stat_button`).click(); |
| 7031 |
expect.verifySteps(["doActionButton"]); |
| 7032 |
}); |
| 7033 |
|
| 7034 |
test.tags("desktop"); |
| 7035 |
test(`clicking on a stat button with x2many in context on desktop`, async () => { |
| 7036 |
Partner._records[1].type_ids = [12]; |
| 7037 |
|
| 7038 |
mockService("action", { |
| 7039 |
doActionButton({ buttonContext }) { |
| 7040 |
expect(buttonContext).toEqual({ test: [12] }); |
| 7041 |
expect.step("doActionButton"); |
| 7042 |
}, |
| 7043 |
}); |
| 7044 |
|
| 7045 |
await mountView({ |
| 7046 |
type: "form", |
| 7047 |
resModel: "partner", |
| 7048 |
arch: ` |
| 7049 |
<form> |
| 7050 |
<sheet> |
| 7051 |
<div class="oe_button_box" name="button_box"> |
| 7052 |
<button class="oe_stat_button" type="action" name="1" context="{'test': type_ids}"> |
| 7053 |
<field name="float_field" widget="statinfo"/> |
| 7054 |
</button> |
| 7055 |
</div> |
| 7056 |
<field name="type_ids" invisible="1"/> |
| 7057 |
</sheet> |
| 7058 |
</form> |
| 7059 |
`, |
| 7060 |
resId: 2, |
| 7061 |
context: { some_context: true }, |
| 7062 |
}); |
| 7063 |
await contains(`button.oe_stat_button`).click(); |
| 7064 |
expect.verifySteps(["doActionButton"]); |
| 7065 |
}); |
| 7066 |
|
| 7067 |
test.tags("mobile"); |
| 7068 |
test(`clicking on a stat button with x2many in context on mobile`, async () => { |
| 7069 |
Partner._records[1].type_ids = [12]; |
| 7070 |
|
| 7071 |
mockService("action", { |
| 7072 |
doActionButton({ buttonContext }) { |
| 7073 |
expect(buttonContext).toEqual({ test: [12] }); |
| 7074 |
expect.step("doActionButton"); |
| 7075 |
}, |
| 7076 |
}); |
| 7077 |
|
| 7078 |
await mountView({ |
| 7079 |
type: "form", |
| 7080 |
resModel: "partner", |
| 7081 |
arch: ` |
| 7082 |
<form> |
| 7083 |
<sheet> |
| 7084 |
<div class="oe_button_box" name="button_box"> |
| 7085 |
<button class="oe_stat_button" type="action" name="1" context="{'test': type_ids}"> |
| 7086 |
<field name="float_field" widget="statinfo"/> |
| 7087 |
</button> |
| 7088 |
</div> |
| 7089 |
<field name="type_ids" invisible="1"/> |
| 7090 |
</sheet> |
| 7091 |
</form> |
| 7092 |
`, |
| 7093 |
resId: 2, |
| 7094 |
context: { some_context: true }, |
| 7095 |
}); |
| 7096 |
await contains(".o-form-buttonbox .o_button_more").click(); |
| 7097 |
await contains(`button.oe_stat_button`).click(); |
| 7098 |
expect.verifySteps(["doActionButton"]); |
| 7099 |
}); |
| 7100 |
|
| 7101 |
test.tags("desktop"); |
| 7102 |
test(`clicking on a stat button with no context on desktop`, async () => { |
| 7103 |
mockService("action", { |
| 7104 |
doActionButton({ buttonContext }) { |
| 7105 |
// button context should have been evaluated and given to the |
| 7106 |
// action, with magic keys but without previous context |
| 7107 |
expect(buttonContext).toEqual({}); |
| 7108 |
expect.step("doActionButton"); |
| 7109 |
}, |
| 7110 |
}); |
| 7111 |
|
| 7112 |
await mountView({ |
| 7113 |
resModel: "partner", |
| 7114 |
type: "form", |
| 7115 |
arch: ` |
| 7116 |
<form> |
| 7117 |
<sheet> |
| 7118 |
<div class="oe_button_box" name="button_box"> |
| 7119 |
<button class="oe_stat_button" type="action" name="1"> |
| 7120 |
<field name="float_field" widget="statinfo"/> |
| 7121 |
</button> |
| 7122 |
</div> |
| 7123 |
</sheet> |
| 7124 |
</form> |
| 7125 |
`, |
| 7126 |
resId: 2, |
| 7127 |
context: { some_context: true }, |
| 7128 |
}); |
| 7129 |
await contains(`button.oe_stat_button`).click(); |
| 7130 |
expect.verifySteps(["doActionButton"]); |
| 7131 |
}); |
| 7132 |
|
| 7133 |
test.tags("mobile"); |
| 7134 |
test(`clicking on a stat button with no context on mobile`, async () => { |
| 7135 |
mockService("action", { |
| 7136 |
doActionButton({ buttonContext }) { |
| 7137 |
// button context should have been evaluated and given to the |
| 7138 |
// action, with magic keys but without previous context |
| 7139 |
expect(buttonContext).toEqual({}); |
| 7140 |
expect.step("doActionButton"); |
| 7141 |
}, |
| 7142 |
}); |
| 7143 |
|
| 7144 |
await mountView({ |
| 7145 |
resModel: "partner", |
| 7146 |
type: "form", |
| 7147 |
arch: ` |
| 7148 |
<form> |
| 7149 |
<sheet> |
| 7150 |
<div class="oe_button_box" name="button_box"> |
| 7151 |
<button class="oe_stat_button" type="action" name="1"> |
| 7152 |
<field name="float_field" widget="statinfo"/> |
| 7153 |
</button> |
| 7154 |
</div> |
| 7155 |
</sheet> |
| 7156 |
</form> |
| 7157 |
`, |
| 7158 |
resId: 2, |
| 7159 |
context: { some_context: true }, |
| 7160 |
}); |
| 7161 |
await contains(".o-form-buttonbox .o_button_more").click(); |
| 7162 |
await contains(`button.oe_stat_button`).click(); |
| 7163 |
expect.verifySteps(["doActionButton"]); |
| 7164 |
}); |
| 7165 |
|
| 7166 |
test(`display a stat button outside a buttonbox`, async () => { |
| 7167 |
await mountView({ |
| 7168 |
resModel: "partner", |
| 7169 |
type: "form", |
| 7170 |
arch: ` |
| 7171 |
<form> |
| 7172 |
<sheet> |
| 7173 |
<button class="oe_stat_button" type="action" name="1"> |
| 7174 |
<field name="int_field" widget="statinfo"/> |
| 7175 |
</button> |
| 7176 |
</sheet> |
| 7177 |
</form> |
| 7178 |
`, |
| 7179 |
resId: 2, |
| 7180 |
}); |
| 7181 |
expect(`button .o_field_widget`).toHaveCount(1); |
| 7182 |
expect(`button .o_field_widget > *`).toHaveCount(2); |
| 7183 |
expect(`button .o_field_widget .o_stat_value`).toHaveText("9"); |
| 7184 |
}); |
| 7185 |
|
| 7186 |
test.tags("desktop"); |
| 7187 |
test(`display something else than a button in a buttonbox on desktop`, async () => { |
| 7188 |
await mountView({ |
| 7189 |
resModel: "partner", |
| 7190 |
type: "form", |
| 7191 |
arch: ` |
| 7192 |
<form> |
| 7193 |
<div name="button_box" class="oe_button_box"> |
| 7194 |
<button type="recordect" class="oe_stat_button" icon="fa-check-square"> |
| 7195 |
<field name="bar"/> |
| 7196 |
</button> |
| 7197 |
<label/> |
| 7198 |
</div> |
| 7199 |
</form> |
| 7200 |
`, |
| 7201 |
resId: 2, |
| 7202 |
}); |
| 7203 |
expect(`.o-form-buttonbox > *`).toHaveCount(2); |
| 7204 |
expect(`.o-form-buttonbox > .oe_stat_button`).toHaveCount(1); |
| 7205 |
expect(`.o-form-buttonbox > label`).toHaveCount(1); |
| 7206 |
}); |
| 7207 |
|
| 7208 |
test.tags("mobile"); |
| 7209 |
test(`display something else than a button in a buttonbox on mobile`, async () => { |
| 7210 |
await mountView({ |
| 7211 |
resModel: "partner", |
| 7212 |
type: "form", |
| 7213 |
arch: ` |
| 7214 |
<form> |
| 7215 |
<div name="button_box" class="oe_button_box"> |
| 7216 |
<button type="recordect" class="oe_stat_button" icon="fa-check-square"> |
| 7217 |
<field name="bar"/> |
| 7218 |
</button> |
| 7219 |
<label/> |
| 7220 |
</div> |
| 7221 |
</form> |
| 7222 |
`, |
| 7223 |
resId: 2, |
| 7224 |
}); |
| 7225 |
await contains(".o-form-buttonbox .o_button_more").click(); |
| 7226 |
expect(`.o-form-buttonbox-small > .o-dropdown-item`).toHaveCount(2); |
| 7227 |
expect(`.o-form-buttonbox-small > .o-dropdown-item > .oe_stat_button`).toHaveCount(1); |
| 7228 |
expect(`.o-form-buttonbox-small > .o-dropdown-item > label`).toHaveCount(1); |
| 7229 |
}); |
| 7230 |
|
| 7231 |
test.tags("desktop"); |
| 7232 |
test(`invisible fields are not considered as visible in a buttonbox on desktop`, async () => { |
| 7233 |
await mountView({ |
| 7234 |
resModel: "partner", |
| 7235 |
type: "form", |
| 7236 |
arch: ` |
| 7237 |
<form> |
| 7238 |
<div name="button_box" class="oe_button_box"> |
| 7239 |
<field name="foo" invisible="1"/> |
| 7240 |
<field name="bar" invisible="1"/> |
| 7241 |
<field name="int_field" invisible="1"/> |
| 7242 |
<field name="float_field" invisible="1"/> |
| 7243 |
<field name="display_name" invisible="1"/> |
| 7244 |
<field name="state" invisible="1"/> |
| 7245 |
<field name="date" invisible="1"/> |
| 7246 |
<field name="datetime" invisible="1"/> |
| 7247 |
<button type="recordect" class="oe_stat_button" icon="fa-check-square"/> |
| 7248 |
</div> |
| 7249 |
</form> |
| 7250 |
`, |
| 7251 |
resId: 2, |
| 7252 |
}); |
| 7253 |
expect(`.o-form-buttonbox > *`).toHaveCount(1); |
| 7254 |
expect(`.o-form-buttonbox`).toHaveClass("o_not_full"); |
| 7255 |
}); |
| 7256 |
|
| 7257 |
test.tags("mobile"); |
| 7258 |
test(`invisible fields are not considered as visible in a buttonbox on mobile`, async () => { |
| 7259 |
await mountView({ |
| 7260 |
resModel: "partner", |
| 7261 |
type: "form", |
| 7262 |
arch: ` |
| 7263 |
<form> |
| 7264 |
<div name="button_box" class="oe_button_box"> |
| 7265 |
<field name="foo" invisible="1"/> |
| 7266 |
<field name="bar" invisible="1"/> |
| 7267 |
<field name="int_field" invisible="1"/> |
| 7268 |
<field name="float_field" invisible="1"/> |
| 7269 |
<field name="display_name" invisible="1"/> |
| 7270 |
<field name="state" invisible="1"/> |
| 7271 |
<field name="date" invisible="1"/> |
| 7272 |
<field name="datetime" invisible="1"/> |
| 7273 |
<button type="recordect" class="oe_stat_button" icon="fa-check-square"/> |
| 7274 |
</div> |
| 7275 |
</form> |
| 7276 |
`, |
| 7277 |
resId: 2, |
| 7278 |
}); |
| 7279 |
expect(`.o-form-buttonbox > *`).toHaveCount(1); |
| 7280 |
expect(`.o-form-buttonbox`).toHaveClass("o_full"); |
| 7281 |
}); |
| 7282 |
|
| 7283 |
test(`display correctly buttonbox, in large size class`, async () => { |
| 7284 |
mockService("ui", (env) => { |
| 7285 |
Object.defineProperty(env, "isSmall", { |
| 7286 |
get() { |
| 7287 |
return false; |
| 7288 |
}, |
| 7289 |
}); |
| 7290 |
return { |
| 7291 |
bus: new EventBus(), |
| 7292 |
get size() { |
| 7293 |
return 6; |
| 7294 |
}, |
| 7295 |
isSmall: false, |
| 7296 |
}; |
| 7297 |
}); |
| 7298 |
|
| 7299 |
await mountView({ |
| 7300 |
resModel: "partner", |
| 7301 |
type: "form", |
| 7302 |
arch: ` |
| 7303 |
<form> |
| 7304 |
<div name="button_box" class="oe_button_box"> |
| 7305 |
<button type="recordect" class="oe_stat_button" icon="fa-check-square"> |
| 7306 |
<field name="bar"/> |
| 7307 |
</button> |
| 7308 |
<button type="recordect" class="oe_stat_button" icon="fa-check-square"> |
| 7309 |
<field name="foo"/> |
| 7310 |
</button> |
| 7311 |
</div> |
| 7312 |
</form> |
| 7313 |
`, |
| 7314 |
resId: 2, |
| 7315 |
}); |
| 7316 |
expect(`.o-form-buttonbox > *`).toHaveCount(2); |
| 7317 |
}); |
| 7318 |
|
| 7319 |
test(`empty button box`, async () => { |
| 7320 |
await mountView({ |
| 7321 |
resModel: "partner", |
| 7322 |
type: "form", |
| 7323 |
arch: `<form><div class="oe_button_box" name="button_box"/></form>`, |
| 7324 |
resId: 2, |
| 7325 |
}); |
| 7326 |
expect(`.o-form-buttonbox`).toHaveCount(0); |
| 7327 |
}); |
| 7328 |
|
| 7329 |
test(`button box accepts extra classes`, async () => { |
| 7330 |
await mountView({ |
| 7331 |
resModel: "partner", |
| 7332 |
type: "form", |
| 7333 |
arch: ` |
| 7334 |
<form> |
| 7335 |
<div class="oe_button_box my_class" name="button_box"><div/></div> |
| 7336 |
</form> |
| 7337 |
`, |
| 7338 |
resId: 2, |
| 7339 |
}); |
| 7340 |
expect(`.o-form-buttonbox.my_class`).toHaveCount(1); |
| 7341 |
}); |
| 7342 |
|
| 7343 |
test.tags("desktop"); |
| 7344 |
test(`many2manys inside one2manys are saved correctly`, async () => { |
| 7345 |
onRpc("web_save", ({ args }) => { |
| 7346 |
expect.step("web_save"); |
| 7347 |
const command = args[1].child_ids; |
| 7348 |
expect(command).toEqual([[0, command[0][1], { type_ids: [[4, 12]] }]]); |
| 7349 |
}); |
| 7350 |
|
| 7351 |
await mountView({ |
| 7352 |
resModel: "partner", |
| 7353 |
type: "form", |
| 7354 |
arch: ` |
| 7355 |
<form> |
| 7356 |
<field name="child_ids"> |
| 7357 |
<list editable="top"> |
| 7358 |
<field name="type_ids" widget="many2many_tags"/> |
| 7359 |
</list> |
| 7360 |
</field> |
| 7361 |
</form> |
| 7362 |
`, |
| 7363 |
}); |
| 7364 |
// add a o2m subrecord with a m2m tag |
| 7365 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 7366 |
await contains(`.o_input_dropdown input`).click(); |
| 7367 |
await contains(`.dropdown-item:contains(gold)`).click(); |
| 7368 |
await contains(`.o_form_button_save`).click(); |
| 7369 |
expect.verifySteps(["web_save"]); |
| 7370 |
}); |
| 7371 |
|
| 7372 |
test(`one2manys (list editable) inside one2manys are saved correctly`, async () => { |
| 7373 |
onRpc("web_save", ({ args }) => { |
| 7374 |
expect.step("web_save"); |
| 7375 |
const command = args[1].child_ids; |
| 7376 |
expect(command).toEqual([ |
| 7377 |
[ |
| 7378 |
0, |
| 7379 |
command[0][1], |
| 7380 |
{ child_ids: [[0, command[0][2].child_ids[0][1], { name: "xtv" }]] }, |
| 7381 |
], |
| 7382 |
]); |
| 7383 |
}); |
| 7384 |
|
| 7385 |
await mountView({ |
| 7386 |
resModel: "partner", |
| 7387 |
type: "form", |
| 7388 |
arch: ` |
| 7389 |
<form> |
| 7390 |
<field name="child_ids"> |
| 7391 |
<list><field name="child_ids"/></list> |
| 7392 |
<form> |
| 7393 |
<field name="child_ids"> |
| 7394 |
<list editable="top"> |
| 7395 |
<field name="name"/> |
| 7396 |
</list> |
| 7397 |
</field> |
| 7398 |
</form> |
| 7399 |
</field> |
| 7400 |
</form> |
| 7401 |
`, |
| 7402 |
}); |
| 7403 |
|
| 7404 |
// add a o2m subrecord |
| 7405 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 7406 |
await contains(`.modal .o_field_x2many_list_row_add a`).click(); |
| 7407 |
await contains(`.modal .o_field_widget[name=name] input`).edit("xtv"); |
| 7408 |
await contains(`.modal-footer .btn-primary`).click(); |
| 7409 |
expect(`.modal`).toHaveCount(0); |
| 7410 |
expect(`.o_data_cell`).toHaveText("1 record"); |
| 7411 |
|
| 7412 |
await contains(`.o_form_button_save`).click(); |
| 7413 |
expect.verifySteps(["web_save"]); |
| 7414 |
}); |
| 7415 |
|
| 7416 |
test.tags("desktop"); |
| 7417 |
test(`*_view_ref in context are passed correctly`, async () => { |
| 7418 |
PartnerType._views = { |
| 7419 |
"list,module.list_view_ref": `<list/>`, |
| 7420 |
}; |
| 7421 |
|
| 7422 |
onRpc("partner.type", "get_views", ({ kwargs }) => expect.step(kwargs.context.list_view_ref)); |
| 7423 |
onRpc(({ kwargs }) => expect.step(`${kwargs.context.some_context}`)); |
| 7424 |
await mountView({ |
| 7425 |
resModel: "partner", |
| 7426 |
type: "form", |
| 7427 |
arch: ` |
| 7428 |
<form> |
| 7429 |
<field name="type_ids" widget="one2many" context="{'list_view_ref':'module.list_view_ref'}"/> |
| 7430 |
</form> |
| 7431 |
`, |
| 7432 |
resId: 1, |
| 7433 |
resIds: [1, 2], |
| 7434 |
context: { some_context: 354 }, |
| 7435 |
}); |
| 7436 |
expect.verifySteps([ |
| 7437 |
"undefined", // main get_views |
| 7438 |
"undefined", // x2many get_views |
| 7439 |
"module.list_view_ref", // x2many get_views |
| 7440 |
"354", // read |
| 7441 |
]); |
| 7442 |
|
| 7443 |
// reload to check that the record's context hasn't been modified |
| 7444 |
await contains(`.o_pager_next`).click(); |
| 7445 |
expect.verifySteps(["354"]); |
| 7446 |
}); |
| 7447 |
|
| 7448 |
test(`non inline subview and create=0 in action context`, async () => { |
| 7449 |
// the create=0 should apply on the main view (form), but not on subviews |
| 7450 |
// this works because we pass the "base_model" in the context for the "get_views" call |
| 7451 |
Product._views = { |
| 7452 |
kanban: ` |
| 7453 |
<kanban> |
| 7454 |
<templates><t t-name="card"> |
| 7455 |
<field name="name"/> |
| 7456 |
</t></templates> |
| 7457 |
</kanban> |
| 7458 |
`, |
| 7459 |
}; |
| 7460 |
|
| 7461 |
await mountView({ |
| 7462 |
resModel: "partner", |
| 7463 |
type: "form", |
| 7464 |
arch: `<form><field name="product_ids" mode="kanban" widget="one2many"/></form>`, |
| 7465 |
resId: 1, |
| 7466 |
context: { create: false }, |
| 7467 |
}); |
| 7468 |
expect(`.o_form_button_create`).toHaveCount(0); |
| 7469 |
expect(`.o-kanban-button-new`).toHaveCount(1); |
| 7470 |
}); |
| 7471 |
|
| 7472 |
test(`readonly fields with modifiers may be saved`, async () => { |
| 7473 |
// the readonly property on the field description only applies on view, |
| 7474 |
// this is not a DB constraint. It should be seen as a default value, |
| 7475 |
// that may be overridden in views, for example with modifiers. So |
| 7476 |
// basically, a field defined as readonly may be edited. |
| 7477 |
Partner._fields.foo = fields.Char({ readonly: true }); |
| 7478 |
|
| 7479 |
onRpc("web_save", ({ args }) => { |
| 7480 |
expect.step("web_save"); |
| 7481 |
expect(args[1]).toEqual({ foo: "New foo value" }); |
| 7482 |
}); |
| 7483 |
await mountView({ |
| 7484 |
type: "form", |
| 7485 |
resModel: "partner", |
| 7486 |
arch: ` |
| 7487 |
<form> |
| 7488 |
<field name="foo" readonly="not bar"/> |
| 7489 |
<field name="bar"/> |
| 7490 |
</form> |
| 7491 |
`, |
| 7492 |
resId: 1, |
| 7493 |
}); |
| 7494 |
|
| 7495 |
// bar being set to true, foo shouldn't be readonly and thus its value |
| 7496 |
// could be saved, even if in its field description it is readonly |
| 7497 |
expect(`.o_field_widget[name="foo"] input`).toHaveCount(1); |
| 7498 |
await contains(`.o_field_widget[name="foo"] input`).edit("New foo value"); |
| 7499 |
await contains(`.o_form_button_save`).click(); |
| 7500 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("New foo value"); |
| 7501 |
expect.verifySteps(["web_save"]); |
| 7502 |
}); |
| 7503 |
|
| 7504 |
test(`readonly sub fields fields with force_save attribute`, async () => { |
| 7505 |
Partner._fields.foo = fields.Char({ readonly: true }); |
| 7506 |
Partner._fields.int_field = fields.Integer({ readonly: true }); |
| 7507 |
|
| 7508 |
onRpc("web_save", ({ args }) => { |
| 7509 |
// foo should be saved because of the "force_save" attribute |
| 7510 |
// float_field should be saved because it isn't readonly |
| 7511 |
// int_field should not be saved as it is readonly |
| 7512 |
expect.step("web_save"); |
| 7513 |
const commands = args[1].child_ids; |
| 7514 |
expect(commands).toEqual([[0, commands[0][1], { foo: "some value", float_field: 6.5 }]]); |
| 7515 |
}); |
| 7516 |
onRpc("onchange", () => { |
| 7517 |
expect.step("onchange"); |
| 7518 |
return { |
| 7519 |
value: { |
| 7520 |
child_ids: [[0, false, { foo: "some value", int_field: 44, float_field: 6.5 }]], |
| 7521 |
}, |
| 7522 |
}; |
| 7523 |
}); |
| 7524 |
await mountView({ |
| 7525 |
resModel: "partner", |
| 7526 |
type: "form", |
| 7527 |
arch: ` |
| 7528 |
<form> |
| 7529 |
<field name="child_ids"> |
| 7530 |
<list editable="bottom"> |
| 7531 |
<field name="foo" force_save="1"/> |
| 7532 |
<field name="int_field"/> |
| 7533 |
<field name="float_field"/> |
| 7534 |
</list> |
| 7535 |
</field> |
| 7536 |
</form> |
| 7537 |
`, |
| 7538 |
}); |
| 7539 |
expect.verifySteps(["onchange"]); |
| 7540 |
|
| 7541 |
await contains(`.o_form_button_save`).click(); |
| 7542 |
expect.verifySteps(["web_save"]); |
| 7543 |
}); |
| 7544 |
|
| 7545 |
test(`readonly set by modifier do not break many2many_tags`, async () => { |
| 7546 |
Partner._onChanges = { |
| 7547 |
bar(record) { |
| 7548 |
record.type_ids = [[4, 12]]; |
| 7549 |
}, |
| 7550 |
}; |
| 7551 |
|
| 7552 |
await mountView({ |
| 7553 |
resModel: "partner", |
| 7554 |
type: "form", |
| 7555 |
arch: ` |
| 7556 |
<form> |
| 7557 |
<field name="bar"/> |
| 7558 |
<field name="type_ids" widget="many2many_tags" readonly="bar"/> |
| 7559 |
</form> |
| 7560 |
`, |
| 7561 |
resId: 5, |
| 7562 |
}); |
| 7563 |
expect(`.o_field_widget[name=type_ids] .o_tag`).toHaveCount(0); |
| 7564 |
|
| 7565 |
await contains(`.o_field_widget[name=bar] input`).click(); |
| 7566 |
expect(`.o_field_widget[name=type_ids] .o_tag`).toHaveCount(1); |
| 7567 |
}); |
| 7568 |
|
| 7569 |
test(`check if id is available in evaluation context`, async () => { |
| 7570 |
let checkOnchange = false; |
| 7571 |
onRpc("onchange", ({ kwargs }) => { |
| 7572 |
if (checkOnchange) { |
| 7573 |
expect.step("onchange"); |
| 7574 |
expect(kwargs.context.current_id).toBe(false); |
| 7575 |
} |
| 7576 |
}); |
| 7577 |
|
| 7578 |
await mountView({ |
| 7579 |
resModel: "partner", |
| 7580 |
type: "form", |
| 7581 |
arch: ` |
| 7582 |
<form> |
| 7583 |
<field name="child_ids" context="{'current_id': id}"> |
| 7584 |
<list><field name="parent_id"/></list> |
| 7585 |
<form><field name="parent_id"/></form> |
| 7586 |
</field> |
| 7587 |
</form> |
| 7588 |
`, |
| 7589 |
}); |
| 7590 |
|
| 7591 |
checkOnchange = true; |
| 7592 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 7593 |
expect.verifySteps(["onchange"]); |
| 7594 |
}); |
| 7595 |
|
| 7596 |
test(`modifiers are considered on multiple <footer/> tags`, async () => { |
| 7597 |
Partner._views = { |
| 7598 |
form: ` |
| 7599 |
<form> |
| 7600 |
<field name="bar"/> |
| 7601 |
<footer invisible="not bar"> |
| 7602 |
<button>Hello</button> |
| 7603 |
<button>World</button> |
| 7604 |
</footer> |
| 7605 |
<footer invisible="bar"> |
| 7606 |
<button>Foo</button> |
| 7607 |
</footer> |
| 7608 |
</form> |
| 7609 |
`, |
| 7610 |
}; |
| 7611 |
|
| 7612 |
defineActions([ |
| 7613 |
{ |
| 7614 |
id: 1, |
| 7615 |
name: "Partner", |
| 7616 |
res_model: "partner", |
| 7617 |
res_id: 1, |
| 7618 |
views: [[false, "form"]], |
| 7619 |
target: "new", |
| 7620 |
}, |
| 7621 |
]); |
| 7622 |
|
| 7623 |
await mountWithCleanup(WebClient); |
| 7624 |
await getService("action").doAction(1); |
| 7625 |
expect(queryAllTexts`.modal-footer button:visible`).toEqual(["Hello", "World"]); |
| 7626 |
|
| 7627 |
await contains(`.o_field_boolean input`).click(); |
| 7628 |
expect(queryAllTexts`.modal-footer button:visible`).toEqual(["Foo"]); |
| 7629 |
}); |
| 7630 |
|
| 7631 |
test(`buttons in footer are moved to $buttons if necessary`, async () => { |
| 7632 |
Partner._views = { |
| 7633 |
form: ` |
| 7634 |
<form> |
| 7635 |
<field name="foo"/> |
| 7636 |
<footer> |
| 7637 |
<button string="Create" type="recordect" class="infooter"/> |
| 7638 |
</footer> |
| 7639 |
</form> |
| 7640 |
`, |
| 7641 |
}; |
| 7642 |
|
| 7643 |
defineActions([ |
| 7644 |
{ |
| 7645 |
id: 1, |
| 7646 |
name: "Partner", |
| 7647 |
res_model: "partner", |
| 7648 |
views: [[false, "form"]], |
| 7649 |
target: "new", |
| 7650 |
}, |
| 7651 |
]); |
| 7652 |
|
| 7653 |
await mountWithCleanup(WebClient); |
| 7654 |
await getService("action").doAction(1); |
| 7655 |
expect(`.modal-footer button.infooter`).toHaveCount(1); |
| 7656 |
expect(`.o_form_view button.infooter`).toHaveCount(0); |
| 7657 |
}); |
| 7658 |
|
| 7659 |
test(`open new record even with warning message`, async () => { |
| 7660 |
Partner._onChanges = { foo: true }; |
| 7661 |
|
| 7662 |
onRpc("onchange", () => ({ |
| 7663 |
warning: { |
| 7664 |
title: "Warning", |
| 7665 |
message: "Any warning.", |
| 7666 |
}, |
| 7667 |
value: {}, |
| 7668 |
})); |
| 7669 |
await mountView({ |
| 7670 |
resModel: "partner", |
| 7671 |
type: "form", |
| 7672 |
arch: `<form><group><field name="foo"/></group></form>`, |
| 7673 |
resId: 2, |
| 7674 |
}); |
| 7675 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("blip"); |
| 7676 |
|
| 7677 |
await contains(`.o_field_widget[name="foo"] input`).edit("tralala"); |
| 7678 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("tralala"); |
| 7679 |
|
| 7680 |
await contains(`.o_form_button_cancel`).click(); |
| 7681 |
await contains(`.o_form_button_create`).click(); |
| 7682 |
expect(`.o_field_widget[name=foo] input`).toHaveValue(""); |
| 7683 |
}); |
| 7684 |
|
| 7685 |
test.tags("desktop"); |
| 7686 |
test(`render stat button with string inline on desktop`, async () => { |
| 7687 |
await mountView({ |
| 7688 |
resModel: "partner", |
| 7689 |
type: "form", |
| 7690 |
resId: 1, |
| 7691 |
arch: ` |
| 7692 |
<form> |
| 7693 |
<sheet> |
| 7694 |
<div class="oe_button_box" name="button_box"> |
| 7695 |
<button string="Inventory Moves" class="oe_stat_button" icon="oi-arrows-v"/> |
| 7696 |
</div> |
| 7697 |
</sheet> |
| 7698 |
</form> |
| 7699 |
`, |
| 7700 |
}); |
| 7701 |
expect(`.o_form_view .o-form-buttonbox button.oe_stat_button`).toHaveText("Inventory Moves"); |
| 7702 |
}); |
| 7703 |
|
| 7704 |
test.tags("mobile"); |
| 7705 |
test(`render stat button with string inline on mobile`, async () => { |
| 7706 |
await mountView({ |
| 7707 |
resModel: "partner", |
| 7708 |
type: "form", |
| 7709 |
resId: 1, |
| 7710 |
arch: ` |
| 7711 |
<form> |
| 7712 |
<sheet> |
| 7713 |
<div class="oe_button_box" name="button_box"> |
| 7714 |
<button string="Inventory Moves" class="oe_stat_button" icon="oi-arrows-v"/> |
| 7715 |
</div> |
| 7716 |
</sheet> |
| 7717 |
</form> |
| 7718 |
`, |
| 7719 |
}); |
| 7720 |
await contains(".o-form-buttonbox .o_button_more").click(); |
| 7721 |
expect(`.o-form-buttonbox-small button.oe_stat_button`).toHaveText("Inventory Moves"); |
| 7722 |
}); |
| 7723 |
|
| 7724 |
test(`open one2many form containing one2many`, async () => { |
| 7725 |
Partner._records[0].product_ids = [37]; |
| 7726 |
|
| 7727 |
Product._fields.type_ids = fields.One2many({ relation: "partner.type" }); |
| 7728 |
Product._records[0].type_ids = [12]; |
| 7729 |
Product._views = { |
| 7730 |
form: ` |
| 7731 |
<form> |
| 7732 |
<field name="type_ids"> |
| 7733 |
<list create="0"> |
| 7734 |
<field name="display_name"/> |
| 7735 |
<field name="color"/> |
| 7736 |
</list> |
| 7737 |
</field> |
| 7738 |
</form> |
| 7739 |
`, |
| 7740 |
}; |
| 7741 |
|
| 7742 |
onRpc(({ method }) => expect.step(method)); |
| 7743 |
await mountView({ |
| 7744 |
resModel: "partner", |
| 7745 |
type: "form", |
| 7746 |
arch: ` |
| 7747 |
<form> |
| 7748 |
<field name="product_ids" widget="one2many"> |
| 7749 |
<list create="0"> |
| 7750 |
<field name="display_name"/> |
| 7751 |
<field name="type_ids"/> |
| 7752 |
</list> |
| 7753 |
</field> |
| 7754 |
</form> |
| 7755 |
`, |
| 7756 |
resId: 1, |
| 7757 |
}); |
| 7758 |
expect.verifySteps(["get_views", "web_read"]); |
| 7759 |
expect(`.o_data_row .o_data_cell:eq(1)`).toHaveText("1 record"); |
| 7760 |
|
| 7761 |
await contains(`.o_data_cell`).click(); |
| 7762 |
expect(`.modal .o_data_row .o_data_cell`).toHaveCount(2); |
| 7763 |
expect(queryAllTexts`.modal .o_data_cell`).toEqual(["gold", "2"]); |
| 7764 |
expect.verifySteps(["get_views", "web_read"]); |
| 7765 |
}); |
| 7766 |
|
| 7767 |
test(`no field should be focused`, async () => { |
| 7768 |
await mountView({ |
| 7769 |
resModel: "partner", |
| 7770 |
type: "form", |
| 7771 |
arch: `<form><field name="foo"/><field name="bar"/></form>`, |
| 7772 |
resId: 1, |
| 7773 |
}); |
| 7774 |
expect(document.body).toBeFocused(); |
| 7775 |
}); |
| 7776 |
|
| 7777 |
test.tags("desktop"); |
| 7778 |
test(`in create mode, first field is focused`, async () => { |
| 7779 |
await mountView({ |
| 7780 |
resModel: "partner", |
| 7781 |
type: "form", |
| 7782 |
arch: `<form><field name="foo"/><field name="bar"/></form>`, |
| 7783 |
}); |
| 7784 |
const input = queryFirst`.o_field_widget[name="foo"] input`; |
| 7785 |
expect(input).toBeFocused(); |
| 7786 |
expect(input.selectionStart).toBe(input.value.length); |
| 7787 |
}); |
| 7788 |
|
| 7789 |
test.tags("desktop"); |
| 7790 |
test(`in create mode, autofocus fields are focused`, async () => { |
| 7791 |
await mountView({ |
| 7792 |
resModel: "partner", |
| 7793 |
type: "form", |
| 7794 |
arch: `<form><field name="int_field"/><field name="foo" default_focus="1"/></form>`, |
| 7795 |
}); |
| 7796 |
expect(`.o_field_widget[name="foo"] input`).toBeFocused(); |
| 7797 |
}); |
| 7798 |
|
| 7799 |
test.tags("desktop"); |
| 7800 |
test(`in create mode, if two fields have default focus, the first gets the focus`, async () => { |
| 7801 |
await mountView({ |
| 7802 |
resModel: "partner", |
| 7803 |
type: "form", |
| 7804 |
arch: `<form><field name="int_field" default_focus="1"/><field name="foo" default_focus="1"/></form>`, |
| 7805 |
}); |
| 7806 |
expect(`.o_field_widget[name="int_field"] input`).toBeFocused(); |
| 7807 |
}); |
| 7808 |
|
| 7809 |
test.tags("desktop"); |
| 7810 |
test(`in create mode, if two fields have default focus but the first is invisible, the second gets the focus`, async () => { |
| 7811 |
await mountView({ |
| 7812 |
resModel: "partner", |
| 7813 |
type: "form", |
| 7814 |
arch: `<form><field name="int_field" default_focus="1" invisible="1"/><field name="foo" default_focus="1"/></form>`, |
| 7815 |
}); |
| 7816 |
expect(`.o_field_widget[name="foo"] input`).toBeFocused(); |
| 7817 |
}); |
| 7818 |
|
| 7819 |
test.tags("desktop"); |
| 7820 |
test(`autofocus first visible field`, async () => { |
| 7821 |
await mountView({ |
| 7822 |
resModel: "partner", |
| 7823 |
type: "form", |
| 7824 |
arch: `<form><field name="int_field" invisible="1"/><field name="foo"/></form>`, |
| 7825 |
}); |
| 7826 |
expect(`.o_field_widget[name="foo"] input`).toBeFocused(); |
| 7827 |
}); |
| 7828 |
|
| 7829 |
test(`on a touch screen, fields are not focused`, async () => { |
| 7830 |
mockTouch(true); |
| 7831 |
|
| 7832 |
await mountView({ |
| 7833 |
type: "form", |
| 7834 |
resModel: "partner", |
| 7835 |
arch: `<form><field name="foo"/><field name="bar"/></form>`, |
| 7836 |
}); |
| 7837 |
expect(`.o_field_widget[name="foo"] input`).not.toBeFocused(); |
| 7838 |
}); |
| 7839 |
|
| 7840 |
test(`no autofocus with disable_autofocus option`, async () => { |
| 7841 |
await mountView({ |
| 7842 |
resModel: "partner", |
| 7843 |
type: "form", |
| 7844 |
arch: `<form disable_autofocus="1"><field name="int_field"/></form>`, |
| 7845 |
}); |
| 7846 |
|
| 7847 |
expect(`.o_field_widget[name="int_field"] input`).not.toBeFocused(); |
| 7848 |
|
| 7849 |
await contains(`.o_form_button_save`).click(); |
| 7850 |
|
| 7851 |
expect(`.o_field_widget[name="int_field"] input`).not.toBeFocused(); |
| 7852 |
}); |
| 7853 |
|
| 7854 |
test.tags("desktop"); |
| 7855 |
test(`In READ mode, focus the first primary button of the form`, async () => { |
| 7856 |
await mountView({ |
| 7857 |
resModel: "partner", |
| 7858 |
type: "form", |
| 7859 |
arch: ` |
| 7860 |
<form edit="0"> |
| 7861 |
<field name="state" invisible="1"/> |
| 7862 |
<header> |
| 7863 |
<button name="post" class="btn-primary firstButton" string="Confirm" type="recordect"/> |
| 7864 |
<button name="post" class="btn-primary secondButton" string="Confirm2" type="recordect"/> |
| 7865 |
</header> |
| 7866 |
<sheet> |
| 7867 |
<group> |
| 7868 |
<div class="oe_title"> |
| 7869 |
<field name="display_name"/> |
| 7870 |
</div> |
| 7871 |
</group> |
| 7872 |
</sheet> |
| 7873 |
</form> |
| 7874 |
`, |
| 7875 |
resId: 2, |
| 7876 |
}); |
| 7877 |
expect(`button.firstButton`).toBeFocused(); |
| 7878 |
}); |
| 7879 |
|
| 7880 |
// should clearly be a mobile test too |
| 7881 |
test.tags("desktop"); |
| 7882 |
test(`check scroll on small height screens`, async () => { |
| 7883 |
Partner._views = { |
| 7884 |
list: `<list><field name="display_name"/></list>`, |
| 7885 |
form: `<form><field name="parent_id"/></form>`, |
| 7886 |
}; |
| 7887 |
PartnerType._views = { |
| 7888 |
list: `<list><field name="name"/></list>`, |
| 7889 |
}; |
| 7890 |
Product._views = { |
| 7891 |
list: `<list><field name="name"/></list>`, |
| 7892 |
}; |
| 7893 |
|
| 7894 |
onRpc("get_formview_id", () => false); |
| 7895 |
await mountViewInDialog({ |
| 7896 |
resModel: "partner", |
| 7897 |
type: "form", |
| 7898 |
arch: ` |
| 7899 |
<form> |
| 7900 |
<sheet> |
| 7901 |
<group> |
| 7902 |
<field name="display_name"/> |
| 7903 |
<field name="foo"/> |
| 7904 |
<field name="bar"/> |
| 7905 |
<field name="child_ids"/> |
| 7906 |
<field name="type_ids"/> |
| 7907 |
<field name="product_ids"/> |
| 7908 |
<field name="parent_id"/> |
| 7909 |
</group> |
| 7910 |
</sheet> |
| 7911 |
</form> |
| 7912 |
`, |
| 7913 |
resId: 2, |
| 7914 |
}); |
| 7915 |
|
| 7916 |
// we make the content height very small so we can test scrolling. |
| 7917 |
Object.assign(queryFirst(`.o_content`).style, { overflow: "auto", "max-height": "300px" }); |
| 7918 |
expect(`.modal-dialog`).toHaveCount(1); |
| 7919 |
|
| 7920 |
expect(queryFirst(`.o_content`).scrollTop).toBe(0); |
| 7921 |
// simply triggerEvent focus doesn't do the trick (doesn't scroll). |
| 7922 |
queryFirst(`[name='parent_id'] input`).focus(); |
| 7923 |
expect(queryFirst(`.o_content`).scrollTop).not.toBe(0); |
| 7924 |
|
| 7925 |
await contains(`.o_external_button`).click(); |
| 7926 |
await contains(`.o_dialog:not(.o_inactive_modal) button[class="btn-close"]`).click(); |
| 7927 |
expect(queryFirst(`.o_content`).scrollTop).not.toBe(0); |
| 7928 |
expect(`.modal-dialog`).toHaveCount(1); |
| 7929 |
}); |
| 7930 |
|
| 7931 |
test(`correct amount of buttons`, async () => { |
| 7932 |
let screenSize = SIZES.XXL; |
| 7933 |
mockService("ui", (env) => { |
| 7934 |
Object.defineProperty(env, "isSmall", { |
| 7935 |
get() { |
| 7936 |
return false; |
| 7937 |
}, |
| 7938 |
}); |
| 7939 |
return { |
| 7940 |
bus: new EventBus(), |
| 7941 |
get size() { |
| 7942 |
return screenSize; |
| 7943 |
}, |
| 7944 |
isSmall: false, |
| 7945 |
}; |
| 7946 |
}); |
| 7947 |
|
| 7948 |
const buttons = Array(8).join(` |
| 7949 |
<button type="recordect" class="oe_stat_button" icon="fa-check-square"> |
| 7950 |
<field name="bar"/> |
| 7951 |
</button> |
| 7952 |
`); |
| 7953 |
|
| 7954 |
const formView = await mountView({ |
| 7955 |
resModel: "partner", |
| 7956 |
type: "form", |
| 7957 |
arch: ` |
| 7958 |
<form> |
| 7959 |
<div name="button_box" class="oe_button_box"> |
| 7960 |
${buttons} |
| 7961 |
</div> |
| 7962 |
</form> |
| 7963 |
`, |
| 7964 |
resId: 2, |
| 7965 |
}); |
| 7966 |
|
| 7967 |
const assertFormContainsNButtonsWithSizeClass = async function (sizeClass, n) { |
| 7968 |
screenSize = sizeClass; |
| 7969 |
formView.render(true); // deep rendering |
| 7970 |
await animationFrame(); |
| 7971 |
expect(`.o-form-buttonbox button.oe_stat_button`).toHaveCount(n); |
| 7972 |
}; |
| 7973 |
|
| 7974 |
await assertFormContainsNButtonsWithSizeClass(SIZES.XS, 0); |
| 7975 |
await assertFormContainsNButtonsWithSizeClass(SIZES.SM, 0); |
| 7976 |
await assertFormContainsNButtonsWithSizeClass(SIZES.MD, 7); |
| 7977 |
await assertFormContainsNButtonsWithSizeClass(SIZES.LG, 3); |
| 7978 |
await assertFormContainsNButtonsWithSizeClass(SIZES.XL, 4); |
| 7979 |
await assertFormContainsNButtonsWithSizeClass(SIZES.XXL, 7); |
| 7980 |
}); |
| 7981 |
|
| 7982 |
test(`can set bin_size to false in context`, async () => { |
| 7983 |
onRpc("web_read", ({ kwargs }) => { |
| 7984 |
expect.step("web_read"); |
| 7985 |
expect(kwargs.context.bin_size).toBe(false); |
| 7986 |
}); |
| 7987 |
await mountView({ |
| 7988 |
resModel: "partner", |
| 7989 |
type: "form", |
| 7990 |
arch: `<form><field name="foo"/></form>`, |
| 7991 |
resId: 1, |
| 7992 |
context: { |
| 7993 |
bin_size: false, |
| 7994 |
}, |
| 7995 |
}); |
| 7996 |
expect.verifySteps(["web_read"]); |
| 7997 |
}); |
| 7998 |
|
| 7999 |
test(`create with false values`, async () => { |
| 8000 |
onRpc("web_save", ({ args }) => { |
| 8001 |
expect.step("web_save"); |
| 8002 |
expect(args[1].bar).toBe(false); |
| 8003 |
}); |
| 8004 |
await mountView({ |
| 8005 |
resModel: "partner", |
| 8006 |
type: "form", |
| 8007 |
arch: `<form><field name="bar"/></form>`, |
| 8008 |
}); |
| 8009 |
await contains(`.o_form_button_save`).click(); |
| 8010 |
expect.verifySteps(["web_save"]); |
| 8011 |
}); |
| 8012 |
|
| 8013 |
test(`open one2many form containing many2many_tags`, async () => { |
| 8014 |
Partner._records[0].product_ids = [37]; |
| 8015 |
Product._fields.type_ids = fields.Many2many({ relation: "partner.type" }); |
| 8016 |
Product._records[0].type_ids = [12, 14]; |
| 8017 |
|
| 8018 |
onRpc(({ method }) => expect.step(method)); |
| 8019 |
await mountView({ |
| 8020 |
type: "form", |
| 8021 |
resModel: "partner", |
| 8022 |
arch: ` |
| 8023 |
<form> |
| 8024 |
<field name="product_ids"> |
| 8025 |
<list create="0"> |
| 8026 |
<field name="display_name"/> |
| 8027 |
<field name="type_ids" widget="many2many_tags"/> |
| 8028 |
</list> |
| 8029 |
<form> |
| 8030 |
<group> |
| 8031 |
<label for="type_ids"/> |
| 8032 |
<div> |
| 8033 |
<field name="type_ids" widget="many2many_tags"/> |
| 8034 |
</div> |
| 8035 |
</group> |
| 8036 |
</form> |
| 8037 |
</field> |
| 8038 |
</form> |
| 8039 |
`, |
| 8040 |
resId: 1, |
| 8041 |
}); |
| 8042 |
expect.verifySteps(["get_views", "web_read"]); |
| 8043 |
|
| 8044 |
await contains(`.o_data_cell`).click(); |
| 8045 |
expect.verifySteps(["web_read"]); |
| 8046 |
}); |
| 8047 |
|
| 8048 |
test(`display toolbar`, async () => { |
| 8049 |
mockService("action", { |
| 8050 |
doAction(id, { additionalContext }) { |
| 8051 |
expect.step("doAction"); |
| 8052 |
expect(id).toBe(29); |
| 8053 |
expect(additionalContext.active_id).toBe(1); |
| 8054 |
expect(additionalContext.active_ids).toEqual([1]); |
| 8055 |
}, |
| 8056 |
}); |
| 8057 |
|
| 8058 |
await mountView({ |
| 8059 |
resModel: "partner", |
| 8060 |
type: "form", |
| 8061 |
arch: `<form><field name="bar"/></form>`, |
| 8062 |
resId: 1, |
| 8063 |
info: { |
| 8064 |
actionMenus: { |
| 8065 |
action: [ |
| 8066 |
{ |
| 8067 |
id: 29, |
| 8068 |
name: "Action partner", |
| 8069 |
}, |
| 8070 |
], |
| 8071 |
}, |
| 8072 |
}, |
| 8073 |
}); |
| 8074 |
await toggleActionMenu(); |
| 8075 |
expect(`.o_cp_action_menus .dropdown-menu_group:contains(Print)`).toHaveCount(0); |
| 8076 |
expect(`.o-dropdown--menu .dropdown-item`).toHaveCount(3); |
| 8077 |
expect(queryAllTexts`.o-dropdown--menu .dropdown-item`).toEqual([ |
| 8078 |
"Duplicate", |
| 8079 |
"Delete", |
| 8080 |
"Action partner", |
| 8081 |
]); |
| 8082 |
|
| 8083 |
await toggleMenuItem("Action partner"); |
| 8084 |
expect.verifySteps(["doAction"]); |
| 8085 |
}); |
| 8086 |
|
| 8087 |
test(`execute ActionMenus actions`, async () => { |
| 8088 |
mockService("action", { |
| 8089 |
doAction(id, { additionalContext, onClose }) { |
| 8090 |
expect.step({ action_id: id, context: additionalContext }); |
| 8091 |
onClose(); // simulate closing of target new action's dialog |
| 8092 |
}, |
| 8093 |
}); |
| 8094 |
|
| 8095 |
onRpc(({ method }) => expect.step(method)); |
| 8096 |
await mountView({ |
| 8097 |
resModel: "partner", |
| 8098 |
type: "form", |
| 8099 |
resId: 1, |
| 8100 |
arch: `<form><field name="bar"/></form>`, |
| 8101 |
info: { |
| 8102 |
actionMenus: { |
| 8103 |
action: [ |
| 8104 |
{ |
| 8105 |
id: 29, |
| 8106 |
name: "Action partner", |
| 8107 |
}, |
| 8108 |
], |
| 8109 |
}, |
| 8110 |
}, |
| 8111 |
}); |
| 8112 |
expect(`.o_cp_action_menus .dropdown-toggle`).toHaveCount(1); |
| 8113 |
expect.verifySteps(["get_views", "web_read"]); |
| 8114 |
|
| 8115 |
await toggleActionMenu(); |
| 8116 |
await toggleMenuItem("Action Partner"); |
| 8117 |
expect.verifySteps([ |
| 8118 |
{ |
| 8119 |
action_id: 29, |
| 8120 |
context: { |
| 8121 |
lang: "en", |
| 8122 |
tz: "taht", |
| 8123 |
uid: 7, |
| 8124 |
allowed_company_ids: [1], |
| 8125 |
active_id: 1, |
| 8126 |
active_ids: [1], |
| 8127 |
active_model: "partner", |
| 8128 |
active_domain: [], |
| 8129 |
}, |
| 8130 |
}, |
| 8131 |
"web_read", |
| 8132 |
]); |
| 8133 |
}); |
| 8134 |
|
| 8135 |
test(`execute ActionMenus actions (create)`, async () => { |
| 8136 |
mockService("action", { |
| 8137 |
doAction(id, { additionalContext, onClose }) { |
| 8138 |
expect.step({ action_id: id, context: additionalContext }); |
| 8139 |
onClose(); // simulate closing of target new action's dialog |
| 8140 |
}, |
| 8141 |
}); |
| 8142 |
|
| 8143 |
onRpc(({ method }) => expect.step(method)); |
| 8144 |
await mountView({ |
| 8145 |
resModel: "partner", |
| 8146 |
type: "form", |
| 8147 |
arch: `<form><field name="foo"/></form>`, |
| 8148 |
info: { |
| 8149 |
actionMenus: { |
| 8150 |
action: [ |
| 8151 |
{ |
| 8152 |
id: 29, |
| 8153 |
name: "Action partner", |
| 8154 |
}, |
| 8155 |
], |
| 8156 |
}, |
| 8157 |
}, |
| 8158 |
}); |
| 8159 |
expect(`.o_field_widget[name='foo'] input`).toHaveValue("My little Foo Value"); |
| 8160 |
expect.verifySteps(["get_views", "onchange"]); |
| 8161 |
|
| 8162 |
await contains(`.o_field_widget[name='foo'] input`).edit("test"); |
| 8163 |
expect(`.o_cp_action_menus .dropdown-toggle`).toHaveCount(1); |
| 8164 |
|
| 8165 |
await toggleActionMenu(); |
| 8166 |
await toggleMenuItem("Action Partner"); |
| 8167 |
expect.verifySteps([ |
| 8168 |
"web_save", |
| 8169 |
{ |
| 8170 |
action_id: 29, |
| 8171 |
context: { |
| 8172 |
lang: "en", |
| 8173 |
tz: "taht", |
| 8174 |
uid: 7, |
| 8175 |
allowed_company_ids: [1], |
| 8176 |
active_id: 6, |
| 8177 |
active_ids: [6], |
| 8178 |
active_model: "partner", |
| 8179 |
active_domain: [], |
| 8180 |
}, |
| 8181 |
}, |
| 8182 |
"web_read", |
| 8183 |
]); |
| 8184 |
expect(`.o_field_widget[name='foo'] input`).toHaveValue("test"); |
| 8185 |
}); |
| 8186 |
|
| 8187 |
test(`control panel is not present in FormViewDialogs`, async () => { |
| 8188 |
Partner._records[0].product_id = 37; |
| 8189 |
Product._views = { |
| 8190 |
form: `<form><field name="display_name"/></form>`, |
| 8191 |
list: `<list><field name="display_name"/></list>`, |
| 8192 |
}; |
| 8193 |
|
| 8194 |
onRpc("get_formview_id", () => false); |
| 8195 |
await mountViewInDialog({ |
| 8196 |
resModel: "partner", |
| 8197 |
type: "form", |
| 8198 |
arch: `<form><field name="product_id"/></form>`, |
| 8199 |
resId: 1, |
| 8200 |
}); |
| 8201 |
expect(`.modal`).toHaveCount(1); |
| 8202 |
expect(`.o_control_panel`).toHaveCount(0); |
| 8203 |
|
| 8204 |
await contains(`.o_external_button`, { visible: false }).click(); |
| 8205 |
expect(`.modal`).toHaveCount(2); |
| 8206 |
expect(`.o_control_panel`).toHaveCount(0); |
| 8207 |
}); |
| 8208 |
|
| 8209 |
test(`check interactions between multiple FormViewDialogs`, async () => { |
| 8210 |
Partner._records[0].product_id = 37; |
| 8211 |
Product._fields.product_ids = fields.One2many({ relation: "product" }); |
| 8212 |
Product._views = { |
| 8213 |
form: ` |
| 8214 |
<form> |
| 8215 |
<field name="name"/> |
| 8216 |
<field name="product_ids"/> |
| 8217 |
</form> |
| 8218 |
`, |
| 8219 |
list: `<list><field name="name"/></list>`, |
| 8220 |
}; |
| 8221 |
|
| 8222 |
onRpc("get_formview_id", () => false); |
| 8223 |
onRpc("web_save", ({ model, args }) => { |
| 8224 |
expect.step("web_save"); |
| 8225 |
expect(model).toBe("product"); |
| 8226 |
expect(args[1].product_ids[0][2].name).toBe("xtv"); |
| 8227 |
}); |
| 8228 |
await mountViewInDialog({ |
| 8229 |
resModel: "partner", |
| 8230 |
type: "form", |
| 8231 |
arch: `<form><field name="product_id"/></form>`, |
| 8232 |
resId: 1, |
| 8233 |
}); |
| 8234 |
expect(`.modal`).toHaveCount(1); |
| 8235 |
|
| 8236 |
await contains(`.o_external_button`, { visible: false }).click(); |
| 8237 |
expect(`.modal`).toHaveCount(2); |
| 8238 |
expect(`.o_dialog:eq(1) .modal-title`).toHaveText("Open: Product"); |
| 8239 |
expect(`.o_dialog:eq(1) .o_field_widget[name=name] input`).toHaveValue("xphone"); |
| 8240 |
|
| 8241 |
await contains(`.o_dialog:eq(1) .o_field_x2many_list_row_add a`).click(); |
| 8242 |
expect(`.modal`).toHaveCount(3); |
| 8243 |
|
| 8244 |
await contains(`.o_dialog:eq(2) .o_field_widget[name=name] input`).edit("xtv"); |
| 8245 |
await contains(`.o_dialog:eq(2) .modal-footer .btn-primary`).click(); |
| 8246 |
expect(`.modal`).toHaveCount(2); |
| 8247 |
expect(`.o_dialog:eq(1) .o_data_row .o_data_cell`).toHaveText("xtv"); |
| 8248 |
|
| 8249 |
await contains(`.o_dialog:eq(1) .modal-footer .btn-primary`).click(); |
| 8250 |
expect.verifySteps(["web_save"]); |
| 8251 |
}); |
| 8252 |
|
| 8253 |
test(`do not activate an hidden tab when switching between records`, async () => { |
| 8254 |
await mountView({ |
| 8255 |
resModel: "partner", |
| 8256 |
type: "form", |
| 8257 |
arch: ` |
| 8258 |
<form> |
| 8259 |
<sheet> |
| 8260 |
<notebook> |
| 8261 |
<page string="Foo" invisible='id == 2'> |
| 8262 |
<field name="foo"/> |
| 8263 |
</page> |
| 8264 |
<page string="Bar"> |
| 8265 |
<field name="bar"/> |
| 8266 |
</page> |
| 8267 |
</notebook> |
| 8268 |
</sheet> |
| 8269 |
</form> |
| 8270 |
`, |
| 8271 |
resIds: [1, 2], |
| 8272 |
resId: 1, |
| 8273 |
}); |
| 8274 |
expect(`.o_notebook .nav-item`).toHaveCount(2); |
| 8275 |
expect(`.o_notebook .nav-link:eq(0)`).toHaveClass("active"); |
| 8276 |
|
| 8277 |
// click on the pager to switch to the next record |
| 8278 |
await contains(`.o_pager_next`).click(); |
| 8279 |
expect(`.o_notebook .nav-item`).toHaveCount(1); |
| 8280 |
expect(`.o_notebook .nav-link`).toHaveClass("active"); |
| 8281 |
|
| 8282 |
// click on the pager to switch back to the previous record |
| 8283 |
await contains(`.o_pager_previous`).click(); |
| 8284 |
expect(`.o_notebook .nav-item`).toHaveCount(2); |
| 8285 |
expect(`.o_notebook .nav-link:eq(1)`).toHaveClass("active"); |
| 8286 |
}); |
| 8287 |
|
| 8288 |
test(`required fields inside notebook`, async () => { |
| 8289 |
await mountView({ |
| 8290 |
resModel: "partner", |
| 8291 |
type: "form", |
| 8292 |
arch: ` |
| 8293 |
<form> |
| 8294 |
<sheet> |
| 8295 |
<notebook> |
| 8296 |
<page string="Name"> |
| 8297 |
<field name="name" required="1"/> |
| 8298 |
</page> |
| 8299 |
<page string="Foo"> |
| 8300 |
<field name="foo" required="1"/> |
| 8301 |
</page> |
| 8302 |
</notebook> |
| 8303 |
</sheet> |
| 8304 |
</form> |
| 8305 |
`, |
| 8306 |
resId: 1, |
| 8307 |
}); |
| 8308 |
await contains(".o_field_char[name=name] input").clear(); |
| 8309 |
await contains(".o_notebook_headers .nav-link:last").click(); |
| 8310 |
await contains(".o_field_char[name=foo] input").clear(); |
| 8311 |
await clickSave(); |
| 8312 |
expect(".o_field_char[name=foo]").toHaveClass("o_field_invalid"); |
| 8313 |
expect(".o_notebook_headers .nav-link:first").toHaveClass("o_page_invalid"); |
| 8314 |
expect(".o_notebook_headers .nav-link:last").toHaveClass("o_page_invalid"); |
| 8315 |
expect(".o_form_button_save").not.toBeEnabled(); |
| 8316 |
await contains(".o_field_char[name=foo] input").edit("a"); |
| 8317 |
expect(".o_notebook_headers .nav-link:first").toHaveClass("o_page_invalid"); |
| 8318 |
expect(".o_notebook_headers .nav-link:last").not.toHaveClass("o_page_invalid"); |
| 8319 |
expect(".o_form_button_save").not.toBeEnabled(); |
| 8320 |
await contains(".o_notebook_headers .nav-link:first").click(); |
| 8321 |
await contains(".o_field_char[name=name] input").edit("b"); |
| 8322 |
expect(".o_notebook_headers .o_page_invalid").toHaveCount(0); |
| 8323 |
}); |
| 8324 |
|
| 8325 |
test(`support anchor tags with action type`, async () => { |
| 8326 |
mockService("action", { |
| 8327 |
doActionButton(action) { |
| 8328 |
expect.step("doActionButton"); |
| 8329 |
expect(action.name).toBe("42"); |
| 8330 |
}, |
| 8331 |
}); |
| 8332 |
|
| 8333 |
await mountView({ |
| 8334 |
resModel: "partner", |
| 8335 |
type: "form", |
| 8336 |
arch: ` |
| 8337 |
<form> |
| 8338 |
<a type="action" name="42" class="btn-primary"><i class="oi oi-arrow-right"/> Click me !</a> |
| 8339 |
</form> |
| 8340 |
`, |
| 8341 |
resId: 1, |
| 8342 |
}); |
| 8343 |
await contains(`a[type='action']`).click(); |
| 8344 |
expect(`a[type='action']`).toHaveClass("btn-primary"); |
| 8345 |
expect.verifySteps(["doActionButton"]); |
| 8346 |
}); |
| 8347 |
|
| 8348 |
test(`do not perform extra RPC to read invisible many2one fields`, async () => { |
| 8349 |
// an invisible manyone should only requests the id, not the display_name |
| 8350 |
// -> invisible: { parent_id: {} }, visible: { parent_id: { fields: { display_name }}} |
| 8351 |
Partner._fields.parent_id = fields.Many2one({ relation: "partner", default: 2 }); |
| 8352 |
|
| 8353 |
onRpc("onchange", ({ args }) => { |
| 8354 |
expect.step("onchange"); |
| 8355 |
expect(args[3]).toEqual({ |
| 8356 |
display_name: {}, |
| 8357 |
parent_id: { |
| 8358 |
fields: {}, // loads "id" only |
| 8359 |
}, |
| 8360 |
}); |
| 8361 |
}); |
| 8362 |
await mountView({ |
| 8363 |
resModel: "partner", |
| 8364 |
type: "form", |
| 8365 |
arch: `<form><field name="parent_id" invisible="1"/></form>`, |
| 8366 |
}); |
| 8367 |
expect.verifySteps(["onchange"]); |
| 8368 |
}); |
| 8369 |
|
| 8370 |
test(`do not perform extra RPC to read invisible x2many fields`, async () => { |
| 8371 |
Object.assign(Partner._records[0], { |
| 8372 |
child_ids: [2], // one2many |
| 8373 |
product_ids: [37], // one2many |
| 8374 |
type_ids: [12], // many2many |
| 8375 |
}); |
| 8376 |
|
| 8377 |
onRpc("web_read", ({ kwargs }) => { |
| 8378 |
expect.step("web_read"); |
| 8379 |
expect(kwargs.specification).toEqual({ |
| 8380 |
child_ids: {}, |
| 8381 |
product_ids: {}, |
| 8382 |
type_ids: {}, |
| 8383 |
display_name: {}, |
| 8384 |
}); |
| 8385 |
}); |
| 8386 |
await mountView({ |
| 8387 |
resModel: "partner", |
| 8388 |
type: "form", |
| 8389 |
arch: ` |
| 8390 |
<form> |
| 8391 |
<field name="child_ids" widget="one2many" invisible="1"/> |
| 8392 |
<field name="product_ids" widget="one2many" invisible="1"> |
| 8393 |
<list><field name="display_name"/></list> |
| 8394 |
</field> |
| 8395 |
<field name="type_ids" invisible="1" widget="many2many_tags"/> |
| 8396 |
</form> |
| 8397 |
`, |
| 8398 |
resId: 1, |
| 8399 |
}); |
| 8400 |
expect.verifySteps(["web_read"]); |
| 8401 |
}); |
| 8402 |
|
| 8403 |
test(`default_order on x2many embedded view`, async () => { |
| 8404 |
Partner._fields.name = fields.Char({ sortable: true }); |
| 8405 |
Partner._records[0].child_ids = [1, 4]; |
| 8406 |
|
| 8407 |
await mountView({ |
| 8408 |
resModel: "partner", |
| 8409 |
type: "form", |
| 8410 |
arch: ` |
| 8411 |
<form> |
| 8412 |
<field name="child_ids"> |
| 8413 |
<list default_order="foo desc"> |
| 8414 |
<field name="name"/> |
| 8415 |
<field name="foo"/> |
| 8416 |
</list> |
| 8417 |
<form><field name="foo"/></form>, |
| 8418 |
</field> |
| 8419 |
</form> |
| 8420 |
`, |
| 8421 |
resId: 1, |
| 8422 |
}); |
| 8423 |
|
| 8424 |
expect(queryAllTexts`.o_data_row .o_data_cell:nth-child(2)`).toEqual([ |
| 8425 |
"yop", |
| 8426 |
"My little Foo Value", |
| 8427 |
]); |
| 8428 |
|
| 8429 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 8430 |
expect(`.modal`).toHaveCount(1); |
| 8431 |
|
| 8432 |
await contains(`.modal .o_field_widget[name=foo] input`).edit("xop"); |
| 8433 |
await contains(`.modal-footer .o_form_button_save_new`).click(); |
| 8434 |
await contains(`.modal .o_field_widget[name=foo] input`).edit("zop"); |
| 8435 |
await contains(`.modal-footer .o_form_button_save`).click(); |
| 8436 |
|
| 8437 |
// client-side sort |
| 8438 |
expect(queryAllTexts`.o_data_row .o_data_cell:nth-child(2)`).toEqual([ |
| 8439 |
"zop", |
| 8440 |
"yop", |
| 8441 |
"xop", |
| 8442 |
"My little Foo Value", |
| 8443 |
]); |
| 8444 |
|
| 8445 |
// server-side sort |
| 8446 |
await contains(`.o_form_button_save`).click(); |
| 8447 |
expect(queryAllTexts`.o_data_row .o_data_cell:nth-child(2)`).toEqual([ |
| 8448 |
"zop", |
| 8449 |
"yop", |
| 8450 |
"xop", |
| 8451 |
"My little Foo Value", |
| 8452 |
]); |
| 8453 |
|
| 8454 |
// no client-side sort after edit |
| 8455 |
await contains(`.o_data_row:eq(1) .o_data_cell:eq(0)`).click(); |
| 8456 |
await contains(`.modal .o_field_widget[name=foo] input`).edit("zzz"); |
| 8457 |
await contains(`.modal-footer .o_form_button_save`).click(); |
| 8458 |
expect(queryAllTexts`.o_data_row .o_data_cell:nth-child(2)`).toEqual([ |
| 8459 |
"zop", |
| 8460 |
"zzz", |
| 8461 |
"xop", |
| 8462 |
"My little Foo Value", |
| 8463 |
]); |
| 8464 |
|
| 8465 |
// server-side sort post save |
| 8466 |
await contains(`.o_form_button_save`).click(); |
| 8467 |
expect(queryAllTexts`.o_data_row .o_data_cell:nth-child(2)`).toEqual([ |
| 8468 |
"zzz", |
| 8469 |
"zop", |
| 8470 |
"xop", |
| 8471 |
"My little Foo Value", |
| 8472 |
]); |
| 8473 |
}); |
| 8474 |
|
| 8475 |
test.tags("desktop"); |
| 8476 |
test(`action context is used when evaluating domains`, async () => { |
| 8477 |
onRpc("web_name_search", ({ kwargs }) => { |
| 8478 |
expect.step("web_name_search"); |
| 8479 |
expect(kwargs.domain[0]).toEqual(["id", "in", [45, 46, 47]]); |
| 8480 |
}); |
| 8481 |
await mountView({ |
| 8482 |
resModel: "partner", |
| 8483 |
type: "form", |
| 8484 |
arch: ` |
| 8485 |
<form> |
| 8486 |
<field name="parent_id" domain="[('id', 'in', context.get('product_ids', []))]"/> |
| 8487 |
</form> |
| 8488 |
`, |
| 8489 |
resId: 1, |
| 8490 |
context: { product_ids: [45, 46, 47] }, |
| 8491 |
}); |
| 8492 |
await contains(`.o_field_widget[name="parent_id"] input`).click(); |
| 8493 |
expect.verifySteps(["web_name_search"]); |
| 8494 |
}); |
| 8495 |
|
| 8496 |
test(`form rendering with groups with col/colspan`, async () => { |
| 8497 |
await mountView({ |
| 8498 |
resModel: "partner", |
| 8499 |
type: "form", |
| 8500 |
arch: ` |
| 8501 |
<form> |
| 8502 |
<sheet> |
| 8503 |
<group col="6" class="parent_group"> |
| 8504 |
<group col="4" colspan="3" class="group_4"> |
| 8505 |
<div colspan="3"/> |
| 8506 |
<div colspan="2"/> |
| 8507 |
<div/> |
| 8508 |
<div colspan="4"/> |
| 8509 |
</group> |
| 8510 |
<group col="3" colspan="4" class="group_3"> |
| 8511 |
<group col="1" class="group_1"> |
| 8512 |
<div/> |
| 8513 |
<div/> |
| 8514 |
<div/> |
| 8515 |
</group> |
| 8516 |
<div/> |
| 8517 |
<group col="3" class="field_group"> |
| 8518 |
<field name="foo" colspan="3"/> |
| 8519 |
<div/> |
| 8520 |
<field name="bar" nolabel="1"/> |
| 8521 |
<field name="float_field"/> |
| 8522 |
<field name="int_field" colspan="3" nolabel="1"/> |
| 8523 |
<span/> |
| 8524 |
<field name="product_id"/> |
| 8525 |
</group> |
| 8526 |
</group> |
| 8527 |
</group> |
| 8528 |
<group> |
| 8529 |
<field name="child_ids"> |
| 8530 |
<list> |
| 8531 |
<field name="display_name"/> |
| 8532 |
<field name="foo"/> |
| 8533 |
<field name="int_field"/> |
| 8534 |
</list> |
| 8535 |
</field> |
| 8536 |
</group> |
| 8537 |
</sheet> |
| 8538 |
</form> |
| 8539 |
`, |
| 8540 |
resId: 1, |
| 8541 |
}); |
| 8542 |
|
| 8543 |
// Verify outergroup/innergroup |
| 8544 |
expect(`.parent_group`).toHaveProperty("tagName", "DIV"); |
| 8545 |
expect(`.group_4`).toHaveProperty("tagName", "DIV"); |
| 8546 |
expect(`.group_3`).toHaveProperty("tagName", "DIV"); |
| 8547 |
expect(`.group_1`).toHaveProperty("tagName", "DIV"); |
| 8548 |
expect(`.field_group`).toHaveProperty("tagName", "DIV"); |
| 8549 |
|
| 8550 |
// Verify .parent_group content |
| 8551 |
expect(`.parent_group > *`).toHaveCount(2); |
| 8552 |
expect(`.parent_group > *:eq(0)`).toHaveClass("col-lg-6"); |
| 8553 |
expect(`.parent_group > *:eq(1)`).toHaveClass("col-lg-8"); |
| 8554 |
|
| 8555 |
// Verify .group_4 content |
| 8556 |
expect(`.group_4 > div.o_cell`).toHaveCount(4); |
| 8557 |
expect(`.group_4 > div.o_cell:first-child`).toHaveAttribute( |
| 8558 |
"style", |
| 8559 |
"--o-grid-column-span: 3;" |
| 8560 |
); |
| 8561 |
expect(`.group_4 > div.o_cell:nth-child(2)`).toHaveAttribute( |
| 8562 |
"style", |
| 8563 |
"--o-grid-column-span: 2;" |
| 8564 |
); |
| 8565 |
expect(`.group_4 > div.o_cell:last-child`).toHaveAttribute("style", "--o-grid-column-span: 4;"); |
| 8566 |
|
| 8567 |
// Verify .group_3 content |
| 8568 |
expect(`.group_3 > *`).toHaveCount(3); |
| 8569 |
expect(`.group_3 > .col-lg-4`).toHaveCount(3); |
| 8570 |
|
| 8571 |
// Verify .group_1 content |
| 8572 |
expect(`.group_1 > .o_cell`).toHaveCount(3); |
| 8573 |
|
| 8574 |
// Verify .field_group content |
| 8575 |
expect(`.field_group > .o_cell`).toHaveCount(10); |
| 8576 |
expect(`.field_group > .o_cell:first-child`).toHaveClass("o_wrap_label"); |
| 8577 |
expect(`.field_group > .o_cell:nth-child(2)`).toHaveAttribute("style", "grid-column: span 2;"); |
| 8578 |
|
| 8579 |
expect(`.field_group > .o_cell:nth-child(5)`).toHaveClass("o_wrap_label"); |
| 8580 |
|
| 8581 |
expect(`.field_group > .o_cell:nth-child(9)`).toHaveClass("o_wrap_label"); |
| 8582 |
}); |
| 8583 |
|
| 8584 |
test(`form rendering innergroup: separator should take one line`, async () => { |
| 8585 |
await mountView({ |
| 8586 |
resModel: "partner", |
| 8587 |
type: "form", |
| 8588 |
arch: ` |
| 8589 |
<form> |
| 8590 |
<sheet> |
| 8591 |
<group> |
| 8592 |
<group> |
| 8593 |
<separator string="sep"/> |
| 8594 |
<td class="o_td_label"> |
| 8595 |
<label for="display_name"/> |
| 8596 |
</td> |
| 8597 |
<field name="display_name" nolabel="1"/> |
| 8598 |
</group> |
| 8599 |
</group> |
| 8600 |
</sheet> |
| 8601 |
</form> |
| 8602 |
`, |
| 8603 |
resId: 1, |
| 8604 |
}); |
| 8605 |
expect(`.o_inner_group > .o_cell`).toHaveCount(3); |
| 8606 |
expect(`.o_inner_group > .o_cell:first-child .o_horizontal_separator`).toHaveCount(1); |
| 8607 |
expect(`.o_inner_group > .o_cell:nth-child(2) label[for=display_name_0]`).toHaveCount(1); |
| 8608 |
expect(`.o_inner_group > .o_cell:last-child div[name=display_name]`).toHaveCount(1); |
| 8609 |
}); |
| 8610 |
|
| 8611 |
test(`outer and inner groups string attribute`, async () => { |
| 8612 |
await mountView({ |
| 8613 |
resModel: "partner", |
| 8614 |
type: "form", |
| 8615 |
arch: ` |
| 8616 |
<form> |
| 8617 |
<sheet> |
| 8618 |
<group string="parent group" class="parent_group"> |
| 8619 |
<group string="child group 1" class="group_1"> |
| 8620 |
<field name="bar"/> |
| 8621 |
</group> |
| 8622 |
<group string="child group 2" class="group_2"> |
| 8623 |
<field name="bar"/> |
| 8624 |
</group> |
| 8625 |
</group> |
| 8626 |
</sheet> |
| 8627 |
</form> |
| 8628 |
`, |
| 8629 |
resId: 1, |
| 8630 |
}); |
| 8631 |
expect(`div.o_inner_group`).toHaveCount(2); |
| 8632 |
expect(`.group_1 .o_horizontal_separator`).toHaveCount(1); |
| 8633 |
expect(`.group_1 .o_horizontal_separator:contains(child group 1)`).toHaveCount(1); |
| 8634 |
expect(`.group_2 .o_horizontal_separator:contains(child group 2)`).toHaveCount(1); |
| 8635 |
expect(`.parent_group > div.o_horizontal_separator:contains(parent group)`).toHaveCount(1); |
| 8636 |
}); |
| 8637 |
|
| 8638 |
test(`inner group with invisible cells`, async () => { |
| 8639 |
await mountView({ |
| 8640 |
resModel: "partner", |
| 8641 |
type: "form", |
| 8642 |
arch: ` |
| 8643 |
<form> |
| 8644 |
<field name="foo"/> |
| 8645 |
<group> |
| 8646 |
<div class="cell1" invisible='foo == "1"'/> |
| 8647 |
<div class="cell2" invisible='foo == "2"'/> |
| 8648 |
</group> |
| 8649 |
</form> |
| 8650 |
`, |
| 8651 |
}); |
| 8652 |
|
| 8653 |
await contains(`[name='foo'] input`).edit("1"); |
| 8654 |
expect(`.cell1`).toHaveCount(0); |
| 8655 |
expect(`.cell2`).toHaveCount(1); |
| 8656 |
|
| 8657 |
await contains(`[name='foo'] input`).edit("2"); |
| 8658 |
expect(`.cell1`).toHaveCount(1); |
| 8659 |
expect(`.cell2`).toHaveCount(0); |
| 8660 |
|
| 8661 |
await contains(`[name='foo'] input`).edit("3"); |
| 8662 |
expect(`.cell1`).toHaveCount(1); |
| 8663 |
expect(`.cell2`).toHaveCount(1); |
| 8664 |
}); |
| 8665 |
|
| 8666 |
test(`form group with newline tag inside`, async () => { |
| 8667 |
await mountView({ |
| 8668 |
resModel: "partner", |
| 8669 |
type: "form", |
| 8670 |
arch: ` |
| 8671 |
<form> |
| 8672 |
<sheet> |
| 8673 |
<group col="5" class="main_inner_group"> |
| 8674 |
<!-- col=5 otherwise the test is ok even without the |
| 8675 |
newline code as this will render a <newline/> DOM |
| 8676 |
element in the third column, leaving no place for |
| 8677 |
the next field and its label on the same line. --> |
| 8678 |
<field name="foo"/> |
| 8679 |
<newline/> |
| 8680 |
<field name="bar"/> |
| 8681 |
<field name="float_field"/> |
| 8682 |
</group> |
| 8683 |
<group col="3"> |
| 8684 |
<!-- col=3 otherwise the test is ok even without the |
| 8685 |
newline code as this will render a <newline/> DOM |
| 8686 |
element with the g-col-2 class, leaving no |
| 8687 |
place for the next group on the same line. --> |
| 8688 |
<group class="top_group"> |
| 8689 |
<div style="height: 200px;"/> |
| 8690 |
</group> |
| 8691 |
<newline/> |
| 8692 |
<group class="bottom_group"> |
| 8693 |
<div/> |
| 8694 |
</group> |
| 8695 |
</group> |
| 8696 |
</sheet> |
| 8697 |
</form> |
| 8698 |
`, |
| 8699 |
resId: 1, |
| 8700 |
}); |
| 8701 |
|
| 8702 |
// Inner group |
| 8703 |
expect(`.main_inner_group .o_cell`).toHaveCount(6); |
| 8704 |
expect(`.main_inner_group > .o_cell.o_wrap_label:first-child`).toHaveCount(1); |
| 8705 |
expect(`.main_inner_group > .o_cell.o_wrap_input:nth-child(2)`).toHaveCount(1); |
| 8706 |
expect(`.main_inner_group > .o_wrap_field_boolean:nth-child(3)`).toHaveCount(1); |
| 8707 |
expect(`.main_inner_group > .o_wrap_field_boolean:nth-child(3) > .o_wrap_label`).toHaveCount(1); |
| 8708 |
expect(`.main_inner_group > .o_wrap_field_boolean:nth-child(3) > .o_wrap_input`).toHaveCount(1); |
| 8709 |
expect(`.main_inner_group > .o_cell.o_wrap_label:nth-child(4)`).toHaveCount(1); |
| 8710 |
expect(`.main_inner_group > .o_cell.o_wrap_input:nth-child(5)`).toHaveCount(1); |
| 8711 |
|
| 8712 |
// Outer group |
| 8713 |
const bottomGroupRect = queryFirst(`.bottom_group`).getBoundingClientRect(); |
| 8714 |
const topGroupRect = queryFirst(`.top_group`).getBoundingClientRect(); |
| 8715 |
expect(bottomGroupRect.top - topGroupRect.top).toBeGreaterThan(200, { |
| 8716 |
message: "outergroup children should not be on the same line", |
| 8717 |
}); |
| 8718 |
}); |
| 8719 |
|
| 8720 |
test(`custom open record dialog title`, async () => { |
| 8721 |
Partner._records[0].child_ids = [2]; |
| 8722 |
|
| 8723 |
await mountView({ |
| 8724 |
resModel: "partner", |
| 8725 |
type: "form", |
| 8726 |
arch: ` |
| 8727 |
<form> |
| 8728 |
<field name="child_ids" widget="many2many" string="custom label"> |
| 8729 |
<list><field name="display_name"/></list> |
| 8730 |
<form><field name="display_name"/></form> |
| 8731 |
</field> |
| 8732 |
</form> |
| 8733 |
`, |
| 8734 |
resId: 1, |
| 8735 |
}); |
| 8736 |
await contains(`.o_data_row .o_data_cell`).click(); |
| 8737 |
expect(`.modal .modal-title`).toHaveText("Open: custom label"); |
| 8738 |
}); |
| 8739 |
|
| 8740 |
test(`can save without any dirty translatable fields`, async () => { |
| 8741 |
serverState.multiLang = true; |
| 8742 |
|
| 8743 |
onRpc(({ method }) => expect.step(method)); |
| 8744 |
await mountView({ |
| 8745 |
type: "form", |
| 8746 |
resModel: "partner", |
| 8747 |
arch: `<form><field name="name"/></form>`, |
| 8748 |
resId: 1, |
| 8749 |
}); |
| 8750 |
expect.verifySteps(["get_views", "web_read"]); |
| 8751 |
expect(`.o_form_editable`).toHaveCount(1); |
| 8752 |
// o_field_translate is on the input and on the translate button |
| 8753 |
expect(`div[name='name'] .o_field_translate`).toHaveCount(2); |
| 8754 |
|
| 8755 |
await contains(`.o_form_button_save`, { visible: false }).click(); |
| 8756 |
expect(`.alert .o_field_translate`).toHaveCount(0); |
| 8757 |
expect(`.o_form_saved`).toHaveCount(1); |
| 8758 |
expect.verifySteps([]); |
| 8759 |
}); |
| 8760 |
|
| 8761 |
test(`translation dialog with right context and domain`, async () => { |
| 8762 |
installLanguages({ |
| 8763 |
CUST: "custom lang", |
| 8764 |
CUST2: "second custom", |
| 8765 |
}); |
| 8766 |
|
| 8767 |
onRpc("get_field_translations", ({ args, kwargs }) => { |
| 8768 |
expect.step(`translate args ${JSON.stringify(args)}`); |
| 8769 |
expect.step(`translate context ${JSON.stringify(kwargs.context)}`); |
| 8770 |
return [ |
| 8771 |
[ |
| 8772 |
{ lang: "CUST", source: "yop", value: "yop" }, |
| 8773 |
{ lang: "CUST2", source: "yop", value: "valeur français" }, |
| 8774 |
], |
| 8775 |
{ translation_type: "char", translation_show_source: false }, |
| 8776 |
]; |
| 8777 |
}); |
| 8778 |
await mountView({ |
| 8779 |
resModel: "partner", |
| 8780 |
type: "form", |
| 8781 |
arch: `<form><field name="name"/></form>`, |
| 8782 |
resId: 1, |
| 8783 |
}); |
| 8784 |
await contains(".o_field_translate").click(); |
| 8785 |
await contains(`.o_field_translate.btn-link`).click(); |
| 8786 |
expect.verifySteps([ |
| 8787 |
`translate args [[1],"name"]`, |
| 8788 |
`translate context {"lang":"en","tz":"taht","uid":7,"allowed_company_ids":[1]}`, |
| 8789 |
]); |
| 8790 |
expect(`.modal`).toHaveCount(1); |
| 8791 |
expect(`.modal-title`).toHaveText("Translate: name"); |
| 8792 |
}); |
| 8793 |
|
| 8794 |
test(`save new record before opening translate dialog`, async () => { |
| 8795 |
installLanguages({ |
| 8796 |
CUST: "custom lang", |
| 8797 |
CUST2: "second custom", |
| 8798 |
}); |
| 8799 |
|
| 8800 |
onRpc("call_button", () => ({ context: {}, domain: [] })); |
| 8801 |
onRpc("get_field_translations", () => [ |
| 8802 |
[ |
| 8803 |
{ lang: "CUST", source: "yop", value: "yop" }, |
| 8804 |
{ lang: "CUST2", source: "yop", value: "valeur français" }, |
| 8805 |
], |
| 8806 |
{ translation_type: "char", translation_show_source: false }, |
| 8807 |
]); |
| 8808 |
onRpc(({ method }) => expect.step(method)); |
| 8809 |
await mountView({ |
| 8810 |
resModel: "partner", |
| 8811 |
type: "form", |
| 8812 |
arch: `<form><field name="name"/></form>`, |
| 8813 |
}); |
| 8814 |
expect.verifySteps(["get_views", "onchange"]); |
| 8815 |
expect(`.o_form_editable`).toHaveCount(1); |
| 8816 |
|
| 8817 |
await contains(`.o_field_translate`).click(); |
| 8818 |
await contains(`.o_field_translate.btn-link`).click(); |
| 8819 |
expect.verifySteps(["web_save", "get_field_translations"]); |
| 8820 |
expect(`.modal`).toHaveCount(1); |
| 8821 |
expect(`.modal-title`).toHaveText("Translate: name"); |
| 8822 |
}); |
| 8823 |
|
| 8824 |
test(`translate event correctly handled with multiple controllers`, async () => { |
| 8825 |
installLanguages({ |
| 8826 |
en_US: "English", |
| 8827 |
fr_BE: "French (Belgium)", |
| 8828 |
}); |
| 8829 |
|
| 8830 |
Partner._records[0].product_id = 37; |
| 8831 |
Product._fields.name = fields.Char({ translate: true }); |
| 8832 |
Product._views = { |
| 8833 |
form: ` |
| 8834 |
<form> |
| 8835 |
<sheet> |
| 8836 |
<group> |
| 8837 |
<field name="name"/> |
| 8838 |
<field name="partner_type_id"/> |
| 8839 |
</group> |
| 8840 |
</sheet> |
| 8841 |
</form> |
| 8842 |
`, |
| 8843 |
}; |
| 8844 |
|
| 8845 |
onRpc("get_formview_id", () => false); |
| 8846 |
onRpc("get_field_translations", () => { |
| 8847 |
expect.step("get_field_translations"); |
| 8848 |
return [ |
| 8849 |
[ |
| 8850 |
{ lang: "en_US", source: "yop", value: "yop" }, |
| 8851 |
{ lang: "fr_BE", source: "yop", value: "valeur français" }, |
| 8852 |
], |
| 8853 |
{ translation_type: "char", translation_show_source: false }, |
| 8854 |
]; |
| 8855 |
}); |
| 8856 |
await mountViewInDialog({ |
| 8857 |
type: "form", |
| 8858 |
resModel: "partner", |
| 8859 |
arch: ` |
| 8860 |
<form> |
| 8861 |
<sheet> |
| 8862 |
<group> |
| 8863 |
<field name="product_id"/> |
| 8864 |
</group> |
| 8865 |
</sheet> |
| 8866 |
</form> |
| 8867 |
`, |
| 8868 |
resId: 1, |
| 8869 |
}); |
| 8870 |
expect(`.o_dialog`).toHaveCount(1); |
| 8871 |
|
| 8872 |
await contains(`[name="product_id"] .o_external_button`, { visible: false }).click(); |
| 8873 |
await contains(`.o_field_translate`).click(); |
| 8874 |
expect(`.o_dialog:eq(1) button.o_field_translate`).toHaveCount(1); |
| 8875 |
|
| 8876 |
await contains(`.o_dialog:eq(1) button.o_field_translate`).click(); |
| 8877 |
expect.verifySteps(["get_field_translations"]); |
| 8878 |
}); |
| 8879 |
|
| 8880 |
test.tags("desktop"); |
| 8881 |
test(`buttons are disabled until status bar action is resolved`, async () => { |
| 8882 |
const deferred = new Deferred(); |
| 8883 |
mockService("action", { |
| 8884 |
async doActionButton() { |
| 8885 |
await deferred; |
| 8886 |
}, |
| 8887 |
}); |
| 8888 |
|
| 8889 |
await mountView({ |
| 8890 |
resModel: "partner", |
| 8891 |
type: "form", |
| 8892 |
arch: ` |
| 8893 |
<form> |
| 8894 |
<header> |
| 8895 |
<button name="post" class="child_ids" string="Confirm" type="object"/> |
| 8896 |
<button name="some_method" class="s" string="Do it" type="object"/> |
| 8897 |
</header> |
| 8898 |
<sheet> |
| 8899 |
<div name="button_box" class="oe_button_box"> |
| 8900 |
<button class="oe_stat_button" name="some_action" type="action"> |
| 8901 |
<field name="bar"/> |
| 8902 |
</button> |
| 8903 |
</div> |
| 8904 |
<group> |
| 8905 |
<field name="foo"/> |
| 8906 |
</group> |
| 8907 |
</sheet> |
| 8908 |
</form> |
| 8909 |
`, |
| 8910 |
resId: 1, |
| 8911 |
}); |
| 8912 |
// Contains invisible buttons that are only displayed under xl screens |
| 8913 |
expect(`.o_control_panel_breadcrumbs button:not(.fa):not(:disabled)`).toHaveCount(3); |
| 8914 |
expect(`.o_form_statusbar button:not(:disabled)`).toHaveCount(2); |
| 8915 |
expect(`.o-form-buttonbox button:not(:disabled)`).toHaveCount(1); |
| 8916 |
|
| 8917 |
await contains(`.o_form_statusbar button`).click(); |
| 8918 |
await animationFrame(); |
| 8919 |
|
| 8920 |
// The unresolved promise lets us check the state of the buttons |
| 8921 |
expect(`.o_control_panel_breadcrumbs button:not(.fa):disabled`).toHaveCount(3); |
| 8922 |
expect(`.o_form_statusbar button:disabled`).toHaveCount(2); |
| 8923 |
expect(`.o-form-buttonbox button:disabled`).toHaveCount(1); |
| 8924 |
|
| 8925 |
deferred.resolve(); |
| 8926 |
await animationFrame(); |
| 8927 |
expect(`.o_control_panel_breadcrumbs button:not(.fa):not(:disabled)`).toHaveCount(3); |
| 8928 |
expect(`.o_form_statusbar button:not(:disabled)`).toHaveCount(2); |
| 8929 |
expect(`.o-form-buttonbox button:not(:disabled)`).toHaveCount(1); |
| 8930 |
}); |
| 8931 |
|
| 8932 |
test(`buttons with "confirm" attribute save before calling the method`, async () => { |
| 8933 |
mockService("action", { |
| 8934 |
doActionButton() { |
| 8935 |
expect.step("execute_action"); |
| 8936 |
}, |
| 8937 |
}); |
| 8938 |
|
| 8939 |
onRpc(({ method }) => expect.step(method)); |
| 8940 |
await mountView({ |
| 8941 |
resModel: "partner", |
| 8942 |
type: "form", |
| 8943 |
arch: ` |
| 8944 |
<form> |
| 8945 |
<header> |
| 8946 |
<button name="post" class="child_ids" string="Confirm" type="object" confirm="Very dangerous. U sure?"/> |
| 8947 |
</header> |
| 8948 |
<sheet> |
| 8949 |
<field name="foo"/> |
| 8950 |
</sheet> |
| 8951 |
</form> |
| 8952 |
`, |
| 8953 |
}); |
| 8954 |
|
| 8955 |
// click on button, and cancel in confirm dialog |
| 8956 |
await contains(`.o_statusbar_buttons button`).click(); |
| 8957 |
expect(`.o_statusbar_buttons button`).not.toBeEnabled(); |
| 8958 |
|
| 8959 |
await contains(`.modal-footer button.btn-secondary`).click(); |
| 8960 |
expect(`.o_statusbar_buttons button`).toBeEnabled(); |
| 8961 |
|
| 8962 |
expect.verifySteps(["get_views", "onchange"]); |
| 8963 |
|
| 8964 |
// click on button, and click on ok in confirm dialog |
| 8965 |
await contains(`.o_statusbar_buttons button`).click(); |
| 8966 |
expect.verifySteps([]); |
| 8967 |
await contains(`.modal-footer button.btn-primary`).click(); |
| 8968 |
expect.verifySteps(["web_save", "execute_action"]); |
| 8969 |
}); |
| 8970 |
|
| 8971 |
test(`buttons with "confirm-title" and "confirm-label" attributes`, async () => { |
| 8972 |
onRpc(({ method }) => expect.step(method)); |
| 8973 |
await mountView({ |
| 8974 |
resModel: "partner", |
| 8975 |
type: "form", |
| 8976 |
arch: ` |
| 8977 |
<form> |
| 8978 |
<header> |
| 8979 |
<button name="post" class="child_ids" string="Confirm" type="object" confirm="Very dangerous. U sure?" |
| 8980 |
confirm-title="Confirm Title" confirm-label="Confirm Label"/> |
| 8981 |
</header> |
| 8982 |
<sheet> |
| 8983 |
<field name="foo"/> |
| 8984 |
</sheet> |
| 8985 |
</form> |
| 8986 |
`, |
| 8987 |
}); |
| 8988 |
await contains(`.o_statusbar_buttons button`).click(); |
| 8989 |
expect(`.modal-title`).toHaveText("Confirm Title"); |
| 8990 |
expect(`.modal-footer button.btn-primary`).toHaveText("Confirm Label"); |
| 8991 |
expect.verifySteps(["get_views", "onchange"]); |
| 8992 |
}); |
| 8993 |
|
| 8994 |
test(`buttons with "confirm" attribute: click twice on "Ok"`, async () => { |
| 8995 |
mockService("action", { |
| 8996 |
doActionButton() { |
| 8997 |
expect.step("execute_action"); // should be called only once |
| 8998 |
}, |
| 8999 |
}); |
| 9000 |
|
| 9001 |
onRpc(({ method }) => expect.step(method)); |
| 9002 |
await mountView({ |
| 9003 |
resModel: "partner", |
| 9004 |
type: "form", |
| 9005 |
arch: ` |
| 9006 |
<form> |
| 9007 |
<header> |
| 9008 |
<button name="post" class="child_ids" string="Confirm" type="object" confirm="U sure?"/> |
| 9009 |
</header> |
| 9010 |
</form> |
| 9011 |
`, |
| 9012 |
}); |
| 9013 |
expect.verifySteps(["get_views", "onchange"]); |
| 9014 |
|
| 9015 |
await contains(`.o_statusbar_buttons button`).click(); |
| 9016 |
expect.verifySteps([]); |
| 9017 |
|
| 9018 |
await click(`.modal-footer button.btn-primary`); |
| 9019 |
expect(`.modal-footer button.btn-primary`).not.toBeEnabled(); |
| 9020 |
await animationFrame(); |
| 9021 |
expect.verifySteps(["web_save", "execute_action"]); |
| 9022 |
}); |
| 9023 |
|
| 9024 |
test(`multiple clicks on save should reload only once`, async () => { |
| 9025 |
const deferred = new Deferred(); |
| 9026 |
|
| 9027 |
onRpc("web_save", () => deferred); |
| 9028 |
onRpc(({ method }) => expect.step(method)); |
| 9029 |
await mountView({ |
| 9030 |
resModel: "partner", |
| 9031 |
type: "form", |
| 9032 |
arch: `<form><field name="foo"/></form>`, |
| 9033 |
resId: 1, |
| 9034 |
}); |
| 9035 |
expect.verifySteps(["get_views", "web_read"]); |
| 9036 |
await contains(`.o_field_widget[name="foo"] input`).edit("test"); |
| 9037 |
await contains(`.o_form_button_save`).click(); |
| 9038 |
expect(`.o_form_button_save`).not.toBeEnabled(); // Save button is disabled, it can't be clicked |
| 9039 |
|
| 9040 |
deferred.resolve(); |
| 9041 |
await animationFrame(); |
| 9042 |
expect.verifySteps(["web_save"]); |
| 9043 |
}); |
| 9044 |
|
| 9045 |
test(`form view is not broken if save operation fails`, async () => { |
| 9046 |
expect.errors(1); |
| 9047 |
|
| 9048 |
onRpc("web_save", ({ args }) => { |
| 9049 |
if (args[1].foo === "incorrect value") { |
| 9050 |
throw makeServerError(); |
| 9051 |
} |
| 9052 |
}); |
| 9053 |
onRpc(({ method }) => expect.step(method)); |
| 9054 |
await mountView({ |
| 9055 |
resModel: "partner", |
| 9056 |
type: "form", |
| 9057 |
arch: `<form><field name="foo"/></form>`, |
| 9058 |
resId: 1, |
| 9059 |
}); |
| 9060 |
expect.verifySteps(["get_views", "web_read"]); |
| 9061 |
|
| 9062 |
await contains(`.o_field_widget[name=foo] input`).edit("incorrect value"); |
| 9063 |
await contains(`.o_form_button_save`).click(); |
| 9064 |
await animationFrame(); |
| 9065 |
expect(`.o_dialog`).toHaveCount(1); |
| 9066 |
expect.verifyErrors(["RPC_ERROR: Odoo Server Error"]); |
| 9067 |
expect.verifySteps(["web_save"]); // write on save (it fails, does not trigger a read) |
| 9068 |
|
| 9069 |
await contains(`.o_dialog .modal-footer .btn-primary`).click(); |
| 9070 |
await contains(`.o_field_widget[name=foo] input`).edit("correct value"); |
| 9071 |
await contains(`.o_form_button_save`).click(); |
| 9072 |
expect.verifySteps(["web_save"]); // write on save (it works) |
| 9073 |
}); |
| 9074 |
|
| 9075 |
test(`form view is not broken if save operation fails with redirect warning`, async () => { |
| 9076 |
onRpc("web_save", ({ args }) => { |
| 9077 |
if (args[1].foo === "incorrect value") { |
| 9078 |
throw makeServerError({ |
| 9079 |
type: `RedirectWarning`, |
| 9080 |
args: [ |
| 9081 |
"The message", |
| 9082 |
{ |
| 9083 |
name: "Sub view", |
| 9084 |
res_model: "partner", |
| 9085 |
type: "ir.actions.act_window", |
| 9086 |
domain: [], |
| 9087 |
target: "new", |
| 9088 |
views: [[false, "form"]], |
| 9089 |
}, |
| 9090 |
"Button Label", |
| 9091 |
{}, |
| 9092 |
], |
| 9093 |
description: "Beep boop server stuff and technical string", |
| 9094 |
}); |
| 9095 |
} |
| 9096 |
}); |
| 9097 |
onRpc(({ method }) => expect.step(method)); |
| 9098 |
await mountView({ |
| 9099 |
resModel: "partner", |
| 9100 |
type: "form", |
| 9101 |
arch: `<form><field name="foo"/></form>`, |
| 9102 |
resId: 1, |
| 9103 |
}); |
| 9104 |
expect.verifySteps(["get_views", "web_read"]); |
| 9105 |
|
| 9106 |
await contains(`.o_field_widget[name=foo] input`).edit("incorrect value"); |
| 9107 |
await contains(`.o_form_button_create`).click(); |
| 9108 |
await animationFrame(); |
| 9109 |
expect.verifySteps(["web_save"]); |
| 9110 |
|
| 9111 |
// Oh snap dialog |
| 9112 |
expect(`.o_dialog`).toHaveCount(1); |
| 9113 |
expect(`.o_dialog .modal-footer .btn-primary`).toHaveCount(1); |
| 9114 |
expect(`.o_dialog .modal-footer .btn-secondary`).toHaveCount(2); |
| 9115 |
await contains(`.o_dialog .modal-footer .btn-secondary:first`).click(); |
| 9116 |
await animationFrame(); |
| 9117 |
expect.verifySteps(["get_views", "onchange"]); |
| 9118 |
|
| 9119 |
// RedirectWarning dialog |
| 9120 |
expect(`.modal-title`).toHaveText("Sub view"); |
| 9121 |
}); |
| 9122 |
|
| 9123 |
test.tags("desktop"); |
| 9124 |
test("Redirect Warning full feature: additional context, action_id, leaving while dirty", async function () { |
| 9125 |
expect.errors(1); |
| 9126 |
defineActions([ |
| 9127 |
{ |
| 9128 |
id: 1, |
| 9129 |
name: "Partner", |
| 9130 |
res_model: "partner", |
| 9131 |
type: "ir.actions.act_window", |
| 9132 |
views: [[false, "form"]], |
| 9133 |
res_id: 1, |
| 9134 |
}, |
| 9135 |
{ |
| 9136 |
id: 2, |
| 9137 |
name: "Partner List", |
| 9138 |
res_model: "partner", |
| 9139 |
type: "ir.actions.act_window", |
| 9140 |
domain: "[['id', 'in', [active_id]]]", |
| 9141 |
views: [[false, "list"]], |
| 9142 |
}, |
| 9143 |
]); |
| 9144 |
Partner._views = { |
| 9145 |
list: ` |
| 9146 |
<list> |
| 9147 |
<field name="name"/> |
| 9148 |
</list>`, |
| 9149 |
form: ` |
| 9150 |
<form> |
| 9151 |
<group> |
| 9152 |
<field name="name"/> |
| 9153 |
</group> |
| 9154 |
</form>`, |
| 9155 |
"partner,false,search": "<search></search>", |
| 9156 |
}; |
| 9157 |
onRpc("partner", "web_save", () => { |
| 9158 |
expect.step("web_save"); |
| 9159 |
throw makeServerError({ |
| 9160 |
type: `RedirectWarning`, |
| 9161 |
args: [ |
| 9162 |
"The message", |
| 9163 |
2, |
| 9164 |
"Button Label", |
| 9165 |
{ |
| 9166 |
active_id: 4, |
| 9167 |
}, |
| 9168 |
], |
| 9169 |
description: "Beep boop server stuff and technical string", |
| 9170 |
}); |
| 9171 |
}); |
| 9172 |
onRpc("partner", "web_search_read", (args) => { |
| 9173 |
expect.step("web_search_read"); |
| 9174 |
expect(args.kwargs.domain).toEqual([["id", "in", [4]]]); |
| 9175 |
}); |
| 9176 |
|
| 9177 |
await mountWithCleanup(WebClient); |
| 9178 |
await getService("action").doAction(1); |
| 9179 |
|
| 9180 |
await contains(".o_field_widget[name='name'] input").edit("some invalid input"); |
| 9181 |
await contains(".o_form_button_save").click(); |
| 9182 |
expect.verifySteps(["web_save"]); |
| 9183 |
|
| 9184 |
await waitFor(".o_error_dialog"); |
| 9185 |
expect.verifyErrors(["RPC_ERROR: Odoo Server Error"]); |
| 9186 |
|
| 9187 |
expect(".o_error_dialog .btn-primary").toHaveCount(1); |
| 9188 |
expect(".o_error_dialog .btn-secondary").toHaveCount(1); |
| 9189 |
|
| 9190 |
await contains(".o_error_dialog .btn-primary").click(); |
| 9191 |
await waitFor(".o_list_view"); |
| 9192 |
expect.verifySteps(["web_search_read"]); |
| 9193 |
expect(".o_breadcrumb").toHaveText("first record\nPartner List"); |
| 9194 |
}); |
| 9195 |
|
| 9196 |
test.tags("desktop"); |
| 9197 |
test(`context is correctly passed after save & new in FormViewDialog`, async () => { |
| 9198 |
Product._views = { |
| 9199 |
form: `<form><field name="partner_type_id" context="{'color': parent.id}"/></form>`, |
| 9200 |
list: `<list><field name="display_name"/></list>`, |
| 9201 |
}; |
| 9202 |
|
| 9203 |
onRpc("web_name_search", ({ kwargs }) => { |
| 9204 |
expect.step("web_name_search"); |
| 9205 |
expect(kwargs.context.color).toBe(4); |
| 9206 |
}); |
| 9207 |
await mountView({ |
| 9208 |
resModel: "partner", |
| 9209 |
type: "form", |
| 9210 |
arch: `<form><field name="product_ids"/></form>`, |
| 9211 |
resId: 4, |
| 9212 |
}); |
| 9213 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 9214 |
expect(`.modal`).toHaveCount(1); |
| 9215 |
|
| 9216 |
// set a value on the m2o and click save & new |
| 9217 |
await contains(`.o_field_many2one[name="partner_type_id"] input`).click(); |
| 9218 |
expect.verifySteps(["web_name_search"]); |
| 9219 |
|
| 9220 |
await contains(`.dropdown .dropdown-item:contains(gold)`).click(); |
| 9221 |
await contains(`.modal-footer .o_form_button_save_new`).click(); |
| 9222 |
|
| 9223 |
// set a value on the m2o |
| 9224 |
await contains(`.o_field_many2one[name="partner_type_id"] input`).click(); |
| 9225 |
expect.verifySteps(["web_name_search"]); |
| 9226 |
|
| 9227 |
await contains(`.dropdown .dropdown-item:contains(silver)`).click(); |
| 9228 |
await contains(`.modal-footer .o_form_button_save`).click(); |
| 9229 |
}); |
| 9230 |
|
| 9231 |
test(`readonly fields are not sent when saving`, async () => { |
| 9232 |
// define an onchange on name to check that the value of readonly |
| 9233 |
// fields is correctly sent for onchanges |
| 9234 |
Partner._onChanges = { |
| 9235 |
name() {}, |
| 9236 |
child_ids() {}, |
| 9237 |
}; |
| 9238 |
let checkOnchange = false; |
| 9239 |
|
| 9240 |
onRpc("onchange", ({ args }) => { |
| 9241 |
if (checkOnchange) { |
| 9242 |
expect.step("onchange"); |
| 9243 |
if (args[2][0] === "name") { |
| 9244 |
// onchange on field name |
| 9245 |
expect(args[1].foo).toBe("foo value"); |
| 9246 |
} else { |
| 9247 |
// onchange on field p |
| 9248 |
expect(args[1].child_ids).toEqual([ |
| 9249 |
[0, args[1].child_ids[0][1], { name: "readonly", foo: "foo value" }], |
| 9250 |
]); |
| 9251 |
} |
| 9252 |
} |
| 9253 |
}); |
| 9254 |
onRpc("web_save", ({ args }) => { |
| 9255 |
expect.step("web_save"); |
| 9256 |
expect(args[1]).toEqual({ |
| 9257 |
child_ids: [[0, args[1].child_ids[0][1], { name: "readonly" }]], |
| 9258 |
}); |
| 9259 |
}); |
| 9260 |
await mountView({ |
| 9261 |
resModel: "partner", |
| 9262 |
type: "form", |
| 9263 |
arch: ` |
| 9264 |
<form> |
| 9265 |
<field name="child_ids"> |
| 9266 |
<list><field name="name"/></list> |
| 9267 |
<form> |
| 9268 |
<field name="name"/> |
| 9269 |
<field name="foo" readonly="name == 'readonly'"/> |
| 9270 |
</form> |
| 9271 |
</field> |
| 9272 |
</form> |
| 9273 |
`, |
| 9274 |
}); |
| 9275 |
|
| 9276 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 9277 |
expect(`.modal .o_field_widget[name=foo] input`).toHaveCount(1); |
| 9278 |
|
| 9279 |
checkOnchange = true; |
| 9280 |
await contains(`.modal .o_field_widget[name=foo] input`).edit("foo value"); |
| 9281 |
await contains(`.modal .o_field_widget[name=name] input`).edit("readonly"); |
| 9282 |
expect.verifySteps(["onchange"]); |
| 9283 |
expect(`.modal .o_field_widget[name=foo] input`).toHaveCount(0); |
| 9284 |
|
| 9285 |
await contains(`.modal-footer .btn-primary`).click(); |
| 9286 |
expect.verifySteps(["onchange"]); |
| 9287 |
|
| 9288 |
checkOnchange = false; |
| 9289 |
await contains(`.o_data_row .o_data_cell`).click(); |
| 9290 |
expect(`.modal .o_field_widget[name=foo]`).toHaveText("foo value"); |
| 9291 |
await contains(`.modal-footer .btn-primary`).click(); |
| 9292 |
|
| 9293 |
await contains(`.o_form_button_save`).click(); |
| 9294 |
expect.verifySteps(["web_save"]); |
| 9295 |
}); |
| 9296 |
|
| 9297 |
test(`id is False in evalContext for new records`, async () => { |
| 9298 |
await mountView({ |
| 9299 |
resModel: "partner", |
| 9300 |
type: "form", |
| 9301 |
arch: ` |
| 9302 |
<form> |
| 9303 |
<field name="id"/> |
| 9304 |
<field name="foo" readonly="not id"/> |
| 9305 |
</form> |
| 9306 |
`, |
| 9307 |
}); |
| 9308 |
expect(`.o_field_widget[name=foo]`).toHaveClass("o_readonly_modifier"); |
| 9309 |
|
| 9310 |
await contains(`.o_form_button_save`).click(); |
| 9311 |
expect(`.o_field_widget[name=foo]`).not.toHaveClass("o_readonly_modifier"); |
| 9312 |
}); |
| 9313 |
|
| 9314 |
test(`delete a duplicated record`, async () => { |
| 9315 |
const newRecordID = 6; // ids from 1 to 5 are already taken so the new record will have id 6 |
| 9316 |
onRpc("unlink", ({ args }) => { |
| 9317 |
expect.step("unlink"); |
| 9318 |
expect(args[0]).toEqual([newRecordID]); |
| 9319 |
}); |
| 9320 |
|
| 9321 |
await mountView({ |
| 9322 |
resModel: "partner", |
| 9323 |
type: "form", |
| 9324 |
arch: `<form><field name="display_name"/></form>`, |
| 9325 |
resId: 1, |
| 9326 |
actionMenus: {}, |
| 9327 |
}); |
| 9328 |
|
| 9329 |
await toggleActionMenu(); |
| 9330 |
await toggleMenuItem("Duplicate"); |
| 9331 |
expect(`.o_form_editable`).toHaveCount(1); |
| 9332 |
expect(`.o_field_widget`).toHaveText("first record (copy)"); |
| 9333 |
|
| 9334 |
await toggleActionMenu(); |
| 9335 |
await toggleMenuItem("Delete"); |
| 9336 |
expect(`.modal`).toHaveCount(1); |
| 9337 |
|
| 9338 |
await contains(`.modal-footer .btn-primary`).click(); |
| 9339 |
expect(`.o_field_widget`).toHaveText("first record"); |
| 9340 |
expect.verifySteps(["unlink"]); |
| 9341 |
}); |
| 9342 |
|
| 9343 |
test.tags("desktop"); |
| 9344 |
test(`display tooltips for buttons (debug = false)`, async () => { |
| 9345 |
await mountView({ |
| 9346 |
resModel: "partner", |
| 9347 |
type: "form", |
| 9348 |
arch: ` |
| 9349 |
<form> |
| 9350 |
<header> |
| 9351 |
<button name="some_method" class="oe_highlight" string="Button" type="object" title="This is title"/> |
| 9352 |
<button name="empty_method" string="Empty Button" type="object"/> |
| 9353 |
</header> |
| 9354 |
<button name="other_method" class="oe_highlight" string="Button2" type="object" help="help Button2"/> |
| 9355 |
</form> |
| 9356 |
`, |
| 9357 |
}); |
| 9358 |
|
| 9359 |
await hover(`button[name='empty_method']`); |
| 9360 |
await runAllTimers(); |
| 9361 |
expect(`.o-tooltip`).toHaveCount(0); |
| 9362 |
|
| 9363 |
await hover(`button[name='some_method']`); |
| 9364 |
await runAllTimers(); |
| 9365 |
expect(`.o-tooltip`).toHaveText("This is title"); |
| 9366 |
|
| 9367 |
await hover(`button[name='other_method']`); |
| 9368 |
await runAllTimers(); |
| 9369 |
expect(`.o-tooltip`).toHaveText("Button2\n\nhelp Button2"); |
| 9370 |
}); |
| 9371 |
|
| 9372 |
test.tags("desktop"); |
| 9373 |
test(`display tooltips for buttons (debug = true)`, async () => { |
| 9374 |
serverState.debug = "1"; |
| 9375 |
|
| 9376 |
await mountView({ |
| 9377 |
resModel: "partner", |
| 9378 |
type: "form", |
| 9379 |
arch: ` |
| 9380 |
<form> |
| 9381 |
<header> |
| 9382 |
<button name="some_method" class="oe_highlight" string="Button" type="object" title="This is title" readonly="display_name == 'readonly'"/> |
| 9383 |
<button name="empty_method" string="Empty Button" type="object"/> |
| 9384 |
</header> |
| 9385 |
<button name="other_method" class="oe_highlight" string="Button2" type="object" help="help Button2"/> |
| 9386 |
</form> |
| 9387 |
`, |
| 9388 |
}); |
| 9389 |
|
| 9390 |
await hover(`button[name='empty_method']`); |
| 9391 |
await runAllTimers(); |
| 9392 |
expect(`.o-tooltip`).toHaveText( |
| 9393 |
"Button : Empty Button\nObject:partner\nButton Type:object\nMethod:empty_method" |
| 9394 |
); |
| 9395 |
|
| 9396 |
await hover(`button[name='some_method']`); |
| 9397 |
await runAllTimers(); |
| 9398 |
expect(`.o-tooltip`).toHaveText( |
| 9399 |
`Button : Button\n\nThis is title\n\nObject:partner\nReadonly:display_name == 'readonly'\nButton Type:object\nMethod:some_method` |
| 9400 |
); |
| 9401 |
|
| 9402 |
await hover(`button[name='other_method']`); |
| 9403 |
await runAllTimers(); |
| 9404 |
expect(`.o-tooltip`).toHaveText( |
| 9405 |
`Button : Button2\n\nhelp Button2\n\nObject:partner\nButton Type:object\nMethod:other_method` |
| 9406 |
); |
| 9407 |
}); |
| 9408 |
|
| 9409 |
test(`reload event is handled only once`, async () => { |
| 9410 |
// In this test, several form controllers are nested (all of them are |
| 9411 |
// opened in dialogs). When the users clicks on save in the last |
| 9412 |
// opened dialog, a 'reload' event is triggered up to reload the (direct) |
| 9413 |
// parent view. If this event isn't stopPropagated by the first controller |
| 9414 |
// catching it, it will crash when the other one will try to handle it, |
| 9415 |
// as this one doesn't know at all the dataPointID to reload. |
| 9416 |
Partner._views = { |
| 9417 |
form: `<form><field name="name"/><field name="parent_id"/></form>`, |
| 9418 |
}; |
| 9419 |
|
| 9420 |
onRpc("get_formview_id", () => false); |
| 9421 |
onRpc(({ method }) => expect.step(method)); |
| 9422 |
await mountViewInDialog({ |
| 9423 |
resModel: "partner", |
| 9424 |
type: "form", |
| 9425 |
arch: `<form><field name="display_name"/><field name="parent_id"/></form>`, |
| 9426 |
resId: 2, |
| 9427 |
}); |
| 9428 |
expect.verifySteps(["get_views", "web_read"]); |
| 9429 |
expect(`.o_dialog`).toHaveCount(1); |
| 9430 |
|
| 9431 |
await contains(`.o_external_button`, { visible: false }).click(); |
| 9432 |
expect(`.o_dialog`).toHaveCount(2); |
| 9433 |
expect.verifySteps([ |
| 9434 |
"get_formview_id", // id of first form view opened in a dialog |
| 9435 |
"get_views", // arch of first form view opened in a dialog |
| 9436 |
"web_read", // first dialog |
| 9437 |
]); |
| 9438 |
|
| 9439 |
await contains(`.o_dialog:eq(1) .o_external_button`, { visible: false }).click(); |
| 9440 |
expect(`.o_dialog`).toHaveCount(3); |
| 9441 |
expect.verifySteps([ |
| 9442 |
"get_formview_id", // id of second form view opened in a dialog |
| 9443 |
"web_read", // second dialog |
| 9444 |
]); |
| 9445 |
|
| 9446 |
await contains(`.o_dialog:eq(2) .o_field_widget[name=name] input`).edit("new name"); |
| 9447 |
await contains(`.o_dialog:eq(2) footer .o_form_button_save`).click(); |
| 9448 |
expect.verifySteps([ |
| 9449 |
"web_save", |
| 9450 |
"read", // reload the name (first dialog) |
| 9451 |
]); |
| 9452 |
expect(`.o_dialog:eq(1) .o_field_widget[name="parent_id"] input`).toHaveValue("new name"); |
| 9453 |
}); |
| 9454 |
|
| 9455 |
test(`process the context for inline subview`, async () => { |
| 9456 |
Partner._records[0].child_ids = [2]; |
| 9457 |
|
| 9458 |
await mountView({ |
| 9459 |
resModel: "partner", |
| 9460 |
type: "form", |
| 9461 |
arch: ` |
| 9462 |
<form> |
| 9463 |
<field name="child_ids"> |
| 9464 |
<list> |
| 9465 |
<field name="foo"/> |
| 9466 |
<field name="bar" column_invisible="context.get('hide_bar', False)"/> |
| 9467 |
<field name="int_field" column_invisible="True"/> |
| 9468 |
</list> |
| 9469 |
</field> |
| 9470 |
</form> |
| 9471 |
`, |
| 9472 |
resId: 1, |
| 9473 |
context: { hide_bar: true }, |
| 9474 |
}); |
| 9475 |
expect(`.o_list_renderer thead tr th:not(.o_list_actions_header)`).toHaveCount(1); |
| 9476 |
}); |
| 9477 |
|
| 9478 |
test.tags("desktop"); |
| 9479 |
test(`process the context for subview not inline`, async () => { |
| 9480 |
Partner._records[0].child_ids = [2]; |
| 9481 |
Partner._views = { |
| 9482 |
list: ` |
| 9483 |
<list> |
| 9484 |
<field name="foo"/> |
| 9485 |
<field name="bar" column_invisible="context.get('hide_bar', False)"/> |
| 9486 |
</list> |
| 9487 |
`, |
| 9488 |
}; |
| 9489 |
|
| 9490 |
await mountView({ |
| 9491 |
resModel: "partner", |
| 9492 |
type: "form", |
| 9493 |
arch: `<form><field name="child_ids" widget="one2many"/></form>`, |
| 9494 |
resId: 1, |
| 9495 |
context: { hide_bar: true }, |
| 9496 |
}); |
| 9497 |
expect(`.o_list_renderer thead tr th:not(.o_list_actions_header)`).toHaveCount(1); |
| 9498 |
}); |
| 9499 |
|
| 9500 |
test(`Can switch to form view on inline tree`, async () => { |
| 9501 |
const id = 2; |
| 9502 |
mockService("action", { |
| 9503 |
doAction(action, options) { |
| 9504 |
expect.step("doAction"); |
| 9505 |
expect(action).toEqual({ |
| 9506 |
context: { |
| 9507 |
allowed_company_ids: [1], |
| 9508 |
lang: "en", |
| 9509 |
tz: "taht", |
| 9510 |
uid: 7, |
| 9511 |
}, |
| 9512 |
res_id: id, |
| 9513 |
res_model: "partner", |
| 9514 |
type: "ir.actions.act_window", |
| 9515 |
views: [[false, "form"]], |
| 9516 |
}); |
| 9517 |
expect(options.props).toEqual({ resIds: [id] }); |
| 9518 |
}, |
| 9519 |
}); |
| 9520 |
|
| 9521 |
Partner._records[0].child_ids = [id]; |
| 9522 |
await mountView({ |
| 9523 |
resModel: "partner", |
| 9524 |
type: "form", |
| 9525 |
arch: ` |
| 9526 |
<form> |
| 9527 |
<field name="child_ids"> |
| 9528 |
<list editable="top" open_form_view="1"> |
| 9529 |
<field name="foo"/> |
| 9530 |
</list> |
| 9531 |
</field> |
| 9532 |
</form> |
| 9533 |
`, |
| 9534 |
resId: 1, |
| 9535 |
}); |
| 9536 |
expect(`td.o_list_record_open_form_view`).toHaveCount(1); |
| 9537 |
|
| 9538 |
await contains(`td.o_list_record_open_form_view`).click(); |
| 9539 |
expect.verifySteps(["doAction"]); |
| 9540 |
}); |
| 9541 |
|
| 9542 |
test(`x2many field, open form view in new window`, async () => { |
| 9543 |
mockService("action", { |
| 9544 |
doAction(params, options) { |
| 9545 |
if (options?.newWindow) { |
| 9546 |
expect.step("opened in a new window"); |
| 9547 |
return; |
| 9548 |
} |
| 9549 |
super.doAction(params); |
| 9550 |
}, |
| 9551 |
loadState() {}, |
| 9552 |
}); |
| 9553 |
Partner._records[0].child_ids = [2]; |
| 9554 |
await mountView({ |
| 9555 |
resModel: "partner", |
| 9556 |
type: "form", |
| 9557 |
arch: ` |
| 9558 |
<form> |
| 9559 |
<field name="child_ids"> |
| 9560 |
<list editable="top" open_form_view="1"> |
| 9561 |
<field name="foo"/> |
| 9562 |
</list> |
| 9563 |
</field> |
| 9564 |
</form> |
| 9565 |
`, |
| 9566 |
resId: 1, |
| 9567 |
}); |
| 9568 |
expect(`td.o_list_record_open_form_view`).toHaveCount(1); |
| 9569 |
|
| 9570 |
await middleClick("td.o_list_record_open_form_view"); |
| 9571 |
await animationFrame(); |
| 9572 |
expect.verifySteps(["opened in a new window"]); |
| 9573 |
}); |
| 9574 |
|
| 9575 |
test(`can toggle column in x2many in sub form view`, async () => { |
| 9576 |
Partner._records[2].child_ids = [1, 2]; |
| 9577 |
Partner._fields.foo = fields.Char({ sortable: true }); |
| 9578 |
Partner._views = { |
| 9579 |
form: ` |
| 9580 |
<form> |
| 9581 |
<field name="child_ids"> |
| 9582 |
<list><field name="foo"/></list> |
| 9583 |
</field> |
| 9584 |
</form> |
| 9585 |
`, |
| 9586 |
}; |
| 9587 |
|
| 9588 |
onRpc("get_formview_id", () => false); |
| 9589 |
await mountViewInDialog({ |
| 9590 |
resModel: "partner", |
| 9591 |
type: "form", |
| 9592 |
arch: `<form><field name="parent_id"/></form>`, |
| 9593 |
resId: 1, |
| 9594 |
}); |
| 9595 |
await contains(`.o_external_button`, { visible: false }).click(); |
| 9596 |
expect(queryAllTexts`.o_dialog:not(.o_inactive_modal) .o_data_cell`).toEqual(["yop", "blip"]); |
| 9597 |
|
| 9598 |
await contains(`.o_dialog:not(.o_inactive_modal) th.o_column_sortable`).click(); |
| 9599 |
expect(queryAllTexts`.o_dialog:not(.o_inactive_modal) .o_data_cell`).toEqual(["blip", "yop"]); |
| 9600 |
}); |
| 9601 |
|
| 9602 |
test(`rainbowman attributes correctly passed on button click`, async () => { |
| 9603 |
mockService("action", { |
| 9604 |
doActionButton({ effect }) { |
| 9605 |
expect.step("doActionButton"); |
| 9606 |
expect(effect).toBe("{'message': 'Congrats!'}"); |
| 9607 |
}, |
| 9608 |
}); |
| 9609 |
|
| 9610 |
await mountView({ |
| 9611 |
resModel: "partner", |
| 9612 |
type: "form", |
| 9613 |
arch: ` |
| 9614 |
<form> |
| 9615 |
<header> |
| 9616 |
<button name="action_won" string="Won" type="object" effect="{'message': 'Congrats!'}"/> |
| 9617 |
</header> |
| 9618 |
</form> |
| 9619 |
`, |
| 9620 |
}); |
| 9621 |
await contains(`.o_form_statusbar .btn-secondary`).click(); |
| 9622 |
expect.verifySteps(["doActionButton"]); |
| 9623 |
}); |
| 9624 |
|
| 9625 |
test(`basic support for widgets`, async () => { |
| 9626 |
class MyComponent extends Component { |
| 9627 |
static props = ["*"]; |
| 9628 |
static template = xml`<div t-esc="value"/>`; |
| 9629 |
get value() { |
| 9630 |
return JSON.stringify(this.props.record.data); |
| 9631 |
} |
| 9632 |
} |
| 9633 |
widgetsRegistry.add("test_widget", { component: MyComponent }); |
| 9634 |
|
| 9635 |
await mountView({ |
| 9636 |
resModel: "partner", |
| 9637 |
type: "form", |
| 9638 |
arch: ` |
| 9639 |
<form> |
| 9640 |
<field name="foo"/> |
| 9641 |
<field name="bar"/> |
| 9642 |
<widget name="test_widget"/> |
| 9643 |
</form> |
| 9644 |
`, |
| 9645 |
}); |
| 9646 |
expect(`.o_widget`).toHaveText(`{"foo":"My little Foo Value","bar":false,"display_name":""}`); |
| 9647 |
}); |
| 9648 |
|
| 9649 |
test(`widget with class attribute`, async () => { |
| 9650 |
class MyComponent extends Component { |
| 9651 |
static props = ["*"]; |
| 9652 |
static template = xml`<span>Hello</span>`; |
| 9653 |
} |
| 9654 |
widgetsRegistry.add("test_widget", { component: MyComponent }); |
| 9655 |
|
| 9656 |
await mountView({ |
| 9657 |
resModel: "partner", |
| 9658 |
type: "form", |
| 9659 |
arch: `<form><widget name="test_widget" class="my_classname"/></form>`, |
| 9660 |
}); |
| 9661 |
expect(`.o_widget.my_classname`).toHaveCount(1); |
| 9662 |
}); |
| 9663 |
|
| 9664 |
test(`widget with readonly attribute`, async () => { |
| 9665 |
class MyComponent extends Component { |
| 9666 |
static props = ["*"]; |
| 9667 |
static template = xml`<span t-esc="value"/>`; |
| 9668 |
get value() { |
| 9669 |
return this.props.readonly ? "readonly" : "not readonly"; |
| 9670 |
} |
| 9671 |
} |
| 9672 |
widgetsRegistry.add("test_widget", { |
| 9673 |
component: MyComponent, |
| 9674 |
extractProps(widgetInfo, dynamicInfo) { |
| 9675 |
return { readonly: dynamicInfo.readonly }; |
| 9676 |
}, |
| 9677 |
}); |
| 9678 |
|
| 9679 |
await mountView({ |
| 9680 |
resModel: "partner", |
| 9681 |
type: "form", |
| 9682 |
arch: ` |
| 9683 |
<form> |
| 9684 |
<field name="bar"/> |
| 9685 |
<widget name="test_widget" readonly="bar"/> |
| 9686 |
</form> |
| 9687 |
`, |
| 9688 |
}); |
| 9689 |
expect(`.o_widget`).toHaveText("not readonly"); |
| 9690 |
|
| 9691 |
await contains(`.o_field_widget[name=bar] input`).click(); |
| 9692 |
expect(`.o_widget`).toHaveText("readonly"); |
| 9693 |
}); |
| 9694 |
|
| 9695 |
test.tags("desktop"); |
| 9696 |
test(`support header button as widgets on form statusbar on desktop`, async () => { |
| 9697 |
await mountView({ |
| 9698 |
resModel: "partner", |
| 9699 |
type: "form", |
| 9700 |
arch: `<form><header><widget name="attach_document" string="Attach document"/></header></form>`, |
| 9701 |
}); |
| 9702 |
expect(`button.o_attachment_button`).toHaveCount(1); |
| 9703 |
expect(`span.o_attach_document`).toHaveText("Attach document"); |
| 9704 |
}); |
| 9705 |
|
| 9706 |
test.tags("mobile"); |
| 9707 |
test(`support header button as widgets on form statusbar on mobile`, async () => { |
| 9708 |
await mountView({ |
| 9709 |
resModel: "partner", |
| 9710 |
type: "form", |
| 9711 |
arch: `<form><header><widget name="attach_document" string="Attach document"/></header></form>`, |
| 9712 |
}); |
| 9713 |
await contains(`.o_cp_action_menus button:has(.fa-cog)`).click(); |
| 9714 |
expect(`button.o_attachment_button`).toHaveCount(1); |
| 9715 |
expect(`span.o_attach_document`).toHaveText("Attach document"); |
| 9716 |
}); |
| 9717 |
|
| 9718 |
test(`basic support for widgets: onchange update`, async () => { |
| 9719 |
class MyWidget extends Component { |
| 9720 |
static props = ["*"]; |
| 9721 |
static template = xml`<t t-esc="state.dataToDisplay" />`; |
| 9722 |
setup() { |
| 9723 |
this.state = useState({ |
| 9724 |
dataToDisplay: this.props.record.data.foo, |
| 9725 |
}); |
| 9726 |
useEffect(() => { |
| 9727 |
this.state.dataToDisplay = this.props.record.data.foo + "!"; |
| 9728 |
}); |
| 9729 |
} |
| 9730 |
} |
| 9731 |
widgetsRegistry.add("test_widget", { component: MyWidget }); |
| 9732 |
|
| 9733 |
await mountView({ |
| 9734 |
resModel: "partner", |
| 9735 |
type: "form", |
| 9736 |
arch: `<form><field name="foo"/><widget name="test_widget"/></form>`, |
| 9737 |
}); |
| 9738 |
await contains(`.o_field_widget[name="foo"] input`).edit("I am alive"); |
| 9739 |
await animationFrame(); // wait for effect |
| 9740 |
expect(`.o_widget`).toHaveText("I am alive!"); |
| 9741 |
}); |
| 9742 |
|
| 9743 |
test.tags("desktop"); |
| 9744 |
test(`proper stringification in debug mode tooltip`, async () => { |
| 9745 |
serverState.debug = "1"; |
| 9746 |
|
| 9747 |
await mountView({ |
| 9748 |
resModel: "partner", |
| 9749 |
type: "form", |
| 9750 |
arch: ` |
| 9751 |
<form> |
| 9752 |
<sheet> |
| 9753 |
<field name="product_id" domain="[]" context="{'lang': 'en_US'}" invisible="product_id == 33" widget="many2one"/> |
| 9754 |
</sheet> |
| 9755 |
</form> |
| 9756 |
`, |
| 9757 |
}); |
| 9758 |
|
| 9759 |
await hover(`[name='product_id']`); |
| 9760 |
await runAllTimers(); |
| 9761 |
expect(`.o-tooltip--technical > li[data-item="context"]`).toHaveCount(1); |
| 9762 |
expect(`.o-tooltip--technical > li[data-item="context"]`).toHaveText(/{'lang': 'en_US'}/); |
| 9763 |
expect(`.o-tooltip--technical > li[data-item="domain"]`).toHaveCount(1); |
| 9764 |
expect(`.o-tooltip--technical > li[data-item="domain"]`).toHaveText(/\[\]/); |
| 9765 |
expect(`.o-tooltip--technical > li[data-item="invisible"]`).toHaveCount(1); |
| 9766 |
expect(`.o-tooltip--technical > li[data-item="invisible"]`).toHaveText(/product_id == 33/); |
| 9767 |
expect(`.o-tooltip--technical > li[data-item="widget"]`).toHaveCount(1); |
| 9768 |
expect(`.o-tooltip--technical > li[data-item="widget"]`).toHaveText( |
| 9769 |
/Widget:Many2one \(many2one\)/ |
| 9770 |
); |
| 9771 |
}); |
| 9772 |
|
| 9773 |
test.tags("desktop"); |
| 9774 |
test(`field tooltip in debug mode, on field with domain attr`, async () => { |
| 9775 |
serverState.debug = "1"; |
| 9776 |
|
| 9777 |
await mountView({ |
| 9778 |
resModel: "partner", |
| 9779 |
type: "form", |
| 9780 |
arch: ` |
| 9781 |
<form> |
| 9782 |
<sheet> |
| 9783 |
<field name="product_id" domain="[['id', '>', 3]]"/> |
| 9784 |
</sheet> |
| 9785 |
</form> |
| 9786 |
`, |
| 9787 |
}); |
| 9788 |
|
| 9789 |
await hover(`[name='product_id']`); |
| 9790 |
await runAllTimers(); |
| 9791 |
expect(`.o-tooltip--technical > li[data-item="domain"]`).toHaveCount(1); |
| 9792 |
expect(`.o-tooltip--technical > li[data-item="domain"]`).toHaveText(/\[\['id', '>', 3\]\]/); |
| 9793 |
}); |
| 9794 |
|
| 9795 |
test.tags("desktop"); |
| 9796 |
test(`do not display unset attributes in debug field tooltip`, async () => { |
| 9797 |
serverState.debug = "1"; |
| 9798 |
|
| 9799 |
await mountView({ |
| 9800 |
resModel: "partner", |
| 9801 |
type: "form", |
| 9802 |
arch: ` |
| 9803 |
<form> |
| 9804 |
<sheet> |
| 9805 |
<field name="product_id"/> |
| 9806 |
</sheet> |
| 9807 |
</form> |
| 9808 |
`, |
| 9809 |
}); |
| 9810 |
|
| 9811 |
await hover(`[name='product_id']`); |
| 9812 |
await runAllTimers(); |
| 9813 |
expect(queryAllTexts`.o-tooltip--technical > li`).toEqual([ |
| 9814 |
"Label:Product", |
| 9815 |
"Field:product_id", |
| 9816 |
"Type:many2one", |
| 9817 |
"Context:{}", |
| 9818 |
"Relation:product", |
| 9819 |
]); |
| 9820 |
}); |
| 9821 |
|
| 9822 |
test.tags("desktop"); |
| 9823 |
test(`do not change pager when discarding current record on desktop`, async () => { |
| 9824 |
await mountView({ |
| 9825 |
resModel: "partner", |
| 9826 |
type: "form", |
| 9827 |
arch: `<form><field name="foo"/></form>`, |
| 9828 |
resIds: [1, 2], |
| 9829 |
resId: 2, |
| 9830 |
}); |
| 9831 |
expect(getPagerValue()).toEqual([2]); |
| 9832 |
expect(getPagerLimit()).toBe(2); |
| 9833 |
|
| 9834 |
await contains(`.o_form_button_cancel`, { visible: false }).click(); |
| 9835 |
expect(getPagerValue()).toEqual([2]); |
| 9836 |
expect(getPagerLimit()).toBe(2); |
| 9837 |
}); |
| 9838 |
|
| 9839 |
test.tags("desktop"); |
| 9840 |
test(`coming to a form view from a grouped and sorted list`, async () => { |
| 9841 |
defineActions([ |
| 9842 |
{ |
| 9843 |
id: 1, |
| 9844 |
name: "test", |
| 9845 |
res_model: "partner", |
| 9846 |
views: [ |
| 9847 |
[false, "list"], |
| 9848 |
[false, "form"], |
| 9849 |
], |
| 9850 |
}, |
| 9851 |
]); |
| 9852 |
|
| 9853 |
Partner._fields.foo = fields.Char({ default: "My little Foo Value", sortable: true }); |
| 9854 |
Partner._records[0].type_ids = [12, 14]; |
| 9855 |
Partner._views = { |
| 9856 |
list: `<list><field name="foo"/></list>`, |
| 9857 |
search: ` |
| 9858 |
<search> |
| 9859 |
<filter string="bar" name="Bar" context="{'group_by': 'bar'}"/> |
| 9860 |
</search> |
| 9861 |
`, |
| 9862 |
form: ` |
| 9863 |
<form> |
| 9864 |
<field name="foo"/> |
| 9865 |
<field name="type_ids"/> |
| 9866 |
</form> |
| 9867 |
`, |
| 9868 |
}; |
| 9869 |
PartnerType._views = { |
| 9870 |
list: `<list><field name="display_name"/></list>`, |
| 9871 |
}; |
| 9872 |
|
| 9873 |
onRpc("partner", "web_read", ({ kwargs }) => { |
| 9874 |
expect(kwargs.context).toEqual({ |
| 9875 |
bin_size: true, |
| 9876 |
lang: "en", |
| 9877 |
tz: "taht", |
| 9878 |
uid: 7, |
| 9879 |
allowed_company_ids: [1], |
| 9880 |
}); |
| 9881 |
}); |
| 9882 |
onRpc(({ model, method }) => expect.step(`${model}:${method}`)); |
| 9883 |
|
| 9884 |
await mountWithCleanup(WebClient); |
| 9885 |
await getService("action").doAction(1); |
| 9886 |
expect.verifySteps(["partner:get_views", "partner:web_search_read", "res.users:has_group"]); |
| 9887 |
expect(`.o_list_view`).toHaveCount(1); |
| 9888 |
expect(`.o_data_row`).toHaveCount(4); |
| 9889 |
expect(queryAllTexts`.o_data_cell`).toEqual(["yop", "blip", "My little Foo Value", ""]); |
| 9890 |
|
| 9891 |
await contains(`th.o_column_sortable`).click(); |
| 9892 |
expect(queryAllTexts`.o_data_cell`).toEqual(["", "My little Foo Value", "blip", "yop"]); |
| 9893 |
expect.verifySteps(["partner:web_search_read"]); |
| 9894 |
|
| 9895 |
await toggleSearchBarMenu(); |
| 9896 |
await toggleMenuItem("bar"); |
| 9897 |
expect(`.o_group_header`).toHaveCount(2); |
| 9898 |
expect(`.o_data_row`).toHaveCount(0); |
| 9899 |
expect.verifySteps(["partner:web_read_group"]); |
| 9900 |
|
| 9901 |
await contains(`.o_group_header:eq(1)`).click(); |
| 9902 |
expect(`.o_group_header`).toHaveCount(2); |
| 9903 |
expect(`.o_data_row`).toHaveCount(2); |
| 9904 |
expect.verifySteps(["partner:web_search_read"]); |
| 9905 |
|
| 9906 |
await contains(`.o_data_row:eq(1) .o_data_cell`).click(); |
| 9907 |
expect(`.o_form_view`).toHaveCount(1); |
| 9908 |
expect(queryAllTexts`.o_data_cell`).toEqual(["gold", "silver"]); |
| 9909 |
expect.verifySteps(["partner:web_read"]); |
| 9910 |
}); |
| 9911 |
|
| 9912 |
test.tags("desktop"); |
| 9913 |
test(`keep editing after call_button fail`, async () => { |
| 9914 |
expect.errors(1); |
| 9915 |
|
| 9916 |
let values = null; |
| 9917 |
mockService("action", { |
| 9918 |
doActionButton({ name, type }) { |
| 9919 |
expect([name, type]).toEqual(["post", "object"]); |
| 9920 |
throw makeServerError(); |
| 9921 |
}, |
| 9922 |
}); |
| 9923 |
|
| 9924 |
onRpc("web_save", ({ args }) => { |
| 9925 |
expect.step("web_save"); |
| 9926 |
expect(args[1].child_ids[0][2]).toEqual(values); |
| 9927 |
}); |
| 9928 |
await mountView({ |
| 9929 |
resModel: "partner", |
| 9930 |
type: "form", |
| 9931 |
arch: ` |
| 9932 |
<form> |
| 9933 |
<button name="post" class="child_ids" string="Raise Error" type="object"/> |
| 9934 |
<field name="child_ids"> |
| 9935 |
<list editable="top"> |
| 9936 |
<field name="name"/> |
| 9937 |
<field name="product_id"/> |
| 9938 |
</list> |
| 9939 |
</field> |
| 9940 |
</form> |
| 9941 |
`, |
| 9942 |
resId: 1, |
| 9943 |
}); |
| 9944 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 9945 |
await contains(`.o_field_widget[name=name] input`).edit("abc", { confirm: false }); |
| 9946 |
values = { |
| 9947 |
name: "abc", |
| 9948 |
product_id: false, |
| 9949 |
}; |
| 9950 |
await contains(`button.child_ids`).click(); |
| 9951 |
expect.verifySteps(["web_save"]); |
| 9952 |
expect.verifyErrors(["RPC_ERROR: Odoo Server Error"]); |
| 9953 |
|
| 9954 |
await contains(`.o_form_view .o_field_one2many .o_data_row .o_data_cell:eq(1)`).click(); |
| 9955 |
await contains(`.o_field_many2one[name="product_id"] input`).click(); |
| 9956 |
await contains(`.dropdown .dropdown-item:contains(xphone)`).click(); |
| 9957 |
expect(`.o_field_many2one input`).toHaveValue("xphone"); |
| 9958 |
|
| 9959 |
values = { |
| 9960 |
product_id: 37, |
| 9961 |
}; |
| 9962 |
await contains(`.o_form_button_save`).click(); |
| 9963 |
expect.verifySteps(["web_save"]); |
| 9964 |
}); |
| 9965 |
|
| 9966 |
test(`no deadlock when saving with uncommitted changes`, async () => { |
| 9967 |
// Before saving a record, all field widgets are asked to commit their changes (new values |
| 9968 |
// that they wouldn't have sent to the model yet). This test is added alongside a bug fix |
| 9969 |
// ensuring that we don't end up in a deadlock when a widget actually has some changes to |
| 9970 |
// commit at that moment. By chance, this situation isn't reached when the user clicks on |
| 9971 |
// 'Save' (which is the natural way to save a record), because by clicking outside the |
| 9972 |
// widget, the 'change' event (this is mainly for InputFields) is triggered, and the widget |
| 9973 |
// notifies the model of its new value on its own initiative, before being requested to. |
| 9974 |
// In this test, we try to reproduce the deadlock situation by forcing the field widget to |
| 9975 |
// commit changes before the save. We thus manually call 'saveRecord', instead of clicking |
| 9976 |
// on 'Save'. |
| 9977 |
onRpc(({ method }) => expect.step(method)); |
| 9978 |
await mountView({ |
| 9979 |
resModel: "partner", |
| 9980 |
type: "form", |
| 9981 |
arch: `<form><field name="foo"/></form>`, |
| 9982 |
}); |
| 9983 |
expect.verifySteps(["get_views", "onchange"]); |
| 9984 |
|
| 9985 |
await contains(`.o_field_widget[name=foo] input`).edit("some foo value"); |
| 9986 |
await contains(`.o_form_button_save`).click(); |
| 9987 |
expect(`.o_form_editable`).toHaveCount(1); |
| 9988 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("some foo value"); |
| 9989 |
expect.verifySteps(["web_save"]); |
| 9990 |
}); |
| 9991 |
|
| 9992 |
test(`saving with invalid uncommitted changes`, async () => { |
| 9993 |
onRpc(({ method }) => expect.step(method)); |
| 9994 |
await mountView({ |
| 9995 |
resModel: "partner", |
| 9996 |
type: "form", |
| 9997 |
arch: `<form><field name="float_field"/></form>`, |
| 9998 |
}); |
| 9999 |
expect.verifySteps(["get_views", "onchange"]); |
| 10000 |
|
| 10001 |
await contains(`.o_field_widget[name=float_field] input`).edit("some float_field value"); |
| 10002 |
await contains(`.o_form_button_save`).click(); |
| 10003 |
expect(`.o_form_editable`).toHaveCount(1); |
| 10004 |
expect(`.o_form_view .o_form_editable input`).toHaveValue("some float_field value"); |
| 10005 |
expect(`[name=float_field]`).toHaveClass("o_field_invalid"); |
| 10006 |
expect(`.o_notification_bar.bg-danger`).toHaveCount(1); |
| 10007 |
expect(`.o_form_editable .o_field_invalid[name=float_field]`).toHaveCount(1); |
| 10008 |
expect.verifySteps([]); |
| 10009 |
}); |
| 10010 |
|
| 10011 |
test(`save record with onchange on one2many with required field`, async () => { |
| 10012 |
// in this test, we have a one2many with a required field, whose value is |
| 10013 |
// set by an onchange on another field ; we manually set the value of that |
| 10014 |
// first field, and directly click on Save (before the onchange RPC returns |
| 10015 |
// and sets the value of the required field) |
| 10016 |
|
| 10017 |
Partner._fields.foo = fields.Char(); |
| 10018 |
Partner._onChanges = { |
| 10019 |
name(record) { |
| 10020 |
record.foo = record.name ? "foo value" : undefined; |
| 10021 |
}, |
| 10022 |
}; |
| 10023 |
|
| 10024 |
let onchangeDeferred = undefined; |
| 10025 |
onRpc("onchange", () => onchangeDeferred); |
| 10026 |
onRpc("web_save", ({ args }) => { |
| 10027 |
expect.step("web_save"); |
| 10028 |
expect(args[1].child_ids[0][2].foo).toBe("foo value"); |
| 10029 |
}); |
| 10030 |
|
| 10031 |
await mountView({ |
| 10032 |
resModel: "partner", |
| 10033 |
type: "form", |
| 10034 |
arch: ` |
| 10035 |
<form> |
| 10036 |
<field name="child_ids"> |
| 10037 |
<list editable="top"> |
| 10038 |
<field name="name"/> |
| 10039 |
<field name="foo" required="1"/> |
| 10040 |
</list> |
| 10041 |
</field> |
| 10042 |
</form> |
| 10043 |
`, |
| 10044 |
}); |
| 10045 |
|
| 10046 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 10047 |
expect(`.o_field_widget[name=name] input`).toHaveValue(""); |
| 10048 |
expect(`.o_field_widget[name=foo] input`).toHaveValue(""); |
| 10049 |
|
| 10050 |
onchangeDeferred = new Deferred(); |
| 10051 |
await contains(`.o_field_widget[name=name] input`).edit("some value"); |
| 10052 |
await contains(`.o_form_button_save`).click(); |
| 10053 |
expect.verifySteps([]); |
| 10054 |
|
| 10055 |
onchangeDeferred.resolve(); |
| 10056 |
await animationFrame(); |
| 10057 |
expect.verifySteps(["web_save"]); |
| 10058 |
}); |
| 10059 |
|
| 10060 |
test.tags("desktop"); |
| 10061 |
test(`leave the form view while saving`, async () => { |
| 10062 |
Partner._onChanges = { |
| 10063 |
foo(record) { |
| 10064 |
record.name = record.foo === "trigger onchange" ? "changed" : "default"; |
| 10065 |
}, |
| 10066 |
}; |
| 10067 |
Partner._views = { |
| 10068 |
list: `<list><field name="name"/></list>`, |
| 10069 |
form: ` |
| 10070 |
<form> |
| 10071 |
<field name="name"/> |
| 10072 |
<field name="foo"/> |
| 10073 |
</form> |
| 10074 |
`, |
| 10075 |
}; |
| 10076 |
|
| 10077 |
defineActions([ |
| 10078 |
{ |
| 10079 |
id: 1, |
| 10080 |
name: "test", |
| 10081 |
res_model: "partner", |
| 10082 |
views: [ |
| 10083 |
[false, "list"], |
| 10084 |
[false, "form"], |
| 10085 |
], |
| 10086 |
}, |
| 10087 |
]); |
| 10088 |
|
| 10089 |
let onchangeDeferred = undefined; |
| 10090 |
onRpc("onchange", () => onchangeDeferred); |
| 10091 |
|
| 10092 |
const createDeferred = new Deferred(); |
| 10093 |
onRpc("web_save", () => createDeferred); |
| 10094 |
|
| 10095 |
await mountWithCleanup(WebClient); |
| 10096 |
await getService("action").doAction(1); |
| 10097 |
await contains(`.o_control_panel_main_buttons button.o_list_button_add`).click(); |
| 10098 |
|
| 10099 |
// edit foo to trigger a delayed onchange |
| 10100 |
onchangeDeferred = new Deferred(); |
| 10101 |
await contains(`.o_field_widget[name=foo] input`).edit("trigger onchange"); |
| 10102 |
expect(`.o_field_widget[name=name] input`).toHaveValue("default"); |
| 10103 |
|
| 10104 |
// save (will wait for the onchange to return), and will be delayed as well |
| 10105 |
await contains(`.o_form_button_save`).click(); |
| 10106 |
expect(`.o_form_editable`).toHaveCount(1); |
| 10107 |
expect(`.o_field_widget[name=name] input`).toHaveValue("default"); |
| 10108 |
|
| 10109 |
// click on the breadcrumbs to leave the form view |
| 10110 |
await contains(`.breadcrumb-item.o_back_button a`).click(); |
| 10111 |
await animationFrame(); |
| 10112 |
expect(`.o_form_editable`).toHaveCount(1); |
| 10113 |
expect(`.o_field_widget[name=name] input`).toHaveValue("default"); |
| 10114 |
|
| 10115 |
// unlock the onchange |
| 10116 |
onchangeDeferred.resolve(); |
| 10117 |
await animationFrame(); |
| 10118 |
expect(`.o_form_editable`).toHaveCount(1); |
| 10119 |
expect(`.o_field_widget[name=name] input`).toHaveValue("changed"); |
| 10120 |
|
| 10121 |
// unlock the create |
| 10122 |
createDeferred.resolve(); |
| 10123 |
await animationFrame(); |
| 10124 |
expect(`.o_list_view`).toHaveCount(1); |
| 10125 |
expect(`.o_list_table .o_data_row:last-child td.o_data_cell`).toHaveText("changed"); |
| 10126 |
}); |
| 10127 |
|
| 10128 |
test.tags("desktop"); |
| 10129 |
test(`leave the form twice (clicking on the breadcrumb) should save only once`, async () => { |
| 10130 |
defineActions([ |
| 10131 |
{ |
| 10132 |
id: 1, |
| 10133 |
name: "test", |
| 10134 |
res_model: "partner", |
| 10135 |
views: [ |
| 10136 |
[false, "list"], |
| 10137 |
[false, "form"], |
| 10138 |
], |
| 10139 |
}, |
| 10140 |
]); |
| 10141 |
|
| 10142 |
Partner._views = { |
| 10143 |
list: `<list><field name="foo"/></list>`, |
| 10144 |
form: ` |
| 10145 |
<form> |
| 10146 |
<field name="display_name"/> |
| 10147 |
<field name="foo"/> |
| 10148 |
</form> |
| 10149 |
`, |
| 10150 |
}; |
| 10151 |
|
| 10152 |
const writeDeferred = new Deferred(); |
| 10153 |
onRpc("web_save", async () => { |
| 10154 |
await writeDeferred; |
| 10155 |
expect.step("web_save"); |
| 10156 |
}); |
| 10157 |
|
| 10158 |
await mountWithCleanup(WebClient); |
| 10159 |
await getService("action").doAction(1); |
| 10160 |
|
| 10161 |
// switch to form view |
| 10162 |
await contains(`.o_list_table .o_data_row .o_data_cell`).click(); |
| 10163 |
expect(`.o_form_editable`).toHaveCount(1); |
| 10164 |
|
| 10165 |
await contains(`.o_field_widget[name=foo] input`).edit("some value"); |
| 10166 |
await contains(`.breadcrumb-item.o_back_button a`).click(); |
| 10167 |
expect(`.modal`).toHaveCount(0); |
| 10168 |
expect.verifySteps([]); |
| 10169 |
|
| 10170 |
await contains(`.breadcrumb-item.o_back_button a`).click(); |
| 10171 |
expect(`.modal`).toHaveCount(0); |
| 10172 |
expect.verifySteps([]); |
| 10173 |
|
| 10174 |
// unlock the create |
| 10175 |
writeDeferred.resolve(); |
| 10176 |
await animationFrame(); |
| 10177 |
expect.verifySteps(["web_save"]); |
| 10178 |
}); |
| 10179 |
|
| 10180 |
test.tags("desktop"); |
| 10181 |
test(`discard after a failed save (and close notifications)`, async () => { |
| 10182 |
Partner._views = { |
| 10183 |
form: ` |
| 10184 |
<form> |
| 10185 |
<field name="date" required="true"/> |
| 10186 |
<field name="foo" required="true"/> |
| 10187 |
</form> |
| 10188 |
`, |
| 10189 |
kanban: ` |
| 10190 |
<kanban> |
| 10191 |
<templates> |
| 10192 |
<t t-name="card"> |
| 10193 |
<field name="foo" /> |
| 10194 |
</t> |
| 10195 |
</templates> |
| 10196 |
</kanban> |
| 10197 |
`, |
| 10198 |
}; |
| 10199 |
|
| 10200 |
defineActions([ |
| 10201 |
{ |
| 10202 |
id: 1, |
| 10203 |
name: "Partner", |
| 10204 |
res_model: "partner", |
| 10205 |
views: [ |
| 10206 |
[false, "kanban"], |
| 10207 |
[false, "form"], |
| 10208 |
], |
| 10209 |
}, |
| 10210 |
]); |
| 10211 |
|
| 10212 |
await mountWithCleanup(WebClient); |
| 10213 |
await getService("action").doAction(1); |
| 10214 |
await contains(`.o_control_panel_main_buttons button.o-kanban-button-new`).click(); |
| 10215 |
|
| 10216 |
//cannot save because there is a required field |
| 10217 |
await contains(`.o_control_panel .o_form_button_save`).click(); |
| 10218 |
expect(`.o_notification`).toHaveCount(1); |
| 10219 |
|
| 10220 |
await contains(`.o_control_panel .o_form_button_cancel`).click(); |
| 10221 |
expect(`.o_form_view`).toHaveCount(0); |
| 10222 |
expect(`.o_kanban_view`).toHaveCount(1); |
| 10223 |
expect(`.o_notification`).toHaveCount(0); |
| 10224 |
}); |
| 10225 |
|
| 10226 |
test(`one2many create record dialog shouldn't have a 'remove' button`, async () => { |
| 10227 |
await mountView({ |
| 10228 |
resModel: "partner", |
| 10229 |
type: "form", |
| 10230 |
arch: ` |
| 10231 |
<form> |
| 10232 |
<field name="child_ids"> |
| 10233 |
<kanban> |
| 10234 |
<templates> |
| 10235 |
<t t-name="card"> |
| 10236 |
<field name="foo"/> |
| 10237 |
</t> |
| 10238 |
</templates> |
| 10239 |
</kanban> |
| 10240 |
<form> |
| 10241 |
<field name="foo"/> |
| 10242 |
</form> |
| 10243 |
</field> |
| 10244 |
</form> |
| 10245 |
`, |
| 10246 |
resId: 1, |
| 10247 |
}); |
| 10248 |
await contains(`.o_form_button_create`).click(); |
| 10249 |
await contains(`.o-kanban-button-new`).click(); |
| 10250 |
expect(`.modal`).toHaveCount(1); |
| 10251 |
expect(`.modal .modal-footer .o_btn_remove`).toHaveCount(0); |
| 10252 |
}); |
| 10253 |
|
| 10254 |
test(`"bare" buttons in template should not trigger button click`, async () => { |
| 10255 |
mockService("action", { |
| 10256 |
doActionButton(args) { |
| 10257 |
expect.step("doActionButton"); |
| 10258 |
delete args.onClose; |
| 10259 |
expect(args).toEqual({ |
| 10260 |
buttonContext: {}, |
| 10261 |
context: { |
| 10262 |
lang: "en", |
| 10263 |
tz: "taht", |
| 10264 |
uid: 7, |
| 10265 |
allowed_company_ids: [1], |
| 10266 |
}, |
| 10267 |
resId: 2, |
| 10268 |
resIds: [2], |
| 10269 |
resModel: "partner", |
| 10270 |
special: "save", |
| 10271 |
}); |
| 10272 |
}, |
| 10273 |
}); |
| 10274 |
|
| 10275 |
await mountView({ |
| 10276 |
resModel: "partner", |
| 10277 |
type: "form", |
| 10278 |
arch: ` |
| 10279 |
<form> |
| 10280 |
<button string="Save" class="btn-primary" special="save"/> |
| 10281 |
<button class="mybutton">westvleteren</button> |
| 10282 |
</form> |
| 10283 |
`, |
| 10284 |
resId: 2, |
| 10285 |
}); |
| 10286 |
expect(`.o_form_view button.mybutton`).not.toBeEnabled(); |
| 10287 |
|
| 10288 |
await contains(`.o_form_view .o_content button.btn-primary`).click(); |
| 10289 |
expect.verifySteps(["doActionButton"]); |
| 10290 |
}); |
| 10291 |
|
| 10292 |
test(`form view with inline list view with optional fields and local storage mock`, async () => { |
| 10293 |
patchWithCleanup(browser.localStorage, { |
| 10294 |
getItem(key) { |
| 10295 |
if (["optional_fields", "debug_open_view"].some((word) => key.startsWith(word))) { |
| 10296 |
expect.step(`getItem ${key}`); |
| 10297 |
} |
| 10298 |
return super.getItem(key); |
| 10299 |
}, |
| 10300 |
setItem(key, value) { |
| 10301 |
if (["optional_fields", "debug_open_view"].some((word) => key.startsWith(word))) { |
| 10302 |
expect.step(`setItem ${key} to ${value}`); |
| 10303 |
} |
| 10304 |
return super.setItem(key, value); |
| 10305 |
}, |
| 10306 |
}); |
| 10307 |
|
| 10308 |
await mountView({ |
| 10309 |
resModel: "partner", |
| 10310 |
type: "form", |
| 10311 |
arch: ` |
| 10312 |
<form> |
| 10313 |
<field name="float_field"/> |
| 10314 |
<field name="child_ids"> |
| 10315 |
<list> |
| 10316 |
<field name="foo"/> |
| 10317 |
<field name="bar" optional="hide"/> |
| 10318 |
</list> |
| 10319 |
</field> |
| 10320 |
</form> |
| 10321 |
`, |
| 10322 |
viewId: 1, |
| 10323 |
}); |
| 10324 |
|
| 10325 |
const localStorageKey = "partner,form,1,child_ids,list,bar,foo"; |
| 10326 |
expect.verifySteps([ |
| 10327 |
`getItem optional_fields,${localStorageKey}`, |
| 10328 |
`getItem debug_open_view,${localStorageKey}`, |
| 10329 |
]); |
| 10330 |
expect(`.o_list_table th`).toHaveCount(2); |
| 10331 |
expect(`th[data-name="foo"]`).toBeVisible(); |
| 10332 |
expect(`th[data-name="bar"]`).not.toHaveCount(); |
| 10333 |
|
| 10334 |
// optional fields |
| 10335 |
await contains(`.o_optional_columns_dropdown .dropdown-toggle`).click(); |
| 10336 |
expect(`.o-dropdown--menu .dropdown-item`).toHaveCount(1); |
| 10337 |
|
| 10338 |
// enable optional field |
| 10339 |
await contains(`.o-dropdown--menu input[name="bar"]`).click(); |
| 10340 |
expect.verifySteps([ |
| 10341 |
`setItem optional_fields,${localStorageKey} to bar`, |
| 10342 |
`getItem optional_fields,${localStorageKey}`, |
| 10343 |
`getItem debug_open_view,${localStorageKey}`, |
| 10344 |
]); |
| 10345 |
|
| 10346 |
expect(`.o_list_table th`).toHaveCount(3); |
| 10347 |
expect(`th[data-name="foo"]`).toBeVisible(); |
| 10348 |
expect(`th[data-name="bar"]`).toBeVisible(); |
| 10349 |
}); |
| 10350 |
|
| 10351 |
test.tags("desktop"); |
| 10352 |
test(`form view with list_view_ref with optional fields and local storage mock`, async () => { |
| 10353 |
patchWithCleanup(browser.localStorage, { |
| 10354 |
getItem(key) { |
| 10355 |
if (["optional_fields", "debug_open_view"].some((word) => key.startsWith(word))) { |
| 10356 |
expect.step(`getItem ${key}`); |
| 10357 |
} |
| 10358 |
return super.getItem(key); |
| 10359 |
}, |
| 10360 |
setItem(key, value) { |
| 10361 |
if (["optional_fields", "debug_open_view"].some((word) => key.startsWith(word))) { |
| 10362 |
expect.step(`setItem ${key} to ${value}`); |
| 10363 |
} |
| 10364 |
return super.setItem(key, value); |
| 10365 |
}, |
| 10366 |
}); |
| 10367 |
|
| 10368 |
Partner._views = { |
| 10369 |
"list,nope_not_this_one": `<list><field name="foo"/><field name="bar"/></list>`, |
| 10370 |
"list,34": ` |
| 10371 |
<list> |
| 10372 |
<field name="foo" optional="hide"/> |
| 10373 |
<field name="bar"/> |
| 10374 |
</list> |
| 10375 |
`, |
| 10376 |
}; |
| 10377 |
|
| 10378 |
await mountView({ |
| 10379 |
resModel: "partner", |
| 10380 |
type: "form", |
| 10381 |
// we add a widget= as a bit of a hack. Without widget, the views are inlined by the server. |
| 10382 |
// the mock server doesn't replicate fully this behavior. |
| 10383 |
// Putting a widget prevent the inlining. |
| 10384 |
arch: ` |
| 10385 |
<form> |
| 10386 |
<field name="float_field"/> |
| 10387 |
<field name="child_ids" widget="one2many" context="{'list_view_ref': '34'}"/> |
| 10388 |
</form> |
| 10389 |
`, |
| 10390 |
viewId: 1, |
| 10391 |
}); |
| 10392 |
|
| 10393 |
const localStorageKey = "partner,form,1,child_ids,list,bar,foo"; |
| 10394 |
expect.verifySteps([ |
| 10395 |
`getItem optional_fields,${localStorageKey}`, |
| 10396 |
`getItem debug_open_view,${localStorageKey}`, |
| 10397 |
]); |
| 10398 |
expect(`.o_list_table th`).toHaveCount(2); |
| 10399 |
expect(`th[data-name="foo"]`).not.toHaveCount(); |
| 10400 |
expect(`th[data-name="bar"]`).toBeVisible(); |
| 10401 |
|
| 10402 |
// optional fields |
| 10403 |
await contains(`.o_optional_columns_dropdown .dropdown-toggle`).click(); |
| 10404 |
expect(`.o-dropdown--menu .dropdown-item`).toHaveCount(1); |
| 10405 |
|
| 10406 |
// enable optional field |
| 10407 |
await contains(`.o-dropdown--menu input[name="foo"]`).click(); |
| 10408 |
expect.verifySteps([ |
| 10409 |
`setItem optional_fields,${localStorageKey} to foo`, |
| 10410 |
`getItem optional_fields,${localStorageKey}`, |
| 10411 |
`getItem debug_open_view,${localStorageKey}`, |
| 10412 |
]); |
| 10413 |
|
| 10414 |
expect(`.o_list_table th`).toHaveCount(3); |
| 10415 |
expect(`th[data-name="foo"]`).toBeVisible(); |
| 10416 |
expect(`th[data-name="bar"]`).toBeVisible(); |
| 10417 |
}); |
| 10418 |
|
| 10419 |
test(`resequence list lines when discardable lines are present`, async () => { |
| 10420 |
Partner._onChanges = { |
| 10421 |
child_ids(record) { |
| 10422 |
expect.step("onchange"); |
| 10423 |
record.foo = record.child_ids ? record.child_ids.length.toString() : "0"; |
| 10424 |
}, |
| 10425 |
}; |
| 10426 |
|
| 10427 |
Partner._views = { |
| 10428 |
list: ` |
| 10429 |
<list editable="bottom"> |
| 10430 |
<field name="int_field" widget="handle"/> |
| 10431 |
<field name="name" required="1"/> |
| 10432 |
</list> |
| 10433 |
`, |
| 10434 |
}; |
| 10435 |
|
| 10436 |
await mountView({ |
| 10437 |
resModel: "partner", |
| 10438 |
type: "form", |
| 10439 |
arch: `<form><field name="foo"/><field name="child_ids"/></form>`, |
| 10440 |
}); |
| 10441 |
expect.verifySteps(["onchange"]); |
| 10442 |
expect(`[name="foo"] input`).toHaveValue("0"); |
| 10443 |
|
| 10444 |
// Add one line |
| 10445 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 10446 |
await contains(`.o_field_cell [name="name"] input`).edit("first line"); |
| 10447 |
expect.verifySteps(["onchange"]); |
| 10448 |
expect(`[name="foo"] input`).toHaveValue("1"); |
| 10449 |
|
| 10450 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 10451 |
await animationFrame(); |
| 10452 |
// Drag and drop second line before first one (with 1 draft and invalid line) |
| 10453 |
// TODO JUM: PRHOOT the events |
| 10454 |
const { drop, moveTo } = await contains( |
| 10455 |
`tbody.ui-sortable tr:nth-child(1) .o_handle_cell` |
| 10456 |
).drag(); |
| 10457 |
await moveTo(`tbody.ui-sortable tr:nth-child(2)`); |
| 10458 |
await drop(document.body); |
| 10459 |
expect(`[name="foo"] input`).toHaveValue("1"); |
| 10460 |
|
| 10461 |
// Add a second line |
| 10462 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 10463 |
await contains(`.o_selected_row input`).edit("second line"); |
| 10464 |
expect.verifySteps(["onchange"]); |
| 10465 |
expect(`[name="foo"] input`).toHaveValue("2"); |
| 10466 |
}); |
| 10467 |
|
| 10468 |
test("resequence list lines when previous resequencing crashed", async () => { |
| 10469 |
expect.errors(1); |
| 10470 |
let onChangeCount = 0; |
| 10471 |
|
| 10472 |
Partner._onChanges = { |
| 10473 |
int_field: function (obj) { |
| 10474 |
if (obj.name === "first line") { |
| 10475 |
if (onChangeCount === 0) { |
| 10476 |
onChangeCount += 1; |
| 10477 |
|
| 10478 |
expect.step("resequence onChange crash"); |
| 10479 |
throw makeErrorFromResponse({ |
| 10480 |
code: 200, |
| 10481 |
message: "Odoo Server Error", |
| 10482 |
data: { |
| 10483 |
name: `odoo.exceptions.${"UserError"}`, |
| 10484 |
debug: "traceback", |
| 10485 |
arguments: [], |
| 10486 |
context: {}, |
| 10487 |
message: "error", |
| 10488 |
}, |
| 10489 |
}); |
| 10490 |
} else { |
| 10491 |
expect.step("resequence onChange ok"); |
| 10492 |
} |
| 10493 |
} |
| 10494 |
}, |
| 10495 |
}; |
| 10496 |
|
| 10497 |
Partner._views = { |
| 10498 |
list: ` |
| 10499 |
<list editable="bottom"> |
| 10500 |
<field name="int_field" widget="handle"/> |
| 10501 |
<field name="name" required="1"/> |
| 10502 |
</list> |
| 10503 |
`, |
| 10504 |
}; |
| 10505 |
|
| 10506 |
await mountView({ |
| 10507 |
resModel: "partner", |
| 10508 |
type: "form", |
| 10509 |
arch: `<form><field name="foo"/><field name="child_ids"/></form>`, |
| 10510 |
resId: 1, |
| 10511 |
}); |
| 10512 |
|
| 10513 |
// Add two lines |
| 10514 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 10515 |
|
| 10516 |
await contains(".o_data_cell [name='name'] input").edit("first line"); |
| 10517 |
await animationFrame(); |
| 10518 |
|
| 10519 |
await contains(".o_selected_row input").edit("second line"); |
| 10520 |
await contains(".o_form_button_save").click(); |
| 10521 |
await animationFrame(); |
| 10522 |
|
| 10523 |
expect(queryAllTexts(".o_list_char")).toEqual(["first line", "second line"]); |
| 10524 |
await contains("tbody.ui-sortable tr:nth-child(1) .o_handle_cell").dragAndDrop( |
| 10525 |
"tbody.ui-sortable tr:nth-child(2)" |
| 10526 |
); |
| 10527 |
await animationFrame(); |
| 10528 |
expect.verifyErrors(["RPC_ERROR"]); |
| 10529 |
expect(queryAllTexts(".o_list_char")).toEqual(["first line", "second line"]); |
| 10530 |
|
| 10531 |
await contains("tbody.ui-sortable tr:nth-child(1) .o_handle_cell").dragAndDrop( |
| 10532 |
"tbody.ui-sortable tr:nth-child(2)" |
| 10533 |
); |
| 10534 |
await animationFrame(); |
| 10535 |
expect(queryAllTexts(".o_list_char")).toEqual(["second line", "first line"]); |
| 10536 |
expect.verifySteps(["resequence onChange crash", "resequence onChange ok"]); |
| 10537 |
}); |
| 10538 |
|
| 10539 |
test(`reload company when creating records of model res.company`, async () => { |
| 10540 |
mockService("action", { |
| 10541 |
async doAction(actionRequest) { |
| 10542 |
if (actionRequest === "reload_context") { |
| 10543 |
expect.step("reload company"); |
| 10544 |
} |
| 10545 |
}, |
| 10546 |
}); |
| 10547 |
|
| 10548 |
onRpc(({ method }) => expect.step(method)); |
| 10549 |
await mountView({ |
| 10550 |
resModel: "res.company", |
| 10551 |
type: "form", |
| 10552 |
arch: `<form><field name="name"/></form>`, |
| 10553 |
}); |
| 10554 |
expect.verifySteps(["get_views", "onchange"]); |
| 10555 |
|
| 10556 |
await contains(`.o_field_widget[name="name"] input`).edit("Test Company"); |
| 10557 |
await contains(`.o_form_button_save`).click(); |
| 10558 |
expect.verifySteps(["web_save", "reload company"]); |
| 10559 |
}); |
| 10560 |
|
| 10561 |
test(`reload company when writing on records of model res.company`, async () => { |
| 10562 |
mockService("action", { |
| 10563 |
async doAction(actionRequest) { |
| 10564 |
if (actionRequest === "reload_context") { |
| 10565 |
expect.step("reload company"); |
| 10566 |
} |
| 10567 |
}, |
| 10568 |
}); |
| 10569 |
|
| 10570 |
ResCompany._records = [{ id: 1, name: "Test Company" }]; |
| 10571 |
|
| 10572 |
onRpc(({ method }) => expect.step(method)); |
| 10573 |
await mountView({ |
| 10574 |
resModel: "res.company", |
| 10575 |
type: "form", |
| 10576 |
arch: `<form><field name="name"/></form>`, |
| 10577 |
resId: 1, |
| 10578 |
}); |
| 10579 |
expect.verifySteps(["get_views", "web_read"]); |
| 10580 |
|
| 10581 |
await contains(`.o_field_widget[name="name"] input`).edit("Test Company2"); |
| 10582 |
await contains(`.o_form_button_save`).click(); |
| 10583 |
expect.verifySteps(["web_save", "reload company"]); |
| 10584 |
}); |
| 10585 |
|
| 10586 |
test.tags("desktop"); |
| 10587 |
test(`company_dependent field in form view, in multi company group`, async () => { |
| 10588 |
Partner._fields.foo = fields.Char({ company_dependent: true }); |
| 10589 |
Partner._fields.product_id = fields.Many2one({ |
| 10590 |
relation: "product", |
| 10591 |
company_dependent: true, |
| 10592 |
help: "this is a tooltip", |
| 10593 |
}); |
| 10594 |
|
| 10595 |
serverState.companies = [ |
| 10596 |
{ id: 1, name: "Company 1", sequence: 1, parent_id: false, child_ids: [] }, |
| 10597 |
{ id: 2, name: "Company 2", sequence: 2, parent_id: false, child_ids: [] }, |
| 10598 |
{ id: 3, name: "Company 3", sequence: 3, parent_id: false, child_ids: [] }, |
| 10599 |
]; |
| 10600 |
await mountView({ |
| 10601 |
resModel: "partner", |
| 10602 |
type: "form", |
| 10603 |
arch: ` |
| 10604 |
<form> |
| 10605 |
<group> |
| 10606 |
<field name="foo"/> |
| 10607 |
<field name="product_id"/> |
| 10608 |
</group> |
| 10609 |
</form> |
| 10610 |
`, |
| 10611 |
}); |
| 10612 |
|
| 10613 |
await hover(`.o_form_label[for=product_id_0] sup`); |
| 10614 |
await runAllTimers(); |
| 10615 |
expect(`.o-tooltip .o-tooltip--help`).toHaveText( |
| 10616 |
"this is a tooltip\n\nValues set here are company-specific." |
| 10617 |
); |
| 10618 |
|
| 10619 |
await hover(`.o_form_label[for=foo_0] sup`); |
| 10620 |
await runAllTimers(); |
| 10621 |
expect(`.o-tooltip .o-tooltip--help`).toHaveText("Values set here are company-specific."); |
| 10622 |
}); |
| 10623 |
|
| 10624 |
test.tags("desktop"); |
| 10625 |
test(`company_dependent field in form view, not in multi company group`, async () => { |
| 10626 |
Partner._fields.product_id = fields.Many2one({ |
| 10627 |
relation: "product", |
| 10628 |
company_dependent: true, |
| 10629 |
help: "this is a tooltip", |
| 10630 |
}); |
| 10631 |
|
| 10632 |
serverState.companies = [ |
| 10633 |
{ id: 1, name: "Company 1", sequence: 1, parent_id: false, child_ids: [] }, |
| 10634 |
]; |
| 10635 |
|
| 10636 |
await mountView({ |
| 10637 |
resModel: "partner", |
| 10638 |
type: "form", |
| 10639 |
arch: ` |
| 10640 |
<form> |
| 10641 |
<group> |
| 10642 |
<field name="product_id"/> |
| 10643 |
</group> |
| 10644 |
</form> |
| 10645 |
`, |
| 10646 |
}); |
| 10647 |
|
| 10648 |
await hover(`.o_form_label sup`); |
| 10649 |
await runAllTimers(); |
| 10650 |
expect(`.o-tooltip .o-tooltip--help`).toHaveText("this is a tooltip"); |
| 10651 |
}); |
| 10652 |
|
| 10653 |
test(`no 'oh snap' error when clicking on a save button`, async () => { |
| 10654 |
expect.errors(1); |
| 10655 |
|
| 10656 |
onRpc("web_save", () => { |
| 10657 |
throw makeServerError({ message: "Some business message" }); |
| 10658 |
}); |
| 10659 |
onRpc(({ method }) => expect.step(method)); |
| 10660 |
await mountView({ |
| 10661 |
resModel: "partner", |
| 10662 |
type: "form", |
| 10663 |
arch: ` |
| 10664 |
<form> |
| 10665 |
<button name="do_it" type="object" string="Do it"/> |
| 10666 |
<field name="name"/> |
| 10667 |
</form> |
| 10668 |
`, |
| 10669 |
}); |
| 10670 |
expect.verifySteps(["get_views", "onchange"]); |
| 10671 |
|
| 10672 |
await contains(`.o_form_button_save`).click(); |
| 10673 |
await animationFrame(); |
| 10674 |
expect.verifyErrors(["Some business message"]); |
| 10675 |
expect.verifySteps(["web_save"]); |
| 10676 |
expect(`.o_error_dialog`).toHaveCount(1); |
| 10677 |
expect(`.o_form_error_dialog`).toHaveCount(0); |
| 10678 |
}); |
| 10679 |
|
| 10680 |
test(`no 'oh snap' error when clicking on a view button`, async () => { |
| 10681 |
expect.errors(1); |
| 10682 |
|
| 10683 |
onRpc("web_save", () => { |
| 10684 |
throw makeServerError({ message: "Some business message" }); |
| 10685 |
}); |
| 10686 |
onRpc(({ method }) => expect.step(method)); |
| 10687 |
await mountView({ |
| 10688 |
resModel: "partner", |
| 10689 |
type: "form", |
| 10690 |
arch: ` |
| 10691 |
<form> |
| 10692 |
<button name="do_it" type="object" string="Do it"/> |
| 10693 |
<field name="name"/> |
| 10694 |
</form> |
| 10695 |
`, |
| 10696 |
}); |
| 10697 |
expect.verifySteps(["get_views", "onchange"]); |
| 10698 |
|
| 10699 |
await contains(`button[name=do_it]`).click(); |
| 10700 |
await animationFrame(); |
| 10701 |
expect.verifyErrors(["Some business message"]); |
| 10702 |
expect.verifySteps(["web_save"]); |
| 10703 |
expect(`.o_error_dialog`).toHaveCount(1); |
| 10704 |
expect(`.o_form_error_dialog`).toHaveCount(0); |
| 10705 |
}); |
| 10706 |
|
| 10707 |
test(`no 'oh snap' error in form view in dialog`, async () => { |
| 10708 |
expect.errors(1); |
| 10709 |
|
| 10710 |
Partner._views = { |
| 10711 |
form: ` |
| 10712 |
<form> |
| 10713 |
<field name="foo"/> |
| 10714 |
<footer> |
| 10715 |
<button type="object" name="some_method" class="myButton"/> |
| 10716 |
</footer> |
| 10717 |
</form> |
| 10718 |
`, |
| 10719 |
}; |
| 10720 |
|
| 10721 |
onRpc("web_save", () => { |
| 10722 |
expect.step("save"); |
| 10723 |
throw makeServerError({ message: "Some business message" }); |
| 10724 |
}); |
| 10725 |
await mountWithCleanup(WebClient); |
| 10726 |
await getService("action").doAction({ |
| 10727 |
type: "ir.actions.act_window", |
| 10728 |
target: "new", |
| 10729 |
res_model: "partner", |
| 10730 |
view_mode: "form", |
| 10731 |
views: [[false, "form"]], |
| 10732 |
}); |
| 10733 |
|
| 10734 |
await contains(`.o_field_widget[name='foo'] input`).edit("test"); |
| 10735 |
await contains(`.modal footer .myButton`).click(); |
| 10736 |
expect.verifyErrors(["Some business message"]); |
| 10737 |
expect.verifySteps(["save"]); |
| 10738 |
await animationFrame(); |
| 10739 |
expect(`.modal`).toHaveCount(2); |
| 10740 |
expect(`.o_error_dialog`).toHaveCount(1); |
| 10741 |
expect(`.o_form_error_dialog`).toHaveCount(0); |
| 10742 |
}); |
| 10743 |
|
| 10744 |
test(`field "length" with value 0: can apply onchange`, async () => { |
| 10745 |
Partner._fields.length = fields.Float(); |
| 10746 |
Partner._fields.foo = fields.Char({ default: "foo default" }); |
| 10747 |
|
| 10748 |
await mountView({ |
| 10749 |
resModel: "partner", |
| 10750 |
type: "form", |
| 10751 |
arch: `<form><field name="foo"/><field name="length"/></form>`, |
| 10752 |
}); |
| 10753 |
expect(`.o_field_widget[name=foo] input`).toHaveValue("foo default"); |
| 10754 |
expect(`.o_field_widget[name=length] input`).toHaveValue("0.00"); |
| 10755 |
}); |
| 10756 |
|
| 10757 |
test(`field "length" with value 0: readonly fields are not sent when saving`, async () => { |
| 10758 |
Partner._fields.length = fields.Float(); |
| 10759 |
Partner._fields.foo = fields.Char({ default: "foo default" }); |
| 10760 |
|
| 10761 |
// define an onchange on name to check that the value of readonly |
| 10762 |
// fields is correctly sent for onchanges |
| 10763 |
Partner._onChanges = { |
| 10764 |
name() {}, |
| 10765 |
child_ids() {}, |
| 10766 |
}; |
| 10767 |
|
| 10768 |
onRpc("web_save", ({ args }) => { |
| 10769 |
expect.step("save"); |
| 10770 |
expect(args[1]).toEqual({ |
| 10771 |
child_ids: [[0, args[1].child_ids[0][1], { length: 0, name: "readonly" }]], |
| 10772 |
}); |
| 10773 |
}); |
| 10774 |
|
| 10775 |
await mountView({ |
| 10776 |
resModel: "partner", |
| 10777 |
type: "form", |
| 10778 |
arch: ` |
| 10779 |
<form> |
| 10780 |
<field name="child_ids"> |
| 10781 |
<list> |
| 10782 |
<field name="name"/> |
| 10783 |
</list> |
| 10784 |
<form> |
| 10785 |
<field name="length"/> |
| 10786 |
<field name="name"/> |
| 10787 |
<field name="foo" readonly="name =='readonly'"/> |
| 10788 |
</form> |
| 10789 |
</field> |
| 10790 |
</form> |
| 10791 |
`, |
| 10792 |
}); |
| 10793 |
|
| 10794 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 10795 |
expect(`.modal .o_field_widget[name=foo] input`).toHaveCount(1); |
| 10796 |
|
| 10797 |
await contains(`.modal .o_field_widget[name=foo] input`).edit("foo value"); |
| 10798 |
await contains(`.modal .o_field_widget[name=name] input`).edit("readonly"); |
| 10799 |
expect(`.modal .o_field_widget[name=foo] span`).toHaveCount(1); |
| 10800 |
|
| 10801 |
await contains(`.modal .o_form_button_save`).click(); |
| 10802 |
await contains(`.o_form_button_save`).click(); |
| 10803 |
expect.verifySteps(["save"]); |
| 10804 |
}); |
| 10805 |
|
| 10806 |
test(`fieldDependencies support for fields`, async () => { |
| 10807 |
Partner._records = [{ id: 1, int_field: 2 }]; |
| 10808 |
|
| 10809 |
fieldsRegistry.add("custom_field", { |
| 10810 |
component: class CustomField extends Component { |
| 10811 |
static props = ["*"]; |
| 10812 |
static template = xml`<span t-esc="props.record.data.int_field"/>`; |
| 10813 |
}, |
| 10814 |
fieldDependencies: [{ name: "int_field", type: "integer" }], |
| 10815 |
}); |
| 10816 |
|
| 10817 |
await mountView({ |
| 10818 |
resModel: "partner", |
| 10819 |
type: "form", |
| 10820 |
resId: 1, |
| 10821 |
arch: `<form><field name="foo" widget="custom_field"/></form>`, |
| 10822 |
}); |
| 10823 |
expect(`[name=foo] span`).toHaveText("2"); |
| 10824 |
}); |
| 10825 |
|
| 10826 |
test(`fieldDependencies support for fields: dependence on a relational field`, async () => { |
| 10827 |
Partner._records[0].product_id = 37; |
| 10828 |
|
| 10829 |
registry.category("fields").add("custom_field", { |
| 10830 |
component: class CustomField extends Component { |
| 10831 |
static props = ["*"]; |
| 10832 |
static template = xml`<span t-esc="props.record.data.product_id.display_name"/>`; |
| 10833 |
}, |
| 10834 |
fieldDependencies: [{ name: "product_id", type: "many2one", relation: "product" }], |
| 10835 |
}); |
| 10836 |
|
| 10837 |
onRpc(({ method }) => expect.step(method)); |
| 10838 |
await mountView({ |
| 10839 |
resModel: "partner", |
| 10840 |
type: "form", |
| 10841 |
resId: 1, |
| 10842 |
arch: `<form><field name="foo" widget="custom_field"/></form>`, |
| 10843 |
}); |
| 10844 |
expect.verifySteps(["get_views", "web_read"]); |
| 10845 |
expect(`[name=foo] span`).toHaveText("xphone"); |
| 10846 |
}); |
| 10847 |
|
| 10848 |
test.tags("desktop"); |
| 10849 |
test(`Action Button clicked with failing action on desktop`, async () => { |
| 10850 |
expect.errors(1); |
| 10851 |
|
| 10852 |
class MyComponent extends Component { |
| 10853 |
static props = ["*"]; |
| 10854 |
static template = xml`<div/>`; |
| 10855 |
setup() { |
| 10856 |
throw new Error("test"); |
| 10857 |
} |
| 10858 |
} |
| 10859 |
registry.category("actions").add("someaction", MyComponent); |
| 10860 |
|
| 10861 |
Partner._views = { |
| 10862 |
form: ` |
| 10863 |
<form> |
| 10864 |
<sheet> |
| 10865 |
<div name="button_box" class="oe_button_box test"> |
| 10866 |
<button class="oe_stat_button" type="action" name="someaction"> |
| 10867 |
Test |
| 10868 |
</button> |
| 10869 |
</div> |
| 10870 |
</sheet> |
| 10871 |
</form> |
| 10872 |
`, |
| 10873 |
}; |
| 10874 |
|
| 10875 |
await mountWithCleanup(WebClient); |
| 10876 |
await getService("action").doAction({ |
| 10877 |
res_id: 1, |
| 10878 |
type: "ir.actions.act_window", |
| 10879 |
target: "current", |
| 10880 |
res_model: "partner", |
| 10881 |
view_mode: "form", |
| 10882 |
views: [[false, "form"]], |
| 10883 |
}); |
| 10884 |
expect(`.o_form_view .test`).toHaveCount(1); |
| 10885 |
|
| 10886 |
await contains(`button.oe_stat_button`).click(); |
| 10887 |
expect(`.o_form_view .test`).toHaveCount(1); |
| 10888 |
expect.verifyErrors(["test"]); |
| 10889 |
}); |
| 10890 |
|
| 10891 |
test.tags("mobile"); |
| 10892 |
test(`Action Button clicked with failing action on mobile`, async () => { |
| 10893 |
expect.errors(1); |
| 10894 |
|
| 10895 |
class MyComponent extends Component { |
| 10896 |
static props = ["*"]; |
| 10897 |
static template = xml`<div/>`; |
| 10898 |
setup() { |
| 10899 |
throw new Error("test"); |
| 10900 |
} |
| 10901 |
} |
| 10902 |
registry.category("actions").add("someaction", MyComponent); |
| 10903 |
|
| 10904 |
Partner._views = { |
| 10905 |
form: ` |
| 10906 |
<form> |
| 10907 |
<sheet> |
| 10908 |
<div name="button_box" class="oe_button_box test"> |
| 10909 |
<button class="oe_stat_button" type="action" name="someaction"> |
| 10910 |
Test |
| 10911 |
</button> |
| 10912 |
</div> |
| 10913 |
</sheet> |
| 10914 |
</form> |
| 10915 |
`, |
| 10916 |
}; |
| 10917 |
|
| 10918 |
await mountWithCleanup(WebClient); |
| 10919 |
await getService("action").doAction({ |
| 10920 |
res_id: 1, |
| 10921 |
type: "ir.actions.act_window", |
| 10922 |
target: "current", |
| 10923 |
res_model: "partner", |
| 10924 |
view_mode: "form", |
| 10925 |
views: [[false, "form"]], |
| 10926 |
}); |
| 10927 |
expect(`.o_form_view .test`).toHaveCount(1); |
| 10928 |
|
| 10929 |
await contains(".o-form-buttonbox .o_button_more").click(); |
| 10930 |
await contains(`button.oe_stat_button`).click(); |
| 10931 |
expect(`.o_form_view .test`).toHaveCount(1); |
| 10932 |
expect.verifyErrors(["test"]); |
| 10933 |
}); |
| 10934 |
|
| 10935 |
test(`form view with edit='0' but create='1', existing record`, async () => { |
| 10936 |
await mountView({ |
| 10937 |
resModel: "partner", |
| 10938 |
type: "form", |
| 10939 |
arch: `<form edit="0"><field name="foo"/></form>`, |
| 10940 |
resId: 1, |
| 10941 |
}); |
| 10942 |
expect(`.o_form_readonly`).toHaveCount(1); |
| 10943 |
|
| 10944 |
await contains(`.o_form_button_create`).click(); |
| 10945 |
expect(`.o_form_editable`).toHaveCount(1); |
| 10946 |
}); |
| 10947 |
|
| 10948 |
test(`form view with edit='0' but create='1', new record`, async () => { |
| 10949 |
await mountView({ |
| 10950 |
resModel: "partner", |
| 10951 |
type: "form", |
| 10952 |
arch: `<form edit="0"><field name="foo"/></form>`, |
| 10953 |
}); |
| 10954 |
expect(`.o_form_editable`).toHaveCount(1); |
| 10955 |
}); |
| 10956 |
|
| 10957 |
test(`save a form view with an invisible required field`, async () => { |
| 10958 |
Partner._fields.text = fields.Text({ required: 1 }); |
| 10959 |
|
| 10960 |
onRpc("web_save", ({ args }) => { |
| 10961 |
expect(args[1]).toEqual({ int_field: 0, text: false }); |
| 10962 |
}); |
| 10963 |
onRpc(({ method }) => expect.step(method)); |
| 10964 |
await mountView({ |
| 10965 |
resModel: "partner", |
| 10966 |
type: "form", |
| 10967 |
arch: ` |
| 10968 |
<form> |
| 10969 |
<sheet> |
| 10970 |
<field name="text" invisible="1"/> |
| 10971 |
<field name="int_field"/> |
| 10972 |
</sheet> |
| 10973 |
</form> |
| 10974 |
`, |
| 10975 |
}); |
| 10976 |
expect.verifySteps(["get_views", "onchange"]); |
| 10977 |
|
| 10978 |
await contains(`.o_form_button_save`).click(); |
| 10979 |
expect.verifySteps(["web_save"]); |
| 10980 |
}); |
| 10981 |
|
| 10982 |
test(`save a form view with a duplicated invisible required field`, async () => { |
| 10983 |
Partner._fields.text = fields.Char({ required: 1 }); |
| 10984 |
|
| 10985 |
await mountView({ |
| 10986 |
resModel: "partner", |
| 10987 |
type: "form", |
| 10988 |
arch: ` |
| 10989 |
<form> |
| 10990 |
<group> |
| 10991 |
<field name="text"/> |
| 10992 |
<field name="text" invisible="1"/> |
| 10993 |
</group> |
| 10994 |
</form> |
| 10995 |
`, |
| 10996 |
}); |
| 10997 |
await contains(`.o_form_button_save`).click(); |
| 10998 |
expect(`.o_form_label.o_field_invalid`).toHaveCount(1); |
| 10999 |
expect(`.o_field_char.o_field_invalid`).toHaveCount(1); |
| 11000 |
}); |
| 11001 |
|
| 11002 |
test(`save a form view with an invisible required field in a x2many`, async () => { |
| 11003 |
Partner._fields.text = fields.Char({ required: 1 }); |
| 11004 |
|
| 11005 |
onRpc("web_save", ({ args }) => { |
| 11006 |
expect(args[1].child_ids[0][2]).toEqual({ int_field: 1, text: false }); |
| 11007 |
}); |
| 11008 |
onRpc(({ method }) => expect.step(method)); |
| 11009 |
await mountView({ |
| 11010 |
resModel: "partner", |
| 11011 |
type: "form", |
| 11012 |
arch: ` |
| 11013 |
<form> |
| 11014 |
<sheet> |
| 11015 |
<field name="child_ids"> |
| 11016 |
<list editable="top"> |
| 11017 |
<field name="text" invisible="1"/> |
| 11018 |
<field name="int_field"/> |
| 11019 |
</list> |
| 11020 |
</field> |
| 11021 |
</sheet> |
| 11022 |
</form> |
| 11023 |
`, |
| 11024 |
}); |
| 11025 |
expect.verifySteps(["get_views", "onchange"]); |
| 11026 |
|
| 11027 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 11028 |
await contains(`[name='int_field'] input`).edit("1", { confirm: "blur" }); |
| 11029 |
expect(`[name='int_field'] input`).toHaveCount(0); |
| 11030 |
expect.verifySteps(["onchange"]); |
| 11031 |
|
| 11032 |
await contains(`.o_form_button_save`).click(); |
| 11033 |
expect(`.o_list_renderer .o_data_row`).toHaveCount(1); |
| 11034 |
expect(`.o_list_renderer .o_data_row [name='int_field']`).toHaveText("1"); |
| 11035 |
expect.verifySteps(["web_save"]); |
| 11036 |
}); |
| 11037 |
|
| 11038 |
test(`help on field as precedence over field's declaration -- form`, async () => { |
| 11039 |
Partner._fields.foo = fields.Char({ help: "pythonhelp" }); |
| 11040 |
serverState.debug = "1"; |
| 11041 |
|
| 11042 |
await mountView({ |
| 11043 |
resModel: "partner", |
| 11044 |
type: "form", |
| 11045 |
resId: 1, |
| 11046 |
arch: `<form><sheet><field name="foo" help="xmlHelp"/></sheet></form>`, |
| 11047 |
}); |
| 11048 |
const element = queryFirst`.o_field_widget`; |
| 11049 |
const tooltipInfo = JSON.parse(element.dataset.tooltipInfo); |
| 11050 |
expect(tooltipInfo.field.help).toBe("xmlHelp"); |
| 11051 |
}); |
| 11052 |
|
| 11053 |
test.tags("desktop"); |
| 11054 |
test(`help on field is shown without debug mode -- form`, async () => { |
| 11055 |
Partner._fields.bar = fields.Boolean({ help: "bar tooltip" }); |
| 11056 |
|
| 11057 |
await mountView({ |
| 11058 |
resModel: "partner", |
| 11059 |
type: "form", |
| 11060 |
arch: ` |
| 11061 |
<form> |
| 11062 |
<group> |
| 11063 |
<label for="foo"/> |
| 11064 |
<div><field name="foo" help="foo xml tooltip"/></div> |
| 11065 |
<label for="bar"/> |
| 11066 |
<div><field name="bar" help="bar xml tooltip"/></div> |
| 11067 |
</group> |
| 11068 |
</form> |
| 11069 |
`, |
| 11070 |
}); |
| 11071 |
|
| 11072 |
await hover(`.o_form_label[for=foo_0] sup`); |
| 11073 |
await runAllTimers(); |
| 11074 |
expect(`.o-tooltip .o-tooltip--help`).toHaveText(/foo xml tooltip/); |
| 11075 |
|
| 11076 |
await hover(`.o_form_label[for=bar_0] sup`); |
| 11077 |
await runAllTimers(); |
| 11078 |
expect(`.o-tooltip .o-tooltip--help`).toHaveText(/bar xml tooltip/); |
| 11079 |
}); |
| 11080 |
|
| 11081 |
test(`onSave/onDiscard props`, async () => { |
| 11082 |
await mountView({ |
| 11083 |
resModel: "partner", |
| 11084 |
type: "form", |
| 11085 |
arch: `<form><field name="foo"/></form>`, |
| 11086 |
resId: 1, |
| 11087 |
onSave: () => expect.step("save"), |
| 11088 |
onDiscard: () => expect.step("discard"), |
| 11089 |
}); |
| 11090 |
|
| 11091 |
await contains(`.o_field_widget input`).edit("to save"); |
| 11092 |
await contains(`.o_form_button_save`).click(); |
| 11093 |
expect.verifySteps(["save"]); |
| 11094 |
|
| 11095 |
await contains(`.o_field_widget input`).edit("to cancel"); |
| 11096 |
await contains(`.o_form_button_cancel`).click(); |
| 11097 |
expect.verifySteps(["discard"]); |
| 11098 |
}); |
| 11099 |
|
| 11100 |
test.tags("desktop"); |
| 11101 |
test(`form view does not deactivate sample data on other views`, async () => { |
| 11102 |
ResUsers._records = []; |
| 11103 |
Partner._records = []; |
| 11104 |
Partner._views = { |
| 11105 |
list: `<list sample="1"><field name="name"/></list>`, |
| 11106 |
form: `<form><field name="name"/></form>`, |
| 11107 |
}; |
| 11108 |
|
| 11109 |
await mountWithCleanup(WebClient); |
| 11110 |
await getService("action").doAction({ |
| 11111 |
name: "Partner", |
| 11112 |
res_model: "partner", |
| 11113 |
type: "ir.actions.act_window", |
| 11114 |
views: [ |
| 11115 |
[false, "list"], |
| 11116 |
[false, "form"], |
| 11117 |
], |
| 11118 |
}); |
| 11119 |
expect(`.o_list_view .o_content.o_view_sample_data`).toHaveCount(1); |
| 11120 |
|
| 11121 |
await contains(`.o_control_panel_main_buttons button.o_list_button_add`).click(); |
| 11122 |
expect(`.o_form_view`).toHaveCount(1); |
| 11123 |
|
| 11124 |
await contains(`.o_form_view .breadcrumb-item a`).click(); |
| 11125 |
expect(`.o_list_view .o_content.o_view_sample_data`).toHaveCount(1); |
| 11126 |
}); |
| 11127 |
|
| 11128 |
test.tags("desktop"); |
| 11129 |
test(`empty x2manys when coming form a list with sample data`, async () => { |
| 11130 |
ResUsers._records = []; |
| 11131 |
Partner._records = []; |
| 11132 |
Partner._views = { |
| 11133 |
list: `<list sample="1"><field name="name"/></list>`, |
| 11134 |
form: ` |
| 11135 |
<form> |
| 11136 |
<field name="child_ids"> |
| 11137 |
<kanban> |
| 11138 |
<templates> |
| 11139 |
<t t-name="card"> |
| 11140 |
<field name="name"/> |
| 11141 |
</t> |
| 11142 |
</templates> |
| 11143 |
</kanban> |
| 11144 |
</field> |
| 11145 |
</form> |
| 11146 |
`, |
| 11147 |
}; |
| 11148 |
await mountWithCleanup(WebClient); |
| 11149 |
await getService("action").doAction({ |
| 11150 |
name: "Partner", |
| 11151 |
res_model: "partner", |
| 11152 |
type: "ir.actions.act_window", |
| 11153 |
views: [ |
| 11154 |
[false, "list"], |
| 11155 |
[false, "form"], |
| 11156 |
], |
| 11157 |
}); |
| 11158 |
expect(`.o_list_view .o_content.o_view_sample_data`).toHaveCount(1); |
| 11159 |
|
| 11160 |
await contains(`.o_control_panel_main_buttons button.o_list_button_add`).click(); |
| 11161 |
expect(`.o_form_view .o_field_x2many .o_kanban_renderer`).toHaveCount(1); |
| 11162 |
expect(`.o_view_nocontent`).toHaveCount(0); |
| 11163 |
}); |
| 11164 |
|
| 11165 |
test(`status indicator: saved state`, async () => { |
| 11166 |
await mountView({ |
| 11167 |
resModel: "partner", |
| 11168 |
type: "form", |
| 11169 |
arch: `<form><field name="foo"/></form>`, |
| 11170 |
resId: 1, |
| 11171 |
}); |
| 11172 |
expect(`.o_form_status_indicator`).toHaveCount(1); |
| 11173 |
expect(`.o_form_status_indicator_buttons`).toHaveCount(1); |
| 11174 |
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(1); |
| 11175 |
expect(`.o_form_status_indicator_buttons button`).toHaveCount(2); |
| 11176 |
}); |
| 11177 |
|
| 11178 |
test(`status indicator: dirty state`, async () => { |
| 11179 |
await mountView({ |
| 11180 |
resModel: "partner", |
| 11181 |
type: "form", |
| 11182 |
arch: `<form><field name="foo"/></form>`, |
| 11183 |
resId: 1, |
| 11184 |
}); |
| 11185 |
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(1); |
| 11186 |
|
| 11187 |
await contains(`.o_field_widget input`).edit("dirty"); |
| 11188 |
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(0); |
| 11189 |
}); |
| 11190 |
|
| 11191 |
test(`status indicator: field dirty state`, async () => { |
| 11192 |
// this test check that the indicator don't need the onchange to be displayed |
| 11193 |
await mountView({ |
| 11194 |
resModel: "partner", |
| 11195 |
type: "form", |
| 11196 |
arch: `<form><field name="foo"/></form>`, |
| 11197 |
resId: 1, |
| 11198 |
}); |
| 11199 |
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(1); |
| 11200 |
|
| 11201 |
await contains(`.o_field_widget input`).edit("dirty", { confirm: false }); |
| 11202 |
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(0); |
| 11203 |
}); |
| 11204 |
|
| 11205 |
test(`status indicator: field dirty state (date)`, async () => { |
| 11206 |
// this test check that the indicator don't need the onchange to be displayed |
| 11207 |
await mountView({ |
| 11208 |
resModel: "partner", |
| 11209 |
type: "form", |
| 11210 |
arch: `<form><field name="date"/></form>`, |
| 11211 |
resId: 1, |
| 11212 |
}); |
| 11213 |
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(1); |
| 11214 |
|
| 11215 |
await contains(".o_field_widget button").click(); |
| 11216 |
await contains(`.o_field_widget input`).edit("03/26/2019", { confirm: false }); |
| 11217 |
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(0); |
| 11218 |
}); |
| 11219 |
|
| 11220 |
test(`status indicator: field dirty state (datetime)`, async () => { |
| 11221 |
// this test check that the indicator don't need the onchange to be displayed |
| 11222 |
await mountView({ |
| 11223 |
resModel: "partner", |
| 11224 |
type: "form", |
| 11225 |
arch: `<form><field name="datetime"/></form>`, |
| 11226 |
resId: 1, |
| 11227 |
}); |
| 11228 |
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(1); |
| 11229 |
|
| 11230 |
await contains(".o_field_widget button").click(); |
| 11231 |
await contains(`.o_field_widget input`).edit("12/12/2012 11:55:05", { confirm: false }); |
| 11232 |
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(0); |
| 11233 |
}); |
| 11234 |
|
| 11235 |
test(`status indicator: save dirty state`, async () => { |
| 11236 |
await mountView({ |
| 11237 |
resModel: "partner", |
| 11238 |
type: "form", |
| 11239 |
arch: `<form><field name="foo"/></form>`, |
| 11240 |
resId: 1, |
| 11241 |
}); |
| 11242 |
expect(`.o_field_widget input`).toHaveValue("yop"); |
| 11243 |
|
| 11244 |
await contains(`.o_field_widget input`).edit("dirty"); |
| 11245 |
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(0); |
| 11246 |
|
| 11247 |
await contains(`.o_form_button_save`).click(); |
| 11248 |
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(1); |
| 11249 |
expect(`.o_field_widget input`).toHaveValue("dirty"); |
| 11250 |
}); |
| 11251 |
|
| 11252 |
test(`status indicator: discard dirty state`, async () => { |
| 11253 |
await mountView({ |
| 11254 |
resModel: "partner", |
| 11255 |
type: "form", |
| 11256 |
arch: `<form><field name="foo"/></form>`, |
| 11257 |
resId: 1, |
| 11258 |
}); |
| 11259 |
expect(`.o_field_widget input`).toHaveValue("yop"); |
| 11260 |
|
| 11261 |
await contains(`.o_field_widget input`).edit("dirty"); |
| 11262 |
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(0); |
| 11263 |
|
| 11264 |
await contains(`.o_form_button_cancel`).click(); |
| 11265 |
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(1); |
| 11266 |
expect(`.o_field_widget input`).toHaveValue("yop"); |
| 11267 |
}); |
| 11268 |
|
| 11269 |
test(`status indicator: invalid state`, async () => { |
| 11270 |
onRpc("web_save", () => { |
| 11271 |
expect.step("save"); // not called |
| 11272 |
throw makeServerError(); |
| 11273 |
}); |
| 11274 |
await mountView({ |
| 11275 |
resModel: "partner", |
| 11276 |
type: "form", |
| 11277 |
arch: `<form><field name="foo" required="1"/></form>`, |
| 11278 |
resId: 1, |
| 11279 |
}); |
| 11280 |
expect(`.o_form_status_indicator`).toHaveText(""); |
| 11281 |
|
| 11282 |
await contains(`.o_field_widget input`).edit(""); |
| 11283 |
expect(`.o_form_status_indicator`).toHaveText(""); |
| 11284 |
|
| 11285 |
await contains(`.o_form_button_save`).click(); |
| 11286 |
expect.verifySteps([]); |
| 11287 |
expect(`.o_form_status_indicator .text-danger`).toHaveAttribute( |
| 11288 |
"data-tooltip", |
| 11289 |
"Unable to save. Correct the issue or discard all changes" |
| 11290 |
); |
| 11291 |
}); |
| 11292 |
|
| 11293 |
test(`execute an action before and after each valid save in a form view`, async () => { |
| 11294 |
const formView = registry.category("views").get("form"); |
| 11295 |
class CustomFormController extends formView.Controller { |
| 11296 |
async onRecordSaved(record) { |
| 11297 |
expect.step(`onRecordSaved ${record.resId}`); |
| 11298 |
} |
| 11299 |
|
| 11300 |
async onWillSaveRecord(record) { |
| 11301 |
expect.step(`onWillSaveRecord ${record.resId}`); |
| 11302 |
} |
| 11303 |
} |
| 11304 |
registry.category("views").add("custom_form", { |
| 11305 |
...formView, |
| 11306 |
Controller: CustomFormController, |
| 11307 |
}); |
| 11308 |
|
| 11309 |
onRpc("web_save", ({ args }) => expect.step(`write ${args[0]}`)); |
| 11310 |
await mountView({ |
| 11311 |
resModel: "partner", |
| 11312 |
type: "form", |
| 11313 |
arch: `<form js_class="custom_form"><field name="foo" required="1"/></form>`, |
| 11314 |
resId: 1, |
| 11315 |
}); |
| 11316 |
|
| 11317 |
await contains(`[name='foo'] input`).edit(""); |
| 11318 |
await contains(`.o_form_button_save`).click(); |
| 11319 |
expect.verifySteps([]); |
| 11320 |
|
| 11321 |
await contains(`[name='foo'] input`).edit("YOLO"); |
| 11322 |
await contains(`.o_form_button_save`).click(); |
| 11323 |
expect.verifySteps(["onWillSaveRecord 1", "write 1", "onRecordSaved 1"]); |
| 11324 |
}); |
| 11325 |
|
| 11326 |
test(`don't exec a valid save with onWillSaveRecord in a form view`, async () => { |
| 11327 |
const formView = registry.category("views").get("form"); |
| 11328 |
class CustomFormController extends formView.Controller { |
| 11329 |
async onRecordSaved() { |
| 11330 |
throw new Error("should not execute onRecordSaved"); |
| 11331 |
} |
| 11332 |
|
| 11333 |
async onWillSaveRecord(record) { |
| 11334 |
expect.step(`onWillSaveRecord ${record.resId}`); |
| 11335 |
return false; |
| 11336 |
} |
| 11337 |
} |
| 11338 |
registry.category("views").add("custom_form", { |
| 11339 |
...formView, |
| 11340 |
Controller: CustomFormController, |
| 11341 |
}); |
| 11342 |
|
| 11343 |
onRpc("web_save", () => expect.step(`web_save`)); |
| 11344 |
await mountView({ |
| 11345 |
resModel: "partner", |
| 11346 |
type: "form", |
| 11347 |
arch: `<form js_class="custom_form"><field name="foo" required="1"/></form>`, |
| 11348 |
resId: 1, |
| 11349 |
}); |
| 11350 |
|
| 11351 |
await contains(`[name='foo'] input`).edit(""); |
| 11352 |
await contains(`.o_form_button_save`).click(); |
| 11353 |
expect.verifySteps([]); |
| 11354 |
|
| 11355 |
await contains(`[name='foo'] input`).edit("YOLO"); |
| 11356 |
await contains(`.o_form_button_save`).click(); |
| 11357 |
expect.verifySteps(["onWillSaveRecord 1"]); |
| 11358 |
}); |
| 11359 |
|
| 11360 |
test(`Can't use FormRenderer implementation details in arch`, async () => { |
| 11361 |
// using t-esc in form view archs isn't accepted, so it displays a warning |
| 11362 |
// in the console |
| 11363 |
patchWithCleanup(console, { |
| 11364 |
warn: () => expect.step("warn"), |
| 11365 |
}); |
| 11366 |
|
| 11367 |
await mountView({ |
| 11368 |
resModel: "partner", |
| 11369 |
type: "form", |
| 11370 |
arch: ` |
| 11371 |
<form> |
| 11372 |
<div> |
| 11373 |
<t t-esc="__owl__"/> |
| 11374 |
<t t-esc="props"/> |
| 11375 |
<t t-esc="env"/> |
| 11376 |
<t t-esc="render"/> |
| 11377 |
</div> |
| 11378 |
</form> |
| 11379 |
`, |
| 11380 |
}); |
| 11381 |
expect(queryFirst`.o_form_nosheet`).toHaveInnerHTML("<div></div>"); |
| 11382 |
expect.verifySteps(["warn", "warn", "warn", "warn"]); |
| 11383 |
}); |
| 11384 |
|
| 11385 |
test(`reload form view with an empty notebook`, async () => { |
| 11386 |
Partner._views = { |
| 11387 |
form: ` |
| 11388 |
<form> |
| 11389 |
<sheet> |
| 11390 |
<notebook> |
| 11391 |
</notebook> |
| 11392 |
</sheet> |
| 11393 |
</form> |
| 11394 |
`, |
| 11395 |
list: `<list><field name="foo"/></list>`, |
| 11396 |
}; |
| 11397 |
|
| 11398 |
defineActions([ |
| 11399 |
{ |
| 11400 |
id: 1, |
| 11401 |
name: "Partner", |
| 11402 |
res_model: "partner", |
| 11403 |
views: [ |
| 11404 |
[false, "list"], |
| 11405 |
[false, "form"], |
| 11406 |
], |
| 11407 |
}, |
| 11408 |
]); |
| 11409 |
|
| 11410 |
await mountWithCleanup(WebClient); |
| 11411 |
await getService("action").doAction(1); |
| 11412 |
await contains(`.o_data_row .o_data_cell`).click(); |
| 11413 |
await contains(`.o_back_button`).click(); |
| 11414 |
await contains(`.o_data_row .o_data_cell`).click(); |
| 11415 |
expect(`.o_form_view`).toHaveCount(1); |
| 11416 |
}); |
| 11417 |
|
| 11418 |
test(`setting : boolean field`, async () => { |
| 11419 |
await mountView({ |
| 11420 |
resModel: "partner", |
| 11421 |
type: "form", |
| 11422 |
arch: ` |
| 11423 |
<form> |
| 11424 |
<setting help="this is bar" documentation="/applications/technical/web/settings/this_is_a_test.html"> |
| 11425 |
<field name="bar"/> |
| 11426 |
<button name="buttonName" icon="oi-arrow-right" type="action" string="Manage Users" class="btn-link"/> |
| 11427 |
</setting> |
| 11428 |
</form> |
| 11429 |
`, |
| 11430 |
}); |
| 11431 |
expect(`.o_setting_left_pane .form-check-input`).toHaveCount(1); |
| 11432 |
expect(`.o_form_label`).toHaveText("Bar"); |
| 11433 |
expect(`.o_doc_link`).toHaveCount(1); |
| 11434 |
expect(`.o_doc_link`).toHaveAttribute( |
| 11435 |
"href", |
| 11436 |
"https://www.odoo.com/documentation/1.0/applications/technical/web/settings/this_is_a_test.html" |
| 11437 |
); |
| 11438 |
expect(`.btn-link[name='buttonName']`).toHaveCount(1); |
| 11439 |
}); |
| 11440 |
|
| 11441 |
test(`setting : char field`, async () => { |
| 11442 |
serverState.companies = [ |
| 11443 |
{ id: 1, name: "Company 1", sequence: 1, parent_id: false, child_ids: [] }, |
| 11444 |
{ id: 2, name: "Company 2", sequence: 2, parent_id: false, child_ids: [] }, |
| 11445 |
{ id: 3, name: "Company 3", sequence: 3, parent_id: false, child_ids: [] }, |
| 11446 |
]; |
| 11447 |
|
| 11448 |
await mountView({ |
| 11449 |
resModel: "partner", |
| 11450 |
type: "form", |
| 11451 |
arch: ` |
| 11452 |
<form> |
| 11453 |
<setting help="this is foo" company_dependent="1"> |
| 11454 |
<field name="foo"/> |
| 11455 |
</setting> |
| 11456 |
</form> |
| 11457 |
`, |
| 11458 |
}); |
| 11459 |
expect(`.o_setting_left_pane > *`).toHaveCount(0); |
| 11460 |
expect(`.o_form_label`).toHaveText("Foo"); |
| 11461 |
expect(`.text-muted`).toHaveText("this is foo"); |
| 11462 |
expect(`.fa-building-o`).toHaveCount(1); |
| 11463 |
expect(`.o_field_char input`).toHaveCount(1); |
| 11464 |
}); |
| 11465 |
|
| 11466 |
test(`setting : without field`, async () => { |
| 11467 |
await mountView({ |
| 11468 |
resModel: "partner", |
| 11469 |
type: "form", |
| 11470 |
arch: ` |
| 11471 |
<form> |
| 11472 |
<setting string="Personalize setting" help="this is full personalize setting"> |
| 11473 |
<div>This is a different setting</div> |
| 11474 |
</setting> |
| 11475 |
</form> |
| 11476 |
`, |
| 11477 |
}); |
| 11478 |
expect(`.o_setting_left_pane > *`).toHaveCount(0); |
| 11479 |
expect(`.o_field_char input`).toHaveCount(0); |
| 11480 |
expect(`.o_form_label`).toHaveText("Personalize setting"); |
| 11481 |
expect(`.text-muted`).toHaveText("this is full personalize setting"); |
| 11482 |
}); |
| 11483 |
|
| 11484 |
test(`action button in x2many should display a notification if the record is virtual`, async () => { |
| 11485 |
mockService("notification", { |
| 11486 |
add(message, { type }) { |
| 11487 |
expect.step(`${type}:${message}`); |
| 11488 |
}, |
| 11489 |
}); |
| 11490 |
|
| 11491 |
await mountView({ |
| 11492 |
resModel: "partner", |
| 11493 |
type: "form", |
| 11494 |
arch: ` |
| 11495 |
<form> |
| 11496 |
<field name="child_ids"> |
| 11497 |
<list editable="bottom"> |
| 11498 |
<field name="foo"/> |
| 11499 |
<button class="oe_stat_button" name="test_action" type="object" icon="fa-check">MyButton</button> |
| 11500 |
</list> |
| 11501 |
</field> |
| 11502 |
</form> |
| 11503 |
`, |
| 11504 |
}); |
| 11505 |
|
| 11506 |
await contains(`.o_field_one2many .o_field_x2many_list_row_add a`).click(); |
| 11507 |
await contains(`button.oe_stat_button[name='test_action']`).click(); |
| 11508 |
expect.verifySteps([`danger:Please save your changes first`]); |
| 11509 |
}); |
| 11510 |
|
| 11511 |
test(`open form view action in x2many should display a notification if the record is virtual`, async () => { |
| 11512 |
mockService("action", { |
| 11513 |
async doAction({ type, res_id, res_model }) { |
| 11514 |
expect.step(`${type}:${res_model}(${res_id})`); |
| 11515 |
}, |
| 11516 |
}); |
| 11517 |
|
| 11518 |
onRpc("web_save", () => expect.step(`web_save`)); |
| 11519 |
|
| 11520 |
await mountView({ |
| 11521 |
resModel: "partner", |
| 11522 |
type: "form", |
| 11523 |
arch: ` |
| 11524 |
<form> |
| 11525 |
<field name="child_ids"> |
| 11526 |
<list editable="bottom" open_form_view="1"> |
| 11527 |
<field name="foo"/> |
| 11528 |
</list> |
| 11529 |
</field> |
| 11530 |
</form> |
| 11531 |
`, |
| 11532 |
}); |
| 11533 |
|
| 11534 |
await contains(`.o_field_one2many .o_field_x2many_list_row_add a`).click(); |
| 11535 |
await contains(`.o_list_record_open_form_view`).click(); |
| 11536 |
expect.verifySteps(["web_save", "ir.actions.act_window:partner(7)"]); |
| 11537 |
}); |
| 11538 |
|
| 11539 |
test(`open form view action in x2many should work with several virtual record`, async () => { |
| 11540 |
mockService("action", { |
| 11541 |
async doAction({ type, res_id, res_model }) { |
| 11542 |
expect.step(`${type}:${res_model}(${res_id})`); |
| 11543 |
}, |
| 11544 |
}); |
| 11545 |
|
| 11546 |
onRpc("web_save", () => expect.step(`web_save`)); |
| 11547 |
|
| 11548 |
await mountView({ |
| 11549 |
resModel: "partner", |
| 11550 |
type: "form", |
| 11551 |
arch: ` |
| 11552 |
<form> |
| 11553 |
<field name="child_ids"> |
| 11554 |
<list editable="bottom" open_form_view="1"> |
| 11555 |
<field name="foo"/> |
| 11556 |
</list> |
| 11557 |
</field> |
| 11558 |
</form> |
| 11559 |
`, |
| 11560 |
}); |
| 11561 |
async function createVirtualRecord(x) { |
| 11562 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 11563 |
await contains(`.o_data_row [name='foo'] input`).edit(`record ${x}`); |
| 11564 |
} |
| 11565 |
await createVirtualRecord("a"); |
| 11566 |
await createVirtualRecord("b"); |
| 11567 |
await createVirtualRecord("c"); |
| 11568 |
await createVirtualRecord("d"); |
| 11569 |
await contains(".o_list_record_open_form_view:eq(4)").click(); |
| 11570 |
expect.verifySteps(["web_save", "ir.actions.act_window:partner(11)"]); |
| 11571 |
}); |
| 11572 |
|
| 11573 |
test(`open form view action in x2many with several virtual record with limit`, async () => { |
| 11574 |
mockService("action", { |
| 11575 |
async doAction({ type, res_id, res_model }) { |
| 11576 |
expect.step(`${type}:${res_model}(${res_id})`); |
| 11577 |
}, |
| 11578 |
}); |
| 11579 |
|
| 11580 |
onRpc("web_save", () => expect.step(`web_save`)); |
| 11581 |
await mountView({ |
| 11582 |
resModel: "partner", |
| 11583 |
type: "form", |
| 11584 |
arch: ` |
| 11585 |
<form> |
| 11586 |
<field name="child_ids"> |
| 11587 |
<list editable="bottom" open_form_view="1" limit="2"> |
| 11588 |
<field name="foo"/> |
| 11589 |
</list> |
| 11590 |
</field> |
| 11591 |
</form> |
| 11592 |
`, |
| 11593 |
}); |
| 11594 |
async function createVirtualRecord(x) { |
| 11595 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 11596 |
await contains(`.o_data_row [name='foo'] input`).edit(`record ${x}`); |
| 11597 |
} |
| 11598 |
await createVirtualRecord("a"); |
| 11599 |
await createVirtualRecord("b"); |
| 11600 |
await createVirtualRecord("c"); |
| 11601 |
await createVirtualRecord("d"); |
| 11602 |
await contains(".o_list_record_open_form_view:eq(6)").click(); |
| 11603 |
expect.verifySteps(["web_save", "ir.actions.act_window:partner(13)"]); |
| 11604 |
}); |
| 11605 |
|
| 11606 |
test(`prevent recreating a deleted record`, async () => { |
| 11607 |
Partner._records = [{ id: 1, name: "first record" }]; |
| 11608 |
Partner._views = { |
| 11609 |
list: `<list><field name="name"/></list>`, |
| 11610 |
form: ` |
| 11611 |
<form> |
| 11612 |
<group> |
| 11613 |
<field name="name"/> |
| 11614 |
</group> |
| 11615 |
</form> |
| 11616 |
`, |
| 11617 |
}; |
| 11618 |
|
| 11619 |
defineActions([ |
| 11620 |
{ |
| 11621 |
id: 1, |
| 11622 |
name: "Partner", |
| 11623 |
res_model: "partner", |
| 11624 |
views: [ |
| 11625 |
[false, "list"], |
| 11626 |
[false, "form"], |
| 11627 |
], |
| 11628 |
}, |
| 11629 |
]); |
| 11630 |
|
| 11631 |
await mountWithCleanup(WebClient); |
| 11632 |
await getService("action").doAction(1); |
| 11633 |
expect(`.o_data_row`).toHaveCount(1); |
| 11634 |
expect(`.o_data_row`).toHaveText("first record"); |
| 11635 |
|
| 11636 |
await contains(`.o_data_row .o_data_cell`).click(); |
| 11637 |
await contains(`.o_field_char .o_input`).edit("now dirty"); |
| 11638 |
expect(`.o_form_status_indicator_buttons`).toBeVisible(); |
| 11639 |
|
| 11640 |
await contains(`.o_cp_action_menus .dropdown-toggle`).click(); |
| 11641 |
await contains(`.o-dropdown--menu .dropdown-item:contains(Delete)`).click(); |
| 11642 |
expect(`.modal`).toHaveCount(1); |
| 11643 |
|
| 11644 |
await contains(`.modal-footer button.btn-primary`).click(); |
| 11645 |
expect(`.o_list_view`).toHaveCount(1); |
| 11646 |
expect(`.o_data_row`).toHaveCount(0); |
| 11647 |
}); |
| 11648 |
|
| 11649 |
test.tags("desktop"); |
| 11650 |
test(`coming to an action with an error from a form view with a dirty x2m`, async () => { |
| 11651 |
expect.errors(1); |
| 11652 |
|
| 11653 |
class TestClientAction extends Component { |
| 11654 |
static props = ["*"]; |
| 11655 |
static template = xml`<div></div>`; |
| 11656 |
setup() { |
| 11657 |
throw new Error("Something went wrong"); |
| 11658 |
} |
| 11659 |
} |
| 11660 |
registry.category("actions").add("TestClientAction", TestClientAction); |
| 11661 |
|
| 11662 |
class MyWidget extends Component { |
| 11663 |
static props = ["*"]; |
| 11664 |
static template = xml` |
| 11665 |
<div class="test_widget"> |
| 11666 |
<button t-on-click="onClick">MyButton</button> |
| 11667 |
</div> |
| 11668 |
`; |
| 11669 |
setup() { |
| 11670 |
this.actionService = useService("action"); |
| 11671 |
} |
| 11672 |
onClick() { |
| 11673 |
this.actionService.doAction({ |
| 11674 |
tag: "TestClientAction", |
| 11675 |
target: "main", |
| 11676 |
type: "ir.actions.client", |
| 11677 |
}); |
| 11678 |
} |
| 11679 |
} |
| 11680 |
widgetsRegistry.add("test_widget", { component: MyWidget }); |
| 11681 |
|
| 11682 |
defineActions([ |
| 11683 |
{ |
| 11684 |
id: 1, |
| 11685 |
name: "test", |
| 11686 |
res_model: "partner", |
| 11687 |
res_id: 1, |
| 11688 |
views: [[false, "form"]], |
| 11689 |
}, |
| 11690 |
]); |
| 11691 |
|
| 11692 |
Partner._views = { |
| 11693 |
list: `<list editable="bottom"><field name="foo"/></list>`, |
| 11694 |
form: ` |
| 11695 |
<form> |
| 11696 |
<widget name="test_widget"/> |
| 11697 |
<field name="foo"/> |
| 11698 |
<field name="child_ids"/> |
| 11699 |
</form> |
| 11700 |
`, |
| 11701 |
}; |
| 11702 |
|
| 11703 |
onRpc(({ method, args }) => { |
| 11704 |
if ((method === "web_read" || method === "web_save") && args[0][0] === 1) { |
| 11705 |
expect.step(method); |
| 11706 |
} |
| 11707 |
}); |
| 11708 |
await mountWithCleanup(WebClient); |
| 11709 |
await getService("action").doAction(1); |
| 11710 |
|
| 11711 |
await contains(`.o_field_one2many[name="child_ids"] .o_field_x2many_list_row_add a`).click(); |
| 11712 |
await contains(`[name="child_ids"] input`).edit("new"); |
| 11713 |
expect.verifySteps(["web_read"]); |
| 11714 |
|
| 11715 |
await contains(`.test_widget button`).click(); |
| 11716 |
await animationFrame(); |
| 11717 |
expect.verifyErrors(["Something went wrong"]); |
| 11718 |
|
| 11719 |
// Close ErrorDialog |
| 11720 |
await contains(`.o_dialog .btn-close`).click(); |
| 11721 |
expect(`[name="child_ids"] .o_data_row`).toHaveCount(1); |
| 11722 |
expect.verifySteps(["web_save", "web_read"]); |
| 11723 |
|
| 11724 |
await contains(`[name=foo] input`).edit("new value"); |
| 11725 |
await contains(`.o_form_button_save`).click(); |
| 11726 |
expect(`[name="child_ids"] .o_data_row`).toHaveCount(1); |
| 11727 |
expect.verifySteps(["web_save"]); |
| 11728 |
}); |
| 11729 |
|
| 11730 |
test(`coming to an action with an error from a form view with a record in creation`, async () => { |
| 11731 |
expect.errors(1); |
| 11732 |
|
| 11733 |
class TestClientAction extends Component { |
| 11734 |
static props = ["*"]; |
| 11735 |
static template = xml`<div></div>`; |
| 11736 |
setup() { |
| 11737 |
throw new Error("Something went wrong"); |
| 11738 |
} |
| 11739 |
} |
| 11740 |
registry.category("actions").add("TestClientAction", TestClientAction); |
| 11741 |
|
| 11742 |
class MyWidget extends Component { |
| 11743 |
static props = ["*"]; |
| 11744 |
static template = xml` |
| 11745 |
<div class="test_widget"> |
| 11746 |
<button t-on-click="onClick">MyButton</button> |
| 11747 |
</div>`; |
| 11748 |
setup() { |
| 11749 |
this.actionService = useService("action"); |
| 11750 |
} |
| 11751 |
onClick() { |
| 11752 |
this.actionService.doAction({ |
| 11753 |
tag: "TestClientAction", |
| 11754 |
target: "main", |
| 11755 |
type: "ir.actions.client", |
| 11756 |
}); |
| 11757 |
} |
| 11758 |
} |
| 11759 |
widgetsRegistry.add("test_widget", { component: MyWidget }); |
| 11760 |
|
| 11761 |
defineActions([ |
| 11762 |
{ |
| 11763 |
id: 1, |
| 11764 |
name: "test", |
| 11765 |
res_model: "partner", |
| 11766 |
views: [[false, "form"]], |
| 11767 |
}, |
| 11768 |
]); |
| 11769 |
|
| 11770 |
Partner._views = { |
| 11771 |
form: ` |
| 11772 |
<form> |
| 11773 |
<widget name="test_widget"/> |
| 11774 |
<field name="foo"/> |
| 11775 |
</form> |
| 11776 |
`, |
| 11777 |
}; |
| 11778 |
|
| 11779 |
onRpc("web_read", ({ args }) => { |
| 11780 |
expect.step("web_read"); |
| 11781 |
expect(args[0]).toEqual([6]); |
| 11782 |
}); |
| 11783 |
onRpc("web_save", ({ args }) => { |
| 11784 |
expect.step("web_save"); |
| 11785 |
expect(args[1]).toEqual({ foo: "new value" }); |
| 11786 |
}); |
| 11787 |
|
| 11788 |
await mountWithCleanup(WebClient); |
| 11789 |
await getService("action").doAction(1); |
| 11790 |
|
| 11791 |
await contains(`[name=foo] input`).edit("new value"); |
| 11792 |
expect(`[name=foo] input`).toHaveValue("new value"); |
| 11793 |
|
| 11794 |
await contains(`.test_widget button`).click(); |
| 11795 |
await animationFrame(); |
| 11796 |
expect.verifyErrors(["Something went wrong"]); |
| 11797 |
|
| 11798 |
// Close ErrorDialog |
| 11799 |
await contains(`.o_dialog .btn-primary`).click(); |
| 11800 |
expect(`[name=foo] input`).toHaveValue("new value"); |
| 11801 |
expect.verifySteps(["web_save", "web_read"]); |
| 11802 |
}); |
| 11803 |
|
| 11804 |
test(`only re-render necessary fields after change`, async () => { |
| 11805 |
function logLifeCycle(component) { |
| 11806 |
patchWithCleanup(component.prototype, { |
| 11807 |
setup() { |
| 11808 |
super.setup(); |
| 11809 |
const prefix = `${this.constructor.name} ${this.props.name}`; |
| 11810 |
onMounted(() => expect.step(`[${prefix}] onMounted`)); |
| 11811 |
onPatched(() => expect.step(`[${prefix}] onPatched`)); |
| 11812 |
onWillStart(() => expect.step(`[${prefix}] onWillStart`)); |
| 11813 |
onWillUpdateProps(() => expect.step(`[${prefix}] onWillUpdateProps`)); |
| 11814 |
}, |
| 11815 |
}); |
| 11816 |
} |
| 11817 |
logLifeCycle(Field); |
| 11818 |
logLifeCycle(CharField); |
| 11819 |
logLifeCycle(IntegerField); |
| 11820 |
logLifeCycle(DateTimeField); |
| 11821 |
|
| 11822 |
await mountView({ |
| 11823 |
resModel: "partner", |
| 11824 |
type: "form", |
| 11825 |
arch: ` |
| 11826 |
<form> |
| 11827 |
<field name="foo"/> |
| 11828 |
<field name="int_field"/> |
| 11829 |
<field name="date"/> |
| 11830 |
</form> |
| 11831 |
`, |
| 11832 |
resId: 2, |
| 11833 |
}); |
| 11834 |
expect.verifySteps([ |
| 11835 |
"[Field foo] onWillStart", |
| 11836 |
"[Field int_field] onWillStart", |
| 11837 |
"[Field date] onWillStart", |
| 11838 |
"[CharField foo] onWillStart", |
| 11839 |
"[IntegerField int_field] onWillStart", |
| 11840 |
"[DateTimeField date] onWillStart", |
| 11841 |
"[DateTimeField date] onMounted", |
| 11842 |
"[IntegerField int_field] onMounted", |
| 11843 |
"[CharField foo] onMounted", |
| 11844 |
"[Field date] onMounted", |
| 11845 |
"[Field int_field] onMounted", |
| 11846 |
"[Field foo] onMounted", |
| 11847 |
]); |
| 11848 |
|
| 11849 |
await contains(`.o_field_widget[name=foo] input`).edit("new value"); |
| 11850 |
expect.verifySteps(["[Field foo] onPatched", "[CharField foo] onPatched"]); |
| 11851 |
|
| 11852 |
await contains(`.o_field_widget[name=int_field] input`).edit("5846"); |
| 11853 |
expect.verifySteps(["[Field int_field] onPatched", "[IntegerField int_field] onPatched"]); |
| 11854 |
}); |
| 11855 |
|
| 11856 |
test(`only re-render necessary fields after change (with onchange)`, async () => { |
| 11857 |
function logLifeCycle(component) { |
| 11858 |
patchWithCleanup(component.prototype, { |
| 11859 |
setup() { |
| 11860 |
super.setup(); |
| 11861 |
const prefix = `${this.constructor.name} ${this.props.name}`; |
| 11862 |
onMounted(() => expect.step(`[${prefix}] onMounted`)); |
| 11863 |
onPatched(() => expect.step(`[${prefix}] onPatched`)); |
| 11864 |
onWillStart(() => expect.step(`[${prefix}] onWillStart`)); |
| 11865 |
onWillUpdateProps(() => expect.step(`[${prefix}] onWillUpdateProps`)); |
| 11866 |
}, |
| 11867 |
}); |
| 11868 |
} |
| 11869 |
logLifeCycle(Field); |
| 11870 |
logLifeCycle(CharField); |
| 11871 |
logLifeCycle(IntegerField); |
| 11872 |
logLifeCycle(DateTimeField); |
| 11873 |
|
| 11874 |
Partner._onChanges = { |
| 11875 |
foo(record) { |
| 11876 |
record.int_field = 23; |
| 11877 |
}, |
| 11878 |
}; |
| 11879 |
|
| 11880 |
await mountView({ |
| 11881 |
resModel: "partner", |
| 11882 |
type: "form", |
| 11883 |
arch: ` |
| 11884 |
<form> |
| 11885 |
<field name="foo"/> |
| 11886 |
<field name="int_field"/> |
| 11887 |
<field name="date"/> |
| 11888 |
</form> |
| 11889 |
`, |
| 11890 |
resId: 2, |
| 11891 |
}); |
| 11892 |
expect.verifySteps([ |
| 11893 |
"[Field foo] onWillStart", |
| 11894 |
"[Field int_field] onWillStart", |
| 11895 |
"[Field date] onWillStart", |
| 11896 |
"[CharField foo] onWillStart", |
| 11897 |
"[IntegerField int_field] onWillStart", |
| 11898 |
"[DateTimeField date] onWillStart", |
| 11899 |
"[DateTimeField date] onMounted", |
| 11900 |
"[IntegerField int_field] onMounted", |
| 11901 |
"[CharField foo] onMounted", |
| 11902 |
"[Field date] onMounted", |
| 11903 |
"[Field int_field] onMounted", |
| 11904 |
"[Field foo] onMounted", |
| 11905 |
]); |
| 11906 |
|
| 11907 |
await contains(`.o_field_widget[name=foo] input`).edit("new value"); |
| 11908 |
expect.verifySteps([ |
| 11909 |
"[Field foo] onPatched", |
| 11910 |
"[CharField foo] onPatched", |
| 11911 |
"[Field int_field] onPatched", |
| 11912 |
"[IntegerField int_field] onPatched", |
| 11913 |
]); |
| 11914 |
|
| 11915 |
await contains(`.o_field_widget[name=int_field] input`).edit("5846"); |
| 11916 |
expect.verifySteps(["[Field int_field] onPatched", "[IntegerField int_field] onPatched"]); |
| 11917 |
}); |
| 11918 |
|
| 11919 |
test(`widget update several fields including an x2m`, async () => { |
| 11920 |
Partner._onChanges = { |
| 11921 |
name() {}, |
| 11922 |
child_ids() {}, |
| 11923 |
}; |
| 11924 |
class TestWidget extends Component { |
| 11925 |
static props = ["*"]; |
| 11926 |
static template = xml`<div><button t-on-click="onClick">Click</button></div>`; |
| 11927 |
|
| 11928 |
onClick() { |
| 11929 |
this.props.record.update({ |
| 11930 |
name: "New Name", |
| 11931 |
child_ids: [[0, false, { name: "yop" }]], |
| 11932 |
}); |
| 11933 |
} |
| 11934 |
} |
| 11935 |
|
| 11936 |
widgetsRegistry.add("test", { |
| 11937 |
component: TestWidget, |
| 11938 |
fieldDependencies: [ |
| 11939 |
{ name: "name", type: "char" }, |
| 11940 |
{ name: "child_ids", type: "one2many", relation: "partner" }, |
| 11941 |
], |
| 11942 |
}); |
| 11943 |
|
| 11944 |
onRpc("onchange", ({ args }) => { |
| 11945 |
expect.step("onchange"); |
| 11946 |
expect(args[1].name).toBe("New Name"); |
| 11947 |
expect(args[1].child_ids).toHaveLength(1); |
| 11948 |
expect(args[1].child_ids[0][2]).toEqual({ name: "yop" }); |
| 11949 |
}); |
| 11950 |
await mountView({ |
| 11951 |
resModel: "partner", |
| 11952 |
type: "form", |
| 11953 |
arch: ` |
| 11954 |
<form> |
| 11955 |
<widget name="test"/> |
| 11956 |
<field name="name"/> |
| 11957 |
<field name="child_ids"> |
| 11958 |
<list> |
| 11959 |
<field name="name"/> |
| 11960 |
</list> |
| 11961 |
</field> |
| 11962 |
</form> |
| 11963 |
`, |
| 11964 |
resId: 2, |
| 11965 |
}); |
| 11966 |
expect(`[name=name] input`).toHaveValue("second record"); |
| 11967 |
expect(queryAllTexts`.o_data_row`).toEqual([]); |
| 11968 |
|
| 11969 |
await contains(`.o_widget_test button`).click(); |
| 11970 |
expect(`[name=name] input`).toHaveValue("New Name"); |
| 11971 |
expect(queryAllTexts`.o_data_row`).toEqual(["yop"]); |
| 11972 |
expect.verifySteps(["onchange"]); |
| 11973 |
}); |
| 11974 |
|
| 11975 |
test(`commitChanges with a field input removed during an update`, async () => { |
| 11976 |
Partner._records[1].child_ids = [1, 5]; |
| 11977 |
Partner._onChanges = { |
| 11978 |
foo() {}, |
| 11979 |
}; |
| 11980 |
|
| 11981 |
const onchangeDeferred = new Deferred(); |
| 11982 |
onRpc("onchange", () => onchangeDeferred); |
| 11983 |
onRpc("web_save", ({ args }) => { |
| 11984 |
expect(args[1]).toEqual({ child_ids: [[1, 1, { foo: "new foo" }]] }); |
| 11985 |
}); |
| 11986 |
|
| 11987 |
await mountView({ |
| 11988 |
resModel: "partner", |
| 11989 |
type: "form", |
| 11990 |
arch: ` |
| 11991 |
<form> |
| 11992 |
<field name="child_ids"> |
| 11993 |
<list editable="bottom"> |
| 11994 |
<field name="foo"/> |
| 11995 |
</list> |
| 11996 |
</field> |
| 11997 |
</form> |
| 11998 |
`, |
| 11999 |
resId: 2, |
| 12000 |
}); |
| 12001 |
|
| 12002 |
await contains(`.o_data_cell[name="foo"]`).click(); |
| 12003 |
await contains(`.o_data_cell[name="foo"] input`).edit("new foo", { confirm: "tab" }); |
| 12004 |
onchangeDeferred.resolve(); |
| 12005 |
await contains(`.o_form_button_save`).click(); |
| 12006 |
}); |
| 12007 |
|
| 12008 |
test(`multiple views for m2m field after list item edit in form`, async () => { |
| 12009 |
Partner._records[0].type_ids = [1, 2]; |
| 12010 |
|
| 12011 |
PartnerType._fields.m2m = fields.Many2many({ relation: "extra" }); |
| 12012 |
PartnerType._records = [ |
| 12013 |
{ id: 1, name: "ma", m2m: [1] }, |
| 12014 |
{ id: 2, name: "cr", m2m: [2] }, |
| 12015 |
]; |
| 12016 |
|
| 12017 |
class Extra extends models.Model { |
| 12018 |
name = fields.Char(); |
| 12019 |
|
| 12020 |
_records = [ |
| 12021 |
{ id: 1, name: "ma" }, |
| 12022 |
{ id: 2, name: "cr" }, |
| 12023 |
]; |
| 12024 |
} |
| 12025 |
defineModels([Extra]); |
| 12026 |
|
| 12027 |
await mountView({ |
| 12028 |
resModel: "partner", |
| 12029 |
type: "form", |
| 12030 |
arch: ` |
| 12031 |
<form> |
| 12032 |
<field name="type_ids"> |
| 12033 |
<list> |
| 12034 |
<field name="display_name"/> |
| 12035 |
<field name="m2m" widget="many2many_tags"/> |
| 12036 |
</list> |
| 12037 |
<form> |
| 12038 |
<field name="name"/> |
| 12039 |
<field name="m2m"> |
| 12040 |
<list> |
| 12041 |
<field name="name"/> |
| 12042 |
</list> |
| 12043 |
</field> |
| 12044 |
</form> |
| 12045 |
</field> |
| 12046 |
</form> |
| 12047 |
`, |
| 12048 |
resId: 1, |
| 12049 |
}); |
| 12050 |
|
| 12051 |
await contains(`.o_data_cell:eq(0)`).click(); |
| 12052 |
expect(`.modal`).toHaveCount(1); |
| 12053 |
|
| 12054 |
await contains(`.modal-body [name='name'] input`).edit("updated"); |
| 12055 |
await contains(`.modal-footer .o_form_button_save`).click(); |
| 12056 |
expect(`.modal`).toHaveCount(0); |
| 12057 |
expect(`.o_data_cell:eq(0)`).toHaveText("updated"); |
| 12058 |
}); |
| 12059 |
|
| 12060 |
test(`custom x2many with relatedFields and list view inline`, async () => { |
| 12061 |
fieldsRegistry.add("my_widget", { |
| 12062 |
...x2ManyField, |
| 12063 |
component: class MyField extends X2ManyField {}, |
| 12064 |
relatedFields: [ |
| 12065 |
{ name: "parent_id", type: "many2one", relation: "partner" }, |
| 12066 |
{ name: "int_field", type: "integer" }, |
| 12067 |
], |
| 12068 |
}); |
| 12069 |
|
| 12070 |
onRpc("web_read", ({ kwargs }) => { |
| 12071 |
expect.step("web_read"); |
| 12072 |
expect(kwargs.specification.child_ids.fields).toEqual({ |
| 12073 |
parent_id: { fields: { display_name: {} } }, |
| 12074 |
foo: {}, |
| 12075 |
int_field: {}, |
| 12076 |
}); |
| 12077 |
}); |
| 12078 |
onRpc("write", ({ args }) => { |
| 12079 |
expect.step("write"); |
| 12080 |
expect(args[1].child_ids[0][2]).toEqual({ |
| 12081 |
foo: "new record", |
| 12082 |
int_field: 0, |
| 12083 |
}); |
| 12084 |
}); |
| 12085 |
onRpc("web_save", ({ kwargs }) => { |
| 12086 |
expect.step("web_save"); |
| 12087 |
expect(kwargs.specification.child_ids.fields).toEqual({ |
| 12088 |
parent_id: { fields: { display_name: {} } }, |
| 12089 |
foo: {}, |
| 12090 |
int_field: {}, |
| 12091 |
}); |
| 12092 |
}); |
| 12093 |
|
| 12094 |
await mountView({ |
| 12095 |
resModel: "partner", |
| 12096 |
type: "form", |
| 12097 |
arch: ` |
| 12098 |
<form> |
| 12099 |
<field name="child_ids" widget="my_widget"> |
| 12100 |
<list editable="bottom" > |
| 12101 |
<field name="foo"/> |
| 12102 |
<field name="int_field" /> |
| 12103 |
</list> |
| 12104 |
</field> |
| 12105 |
</form> |
| 12106 |
`, |
| 12107 |
resId: 2, |
| 12108 |
}); |
| 12109 |
|
| 12110 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 12111 |
await contains(`.o_data_row [name='foo'] input`).edit("new record"); |
| 12112 |
await contains(`.o_form_button_save`).click(); |
| 12113 |
expect.verifySteps(["web_read", "web_save"]); |
| 12114 |
}); |
| 12115 |
|
| 12116 |
test(`custom x2many with a m2o in relatedFields and column_invisible`, async () => { |
| 12117 |
fieldsRegistry.add("my_widget", { |
| 12118 |
...x2ManyField, |
| 12119 |
component: class MyField extends X2ManyField {}, |
| 12120 |
relatedFields: [{ name: "parent_id", type: "many2one", relation: "partner" }], |
| 12121 |
}); |
| 12122 |
|
| 12123 |
onRpc("web_read", ({ kwargs }) => { |
| 12124 |
expect.step("web_read"); |
| 12125 |
expect(kwargs.specification.child_ids.fields).toEqual({ |
| 12126 |
parent_id: { fields: { display_name: {} } }, |
| 12127 |
foo: {}, |
| 12128 |
}); |
| 12129 |
}); |
| 12130 |
onRpc("write", ({ args }) => { |
| 12131 |
expect.step("write"); |
| 12132 |
expect(args[1].child_ids[0][2]).toEqual({ |
| 12133 |
foo: "new record", |
| 12134 |
int_field: 0, |
| 12135 |
}); |
| 12136 |
}); |
| 12137 |
onRpc("web_save", ({ kwargs }) => { |
| 12138 |
expect.step("web_save"); |
| 12139 |
expect(kwargs.specification.child_ids.fields).toEqual({ |
| 12140 |
parent_id: { fields: { display_name: {} } }, |
| 12141 |
foo: {}, |
| 12142 |
}); |
| 12143 |
}); |
| 12144 |
|
| 12145 |
await mountView({ |
| 12146 |
resModel: "partner", |
| 12147 |
type: "form", |
| 12148 |
arch: ` |
| 12149 |
<form> |
| 12150 |
<field name="child_ids" widget="my_widget"> |
| 12151 |
<list editable="bottom" > |
| 12152 |
<field name="foo"/> |
| 12153 |
<field name="parent_id" column_invisible="True"/> |
| 12154 |
</list> |
| 12155 |
</field> |
| 12156 |
</form> |
| 12157 |
`, |
| 12158 |
resId: 2, |
| 12159 |
}); |
| 12160 |
|
| 12161 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 12162 |
await contains(`.o_data_row [name='foo'] input`).edit("new record"); |
| 12163 |
await contains(`.o_form_button_save`).click(); |
| 12164 |
expect.verifySteps(["web_read", "web_save"]); |
| 12165 |
}); |
| 12166 |
|
| 12167 |
test.tags("desktop"); |
| 12168 |
test(`custom x2many with relatedFields and list view not inline`, async () => { |
| 12169 |
fieldsRegistry.add("my_widget", { |
| 12170 |
...x2ManyField, |
| 12171 |
component: class MyField extends X2ManyField {}, |
| 12172 |
relatedFields: [ |
| 12173 |
{ name: "parent_id", type: "many2one", relation: "partner" }, |
| 12174 |
{ name: "int_field", type: "integer" }, |
| 12175 |
], |
| 12176 |
}); |
| 12177 |
|
| 12178 |
Partner._views = { |
| 12179 |
list: ` |
| 12180 |
<list editable="bottom"> |
| 12181 |
<field name="foo"/> |
| 12182 |
<field name="int_field"/> |
| 12183 |
</list> |
| 12184 |
`, |
| 12185 |
}; |
| 12186 |
|
| 12187 |
onRpc("web_read", ({ kwargs }) => { |
| 12188 |
expect.step("web_read"); |
| 12189 |
expect(kwargs.specification.child_ids.fields).toEqual({ |
| 12190 |
parent_id: { fields: { display_name: {} } }, |
| 12191 |
foo: {}, |
| 12192 |
int_field: {}, |
| 12193 |
}); |
| 12194 |
}); |
| 12195 |
onRpc("write", ({ args }) => { |
| 12196 |
expect.step("write"); |
| 12197 |
expect(args[1].child_ids[0][2]).toEqual({ |
| 12198 |
foo: "new record", |
| 12199 |
int_field: 0, |
| 12200 |
}); |
| 12201 |
}); |
| 12202 |
onRpc("web_save", ({ kwargs }) => { |
| 12203 |
expect.step("web_save"); |
| 12204 |
expect(kwargs.specification.child_ids.fields).toEqual({ |
| 12205 |
parent_id: { fields: { display_name: {} } }, |
| 12206 |
foo: {}, |
| 12207 |
int_field: {}, |
| 12208 |
}); |
| 12209 |
}); |
| 12210 |
|
| 12211 |
await mountView({ |
| 12212 |
resModel: "partner", |
| 12213 |
type: "form", |
| 12214 |
arch: `<form><field name="child_ids" widget="my_widget"/></form>`, |
| 12215 |
resId: 2, |
| 12216 |
}); |
| 12217 |
|
| 12218 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 12219 |
await contains(`.o_data_row [name='foo'] input`).edit("new record"); |
| 12220 |
await contains(`.o_form_button_save`).click(); |
| 12221 |
expect.verifySteps(["web_read", "web_save"]); |
| 12222 |
}); |
| 12223 |
|
| 12224 |
test(`custom many2one with relatedFields`, async () => { |
| 12225 |
class CustomMany2One extends Component { |
| 12226 |
static template = xml` |
| 12227 |
<t t-set="value" t-value="props.record.data[props.name]"/> |
| 12228 |
<div class="content"> |
| 12229 |
<div t-esc="value.id"/> |
| 12230 |
<div t-esc="value.display_name"/> |
| 12231 |
<div t-esc="value.foo"/> |
| 12232 |
<div t-esc="value.int_field"/> |
| 12233 |
</div> |
| 12234 |
<button id="update-m2o" t-on-click="() => this.update()">Update</button> |
| 12235 |
`; |
| 12236 |
static props = ["*"]; |
| 12237 |
|
| 12238 |
update() { |
| 12239 |
return this.props.record.update({ [this.props.name]: { id: 2 } }); |
| 12240 |
} |
| 12241 |
} |
| 12242 |
fieldsRegistry.add("my_widget", { |
| 12243 |
component: CustomMany2One, |
| 12244 |
relatedFields: [ |
| 12245 |
{ name: "foo", type: "char" }, |
| 12246 |
{ name: "int_field", type: "integer" }, |
| 12247 |
], |
| 12248 |
}); |
| 12249 |
|
| 12250 |
onRpc("web_read", ({ kwargs }) => { |
| 12251 |
expect.step("web_read"); |
| 12252 |
expect.step(kwargs.specification); |
| 12253 |
}); |
| 12254 |
|
| 12255 |
await mountView({ |
| 12256 |
resModel: "partner", |
| 12257 |
type: "form", |
| 12258 |
arch: `<form><field name="parent_id" widget="my_widget"/></form>`, |
| 12259 |
resId: 1, |
| 12260 |
}); |
| 12261 |
expect.verifySteps([ |
| 12262 |
"web_read", |
| 12263 |
{ |
| 12264 |
display_name: {}, |
| 12265 |
parent_id: { |
| 12266 |
fields: { |
| 12267 |
display_name: {}, |
| 12268 |
foo: {}, |
| 12269 |
int_field: {}, |
| 12270 |
}, |
| 12271 |
}, |
| 12272 |
}, |
| 12273 |
]); |
| 12274 |
expect(`.o_field_widget[name="parent_id"] .content`).toHaveText( |
| 12275 |
"4\naaa\nMy little Foo Value\n0" |
| 12276 |
); |
| 12277 |
|
| 12278 |
await contains(`#update-m2o`).click(); |
| 12279 |
expect.verifySteps([ |
| 12280 |
"web_read", |
| 12281 |
{ |
| 12282 |
display_name: {}, |
| 12283 |
foo: {}, |
| 12284 |
int_field: {}, |
| 12285 |
}, |
| 12286 |
]); |
| 12287 |
expect(`.o_field_widget[name="parent_id"] .content`).toHaveText("2\nsecond record\nblip\n9"); |
| 12288 |
}); |
| 12289 |
|
| 12290 |
test(`existing record with falsy display_name`, async () => { |
| 12291 |
Partner._records[0].name = ""; |
| 12292 |
await mountView({ |
| 12293 |
resModel: "partner", |
| 12294 |
type: "form", |
| 12295 |
arch: `<form><field name="int_field"/></form>`, |
| 12296 |
resId: 1, |
| 12297 |
}); |
| 12298 |
expect(`.o_breadcrumb`).toHaveText("Unnamed"); |
| 12299 |
}); |
| 12300 |
|
| 12301 |
test(`field with special data`, async () => { |
| 12302 |
class MyWidget extends Component { |
| 12303 |
static props = ["*"]; |
| 12304 |
static template = xml`<div>MyWidget</div>`; |
| 12305 |
setup() { |
| 12306 |
this.specialData = useSpecialData((orm, props) => { |
| 12307 |
const { record } = props; |
| 12308 |
return orm.call("my.model", "get_special_data", [record.data.int_field]); |
| 12309 |
}); |
| 12310 |
} |
| 12311 |
} |
| 12312 |
widgetsRegistry.add("my_widget", { component: MyWidget }); |
| 12313 |
|
| 12314 |
onRpc("get_special_data", ({ args }) => { |
| 12315 |
expect.step(`get_special_data ${args[0]}`); |
| 12316 |
return {}; |
| 12317 |
}); |
| 12318 |
|
| 12319 |
await mountView({ |
| 12320 |
resModel: "partner", |
| 12321 |
type: "form", |
| 12322 |
arch: ` |
| 12323 |
<form> |
| 12324 |
<field name="int_field" /> |
| 12325 |
<widget name="my_widget" /> |
| 12326 |
</form> |
| 12327 |
`, |
| 12328 |
resId: 2, |
| 12329 |
}); |
| 12330 |
|
| 12331 |
await contains(`[name='int_field'] input`).edit("42"); |
| 12332 |
expect.verifySteps(["get_special_data 9", "get_special_data 42"]); |
| 12333 |
}); |
| 12334 |
|
| 12335 |
test(`field with special data (with persistent Cache)`, async () => { |
| 12336 |
class MyWidget extends Component { |
| 12337 |
static props = ["*"]; |
| 12338 |
static template = xml`<div class="my_widget">MyWidget <t t-esc="specialData.data.test"/></div>`; |
| 12339 |
setup() { |
| 12340 |
this.specialData = useSpecialData((orm, props) => { |
| 12341 |
const { record } = props; |
| 12342 |
return orm.call("my.model", "get_special_data", [record.data.int_field]); |
| 12343 |
}); |
| 12344 |
} |
| 12345 |
} |
| 12346 |
widgetsRegistry.add("my_widget", { component: MyWidget }); |
| 12347 |
|
| 12348 |
let def = new Deferred(); |
| 12349 |
onRpc("get_special_data", ({ args }) => { |
| 12350 |
expect.step(`get_special_data ${args[0]}`); |
| 12351 |
return def; |
| 12352 |
}); |
| 12353 |
|
| 12354 |
defineActions([ |
| 12355 |
{ |
| 12356 |
id: 1, |
| 12357 |
name: "Partner", |
| 12358 |
res_model: "partner", |
| 12359 |
views: [[false, "form"]], |
| 12360 |
view_mode: "form", |
| 12361 |
res_id: 2, |
| 12362 |
}, |
| 12363 |
{ |
| 12364 |
id: 2, |
| 12365 |
res_model: "res.users", |
| 12366 |
res_id: 19, |
| 12367 |
view_mode: "form", |
| 12368 |
views: [[false, "form"]], |
| 12369 |
}, |
| 12370 |
]); |
| 12371 |
Partner._views = { |
| 12372 |
form: ` |
| 12373 |
<form> |
| 12374 |
<field name="int_field" /> |
| 12375 |
<widget name="my_widget" /> |
| 12376 |
</form>`, |
| 12377 |
}; |
| 12378 |
await mountWithCleanup(WebClient); |
| 12379 |
|
| 12380 |
def.resolve({ test: 1 }); |
| 12381 |
await getService("action").doAction(1); |
| 12382 |
expect(`.o_last_breadcrumb_item`).toHaveText("second record"); |
| 12383 |
expect(`.my_widget`).toHaveText("MyWidget 1"); |
| 12384 |
await contains(`[name='int_field'] input`).edit("42"); |
| 12385 |
expect.verifySteps(["get_special_data 9", "get_special_data 42"]); |
| 12386 |
|
| 12387 |
// Go to another model, to remove the model cache |
| 12388 |
await getService("action").doAction(2); |
| 12389 |
expect(`.o_last_breadcrumb_item`).toHaveText("Christine"); |
| 12390 |
|
| 12391 |
//Came back to the model with the special data |
| 12392 |
def = new Deferred(); |
| 12393 |
await getService("action").doAction(1); |
| 12394 |
expect(`.o_last_breadcrumb_item`).toHaveText("second record"); |
| 12395 |
expect(`.my_widget`).toHaveText("MyWidget 1"); |
| 12396 |
|
| 12397 |
def.resolve({ test: 2 }); |
| 12398 |
await animationFrame(); |
| 12399 |
expect(`.o_last_breadcrumb_item`).toHaveText("second record"); |
| 12400 |
expect(`.my_widget`).toHaveText("MyWidget 2"); |
| 12401 |
expect.verifySteps(["get_special_data 42"]); |
| 12402 |
}); |
| 12403 |
|
| 12404 |
test(`x2many field in form dialog view is correctly saved when using a view button`, async () => { |
| 12405 |
defineActions([ |
| 12406 |
{ |
| 12407 |
id: 1, |
| 12408 |
name: "Partner", |
| 12409 |
res_model: "partner", |
| 12410 |
views: [[false, "form"]], |
| 12411 |
view_mode: "form", |
| 12412 |
res_id: 6, |
| 12413 |
}, |
| 12414 |
]); |
| 12415 |
|
| 12416 |
Partner._views = { |
| 12417 |
form: `<form><field name="name"/></form>`, |
| 12418 |
}; |
| 12419 |
ResUsers._views = { |
| 12420 |
form: ` |
| 12421 |
<form> |
| 12422 |
<field name="partner_ids"> |
| 12423 |
<list> |
| 12424 |
<field name="name"/> |
| 12425 |
</list> |
| 12426 |
<form> |
| 12427 |
<header> |
| 12428 |
<button type="action" name="1" string="test"/> |
| 12429 |
</header> |
| 12430 |
<field name="name"/> |
| 12431 |
</form> |
| 12432 |
</field> |
| 12433 |
</form> |
| 12434 |
`, |
| 12435 |
}; |
| 12436 |
|
| 12437 |
onRpc("partner", "web_save", ({ args }) => { |
| 12438 |
expect.step("web_save_partner"); |
| 12439 |
expect(args[1]).toEqual({ name: "new value" }); |
| 12440 |
}); |
| 12441 |
onRpc("res.users", "web_save", ({ args }) => { |
| 12442 |
expect.step("web_save_user"); |
| 12443 |
expect(args[1]).toEqual({ partner_ids: [[4, 6]] }); |
| 12444 |
}); |
| 12445 |
|
| 12446 |
await mountWithCleanup(WebClient); |
| 12447 |
await getService("action").doAction({ |
| 12448 |
res_id: 19, |
| 12449 |
type: "ir.actions.act_window", |
| 12450 |
res_model: "res.users", |
| 12451 |
view_mode: "form", |
| 12452 |
views: [[false, "form"]], |
| 12453 |
}); |
| 12454 |
|
| 12455 |
expect(`.o_data_cell`).toHaveCount(0); |
| 12456 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 12457 |
await contains(`.o_field_widget[name=name] input`).edit("new value"); |
| 12458 |
await contains(`.modal-dialog .o_form_button_save`).click(); |
| 12459 |
await contains(`.o_data_cell`).click(); |
| 12460 |
await contains(`[name='1']`).click(); |
| 12461 |
expect.verifySteps(["web_save_partner", "web_save_user"]); |
| 12462 |
expect(`.o_field_widget[name=name] input`).toHaveValue("new value"); |
| 12463 |
}); |
| 12464 |
|
| 12465 |
test(`nested form view doesn't parasite the main one`, async () => { |
| 12466 |
await mountView({ |
| 12467 |
resModel: "partner", |
| 12468 |
type: "form", |
| 12469 |
arch: ` |
| 12470 |
<form> |
| 12471 |
<field name="child_ids"> |
| 12472 |
<form> |
| 12473 |
<div name="button_box" invisible="crash == True"> |
| 12474 |
<button name="somename" type="object" /> |
| 12475 |
</div> |
| 12476 |
<field name="child_ids"> |
| 12477 |
<form> |
| 12478 |
<footer> |
| 12479 |
<button name="someothername" type="object" /> |
| 12480 |
</footer> |
| 12481 |
</form> |
| 12482 |
<list><field name="display_name" /></list> |
| 12483 |
</field> |
| 12484 |
<footer> |
| 12485 |
<button name="somename" type="object" /> |
| 12486 |
</footer> |
| 12487 |
</form> |
| 12488 |
<list> |
| 12489 |
<field name="display_name" /> |
| 12490 |
</list> |
| 12491 |
</field> |
| 12492 |
</form> |
| 12493 |
`, |
| 12494 |
resId: 2, |
| 12495 |
}); |
| 12496 |
expect(`.o_form_view`).toHaveCount(1); |
| 12497 |
expect(`.o-form-buttonbox`).toHaveCount(0); |
| 12498 |
|
| 12499 |
await contains(`.o_field_x2many_list_row_add a`).click(); |
| 12500 |
expect(`.modal .modal-footer button[name='somename']`).toHaveCount(1); |
| 12501 |
expect(`.modal .modal-footer button[name='someothername']`).toHaveCount(0); |
| 12502 |
|
| 12503 |
await contains(`.modal .o_field_x2many_list_row_add a`).click(); |
| 12504 |
expect(`.modal:not(.o_inactive_modal) .modal-footer button[name='someothername']`).toHaveCount( |
| 12505 |
1 |
| 12506 |
); |
| 12507 |
}); |
| 12508 |
|
| 12509 |
test(`an empty json object does not pass the required check`, async () => { |
| 12510 |
Partner._fields.json_field = fields.Json({ string: "json_field" }); |
| 12511 |
|
| 12512 |
class JsonField extends Component { |
| 12513 |
static props = ["*"]; |
| 12514 |
static supportedTypes = ["json"]; |
| 12515 |
static template = xml`<span><input t-on-change="onChange"/></span>`; |
| 12516 |
|
| 12517 |
onChange(ev) { |
| 12518 |
this.props.record.update({ [this.props.name]: JSON.parse(ev.target.value) }); |
| 12519 |
} |
| 12520 |
} |
| 12521 |
fieldsRegistry.add("my_json", { component: JsonField }); |
| 12522 |
|
| 12523 |
mockService("notification", { |
| 12524 |
add(message, params) { |
| 12525 |
expect.step("notification"); |
| 12526 |
expect(message).toBe("Missing required fields"); |
| 12527 |
expect(params).toEqual({ type: "danger" }); |
| 12528 |
}, |
| 12529 |
}); |
| 12530 |
|
| 12531 |
await mountView({ |
| 12532 |
resModel: "partner", |
| 12533 |
type: "form", |
| 12534 |
arch: `<form><field name="json_field" widget="my_json" required="1"/></form>`, |
| 12535 |
}); |
| 12536 |
|
| 12537 |
await contains(`.o_field_widget[name=json_field] input`).edit("{}"); |
| 12538 |
await contains(`.o_form_button_save`).click(); |
| 12539 |
expect(`.o_field_widget[name=json_field]`).toHaveClass("o_field_invalid"); |
| 12540 |
expect.verifySteps(["notification"]); |
| 12541 |
}); |
| 12542 |
|
| 12543 |
test("onchange returns values w.r.t. extended record specs, for not extended one", async () => { |
| 12544 |
Product._fields.partner_type_ids = fields.One2many({ |
| 12545 |
string: "Partner type", |
| 12546 |
relation: "partner", |
| 12547 |
}); |
| 12548 |
Product._views = { |
| 12549 |
form: ` |
| 12550 |
<form> |
| 12551 |
<field name="name"/> |
| 12552 |
<field name="partner_type_ids"> |
| 12553 |
<list> |
| 12554 |
<field name="name"/> |
| 12555 |
</list> |
| 12556 |
</field> |
| 12557 |
</form> |
| 12558 |
`, |
| 12559 |
}; |
| 12560 |
Partner._records[1].product_ids = [37, 41]; |
| 12561 |
Partner._onChanges = { |
| 12562 |
bar(record) { |
| 12563 |
record.product_ids = [ |
| 12564 |
[ |
| 12565 |
1, |
| 12566 |
37, |
| 12567 |
{ |
| 12568 |
name: "name changed", |
| 12569 |
partner_type_ids: [[0, 0, { name: "one" }]], |
| 12570 |
}, |
| 12571 |
], |
| 12572 |
[ |
| 12573 |
1, |
| 12574 |
41, |
| 12575 |
{ |
| 12576 |
name: "name twisted", |
| 12577 |
partner_type_ids: [[0, 0, { name: "two" }]], |
| 12578 |
}, |
| 12579 |
], |
| 12580 |
]; |
| 12581 |
}, |
| 12582 |
}; |
| 12583 |
onRpc("web_save", ({ args }) => { |
| 12584 |
expect.step("web_save"); |
| 12585 |
expect(args[1]).toEqual({ |
| 12586 |
bar: false, |
| 12587 |
product_ids: [ |
| 12588 |
[ |
| 12589 |
1, |
| 12590 |
37, |
| 12591 |
{ |
| 12592 |
name: "name changed", |
| 12593 |
partner_type_ids: [[0, 0, { name: "one" }]], |
| 12594 |
}, |
| 12595 |
], |
| 12596 |
[ |
| 12597 |
1, |
| 12598 |
41, |
| 12599 |
{ |
| 12600 |
name: "name twisted", |
| 12601 |
partner_type_ids: [[0, 0, { name: "two" }]], |
| 12602 |
}, |
| 12603 |
], |
| 12604 |
], |
| 12605 |
}); |
| 12606 |
}); |
| 12607 |
await mountView({ |
| 12608 |
resModel: "partner", |
| 12609 |
type: "form", |
| 12610 |
arch: ` |
| 12611 |
<form> |
| 12612 |
<field name="bar"/> |
| 12613 |
<field name="product_ids"> |
| 12614 |
<list> |
| 12615 |
<field name="name"/> |
| 12616 |
</list> |
| 12617 |
</field> |
| 12618 |
</form> |
| 12619 |
`, |
| 12620 |
resId: 2, |
| 12621 |
}); |
| 12622 |
|
| 12623 |
await contains(`.o_data_cell`).click(); |
| 12624 |
await contains(`.btn-secondary.o_form_button_cancel`).click(); |
| 12625 |
await contains(`.o-checkbox`).click(); |
| 12626 |
expect(queryAllTexts(`.o_data_cell`)).toEqual(["name changed", "name twisted"]); |
| 12627 |
await contains(`.o_form_button_save`).click(); |
| 12628 |
expect.verifySteps(["web_save"]); |
| 12629 |
}); |
| 12630 |
|
| 12631 |
test.tags("mobile"); |
| 12632 |
test(`statusbar buttons are correctly rendered in mobile`, async () => { |
| 12633 |
await mountView({ |
| 12634 |
type: "form", |
| 12635 |
resModel: "partner", |
| 12636 |
resId: 1, |
| 12637 |
arch: ` |
| 12638 |
<form> |
| 12639 |
<header> |
| 12640 |
<button string="Confirm" /> |
| 12641 |
<button string="Do it" /> |
| 12642 |
</header> |
| 12643 |
<sheet> |
| 12644 |
<group> |
| 12645 |
<button name="name" /> |
| 12646 |
</group> |
| 12647 |
</sheet> |
| 12648 |
</form> |
| 12649 |
`, |
| 12650 |
}); |
| 12651 |
|
| 12652 |
expect(".o_statusbar_buttons button:eq(0)").toHaveText("Confirm"); |
| 12653 |
// open the dropdown |
| 12654 |
await contains(".o_statusbar_buttons button:has(.oi-ellipsis-v)").click(); |
| 12655 |
await animationFrame(); |
| 12656 |
expect(".o-dropdown--menu:visible").toHaveCount(1, { message: "dropdown should be visible" }); |
| 12657 |
expect(".o-dropdown--menu button").toHaveCount(1, { |
| 12658 |
message: "should have 1 button in the dropdown", |
| 12659 |
}); |
| 12660 |
}); |
| 12661 |
|
| 12662 |
test.tags("mobile"); |
| 12663 |
test(`statusbar widgets should appear in the CogMenu dropdown`, async () => { |
| 12664 |
await mountView({ |
| 12665 |
type: "form", |
| 12666 |
resModel: "partner", |
| 12667 |
resId: 2, |
| 12668 |
arch: ` |
| 12669 |
<form> |
| 12670 |
<header> |
| 12671 |
<widget name="attach_document" string="Attach document" /> |
| 12672 |
<button string="Ciao" invisible="name == 'first record'" /> |
| 12673 |
</header> |
| 12674 |
<sheet> |
| 12675 |
<group> |
| 12676 |
<field name="name" /> |
| 12677 |
</group> |
| 12678 |
</sheet> |
| 12679 |
</form> |
| 12680 |
`, |
| 12681 |
}); |
| 12682 |
|
| 12683 |
expect(".o_statusbar_buttons button:eq(0)").toHaveText("Attach document"); |
| 12684 |
// Now there should an action dropdown, because there are two visible buttons |
| 12685 |
expect(".o_statusbar_buttons button:has(.oi-ellipsis-v)").toHaveCount(1, { |
| 12686 |
message: "should have 'More' dropdown", |
| 12687 |
}); |
| 12688 |
|
| 12689 |
await contains(".o_statusbar_buttons button:has(.oi-ellipsis-v)").click(); |
| 12690 |
expect(".o-dropdown--menu button").toHaveCount(1, { |
| 12691 |
message: "should have 1 button in the dropdown", |
| 12692 |
}); |
| 12693 |
|
| 12694 |
// change display_name to update buttons modifiers and make one button visible |
| 12695 |
await contains(".o_field_widget[name=name] input").edit("first record"); |
| 12696 |
expect(".o_statusbar_buttons button:eq(0)").toHaveText("Attach document"); |
| 12697 |
expect(".o_statusbar_buttons button:has(.oi-ellipsis-v)").toHaveCount(0, { |
| 12698 |
message: "shouldn't have 'More' dropdown", |
| 12699 |
}); |
| 12700 |
}); |
| 12701 |
|
| 12702 |
test.tags("mobile"); |
| 12703 |
test(`CogMenu dropdown's open/close state shouldn't be modified after 'onchange'`, async () => { |
| 12704 |
Partner._onChanges = { |
| 12705 |
name() {}, |
| 12706 |
}; |
| 12707 |
const onchangeDef = new Deferred(); |
| 12708 |
onRpc("partner", "onchange", ({ args }) => { |
| 12709 |
if (args[2][0] === "name") { |
| 12710 |
return onchangeDef; |
| 12711 |
} |
| 12712 |
}); |
| 12713 |
|
| 12714 |
await mountView({ |
| 12715 |
type: "form", |
| 12716 |
resModel: "partner", |
| 12717 |
arch: ` |
| 12718 |
<form> |
| 12719 |
<header> |
| 12720 |
<button name="create" string="Create Invoice" type="action" /> |
| 12721 |
<button name="send" string="Send by Email" type="action" /> |
| 12722 |
</header> |
| 12723 |
<sheet> |
| 12724 |
<field name="name" /> |
| 12725 |
</sheet> |
| 12726 |
</form> |
| 12727 |
`, |
| 12728 |
}); |
| 12729 |
|
| 12730 |
expect(".o_cp_action_menus button:has(.fa-cog)").toHaveCount(1, { |
| 12731 |
message: "statusbar should contain a dropdown", |
| 12732 |
}); |
| 12733 |
expect(".o_cp_action_menus button:has(.fa-cog)").not.toHaveClass("show", { |
| 12734 |
message: "dropdown should be opened", |
| 12735 |
}); |
| 12736 |
|
| 12737 |
await contains(".o_field_widget[name=name] input").edit("before onchange"); |
| 12738 |
await contains(".o_cp_action_menus button:has(.fa-cog)").click(); |
| 12739 |
expect(".o_cp_action_menus button:has(.fa-cog)").toHaveClass("show", { |
| 12740 |
message: "dropdown should be opened", |
| 12741 |
}); |
| 12742 |
|
| 12743 |
onchangeDef.resolve({ value: { name: "after onchange" } }); |
| 12744 |
await animationFrame(); |
| 12745 |
expect(".o_field_widget[name=name] input").toHaveValue("after onchange"); |
| 12746 |
expect(".o_cp_action_menus button:has(.fa-cog)").toHaveClass("show", { |
| 12747 |
message: "dropdown should be opened", |
| 12748 |
}); |
| 12749 |
}); |
| 12750 |
|
| 12751 |
test(`cog menu action is executed with up to date context`, async () => { |
| 12752 |
// this test simulates a case where the context of a form view evolves, which can happen with |
| 12753 |
// js customizations (js_class, custom widgets...) and the user then executes a cog menu action. |
| 12754 |
mockService("action", { |
| 12755 |
doAction(id, { additionalContext }) { |
| 12756 |
expect.step(`doAction ${additionalContext.x}`); |
| 12757 |
}, |
| 12758 |
}); |
| 12759 |
|
| 12760 |
class MyField extends CharField { |
| 12761 |
static template = xml`<button class="my_btn" t-on-click="onClick">Reload</button>`; |
| 12762 |
onClick() { |
| 12763 |
this.props.record.model.load({ context: { x: "z" } }); |
| 12764 |
} |
| 12765 |
} |
| 12766 |
fieldsRegistry.add("my_widget", { |
| 12767 |
component: MyField, |
| 12768 |
}); |
| 12769 |
|
| 12770 |
await mountView({ |
| 12771 |
resModel: "partner", |
| 12772 |
type: "form", |
| 12773 |
resId: 1, |
| 12774 |
arch: `<form><field name="bar" widget="my_widget"/></form>`, |
| 12775 |
context: { |
| 12776 |
x: "y", |
| 12777 |
}, |
| 12778 |
info: { |
| 12779 |
actionMenus: { |
| 12780 |
action: [ |
| 12781 |
{ |
| 12782 |
id: 29, |
| 12783 |
name: "Action partner", |
| 12784 |
}, |
| 12785 |
], |
| 12786 |
}, |
| 12787 |
}, |
| 12788 |
}); |
| 12789 |
expect(`.o_cp_action_menus .dropdown-toggle`).toHaveCount(1); |
| 12790 |
await toggleActionMenu(); |
| 12791 |
await toggleMenuItem("Action Partner"); |
| 12792 |
|
| 12793 |
await contains(".my_btn").click(); |
| 12794 |
await toggleActionMenu(); |
| 12795 |
await toggleMenuItem("Action Partner"); |
| 12796 |
expect.verifySteps(["doAction y", "doAction z"]); |
| 12797 |
}); |
| 12798 |
|
| 12799 |
test("CogMenu receives the model in env", async () => { |
| 12800 |
class CogItem extends Component { |
| 12801 |
static props = ["*"]; |
| 12802 |
static template = xml`<button class="test-cog" t-on-click="onClick">Test</button>`; |
| 12803 |
onClick() { |
| 12804 |
expect.step([`cog clicked`, this.env.model.root.resModel, this.env.model.root.resId]); |
| 12805 |
} |
| 12806 |
} |
| 12807 |
registry.category("cogMenu").add("test-cog", { |
| 12808 |
Component: CogItem, |
| 12809 |
isDisplayed: (env) => { |
| 12810 |
expect.step([`cog displayed`, env.model.root.resModel, env.model.root.resId]); |
| 12811 |
return true; |
| 12812 |
}, |
| 12813 |
}); |
| 12814 |
await mountView({ |
| 12815 |
resModel: "partner", |
| 12816 |
type: "form", |
| 12817 |
resId: 5, |
| 12818 |
arch: `<form><field name="display_name"/></form>`, |
| 12819 |
}); |
| 12820 |
expect.verifySteps([["cog displayed", "partner", 5]]); |
| 12821 |
await contains(".o_cp_action_menus button").click(); |
| 12822 |
await contains("button.test-cog").click(); |
| 12823 |
expect.verifySteps([["cog clicked", "partner", 5]]); |
| 12824 |
}); |
| 12825 |
|
| 12826 |
test.tags("mobile"); |
| 12827 |
test(`preserve current scroll position on form view while closing dialog`, async () => { |
| 12828 |
Partner._views = { |
| 12829 |
kanban: `<kanban><templates><t t-name="card"><field name="name" /></t></templates></kanban>`, |
| 12830 |
}; |
| 12831 |
|
| 12832 |
await mountView({ |
| 12833 |
type: "form", |
| 12834 |
resModel: "partner", |
| 12835 |
resId: 2, |
| 12836 |
arch: ` |
| 12837 |
<form> |
| 12838 |
<sheet> |
| 12839 |
<p style="height:500px" /> |
| 12840 |
<field name="parent_id" /> |
| 12841 |
<p style="height:500px" /> |
| 12842 |
</sheet> |
| 12843 |
</form> |
| 12844 |
`, |
| 12845 |
}); |
| 12846 |
|
| 12847 |
let position = { top: 0, left: 0 }; |
| 12848 |
patchWithCleanup(window, { |
| 12849 |
scrollTo(newPosition) { |
| 12850 |
position = newPosition; |
| 12851 |
}, |
| 12852 |
get scrollX() { |
| 12853 |
return position.left; |
| 12854 |
}, |
| 12855 |
get scrollY() { |
| 12856 |
return position.top; |
| 12857 |
}, |
| 12858 |
}); |
| 12859 |
|
| 12860 |
window.scrollTo({ top: 265, left: 0 }); |
| 12861 |
expect(window.scrollY).toBe(265, { message: "Should have scrolled 265 px vertically" }); |
| 12862 |
expect(window.scrollX).toBe(0, { message: "Should be 0 px from left as it is" }); |
| 12863 |
|
| 12864 |
// click on m2o field |
| 12865 |
await contains(".o_field_many2one input").click(); |
| 12866 |
// assert.strictEqual(window.scrollY, 0, "Should have scrolled to top (0) px"); |
| 12867 |
expect(".modal.o_modal_full").toHaveCount(1, { |
| 12868 |
message: "there should be a many2one modal opened in full screen", |
| 12869 |
}); |
| 12870 |
|
| 12871 |
// click on back button |
| 12872 |
await contains(".modal .modal-header .oi-arrow-left").click(); |
| 12873 |
|
| 12874 |
expect(window.scrollY).toBe(265, { message: "Should have scrolled 265 px vertically" }); |
| 12875 |
expect(window.scrollX).toBe(0, { message: "Should be 0 px from left as it is" }); |
| 12876 |
}); |
| 12877 |
|
| 12878 |
test.tags("mobile"); |
| 12879 |
test("attach_document widget also works inside a dropdown", async () => { |
| 12880 |
let fileInput; |
| 12881 |
patchWithCleanup(AttachDocumentWidget.prototype, { |
| 12882 |
setup() { |
| 12883 |
super.setup(); |
| 12884 |
fileInput = this.fileInput; |
| 12885 |
}, |
| 12886 |
}); |
| 12887 |
mockService("http", { |
| 12888 |
post: (route, params) => { |
| 12889 |
expect.step("post"); |
| 12890 |
expect(route).toBe("/web/binary/upload_attachment"); |
| 12891 |
expect(params.model).toBe("partner"); |
| 12892 |
expect(params.id).toBe(1); |
| 12893 |
return '[{ "id": 5 }, { "id": 2 }]'; |
| 12894 |
}, |
| 12895 |
}); |
| 12896 |
|
| 12897 |
await mountView({ |
| 12898 |
type: "form", |
| 12899 |
resModel: "partner", |
| 12900 |
resId: 1, |
| 12901 |
arch: ` |
| 12902 |
<form> |
| 12903 |
<header> |
| 12904 |
<button string="Confirm" /> |
| 12905 |
<widget name="attach_document" string="Attach Document"/> |
| 12906 |
</header> |
| 12907 |
<sheet> |
| 12908 |
<group> |
| 12909 |
<button name="name" /> |
| 12910 |
</group> |
| 12911 |
</sheet> |
| 12912 |
</form> |
| 12913 |
`, |
| 12914 |
}); |
| 12915 |
|
| 12916 |
await contains(".o_statusbar_buttons button:has(.oi-ellipsis-v)").click(); |
| 12917 |
await contains(".o_attach_document").click(); |
| 12918 |
await manuallyDispatchProgrammaticEvent(fileInput, "change"); |
| 12919 |
await animationFrame(); |
| 12920 |
expect.verifySteps(["post"]); |
| 12921 |
}); |
| 12922 |
|
| 12923 |
test(`do not perform button action for records with invalid datas`, async () => { |
| 12924 |
mockService("action", { |
| 12925 |
doActionButton(params) { |
| 12926 |
expect.step("Perform Action"); |
| 12927 |
expect(params.name).toBe("lovely action"); |
| 12928 |
}, |
| 12929 |
}); |
| 12930 |
mockService("notification", { |
| 12931 |
add: (message) => { |
| 12932 |
expect.step(`Pop Up: Invalid Field: ${message}`); |
| 12933 |
}, |
| 12934 |
}); |
| 12935 |
defineActions([ |
| 12936 |
{ |
| 12937 |
id: "lovely action", |
| 12938 |
name: "lovely action", |
| 12939 |
res_model: "partner", |
| 12940 |
type: "ir.actions.server", |
| 12941 |
}, |
| 12942 |
]); |
| 12943 |
patchWithCleanup(FormController.prototype, { |
| 12944 |
beforeExecuteActionButton(clickParams) { |
| 12945 |
expect.step("Check/prepare record datas"); |
| 12946 |
return super.beforeExecuteActionButton(clickParams); |
| 12947 |
}, |
| 12948 |
}); |
| 12949 |
onRpc("partner", "web_save", () => { |
| 12950 |
expect.step("web_save"); |
| 12951 |
}); |
| 12952 |
// The records data are invalid since foo is required |
| 12953 |
Partner._records[0].name = "Bob"; |
| 12954 |
Partner._records[0].foo = ""; |
| 12955 |
await mountView({ |
| 12956 |
resModel: "partner", |
| 12957 |
type: "form", |
| 12958 |
arch: ` |
| 12959 |
<form> |
| 12960 |
<field name="foo" required="1"></field> |
| 12961 |
<button type="action" name="lovely action" string="Use Foo"/> |
| 12962 |
</form>`, |
| 12963 |
resId: 1, |
| 12964 |
}); |
| 12965 |
expect.verifySteps([]); |
| 12966 |
// Try to perform the action with invalid datas |
| 12967 |
await contains(".btn[name='lovely action']").click(); |
| 12968 |
// the action should not be called thanks to the `_checkValidity` |
| 12969 |
expect.verifySteps([ |
| 12970 |
"Check/prepare record datas", |
| 12971 |
"Pop Up: Invalid Field: Missing required fields", |
| 12972 |
]); |
| 12973 |
// Edit the required field |
| 12974 |
await contains(`.o_input`).edit("Foo Value"); |
| 12975 |
// Try to perform the action once more |
| 12976 |
await contains(".btn[name='lovely action']").click(); |
| 12977 |
// the record should have been saved and the action performed. |
| 12978 |
expect.verifySteps(["Check/prepare record datas", "web_save", "Perform Action"]); |
| 12979 |
}); |
| 12980 |
|
| 12981 |
test(`open x2many with non inline form view, delayed get_views, form destroyed`, async () => { |
| 12982 |
Partner._records[0].product_ids = [37]; |
| 12983 |
Product._views = { |
| 12984 |
form: `<form><field name="name"/></form>`, |
| 12985 |
}; |
| 12986 |
|
| 12987 |
let def; |
| 12988 |
onRpc("get_views", async () => { |
| 12989 |
expect.step("get_views"); |
| 12990 |
await def; |
| 12991 |
}); |
| 12992 |
|
| 12993 |
const form = await mountView({ |
| 12994 |
resModel: "partner", |
| 12995 |
type: "form", |
| 12996 |
arch: ` |
| 12997 |
<form> |
| 12998 |
<field name="product_ids"> |
| 12999 |
<list> |
| 13000 |
<field name="name"/> |
| 13001 |
</list> |
| 13002 |
</field> |
| 13003 |
</form>`, |
| 13004 |
resId: 1, |
| 13005 |
}); |
| 13006 |
|
| 13007 |
// click on an x2many record to open it in dialog (get_views delayed) |
| 13008 |
def = new Deferred(); |
| 13009 |
await contains(".o_data_row .o_data_cell").click(); |
| 13010 |
expect(".o_dialog").toHaveCount(0); |
| 13011 |
|
| 13012 |
// destroy the form view while get_views is pending |
| 13013 |
form.__owl__.destroy(); |
| 13014 |
def.resolve(); |
| 13015 |
await animationFrame(); |
| 13016 |
|
| 13017 |
// everything should have gone smoothly, nothing should have happened as the view is destroyed |
| 13018 |
expect.verifySteps(["get_views", "get_views"]); |
| 13019 |
}); |
| 13020 |
|
| 13021 |
test.tags("desktop"); |
| 13022 |
test("executing new action, closes dialog, and avoid reload previous view", async () => { |
| 13023 |
onRpc(({ method }) => expect.step(method)); |
| 13024 |
defineActions([ |
| 13025 |
{ |
| 13026 |
id: 1, |
| 13027 |
xml_id: "someaction", |
| 13028 |
res_id: 1, |
| 13029 |
res_model: "partner", |
| 13030 |
type: "ir.actions.act_window", |
| 13031 |
target: "new", |
| 13032 |
views: [[false, "form"]], |
| 13033 |
}, |
| 13034 |
]); |
| 13035 |
Partner._views = { |
| 13036 |
form: ` |
| 13037 |
<form> |
| 13038 |
<sheet> |
| 13039 |
<div name="button_box" class="oe_button_box test"> |
| 13040 |
<button class="oe_stat_button" type="action" name="someaction"> |
| 13041 |
Test |
| 13042 |
</button> |
| 13043 |
</div> |
| 13044 |
</sheet> |
| 13045 |
</form>`, |
| 13046 |
kanban: ` |
| 13047 |
<kanban> |
| 13048 |
<templates> |
| 13049 |
<t t-name="card"> |
| 13050 |
<field name="foo" /> |
| 13051 |
</t> |
| 13052 |
</templates> |
| 13053 |
</kanban>`, |
| 13054 |
}; |
| 13055 |
|
| 13056 |
await mountWithCleanup(WebClient); |
| 13057 |
await getService("action").doAction({ |
| 13058 |
res_id: 1, |
| 13059 |
type: "ir.actions.act_window", |
| 13060 |
target: "current", |
| 13061 |
res_model: "partner", |
| 13062 |
view_mode: "form", |
| 13063 |
views: [[false, "form"]], |
| 13064 |
}); |
| 13065 |
|
| 13066 |
expect(`.o_form_view`).toHaveCount(1); |
| 13067 |
expect.verifySteps(["get_views", "web_read"]); |
| 13068 |
|
| 13069 |
await contains(`.oe_stat_button`).click(); |
| 13070 |
await animationFrame(); |
| 13071 |
expect(".o_dialog .o_form_view").toHaveCount(1); |
| 13072 |
|
| 13073 |
await getService("action").doAction({ |
| 13074 |
type: "ir.actions.act_window", |
| 13075 |
res_model: "partner", |
| 13076 |
view_mode: "kanban", |
| 13077 |
views: [[false, "kanban"]], |
| 13078 |
}); |
| 13079 |
expect(`.o_kanban_view`).toHaveCount(1); |
| 13080 |
expect.verifySteps([ |
| 13081 |
"get_views", |
| 13082 |
//"web_read", We shouldn't be doing a web_read for the view that we are leaving. |
| 13083 |
"get_views", |
| 13084 |
"web_search_read", |
| 13085 |
"has_group", |
| 13086 |
]); |
| 13087 |
}); |
| 13088 |
|
| 13089 |
test.tags("mobile"); |
| 13090 |
test(`pager is up to date`, async () => { |
| 13091 |
patchWithCleanup(transitionConfig, { disabled: true }); |
| 13092 |
await mountView({ |
| 13093 |
resModel: "partner", |
| 13094 |
type: "form", |
| 13095 |
arch: `<form><field name="foo"/></form>`, |
| 13096 |
resIds: [1, 2], |
| 13097 |
resId: 1, |
| 13098 |
}); |
| 13099 |
await contains(`.o_pager_next`).click(); |
| 13100 |
await animationFrame(); |
| 13101 |
expect(".o_pager_indicator").toHaveCount(1, { |
| 13102 |
message: "the pager indicator should be displayed", |
| 13103 |
}); |
| 13104 |
expect(".o_pager_indicator").toHaveText("2 / 2"); |
| 13105 |
}); |
| 13106 |
|
| 13107 |
test(`cached web_read`, async () => { |
| 13108 |
let def = null; |
| 13109 |
onRpc("web_read", async () => { |
| 13110 |
expect.step("web_read"); |
| 13111 |
return def; |
| 13112 |
}); |
| 13113 |
|
| 13114 |
Partner._views = { |
| 13115 |
form: `<form><field name="foo"/></form>`, |
| 13116 |
}; |
| 13117 |
|
| 13118 |
defineActions([ |
| 13119 |
{ |
| 13120 |
id: 1, |
| 13121 |
name: "Partner", |
| 13122 |
res_model: "partner", |
| 13123 |
res_id: 1, |
| 13124 |
views: [[false, "form"]], |
| 13125 |
cache: true, // true is the default ! |
| 13126 |
}, |
| 13127 |
{ |
| 13128 |
id: 2, |
| 13129 |
name: "Partner", |
| 13130 |
res_model: "partner", |
| 13131 |
res_id: 2, |
| 13132 |
views: [[false, "form"]], |
| 13133 |
}, |
| 13134 |
]); |
| 13135 |
|
| 13136 |
await mountWithCleanup(WebClient); |
| 13137 |
// Open and Cache the first action |
| 13138 |
await getService("action").doAction(1); |
| 13139 |
expect(`.o_field_char input`).toHaveValue("yop"); |
| 13140 |
expect(`.o_last_breadcrumb_item`).toHaveText("first record"); |
| 13141 |
|
| 13142 |
// Change the record to the second record |
| 13143 |
await getService("action").doAction(2); |
| 13144 |
expect(`.o_field_char input`).toHaveValue("blip"); |
| 13145 |
expect(`.o_last_breadcrumb_item`).toHaveText("second record"); |
| 13146 |
|
| 13147 |
def = new Deferred(); |
| 13148 |
|
| 13149 |
// Come back to the first action |
| 13150 |
getService("action").doAction(1); |
| 13151 |
await animationFrame(); |
| 13152 |
// The record is shown even if the rpc is not finish (cached values) |
| 13153 |
expect(`.o_field_char input`).toHaveValue("yop"); |
| 13154 |
expect(`.o_last_breadcrumb_item`).toHaveText("first record"); |
| 13155 |
|
| 13156 |
def.resolve([{ id: 1, foo: "new yop", display_name: "new first record" }]); |
| 13157 |
await animationFrame(); |
| 13158 |
// The record is updated with the new values |
| 13159 |
expect(`.o_field_char input`).toHaveValue("new yop"); |
| 13160 |
expect(`.o_last_breadcrumb_item`).toHaveText("new first record"); |
| 13161 |
expect.verifySteps(["web_read", "web_read", "web_read"]); |
| 13162 |
}); |
| 13163 |
|
| 13164 |
test(`cached web_read: don't cache if action have cache:false`, async () => { |
| 13165 |
let def = null; |
| 13166 |
onRpc("web_read", async () => { |
| 13167 |
expect.step("web_read"); |
| 13168 |
return def; |
| 13169 |
}); |
| 13170 |
|
| 13171 |
Partner._views = { |
| 13172 |
form: `<form><field name="foo"/></form>`, |
| 13173 |
}; |
| 13174 |
|
| 13175 |
defineActions([ |
| 13176 |
{ |
| 13177 |
id: 1, |
| 13178 |
name: "Partner", |
| 13179 |
res_model: "partner", |
| 13180 |
res_id: 1, |
| 13181 |
views: [[false, "form"]], |
| 13182 |
cache: false, // true is the default ! |
| 13183 |
}, |
| 13184 |
{ |
| 13185 |
id: 2, |
| 13186 |
name: "Partner", |
| 13187 |
res_model: "partner", |
| 13188 |
res_id: 2, |
| 13189 |
views: [[false, "form"]], |
| 13190 |
cache: false, // true is the default ! |
| 13191 |
}, |
| 13192 |
]); |
| 13193 |
|
| 13194 |
await mountWithCleanup(WebClient); |
| 13195 |
// Open the first action |
| 13196 |
await getService("action").doAction(1); |
| 13197 |
expect(`.o_field_char input`).toHaveValue("yop"); |
| 13198 |
expect(`.o_last_breadcrumb_item`).toHaveText("first record"); |
| 13199 |
|
| 13200 |
// Change the record (the second record) |
| 13201 |
await getService("action").doAction(2); |
| 13202 |
expect(`.o_field_char input`).toHaveValue("blip"); |
| 13203 |
expect(`.o_last_breadcrumb_item`).toHaveText("second record"); |
| 13204 |
|
| 13205 |
def = new Deferred(); |
| 13206 |
|
| 13207 |
// Come back to the first action |
| 13208 |
getService("action").doAction(1); |
| 13209 |
await animationFrame(); |
| 13210 |
// The second record is still shown, waiting to the RPC to be finish |
| 13211 |
expect(`.o_field_char input`).toHaveValue("blip"); |
| 13212 |
expect(`.o_last_breadcrumb_item`).toHaveText("second record"); |
| 13213 |
|
| 13214 |
def.resolve([{ id: 1, foo: "new yop", display_name: "new first record" }]); |
| 13215 |
await animationFrame(); |
| 13216 |
// Show the new values when the rpc is finish |
| 13217 |
expect(`.o_field_char input`).toHaveValue("new yop"); |
| 13218 |
expect(`.o_last_breadcrumb_item`).toHaveText("new first record"); |
| 13219 |
expect.verifySteps(["web_read", "web_read", "web_read"]); |
| 13220 |
}); |
| 13221 |
|
| 13222 |
test(`cached web_read - don't loose changes`, async () => { |
| 13223 |
let def = null; |
| 13224 |
onRpc("web_read", async () => { |
| 13225 |
expect.step("web_read"); |
| 13226 |
return def; |
| 13227 |
}); |
| 13228 |
|
| 13229 |
Partner._views = { |
| 13230 |
form: `<form><field name="foo"/></form>`, |
| 13231 |
}; |
| 13232 |
|
| 13233 |
defineActions([ |
| 13234 |
{ |
| 13235 |
id: 1, |
| 13236 |
name: "Partner", |
| 13237 |
res_model: "partner", |
| 13238 |
res_id: 1, |
| 13239 |
views: [[false, "form"]], |
| 13240 |
cache: true, // true is the default ! |
| 13241 |
}, |
| 13242 |
{ |
| 13243 |
id: 2, |
| 13244 |
name: "Partner", |
| 13245 |
res_model: "partner", |
| 13246 |
res_id: 2, |
| 13247 |
views: [[false, "form"]], |
| 13248 |
}, |
| 13249 |
]); |
| 13250 |
|
| 13251 |
await mountWithCleanup(WebClient); |
| 13252 |
// Open and Cache the first action |
| 13253 |
await getService("action").doAction(1); |
| 13254 |
expect(`.o_field_char input`).toHaveValue("yop"); |
| 13255 |
expect(`.o_last_breadcrumb_item`).toHaveText("first record"); |
| 13256 |
|
| 13257 |
// Open and Cache the second action |
| 13258 |
await getService("action").doAction(2); |
| 13259 |
expect(`.o_field_char input`).toHaveValue("blip"); |
| 13260 |
expect(`.o_last_breadcrumb_item`).toHaveText("second record"); |
| 13261 |
|
| 13262 |
def = new Deferred(); |
| 13263 |
|
| 13264 |
// Come back to the first action |
| 13265 |
getService("action").doAction(1); |
| 13266 |
await animationFrame(); |
| 13267 |
// The record is shown even if the rpc is not finish (cached values) |
| 13268 |
expect(`.o_field_char input`).toHaveValue("yop"); |
| 13269 |
expect(`.o_last_breadcrumb_item`).toHaveText("first record"); |
| 13270 |
|
| 13271 |
// Edit the field while the rpc is pending |
| 13272 |
await contains(`.o_field_widget[name=foo] input`).edit("This is yop"); |
| 13273 |
|
| 13274 |
// The rpc returns differnt values. |
| 13275 |
def.resolve([{ id: 1, foo: "new yop", display_name: "new first record" }]); |
| 13276 |
await animationFrame(); |
| 13277 |
|
| 13278 |
// The record is updated with the new values and the edition is kept |
| 13279 |
expect(`.o_field_char input`).toHaveValue("This is yop"); |
| 13280 |
expect(`.o_last_breadcrumb_item`).toHaveText("new first record"); |
| 13281 |
expect.verifySteps(["web_read", "web_read", "web_read"]); |
| 13282 |
}); |
| 13283 |
|
| 13284 |
test(`cached onchange - don't loose changes`, async () => { |
| 13285 |
let def = null; |
| 13286 |
onRpc("onchange", async () => { |
| 13287 |
expect.step("onchange"); |
| 13288 |
return def; |
| 13289 |
}); |
| 13290 |
|
| 13291 |
Partner._views = { |
| 13292 |
form: `<form><field name="foo"/></form>`, |
| 13293 |
}; |
| 13294 |
|
| 13295 |
defineActions([ |
| 13296 |
{ |
| 13297 |
id: 1, |
| 13298 |
name: "Partner", |
| 13299 |
res_model: "partner", |
| 13300 |
views: [[false, "form"]], |
| 13301 |
cache: true, // true is the default ! |
| 13302 |
}, |
| 13303 |
{ |
| 13304 |
id: 2, |
| 13305 |
name: "Partner", |
| 13306 |
res_model: "partner", |
| 13307 |
res_id: 2, |
| 13308 |
views: [[false, "form"]], |
| 13309 |
}, |
| 13310 |
]); |
| 13311 |
|
| 13312 |
await mountWithCleanup(WebClient); |
| 13313 |
// Open and Cache the first action |
| 13314 |
await getService("action").doAction(1); |
| 13315 |
expect(`.o_field_char input`).toHaveValue("My little Foo Value"); |
| 13316 |
expect(`.o_last_breadcrumb_item`).toHaveText("New"); |
| 13317 |
|
| 13318 |
// Open and Cache the second action |
| 13319 |
await getService("action").doAction(2); |
| 13320 |
expect(`.o_field_char input`).toHaveValue("blip"); |
| 13321 |
expect(`.o_last_breadcrumb_item`).toHaveText("second record"); |
| 13322 |
|
| 13323 |
def = new Deferred(); |
| 13324 |
|
| 13325 |
// Come back to the first action |
| 13326 |
getService("action").doAction(1); |
| 13327 |
await animationFrame(); |
| 13328 |
// The record is shown even if the rpc is not finish (cached values) |
| 13329 |
expect(`.o_field_char input`).toHaveValue("My little Foo Value"); |
| 13330 |
expect(`.o_last_breadcrumb_item`).toHaveText("New"); |
| 13331 |
|
| 13332 |
// Edit the field while the rpc is pending |
| 13333 |
await contains(`.o_field_widget[name=foo] input`).edit("This is yop"); |
| 13334 |
|
| 13335 |
// The rpc returns differnt values. |
| 13336 |
def.resolve({ |
| 13337 |
value: { |
| 13338 |
foo: "My New little Foo Value", |
| 13339 |
display_name: "", |
| 13340 |
}, |
| 13341 |
}); |
| 13342 |
await animationFrame(); |
| 13343 |
|
| 13344 |
// The record is updated with the new values and the edition is kept |
| 13345 |
expect(`.o_field_char input`).toHaveValue("This is yop"); |
| 13346 |
expect(`.o_last_breadcrumb_item`).toHaveText("New"); |
| 13347 |
expect.verifySteps(["onchange", "onchange"]); |
| 13348 |
}); |