| 1 |
import { PropertiesField } from "@web/views/fields/properties/properties_field"; |
| 2 |
import { Many2XAutocomplete } from "@web/views/fields/relational_utils"; |
| 3 |
import { SelectCreateDialog } from "@web/views/view_dialogs/select_create_dialog"; |
| 4 |
import { WebClient } from "@web/webclient/webclient"; |
| 5 |
|
| 6 |
import { expect, getFixture, test } from "@odoo/hoot"; |
| 7 |
import { |
| 8 |
click, |
| 9 |
edit, |
| 10 |
press, |
| 11 |
queryAll, |
| 12 |
queryAllTexts, |
| 13 |
queryAllValues, |
| 14 |
queryAttribute, |
| 15 |
queryFirst, |
| 16 |
waitFor, |
| 17 |
} from "@odoo/hoot-dom"; |
| 18 |
import { animationFrame, mockDate, runAllTimers } from "@odoo/hoot-mock"; |
| 19 |
import { editTime, getPickerCell } from "@web/../tests/core/datetime/datetime_test_helpers"; |
| 20 |
import { |
| 21 |
clickCancel, |
| 22 |
clickSave, |
| 23 |
contains, |
| 24 |
defineModels, |
| 25 |
fields, |
| 26 |
getService, |
| 27 |
models, |
| 28 |
mountView, |
| 29 |
mountWithCleanup, |
| 30 |
onRpc, |
| 31 |
patchWithCleanup, |
| 32 |
serverState, |
| 33 |
toggleActionMenu, |
| 34 |
toggleMenuItem, |
| 35 |
} from "@web/../tests/web_test_helpers"; |
| 36 |
|
| 37 |
async function closePopover() { |
| 38 |
// Close the popover by clicking outside |
| 39 |
await click(getFixture()); |
| 40 |
await runAllTimers(); |
| 41 |
await animationFrame(); |
| 42 |
} |
| 43 |
|
| 44 |
async function changeType(propertyType) { |
| 45 |
const TYPES = [ |
| 46 |
"char", |
| 47 |
"text", |
| 48 |
"html", |
| 49 |
"boolean", |
| 50 |
"integer", |
| 51 |
"float", |
| 52 |
"monetary", |
| 53 |
"date", |
| 54 |
"datetime", |
| 55 |
"selection", |
| 56 |
"tags", |
| 57 |
"many2one", |
| 58 |
"many2many", |
| 59 |
"separator" |
| 60 |
]; |
| 61 |
const propertyTypeIndex = TYPES.indexOf(propertyType); |
| 62 |
await click(".o_field_property_definition_type input"); |
| 63 |
await animationFrame(); |
| 64 |
await click(`.o-dropdown--menu .dropdown-item:eq(${propertyTypeIndex})`); |
| 65 |
await animationFrame(); |
| 66 |
} |
| 67 |
|
| 68 |
// ----------------------------------------- |
| 69 |
// Separators tests utils |
| 70 |
// ----------------------------------------- |
| 71 |
|
| 72 |
/** |
| 73 |
* @param {boolean[]} propertySpecs |
| 74 |
*/ |
| 75 |
async function makePropertiesGroupView(propertySpecs) { |
| 76 |
// mock random function to have predictable auto generated properties names |
| 77 |
let counter = 1; |
| 78 |
patchWithCleanup(PropertiesField.prototype, { |
| 79 |
generatePropertyName: (propertyType) => { |
| 80 |
counter++; |
| 81 |
const name = `property_gen_${counter}`; |
| 82 |
return propertyType === "html" ? `${name}_html` : name; |
| 83 |
}, |
| 84 |
}); |
| 85 |
|
| 86 |
onRpc("has_access", () => true); |
| 87 |
|
| 88 |
const { properties } = Partner._records[1]; |
| 89 |
const definitions = propertySpecs.map((isSeparator, i) => { |
| 90 |
const property = { |
| 91 |
name: `property_${i + 1}`, |
| 92 |
string: isSeparator ? `Separator ${i + 1}` : `Property ${i + 1}`, |
| 93 |
type: isSeparator ? "separator" : "char", |
| 94 |
}; |
| 95 |
properties[property.name] = false; |
| 96 |
return property; |
| 97 |
}); |
| 98 |
|
| 99 |
ResCompany._records[0].definitions = definitions; |
| 100 |
|
| 101 |
await mountView({ |
| 102 |
type: "form", |
| 103 |
resModel: "partner", |
| 104 |
resId: 2, |
| 105 |
arch: /* xml */ ` |
| 106 |
<form> |
| 107 |
<sheet> |
| 108 |
<group> |
| 109 |
<field name="company_id"/> |
| 110 |
<field name="properties" columns="2"/> |
| 111 |
</group> |
| 112 |
</sheet> |
| 113 |
</form>`, |
| 114 |
actionMenus: {}, |
| 115 |
}); |
| 116 |
} |
| 117 |
|
| 118 |
async function toggleSeparator(separatorName, isSeparator) { |
| 119 |
await click(`[property-name="${separatorName}"] > * > .o_field_property_open_popover`); |
| 120 |
await animationFrame(); |
| 121 |
await changeType(isSeparator ? "separator" : "char"); |
| 122 |
if (isSeparator) { |
| 123 |
// set unfold by default when switching to a separator |
| 124 |
await click(`.o_field_property_definition_fold .o_form_label:eq(0)`); |
| 125 |
} |
| 126 |
await closePopover(); |
| 127 |
} |
| 128 |
|
| 129 |
function getGroups() { |
| 130 |
const groups = queryAll(".o_field_properties .row:first-child .o_property_group"); |
| 131 |
return groups.map((group) => [ |
| 132 |
[ |
| 133 |
queryFirst(".o_field_property_group_label", { root: group })?.innerText || "", |
| 134 |
group.getAttribute("property-name"), |
| 135 |
], |
| 136 |
...queryAll("[property-name]:not(.o_property_folded)", { root: group }).map((property) => [ |
| 137 |
property.innerText, |
| 138 |
property.getAttribute("property-name"), |
| 139 |
]), |
| 140 |
]); |
| 141 |
} |
| 142 |
|
| 143 |
function getPropertyHandleElement(propertyName) { |
| 144 |
return queryFirst(`*[property-name='${propertyName}'] .oi-draggable`); |
| 145 |
} |
| 146 |
|
| 147 |
class Partner extends models.Model { |
| 148 |
display_name = fields.Char(); |
| 149 |
properties = fields.Properties({ |
| 150 |
string: "Properties", |
| 151 |
searchable: false, |
| 152 |
definition_record: "company_id", |
| 153 |
definition_record_field: "definitions", |
| 154 |
}); |
| 155 |
company_id = fields.Many2one({ |
| 156 |
string: "Company", |
| 157 |
relation: "res.company", |
| 158 |
}); |
| 159 |
_records = [ |
| 160 |
{ |
| 161 |
id: 1, |
| 162 |
display_name: "first partner", |
| 163 |
properties: { |
| 164 |
property_1: "char value", |
| 165 |
property_2: "b", |
| 166 |
}, |
| 167 |
company_id: 37, |
| 168 |
}, |
| 169 |
{ |
| 170 |
id: 2, |
| 171 |
display_name: "second partner", |
| 172 |
properties: { |
| 173 |
property_1: "char value", |
| 174 |
property_2: "c", |
| 175 |
property_3: "char value 3", |
| 176 |
property_4: "char value 4", |
| 177 |
}, |
| 178 |
company_id: 37, |
| 179 |
}, |
| 180 |
{ |
| 181 |
id: 3, |
| 182 |
display_name: "third partner", |
| 183 |
properties: { |
| 184 |
property_1: false, |
| 185 |
property_3: false, |
| 186 |
property_4: false, |
| 187 |
}, |
| 188 |
company_id: 37, |
| 189 |
}, |
| 190 |
{ |
| 191 |
id: 4, |
| 192 |
display_name: "fourth partner", |
| 193 |
properties: {}, |
| 194 |
company_id: 37, |
| 195 |
}, |
| 196 |
]; |
| 197 |
} |
| 198 |
|
| 199 |
class ResCompany extends models.Model { |
| 200 |
_name = "res.company"; |
| 201 |
name = fields.Char({ string: "Name" }); |
| 202 |
definitions = fields.PropertiesDefinition(); |
| 203 |
_records = [ |
| 204 |
{ |
| 205 |
id: 37, |
| 206 |
name: "Company 1", |
| 207 |
definitions: [ |
| 208 |
{ |
| 209 |
name: "property_1", |
| 210 |
string: "My Char", |
| 211 |
type: "char", |
| 212 |
suffix: "suffix", |
| 213 |
view_in_cards: true, |
| 214 |
}, |
| 215 |
{ |
| 216 |
name: "property_2", |
| 217 |
string: "My Selection", |
| 218 |
type: "selection", |
| 219 |
selection: [ |
| 220 |
["a", "A"], |
| 221 |
["b", "B"], |
| 222 |
["c", "C"], |
| 223 |
], |
| 224 |
default: "c", |
| 225 |
view_in_cards: true, |
| 226 |
}, |
| 227 |
{ |
| 228 |
name: "property_3", |
| 229 |
string: "My Char 3", |
| 230 |
type: "char", |
| 231 |
}, |
| 232 |
{ |
| 233 |
name: "property_4", |
| 234 |
string: "My Char 4", |
| 235 |
type: "char", |
| 236 |
view_in_cards: true, |
| 237 |
}, |
| 238 |
], |
| 239 |
}, |
| 240 |
]; |
| 241 |
} |
| 242 |
|
| 243 |
class User extends models.Model { |
| 244 |
_name = "res.users"; |
| 245 |
|
| 246 |
name = fields.Char({ string: "Name" }); |
| 247 |
|
| 248 |
_records = [ |
| 249 |
{ |
| 250 |
id: 1, |
| 251 |
name: "Alice", |
| 252 |
}, |
| 253 |
{ |
| 254 |
id: 2, |
| 255 |
name: "Bob", |
| 256 |
}, |
| 257 |
{ |
| 258 |
id: 3, |
| 259 |
name: "Eve", |
| 260 |
}, |
| 261 |
]; |
| 262 |
|
| 263 |
has_group() { |
| 264 |
return true; |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
class ResCurrency extends models.Model { |
| 269 |
name = fields.Char(); |
| 270 |
symbol = fields.Char(); |
| 271 |
|
| 272 |
_records = Object.entries(serverState.currencies).map( |
| 273 |
([id, { name, symbol }]) => ({ |
| 274 |
id: Number(id) + 1, |
| 275 |
name, |
| 276 |
symbol, |
| 277 |
}) |
| 278 |
); |
| 279 |
} |
| 280 |
|
| 281 |
defineModels([Partner, ResCompany, User, ResCurrency]); |
| 282 |
|
| 283 |
/** |
| 284 |
* If the current user can not write on the parent, he should not |
| 285 |
* be able to change the properties definition (but he should be able to |
| 286 |
* change the properties value). |
| 287 |
*/ |
| 288 |
test("properties: no access to parent", async () => { |
| 289 |
onRpc("has_access", () => false); |
| 290 |
|
| 291 |
const formView = await mountView({ |
| 292 |
type: "form", |
| 293 |
resModel: "partner", |
| 294 |
resId: 1, |
| 295 |
arch: /* xml */ ` |
| 296 |
<form> |
| 297 |
<sheet> |
| 298 |
<group> |
| 299 |
<field name="company_id"/> |
| 300 |
<field name="properties"/> |
| 301 |
</group> |
| 302 |
</sheet> |
| 303 |
</form>`, |
| 304 |
actionMenus: {}, |
| 305 |
}); |
| 306 |
|
| 307 |
patchWithCleanup(formView.env.services.notification, { |
| 308 |
add: (message, options) => { |
| 309 |
expect(message).toBe('Oops! You cannot edit the Company "Company 1".'); |
| 310 |
}, |
| 311 |
}); |
| 312 |
|
| 313 |
expect(".o_field_properties").toHaveCount(1, { message: "The field must be in the view" }); |
| 314 |
|
| 315 |
await toggleActionMenu(); |
| 316 |
expect(".o-dropdown--menu span:contains(Edit Properties)").toHaveCount(1, { |
| 317 |
message: "The 'Edit Properties' btn should be in the cog menu", |
| 318 |
}); |
| 319 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 320 |
expect(".o_field_properties:first-child .o_field_property_open_popover").toHaveCount(0, { |
| 321 |
message: "The edit definition button must not be in the view", |
| 322 |
}); |
| 323 |
expect(".o_field_properties:first-child .o_property_field_value input:first").toHaveValue( |
| 324 |
"char value" |
| 325 |
); |
| 326 |
}); |
| 327 |
|
| 328 |
/** |
| 329 |
* If the current user can write on the parent, he should |
| 330 |
* be able to change the properties definition. |
| 331 |
*/ |
| 332 |
test("properties: access to parent", async () => { |
| 333 |
onRpc("has_access", () => true); |
| 334 |
|
| 335 |
await mountView({ |
| 336 |
type: "form", |
| 337 |
resModel: "partner", |
| 338 |
resId: 1, |
| 339 |
arch: /* xml */ ` |
| 340 |
<form> |
| 341 |
<sheet> |
| 342 |
<group> |
| 343 |
<field name="company_id"/> |
| 344 |
<field name="properties"/> |
| 345 |
</group> |
| 346 |
</sheet> |
| 347 |
</form>`, |
| 348 |
actionMenus: {}, |
| 349 |
}); |
| 350 |
|
| 351 |
expect(".o_field_properties").toHaveCount(1, { message: "The field must be in the view" }); |
| 352 |
|
| 353 |
await toggleActionMenu(); |
| 354 |
expect(".o-dropdown--menu span:contains(Edit Properties)").toHaveCount(1, { |
| 355 |
message: "Show 'Edit Properties' btn in cog menu", |
| 356 |
}); |
| 357 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 358 |
|
| 359 |
expect(".o_field_properties:first-child .o_field_property_open_popover").not.toBeEmpty({ |
| 360 |
message: "The edit definition button must be in the view", |
| 361 |
}); |
| 362 |
|
| 363 |
expect(".o_field_properties:first-child .o_property_field_value input:first").toHaveValue( |
| 364 |
"char value" |
| 365 |
); |
| 366 |
|
| 367 |
// Open the definition popover |
| 368 |
await click( |
| 369 |
".o_field_properties:first-child .o_property_field:first-child .o_field_property_open_popover" |
| 370 |
); |
| 371 |
await animationFrame(); |
| 372 |
|
| 373 |
expect(".o_property_field_popover").toHaveCount(1, { |
| 374 |
message: "Should have opened the definition popover", |
| 375 |
}); |
| 376 |
expect(".o_field_property_definition_header").toHaveValue("My Char"); |
| 377 |
|
| 378 |
expect(".o_field_property_definition_type input").toHaveValue("Text"); |
| 379 |
|
| 380 |
// Change the property type to "Date & Time" |
| 381 |
await contains(".o_field_property_definition_header").edit("My Datetime"); |
| 382 |
await changeType("datetime"); |
| 383 |
expect(".o_property_field_popover .o_field_property_definition_type input").toHaveValue( |
| 384 |
"Date & Time", |
| 385 |
{ message: "Should have changed the property type" } |
| 386 |
); |
| 387 |
|
| 388 |
// Choosing a date in the date picker should not close the definition popover |
| 389 |
await click(".o_field_property_definition_value .o_datetime_input"); |
| 390 |
await animationFrame(); |
| 391 |
await click(getPickerCell("3")); |
| 392 |
await animationFrame(); |
| 393 |
expect(".o_datetime_picker").toHaveCount(1); |
| 394 |
|
| 395 |
expect(".o_property_field_popover").toHaveCount(1, { |
| 396 |
message: "Should not close the definition popover after selecting a date", |
| 397 |
}); |
| 398 |
|
| 399 |
await closePopover(); |
| 400 |
|
| 401 |
// Check that the type change have been propagated |
| 402 |
expect(".o_field_property_label:eq(0)").toHaveText("My Datetime", { |
| 403 |
message: "Should have updated the property label", |
| 404 |
}); |
| 405 |
expect(".o_property_field_value .o_datetime_input").toHaveCount(1, { |
| 406 |
message: "Should have changed the property type", |
| 407 |
}); |
| 408 |
|
| 409 |
// Check that the value is reset (because the type changed) |
| 410 |
expect(".o_property_field_value input").toHaveValue(""); |
| 411 |
// Discard the form view and check that the properties take its old values |
| 412 |
await clickCancel(); |
| 413 |
await animationFrame(); |
| 414 |
expect(".o_property_field:first-child .o_property_field_value input:first").toHaveValue( |
| 415 |
"char value", |
| 416 |
{ message: "Discarding the form view should reset the old values" } |
| 417 |
); |
| 418 |
}); |
| 419 |
|
| 420 |
/** |
| 421 |
* Test the creation of a new property. |
| 422 |
*/ |
| 423 |
test("properties: add a new property", async () => { |
| 424 |
ResCompany._records[0].definitions.pop(); |
| 425 |
ResCompany._records[0].definitions.pop(); |
| 426 |
|
| 427 |
onRpc("has_access", () => true); |
| 428 |
|
| 429 |
await mountView({ |
| 430 |
type: "form", |
| 431 |
resModel: "partner", |
| 432 |
resId: 1, |
| 433 |
arch: /* xml */ ` |
| 434 |
<form> |
| 435 |
<sheet> |
| 436 |
<group> |
| 437 |
<field name="company_id"/> |
| 438 |
<field name="properties"/> |
| 439 |
</group> |
| 440 |
</sheet> |
| 441 |
</form>`, |
| 442 |
actionMenus: {}, |
| 443 |
}); |
| 444 |
|
| 445 |
expect(".o_field_properties").toHaveCount(1); |
| 446 |
|
| 447 |
await toggleActionMenu(); |
| 448 |
expect(".o-dropdown--menu span:contains(Edit Properties)").toHaveCount(1, { |
| 449 |
message: "The 'Edit Properties' btn should be in the cog menu", |
| 450 |
}); |
| 451 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 452 |
|
| 453 |
// Create a new property |
| 454 |
await click(".o_field_property_add button"); |
| 455 |
await waitFor(".o_property_field_popover"); |
| 456 |
|
| 457 |
expect(".o_property_field_popover").toHaveCount(1, { |
| 458 |
message: "Should have opened the definition popover", |
| 459 |
}); |
| 460 |
|
| 461 |
expect(".o_field_property_definition_header").toHaveValue("Property 3", { |
| 462 |
message: "Should have added a default label", |
| 463 |
}); |
| 464 |
|
| 465 |
expect(".o_field_property_definition_type input").toHaveValue("Text", { |
| 466 |
message: "Default type must be text", |
| 467 |
}); |
| 468 |
|
| 469 |
await closePopover(); |
| 470 |
|
| 471 |
const properties = queryAll(".o_field_property_label"); |
| 472 |
expect(properties).toHaveCount(3); |
| 473 |
|
| 474 |
const newProperty = properties[2]; |
| 475 |
expect(newProperty).toHaveText("Property 3"); |
| 476 |
}); |
| 477 |
|
| 478 |
test.tags("desktop", "focus required"); |
| 479 |
test("properties: selection", async () => { |
| 480 |
onRpc("has_access", () => true); |
| 481 |
|
| 482 |
await mountView({ |
| 483 |
type: "form", |
| 484 |
resModel: "partner", |
| 485 |
resId: 1, |
| 486 |
arch: /* xml */ ` |
| 487 |
<form> |
| 488 |
<sheet> |
| 489 |
<group> |
| 490 |
<field name="company_id"/> |
| 491 |
<field name="properties"/> |
| 492 |
</group> |
| 493 |
</sheet> |
| 494 |
</form>`, |
| 495 |
actionMenus: {}, |
| 496 |
}); |
| 497 |
|
| 498 |
expect(".o_field_properties").toHaveCount(1); |
| 499 |
expect(".o_property_field:nth-child(2) select").toHaveCount(1); |
| 500 |
expect(".o_property_field:nth-child(2) select").toHaveValue("b"); |
| 501 |
|
| 502 |
await toggleActionMenu(); |
| 503 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 504 |
// Edit the selection property |
| 505 |
await click(".o_property_field:nth-child(2) .o_field_property_open_popover"); |
| 506 |
await animationFrame(); |
| 507 |
|
| 508 |
expect(".o_property_field_popover").toHaveCount(1); |
| 509 |
|
| 510 |
expect(".o_property_field_popover .o_field_property_selection").toHaveCount(1, { |
| 511 |
message: "Must instantiate the selection component", |
| 512 |
}); |
| 513 |
|
| 514 |
// Check the default option, must be the third one" |
| 515 |
expect( |
| 516 |
".o_property_field_popover .o_field_property_selection_option:nth-child(1) .fa-star" |
| 517 |
).toHaveCount(0); |
| 518 |
expect( |
| 519 |
".o_property_field_popover .o_field_property_selection_option:nth-child(2) .fa-star" |
| 520 |
).toHaveCount(0); |
| 521 |
expect( |
| 522 |
".o_property_field_popover .o_field_property_selection_option:nth-child(3) .fa-star" |
| 523 |
).toHaveCount(1); |
| 524 |
expect(".o_property_field_popover .o_field_property_definition_type input").toHaveValue( |
| 525 |
"Selection" |
| 526 |
); |
| 527 |
|
| 528 |
const getOptions = () => |
| 529 |
queryAll(".o_property_field_popover .o_field_property_selection_option"); |
| 530 |
const getOptionsValues = () => |
| 531 |
queryAllValues(".o_property_field_popover .o_field_property_selection_option input"); |
| 532 |
|
| 533 |
// Create a new selection option |
| 534 |
await click(".o_field_property_selection .fa-plus"); |
| 535 |
await animationFrame(); |
| 536 |
expect(getOptions()).toHaveCount(4, { message: "Should have added the new option" }); |
| 537 |
expect(queryFirst("input", { root: getOptions()[3] })).toBeFocused({ |
| 538 |
message: "Should focus the new option", |
| 539 |
}); |
| 540 |
await edit("New option"); |
| 541 |
await runAllTimers(); |
| 542 |
// Press enter to add a second new option |
| 543 |
await press("Enter"); |
| 544 |
await runAllTimers(); |
| 545 |
expect(getOptions()).toHaveCount(5, { message: "Should have added the new option on Enter" }); |
| 546 |
expect(queryFirst("input", { root: getOptions()[4] })).toBeFocused({ |
| 547 |
message: "Should focus the new option", |
| 548 |
}); |
| 549 |
// Up arrow should give the focus to the previous option |
| 550 |
// because the new option is empty and lost focus, it should be removed |
| 551 |
await press("ArrowUp"); |
| 552 |
await animationFrame(); |
| 553 |
await runAllTimers(); |
| 554 |
expect(getOptions()).toHaveCount(4, { |
| 555 |
message: "Should have remove the option because it is empty and lost focus", |
| 556 |
}); |
| 557 |
expect(queryFirst("input", { root: getOptions()[3] })).toBeFocused({ |
| 558 |
message: "Should focus the previous option", |
| 559 |
}); |
| 560 |
|
| 561 |
// Up again, should focus the previous option |
| 562 |
await press("ArrowUp"); |
| 563 |
await animationFrame(); |
| 564 |
await runAllTimers(); |
| 565 |
|
| 566 |
expect(getOptions()).toHaveCount(4, { message: "Should not remove any options" }); |
| 567 |
expect(queryFirst("input", { root: getOptions()[2] })).toBeFocused(); |
| 568 |
|
| 569 |
// Remove the second option |
| 570 |
await click(".o_field_property_selection_option:nth-child(2) .fa-trash-o"); |
| 571 |
await animationFrame(); |
| 572 |
expect(getOptionsValues()).toEqual(["A", "C", "New option"], { |
| 573 |
message: "Should have removed the second option", |
| 574 |
}); |
| 575 |
await click(".o_field_property_selection_option:nth-child(2) input"); |
| 576 |
await animationFrame(); |
| 577 |
// test that pressing 'Enter' inserts a new option after the one currently focused (and not last). |
| 578 |
await press("Enter"); |
| 579 |
await animationFrame(); |
| 580 |
await click(".o_field_property_selection_option:nth-child(3) input"); |
| 581 |
await edit("New option 2"); |
| 582 |
await runAllTimers(); |
| 583 |
await animationFrame(); |
| 584 |
expect(getOptionsValues()).toEqual(["A", "C", "New option 2", "New option"], { |
| 585 |
message: "Should have added a new option at the correct spot", |
| 586 |
}); |
| 587 |
|
| 588 |
const getOptionDraggableElement = (index) => |
| 589 |
queryFirst( |
| 590 |
`.o_field_property_selection_option:nth-child(${ |
| 591 |
index + 1 |
| 592 |
}) .o_field_property_selection_drag` |
| 593 |
); |
| 594 |
|
| 595 |
await contains(getOptionDraggableElement(0)).dragAndDrop(getOptionDraggableElement(2)); |
| 596 |
expect(getOptionsValues()).toEqual(["C", "New option 2", "A", "New option"]); |
| 597 |
|
| 598 |
await contains(getOptionDraggableElement(3)).dragAndDrop(getOptionDraggableElement(0)); |
| 599 |
expect(getOptionsValues()).toEqual(["New option", "C", "New option 2", "A"]); |
| 600 |
|
| 601 |
// create an empty option and move it |
| 602 |
await click(".o_field_property_selection > div > .btn-link"); |
| 603 |
await animationFrame(); |
| 604 |
expect(getOptionsValues()).toEqual(["New option", "C", "New option 2", "A", ""]); |
| 605 |
await contains(getOptionDraggableElement(4)).dragAndDrop(getOptionDraggableElement(1)); |
| 606 |
expect(getOptionsValues()).toEqual(["New option", "", "C", "New option 2", "A"]); |
| 607 |
}); |
| 608 |
|
| 609 |
/** |
| 610 |
* Test the float and the integer property. |
| 611 |
*/ |
| 612 |
test("properties: float and integer", async () => { |
| 613 |
onRpc("has_access", () => true); |
| 614 |
|
| 615 |
await mountView({ |
| 616 |
type: "form", |
| 617 |
resModel: "partner", |
| 618 |
resId: 1, |
| 619 |
arch: /* xml */ ` |
| 620 |
<form> |
| 621 |
<sheet> |
| 622 |
<group> |
| 623 |
<field name="company_id"/> |
| 624 |
<field name="properties"/> |
| 625 |
</group> |
| 626 |
</sheet> |
| 627 |
</form>`, |
| 628 |
actionMenus: {}, |
| 629 |
}); |
| 630 |
|
| 631 |
expect(".o_field_properties").toHaveCount(1); |
| 632 |
|
| 633 |
await toggleActionMenu(); |
| 634 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 635 |
|
| 636 |
// change type to float |
| 637 |
await click(".o_property_field:nth-child(2) .o_field_property_open_popover"); |
| 638 |
await animationFrame(); |
| 639 |
await changeType("float"); |
| 640 |
await closePopover(); |
| 641 |
|
| 642 |
const editValue = async (newValue, expected, message) => { |
| 643 |
await contains(".o_property_field:nth-child(2) .o_field_property_input").edit(newValue); |
| 644 |
// click away |
| 645 |
await click(".o_form_sheet_bg"); |
| 646 |
await animationFrame(); |
| 647 |
expect(".o_property_field:nth-child(2) .o_field_property_input").toHaveValue(expected, { |
| 648 |
message, |
| 649 |
}); |
| 650 |
}; |
| 651 |
|
| 652 |
await editValue("0", "0.00"); |
| 653 |
await editValue("2", "2.00"); |
| 654 |
await editValue("2.11", "2.11"); |
| 655 |
await editValue("2.1234567", "2.12", "Decimal precision is 2"); |
| 656 |
await editValue("azerty", "0.00", "Wrong float value should be interpreted as 0.00"); |
| 657 |
await editValue("1,2,3,4,5,6.1,2,3,5", "123,456.12"); |
| 658 |
|
| 659 |
// change type to integer |
| 660 |
await click(".o_property_field:nth-child(2) .o_field_property_open_popover"); |
| 661 |
await animationFrame(); |
| 662 |
await changeType("integer"); |
| 663 |
await closePopover(); |
| 664 |
|
| 665 |
await editValue("0", "0"); |
| 666 |
await editValue("2", "2"); |
| 667 |
await editValue("2.11", "0"); |
| 668 |
await editValue("azerty", "0", "Wrong integer value should be interpreted as 0"); |
| 669 |
await editValue("1,2,3,4,5,6", "123,456"); |
| 670 |
await editValue("1,2,3,4,5,6.1,2,3", "0"); |
| 671 |
}); |
| 672 |
|
| 673 |
/** |
| 674 |
* Test the text property. |
| 675 |
*/ |
| 676 |
test("properties: text", async () => { |
| 677 |
onRpc("has_access", () => true); |
| 678 |
|
| 679 |
Partner._records = [ |
| 680 |
{ |
| 681 |
id: 1337, |
| 682 |
company_id: 42, |
| 683 |
properties: { |
| 684 |
property_1: "text value", |
| 685 |
}, |
| 686 |
}, |
| 687 |
]; |
| 688 |
|
| 689 |
ResCompany._records.push({ |
| 690 |
id: 42, |
| 691 |
name: "Company 2", |
| 692 |
definitions: [ |
| 693 |
{ |
| 694 |
name: "property_1", |
| 695 |
string: "My Text", |
| 696 |
type: "text", |
| 697 |
view_in_kanban: true, |
| 698 |
}, |
| 699 |
], |
| 700 |
}); |
| 701 |
|
| 702 |
await mountView({ |
| 703 |
type: "form", |
| 704 |
resModel: "partner", |
| 705 |
resId: 1337, |
| 706 |
arch: /* xml */ ` |
| 707 |
<form> |
| 708 |
<sheet> |
| 709 |
<group> |
| 710 |
<field name="company_id"/> |
| 711 |
<field name="properties"/> |
| 712 |
</group> |
| 713 |
</sheet> |
| 714 |
</form>`, |
| 715 |
}); |
| 716 |
|
| 717 |
expect(".o_field_properties textarea").toHaveCount(1); |
| 718 |
expect(".o_field_properties textarea").toHaveValue("text value"); |
| 719 |
}); |
| 720 |
|
| 721 |
/** |
| 722 |
* Test the properties re-arrangement |
| 723 |
*/ |
| 724 |
test.tags("desktop"); |
| 725 |
test("properties: move properties", async () => { |
| 726 |
onRpc("has_access", () => true); |
| 727 |
|
| 728 |
await mountView({ |
| 729 |
type: "form", |
| 730 |
resModel: "partner", |
| 731 |
resId: 2, |
| 732 |
arch: /* xml */ ` |
| 733 |
<form> |
| 734 |
<sheet> |
| 735 |
<group> |
| 736 |
<field name="company_id"/> |
| 737 |
<field name="properties"/> |
| 738 |
</group> |
| 739 |
</sheet> |
| 740 |
</form>`, |
| 741 |
actionMenus: {}, |
| 742 |
}); |
| 743 |
|
| 744 |
expect(".o_field_properties").toHaveCount(1, { message: "The field must be in the view" }); |
| 745 |
|
| 746 |
await toggleActionMenu(); |
| 747 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 748 |
|
| 749 |
// Edit the selection property |
| 750 |
await click(".o_property_field:nth-child(2) .o_field_property_open_popover"); |
| 751 |
await waitFor(".o_property_field_popover"); |
| 752 |
const popover = queryFirst(".o_property_field_popover"); |
| 753 |
expect(popover).toHaveCount(1, { message: "Should have opened the definition popover" }); |
| 754 |
// Move the property up |
| 755 |
await contains(queryFirst(".oi-chevron-up", { root: popover })).click(); |
| 756 |
expect(queryAllTexts(".o_field_properties .o_field_property_label")).toEqual([ |
| 757 |
"My Selection", |
| 758 |
"My Char", |
| 759 |
"My Char 3", |
| 760 |
"My Char 4", |
| 761 |
]); |
| 762 |
expect(".o_property_field:nth-child(1) .o_property_field_highlight").toHaveCount(1, { |
| 763 |
message: "Should highlight the moved property", |
| 764 |
}); |
| 765 |
|
| 766 |
// Move the property up again, should have no effect |
| 767 |
await click(popover, ".oi-chevron-up"); |
| 768 |
expect(queryAllTexts(".o_field_properties .o_field_property_label")).toEqual([ |
| 769 |
"My Selection", |
| 770 |
"My Char", |
| 771 |
"My Char 3", |
| 772 |
"My Char 4", |
| 773 |
]); |
| 774 |
// Move the property down |
| 775 |
await contains(queryFirst(".oi-chevron-down", { root: popover })).click(); |
| 776 |
|
| 777 |
expect(queryAllTexts(".o_field_properties .o_field_property_label")).toEqual([ |
| 778 |
"My Char", |
| 779 |
"My Selection", |
| 780 |
"My Char 3", |
| 781 |
"My Char 4", |
| 782 |
]); |
| 783 |
|
| 784 |
// Move the property at the bottom |
| 785 |
await contains(queryFirst(".oi-chevron-down", { root: popover })).click(); |
| 786 |
await contains(queryFirst(".oi-chevron-down", { root: popover })).click(); |
| 787 |
expect(queryAllTexts(".o_field_properties .o_field_property_label")).toEqual([ |
| 788 |
"My Char", |
| 789 |
"My Char 3", |
| 790 |
"My Char 4", |
| 791 |
"My Selection", |
| 792 |
]); |
| 793 |
|
| 794 |
await closePopover(); |
| 795 |
expect(".o_property_field:nth-child(2) .o_property_field_highlight").toHaveCount(0, { |
| 796 |
message: "Should have removed the highlight", |
| 797 |
}); |
| 798 |
}); |
| 799 |
|
| 800 |
/** |
| 801 |
* Test the properties tags |
| 802 |
*/ |
| 803 |
test("properties: tags", async () => { |
| 804 |
onRpc("has_access", () => true); |
| 805 |
|
| 806 |
await mountView({ |
| 807 |
type: "form", |
| 808 |
resModel: "partner", |
| 809 |
resId: 2, |
| 810 |
arch: /* xml */ ` |
| 811 |
<form> |
| 812 |
<sheet> |
| 813 |
<group> |
| 814 |
<field name="company_id"/> |
| 815 |
<field name="properties"/> |
| 816 |
</group> |
| 817 |
</sheet> |
| 818 |
</form>`, |
| 819 |
actionMenus: {}, |
| 820 |
}); |
| 821 |
|
| 822 |
const createNewTag = async (selector, text) => { |
| 823 |
await click(selector); |
| 824 |
await edit(text); |
| 825 |
await runAllTimers(); |
| 826 |
await click(".o_field_property_dropdown_add .dropdown-item"); |
| 827 |
await animationFrame(); |
| 828 |
}; |
| 829 |
|
| 830 |
await toggleActionMenu(); |
| 831 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 832 |
|
| 833 |
await click(".o_property_field:nth-child(2) .o_field_property_open_popover"); |
| 834 |
await animationFrame(); |
| 835 |
// Select the tags type |
| 836 |
await changeType("tags"); |
| 837 |
|
| 838 |
// Create 3 tags |
| 839 |
const tagsInputSelector = ".o_property_field_popover .o_field_property_dropdown_menu input"; |
| 840 |
await createNewTag(tagsInputSelector, "A"); |
| 841 |
await createNewTag(tagsInputSelector, "B"); |
| 842 |
await createNewTag(tagsInputSelector, "C"); |
| 843 |
expect(queryAllTexts(".o_tag")).toEqual(["A", "B", "C"]); |
| 844 |
|
| 845 |
await closePopover(); |
| 846 |
|
| 847 |
// Edit the tags valuegetVisibleTags |
| 848 |
await click(".o_property_field_value .o_input_dropdown input"); |
| 849 |
await animationFrame(); |
| 850 |
// Check that he newly created tags are available |
| 851 |
const dropdownItemsSelector = ".o_property_field_value .o_input_dropdown .dropdown-item"; |
| 852 |
expect(queryAllTexts(dropdownItemsSelector)).toEqual(["A", "B", "C"], { |
| 853 |
message: "Should be able to selected the created tags", |
| 854 |
}); |
| 855 |
|
| 856 |
// Select one tag in the list |
| 857 |
await click(".o_property_field_value .ui-menu-item:nth-child(2)"); |
| 858 |
await animationFrame(); |
| 859 |
|
| 860 |
expect(queryAllTexts(".o_property_field_value .o_tag")).toEqual(["B"], { |
| 861 |
message: "Should have selected the tag B", |
| 862 |
}); |
| 863 |
|
| 864 |
// Re-open the tag dropdown and verify that the selected tag is not in the list |
| 865 |
// (because it's already selected) |
| 866 |
await click(".o_property_field_value .o_input_dropdown input"); |
| 867 |
await animationFrame(); |
| 868 |
|
| 869 |
expect(queryAllTexts(dropdownItemsSelector)).toEqual(["A", "C"], { |
| 870 |
message: "The tag B is already selected and should not be visible in the dropdown", |
| 871 |
}); |
| 872 |
|
| 873 |
// Create a new tag from the property value component |
| 874 |
await createNewTag(".o_property_field_value .o_field_property_dropdown_menu input", "D"); |
| 875 |
expect(queryAllTexts(".o_property_field_value .o_tag")).toEqual(["B", "D"], { |
| 876 |
message: "Should have created and selected the tag D", |
| 877 |
}); |
| 878 |
|
| 879 |
// Re-open the popover and check that the new tag has been added in the definition |
| 880 |
await click(".o_property_field:nth-child(2) .o_field_property_open_popover"); |
| 881 |
await animationFrame(); |
| 882 |
const popover = queryFirst(".o_property_field_popover"); |
| 883 |
expect(queryAllTexts(".o_tag", { root: popover })).toEqual(["A", "B", "C", "D"]); |
| 884 |
|
| 885 |
// Change the tag color |
| 886 |
await click(".o_tag:nth-child(2)", { root: popover }); |
| 887 |
await animationFrame(); |
| 888 |
await click(".o_tag_popover .o_colorlist_item_color_11"); |
| 889 |
await animationFrame(); |
| 890 |
expect(queryFirst(".o_tag:nth-child(2)", { root: popover })).toHaveClass("o_tag_color_11", { |
| 891 |
message: "Should have changed the tag color", |
| 892 |
}); |
| 893 |
|
| 894 |
// Check that the new B color has been propagated in the form view |
| 895 |
await closePopover(); |
| 896 |
expect(queryFirst(".o_property_field_value .o_tag:first-child")).toHaveClass("o_tag_color_11", { |
| 897 |
message: "Should have changed the tag color", |
| 898 |
}); |
| 899 |
|
| 900 |
// Open the popover and remove B from the definition |
| 901 |
await click(".o_property_field:nth-child(2) .o_field_property_open_popover"); |
| 902 |
await animationFrame(); |
| 903 |
await click(".o_property_field_popover .o_tag:nth-child(2) .o_delete"); |
| 904 |
await closePopover(); |
| 905 |
expect(".o_property_field_value .o_tag").toHaveCount(1, { |
| 906 |
message: "Should have unselected the removed tag B", |
| 907 |
}); |
| 908 |
|
| 909 |
// Remove a tag by pressing backspace |
| 910 |
await click(".o_property_field_value .o_input_dropdown input"); |
| 911 |
await press("backspace"); |
| 912 |
await animationFrame(); |
| 913 |
expect(".o_property_field_value .o_tag").toHaveCount(0, { |
| 914 |
message: "Should have unselected the tag", |
| 915 |
}); |
| 916 |
}); |
| 917 |
|
| 918 |
/** |
| 919 |
* Test the properties many2one |
| 920 |
*/ |
| 921 |
test.tags("desktop"); |
| 922 |
test("properties: many2one", async () => { |
| 923 |
onRpc(({ method, model, args }) => { |
| 924 |
if (method === "has_access") { |
| 925 |
return true; |
| 926 |
} else if (method === "get_available_models" && model === "ir.model") { |
| 927 |
return [ |
| 928 |
{ model: "res.partner", display_name: "Partner" }, |
| 929 |
{ model: "res.users", display_name: "User" }, |
| 930 |
]; |
| 931 |
} else if (method === "name_search" && model === "res.users") { |
| 932 |
return [ |
| 933 |
[1, "Alice"], |
| 934 |
[2, "Bob"], |
| 935 |
[3, "Eve"], |
| 936 |
]; |
| 937 |
} else if (method === "name_create" && model === "res.users") { |
| 938 |
// Add a prefix to check that "name_create" |
| 939 |
// has been called with the right parameters |
| 940 |
return [1234, "Created:" + args[0]]; |
| 941 |
} else if (method === "fields_get" && model === "res.users") { |
| 942 |
return { |
| 943 |
name: { searchable: true, string: "Name", type: "char" }, |
| 944 |
login: { searchable: true, string: "Name", type: "char" }, |
| 945 |
}; |
| 946 |
} else if (method === "search_count" && model === "res.users") { |
| 947 |
return 5; |
| 948 |
} |
| 949 |
}); |
| 950 |
|
| 951 |
await mountView({ |
| 952 |
type: "form", |
| 953 |
resModel: "partner", |
| 954 |
resId: 2, |
| 955 |
arch: /* xml */ ` |
| 956 |
<form> |
| 957 |
<sheet> |
| 958 |
<group> |
| 959 |
<field name="company_id"/> |
| 960 |
<field name="properties"/> |
| 961 |
</group> |
| 962 |
</sheet> |
| 963 |
</form>`, |
| 964 |
actionMenus: {}, |
| 965 |
}); |
| 966 |
|
| 967 |
await toggleActionMenu(); |
| 968 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 969 |
|
| 970 |
await click(".o_property_field:nth-child(2) .o_field_property_open_popover"); |
| 971 |
await waitFor(".o_property_field_popover"); |
| 972 |
const popover = queryFirst(".o_property_field_popover"); |
| 973 |
// Select the many2one type |
| 974 |
await changeType("many2one"); |
| 975 |
|
| 976 |
// Choose the "User" model |
| 977 |
await click(".o_field_property_definition_model input", { root: popover }); |
| 978 |
await animationFrame(); |
| 979 |
expect(queryAllTexts(".o_field_property_definition_model .ui-menu-item")).toEqual([ |
| 980 |
"Partner", |
| 981 |
"User", |
| 982 |
]); |
| 983 |
await click(".o_field_property_definition_model .ui-menu-item:nth-child(2)", { root: popover }); |
| 984 |
await animationFrame(); |
| 985 |
expect(".o_field_property_definition_model input").toHaveValue("User", { |
| 986 |
message: "Should have selected the User model", |
| 987 |
}); |
| 988 |
|
| 989 |
// Choose a many2one value |
| 990 |
await click(".o_field_property_definition_value input", { root: popover }); |
| 991 |
await animationFrame(); |
| 992 |
await click(".o_field_property_definition_value .ui-menu-item:nth-child(3)", { root: popover }); |
| 993 |
await animationFrame(); |
| 994 |
expect(".o_field_property_definition_value input").toHaveValue("Eve", { |
| 995 |
message: "Should have selected the third user", |
| 996 |
}); |
| 997 |
|
| 998 |
await closePopover(); |
| 999 |
|
| 1000 |
// Quick create a user |
| 1001 |
await click(".o_property_field:nth-child(2) .o_property_field_value input"); |
| 1002 |
await animationFrame(); |
| 1003 |
await edit("New User"); |
| 1004 |
await runAllTimers(); |
| 1005 |
await click(".o_property_field:nth-child(2) .o_m2o_dropdown_option_create .dropdown-item"); |
| 1006 |
await animationFrame(); |
| 1007 |
expect(".o_property_field:nth-child(2) .o_property_field_value input").toHaveValue( |
| 1008 |
"Created:New User", |
| 1009 |
{ message: "Should have created a new user" } |
| 1010 |
); |
| 1011 |
}); |
| 1012 |
|
| 1013 |
/** |
| 1014 |
* Test the properties many2many |
| 1015 |
*/ |
| 1016 |
test.tags("desktop"); |
| 1017 |
test("properties: many2many", async () => { |
| 1018 |
onRpc(({ method, model, args }) => { |
| 1019 |
if (method === "has_access") { |
| 1020 |
return true; |
| 1021 |
} else if (method === "get_available_models" && model === "ir.model") { |
| 1022 |
return [ |
| 1023 |
{ model: "res.partner", display_name: "Partner" }, |
| 1024 |
{ model: "res.users", display_name: "User" }, |
| 1025 |
]; |
| 1026 |
} else if ( |
| 1027 |
method === "display_name_for" && |
| 1028 |
model === "ir.model" && |
| 1029 |
args[0][0] === "res.users" |
| 1030 |
) { |
| 1031 |
return [{ display_name: "User", model: "res.users" }]; |
| 1032 |
} else if (method === "name_create" && model === "res.users") { |
| 1033 |
// Add a prefix to check that "name_create" |
| 1034 |
// has been called with the right parameters |
| 1035 |
return [1234, "Created:" + args[0]]; |
| 1036 |
} else if (method === "search_count" && model === "res.users") { |
| 1037 |
return 5; |
| 1038 |
} |
| 1039 |
}); |
| 1040 |
|
| 1041 |
await mountView({ |
| 1042 |
type: "form", |
| 1043 |
resModel: "partner", |
| 1044 |
resId: 2, |
| 1045 |
arch: /* xml */ ` |
| 1046 |
<form> |
| 1047 |
<sheet> |
| 1048 |
<group> |
| 1049 |
<field name="company_id"/> |
| 1050 |
<field name="properties"/> |
| 1051 |
</group> |
| 1052 |
</sheet> |
| 1053 |
</form>`, |
| 1054 |
actionMenus: {}, |
| 1055 |
}); |
| 1056 |
|
| 1057 |
const getSelectedUsers = () => queryAllTexts(".o_property_field_value .o_tag_badge_text"); |
| 1058 |
|
| 1059 |
await toggleActionMenu(); |
| 1060 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 1061 |
|
| 1062 |
await click(".o_property_field:nth-child(2) .o_field_property_open_popover"); |
| 1063 |
await animationFrame(); |
| 1064 |
const popover = queryFirst(".o_property_field_popover"); |
| 1065 |
// Select the many2many type |
| 1066 |
await changeType("many2many"); |
| 1067 |
|
| 1068 |
// Choose the "User" model |
| 1069 |
await click(".o_field_property_definition_model input", { root: popover }); |
| 1070 |
await animationFrame(); |
| 1071 |
expect(queryAllTexts(".o_field_property_definition_model .ui-menu-item")).toEqual([ |
| 1072 |
"Partner", |
| 1073 |
"User", |
| 1074 |
]); |
| 1075 |
|
| 1076 |
await click(".o_field_property_definition_model .ui-menu-item:nth-child(2)", { root: popover }); |
| 1077 |
await animationFrame(); |
| 1078 |
expect(".o_field_property_definition_model input").toHaveValue("User", { |
| 1079 |
message: "Should have selected the User model", |
| 1080 |
}); |
| 1081 |
|
| 1082 |
await closePopover(); |
| 1083 |
|
| 1084 |
// Add Eve in the list |
| 1085 |
await click(".o_property_field:nth-child(2) input"); |
| 1086 |
await animationFrame(); |
| 1087 |
await click(".o_property_field:nth-child(2) .ui-menu-item:nth-child(3)"); |
| 1088 |
await animationFrame(); |
| 1089 |
expect(getSelectedUsers()).toEqual(["Eve"], { message: "Should have selected the third user" }); |
| 1090 |
|
| 1091 |
// Add Bob in the list |
| 1092 |
await click(".o_property_field:nth-child(2) input"); |
| 1093 |
await animationFrame(); |
| 1094 |
await click(".o_property_field:nth-child(2) .ui-menu-item:nth-child(2)"); |
| 1095 |
await animationFrame(); |
| 1096 |
expect(getSelectedUsers()).toEqual(["Eve", "Bob"], { |
| 1097 |
message: "Should have selected the second user", |
| 1098 |
}); |
| 1099 |
|
| 1100 |
// Quick create a user |
| 1101 |
await click(".o_property_field:nth-child(2) .o_property_field_value input"); |
| 1102 |
await animationFrame(); |
| 1103 |
await click(".o_property_field:nth-child(2) input"); |
| 1104 |
await edit("New User"); |
| 1105 |
await runAllTimers(); |
| 1106 |
await click(".o_property_field:nth-child(2) .o_m2o_dropdown_option_create"); |
| 1107 |
await animationFrame(); |
| 1108 |
expect(getSelectedUsers()).toEqual(["Eve", "Bob", "Created:New User"], { |
| 1109 |
message: "Should have created a new user", |
| 1110 |
}); |
| 1111 |
|
| 1112 |
// Remove Bob from the list |
| 1113 |
await click(".o_property_field:nth-child(2) .o_tag:nth-child(2) .o_delete"); |
| 1114 |
await animationFrame(); |
| 1115 |
expect(getSelectedUsers()).toEqual(["Eve", "Created:New User"], { |
| 1116 |
message: "Should have removed Bob from the list", |
| 1117 |
}); |
| 1118 |
}); |
| 1119 |
|
| 1120 |
/** |
| 1121 |
* When the user creates a property field of type many2many, many2one, etc. |
| 1122 |
* and changes the co-model of the field, the model loaded by the "Search more..." |
| 1123 |
* modal should correspond to the selected model and should be updated dynamically. |
| 1124 |
*/ |
| 1125 |
test.tags("desktop"); |
| 1126 |
test("properties: many2one 'Search more...' + internal link save keeps data", async () => { |
| 1127 |
onRpc(({ method, model }) => { |
| 1128 |
if (["has_access", "has_group"].includes(method)) { |
| 1129 |
return true; |
| 1130 |
} else if (method === "display_name_for" && model === "ir.model") { |
| 1131 |
return [ |
| 1132 |
{ model: "partner", display_name: "Partner" }, |
| 1133 |
{ model: "res.users", display_name: "User" }, |
| 1134 |
]; |
| 1135 |
} else if (method === "get_available_models" && model === "ir.model") { |
| 1136 |
return [ |
| 1137 |
{ model: "partner", display_name: "Partner" }, |
| 1138 |
{ model: "res.users", display_name: "User" }, |
| 1139 |
]; |
| 1140 |
} else if (method === "get_formview_id") { |
| 1141 |
return false; |
| 1142 |
} |
| 1143 |
}); |
| 1144 |
|
| 1145 |
// Patch the test data |
| 1146 |
Partner._records = [ |
| 1147 |
{ |
| 1148 |
id: 1, |
| 1149 |
company_id: 37, |
| 1150 |
display_name: "Pierre", |
| 1151 |
properties: { |
| 1152 |
many_2_one: false, |
| 1153 |
}, |
| 1154 |
}, |
| 1155 |
]; |
| 1156 |
ResCompany._records[0].definitions = [ |
| 1157 |
{ |
| 1158 |
name: "many_2_one", |
| 1159 |
type: "many2one", |
| 1160 |
string: "My Many-2-one", |
| 1161 |
comodel: "partner", |
| 1162 |
}, |
| 1163 |
]; |
| 1164 |
Partner._views[["list", false]] = /* xml */ ` |
| 1165 |
<list> |
| 1166 |
<field name="id"/> |
| 1167 |
<field name="display_name"/> |
| 1168 |
</list>`; |
| 1169 |
User._views[["form", false]] = /* xml */ ` |
| 1170 |
<form> |
| 1171 |
<sheet> |
| 1172 |
<group> |
| 1173 |
<field name="display_name"/> |
| 1174 |
</group> |
| 1175 |
</sheet> |
| 1176 |
</form>`; |
| 1177 |
User._views[["list", false]] = /* xml */ ` |
| 1178 |
<list> |
| 1179 |
<field name="id"/> |
| 1180 |
<field name="display_name"/> |
| 1181 |
</list>`; |
| 1182 |
|
| 1183 |
// Patch the Many2XAutocomplete default search limit options |
| 1184 |
patchWithCleanup(Many2XAutocomplete.defaultProps, { |
| 1185 |
searchLimit: 0, |
| 1186 |
}); |
| 1187 |
|
| 1188 |
// Patch the SelectCreateDialog component |
| 1189 |
patchWithCleanup(SelectCreateDialog.prototype, { |
| 1190 |
/** |
| 1191 |
* @override |
| 1192 |
*/ |
| 1193 |
setup() { |
| 1194 |
super.setup(); |
| 1195 |
expect.step(this.props.resModel); |
| 1196 |
}, |
| 1197 |
}); |
| 1198 |
|
| 1199 |
await mountView({ |
| 1200 |
type: "form", |
| 1201 |
resModel: "partner", |
| 1202 |
resId: 1, |
| 1203 |
arch: /* xml */ ` |
| 1204 |
<form> |
| 1205 |
<sheet> |
| 1206 |
<group> |
| 1207 |
<field name="company_id" invisible="1"/> |
| 1208 |
<field name="properties"/> |
| 1209 |
</group> |
| 1210 |
</sheet> |
| 1211 |
</form>`, |
| 1212 |
actionMenus: {}, |
| 1213 |
}); |
| 1214 |
|
| 1215 |
await toggleActionMenu(); |
| 1216 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 1217 |
|
| 1218 |
// Opening the popover |
| 1219 |
await click('[property-name="many_2_one"] .o_field_property_open_popover'); |
| 1220 |
await animationFrame(); |
| 1221 |
|
| 1222 |
const popover = queryFirst(".o_property_field_popover"); |
| 1223 |
|
| 1224 |
// Opening the "Search more..." modal |
| 1225 |
await click(".o_field_property_definition_value input", { root: popover }); |
| 1226 |
await animationFrame(); |
| 1227 |
await click(".o_m2o_dropdown_option_search_more", { root: popover }); |
| 1228 |
await animationFrame(); |
| 1229 |
|
| 1230 |
// Checking the model loaded |
| 1231 |
expect.verifySteps(["partner"]); |
| 1232 |
|
| 1233 |
// Closing the modal |
| 1234 |
await click(".modal .btn-close"); |
| 1235 |
await animationFrame(); |
| 1236 |
|
| 1237 |
// Switching the co-model of the property field |
| 1238 |
await click(".o_field_property_definition_model input", { root: popover }); |
| 1239 |
await animationFrame(); |
| 1240 |
await click(".o_field_property_definition_model .ui-menu-item:nth-child(2)", { root: popover }); |
| 1241 |
await animationFrame(); |
| 1242 |
|
| 1243 |
// Opening the "Search more..." modal |
| 1244 |
await click(".o_field_property_definition_value input", { root: popover }); |
| 1245 |
await animationFrame(); |
| 1246 |
await click(".o_m2o_dropdown_option_search_more", { root: popover }); |
| 1247 |
await animationFrame(); |
| 1248 |
// Checking the model loaded |
| 1249 |
expect.verifySteps(["res.users"]); |
| 1250 |
|
| 1251 |
// Select the first value |
| 1252 |
await click(".o_list_table tbody tr:first-child td[name='display_name']"); |
| 1253 |
await animationFrame(); |
| 1254 |
|
| 1255 |
// Click on external button |
| 1256 |
await click(".o_properties_external_button"); |
| 1257 |
await animationFrame(); |
| 1258 |
|
| 1259 |
// Click on Save & close button |
| 1260 |
await click(".modal .o_form_button_save"); |
| 1261 |
await animationFrame(); |
| 1262 |
|
| 1263 |
// Check that value does not disappear |
| 1264 |
expect(".o_field_property_definition_value input").toHaveValue("Alice"); |
| 1265 |
}); |
| 1266 |
|
| 1267 |
test("properties: date(time) property manipulations", async () => { |
| 1268 |
Partner._records.push({ |
| 1269 |
id: 5000, |
| 1270 |
display_name: "third partner", |
| 1271 |
properties: { |
| 1272 |
property_1: "2019-01-01", |
| 1273 |
property_2: "2019-01-01 10:00:00", |
| 1274 |
}, |
| 1275 |
company_id: 37, |
| 1276 |
}); |
| 1277 |
ResCompany._records[0].definitions = [ |
| 1278 |
{ |
| 1279 |
name: "property_1", |
| 1280 |
string: "My Date", |
| 1281 |
type: "date", |
| 1282 |
}, |
| 1283 |
{ |
| 1284 |
name: "property_2", |
| 1285 |
string: "My DateTime", |
| 1286 |
type: "datetime", |
| 1287 |
}, |
| 1288 |
]; |
| 1289 |
onRpc(({ method, args }) => { |
| 1290 |
expect.step(method); |
| 1291 |
if (method === "has_access") { |
| 1292 |
return true; |
| 1293 |
} |
| 1294 |
if (method === "web_save") { |
| 1295 |
expect(args[1].properties).toEqual([ |
| 1296 |
{ |
| 1297 |
name: "property_1", |
| 1298 |
string: "My Date", |
| 1299 |
type: "date", |
| 1300 |
value: "2018-12-31", |
| 1301 |
}, |
| 1302 |
{ |
| 1303 |
name: "property_2", |
| 1304 |
string: "My DateTime", |
| 1305 |
type: "datetime", |
| 1306 |
value: "2018-12-31 11:05:00", |
| 1307 |
}, |
| 1308 |
]); |
| 1309 |
} |
| 1310 |
}); |
| 1311 |
await mountView({ |
| 1312 |
type: "form", |
| 1313 |
resModel: "partner", |
| 1314 |
resId: 5000, |
| 1315 |
arch: /* xml */ `<form><field name="company_id"/><field name="properties"/></form>`, |
| 1316 |
}); |
| 1317 |
expect.verifySteps(["get_views", "web_read"]); |
| 1318 |
|
| 1319 |
// check initial properties |
| 1320 |
expect("[property-name=property_1] .o_property_field_value input").toHaveValue("01/01/2019"); |
| 1321 |
expect("[property-name=property_2] .o_property_field_value input").toHaveValue( |
| 1322 |
"01/01/2019 11:00:00" |
| 1323 |
); |
| 1324 |
|
| 1325 |
// edit date property |
| 1326 |
await click(".o_property_field[property-name=property_1] input"); |
| 1327 |
await animationFrame(); |
| 1328 |
await click(".o_datetime_picker .o_previous"); |
| 1329 |
await animationFrame(); |
| 1330 |
await click(getPickerCell("31")); |
| 1331 |
expect("[property-name=property_1] input").toHaveValue("12/31/2018"); |
| 1332 |
|
| 1333 |
// edit date time property |
| 1334 |
await click(".o_property_field[property-name=property_2] input"); |
| 1335 |
await animationFrame(); |
| 1336 |
await click(".o_datetime_picker .o_previous"); |
| 1337 |
await animationFrame(); |
| 1338 |
await click(getPickerCell("31")); |
| 1339 |
await animationFrame(); |
| 1340 |
await editTime("12:05"); |
| 1341 |
expect("[property-name=property_2] input").toHaveValue("12/31/2018 12:05:00"); |
| 1342 |
|
| 1343 |
// save |
| 1344 |
expect.verifySteps([]); |
| 1345 |
await clickSave(); |
| 1346 |
expect.verifySteps(["web_save"]); |
| 1347 |
}); |
| 1348 |
|
| 1349 |
/** |
| 1350 |
* Changing the type or the model of a property must regenerate it's name. |
| 1351 |
* (so if we change the type / model, all other property values on other records |
| 1352 |
* are set to False). |
| 1353 |
* Resetting the old model / type should reset the original name. |
| 1354 |
*/ |
| 1355 |
test.tags("desktop"); |
| 1356 |
test("properties: name reset", async () => { |
| 1357 |
onRpc(({ method, model }) => { |
| 1358 |
if (method === "has_access") { |
| 1359 |
return true; |
| 1360 |
} else if (method === "get_available_models" && model === "ir.model") { |
| 1361 |
return [ |
| 1362 |
{ model: "res.partner", display_name: "Partner" }, |
| 1363 |
{ model: "res.users", display_name: "User" }, |
| 1364 |
]; |
| 1365 |
} else if (method === "display_name_for" && model === "ir.model") { |
| 1366 |
return [ |
| 1367 |
{ display_name: "User", model: "res.users" }, |
| 1368 |
{ display_name: "Partner", model: "res.partner" }, |
| 1369 |
]; |
| 1370 |
} else if (method === "search_count") { |
| 1371 |
return 5; |
| 1372 |
} |
| 1373 |
}); |
| 1374 |
|
| 1375 |
await mountView({ |
| 1376 |
type: "form", |
| 1377 |
resModel: "partner", |
| 1378 |
resId: 1, |
| 1379 |
arch: /* xml */ ` |
| 1380 |
<form> |
| 1381 |
<sheet> |
| 1382 |
<group> |
| 1383 |
<field name="company_id"/> |
| 1384 |
<field name="properties"/> |
| 1385 |
</group> |
| 1386 |
</sheet> |
| 1387 |
</form>`, |
| 1388 |
actionMenus: {}, |
| 1389 |
}); |
| 1390 |
|
| 1391 |
expect('.o_property_field[property-name="property_2"]').toHaveCount(1); |
| 1392 |
|
| 1393 |
await toggleActionMenu(); |
| 1394 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 1395 |
|
| 1396 |
// open the definition popover |
| 1397 |
await click(".o_property_field:nth-child(2) .o_field_property_open_popover"); |
| 1398 |
await animationFrame(); |
| 1399 |
// change the type to "many2one" |
| 1400 |
await changeType("many2one"); |
| 1401 |
|
| 1402 |
// select the "User" model |
| 1403 |
await click(".o_field_property_definition_model input"); |
| 1404 |
await contains(".o_field_property_definition_model .ui-menu-item:nth-child(2)").click(); |
| 1405 |
await animationFrame(); |
| 1406 |
await closePopover(); |
| 1407 |
|
| 1408 |
// check that the name has been regenerated |
| 1409 |
expect(".o_property_field:nth-child(2)").not.toHaveAttribute("property-name", "property_2", { |
| 1410 |
message: "Name must have been regenerated", |
| 1411 |
}); |
| 1412 |
|
| 1413 |
// change back to "Selection" and verify that the original name is restored |
| 1414 |
await click(".o_property_field:nth-child(2) .o_field_property_open_popover"); |
| 1415 |
await animationFrame(); |
| 1416 |
await changeType("selection"); |
| 1417 |
await closePopover(); |
| 1418 |
await animationFrame(); |
| 1419 |
expect(".o_property_field:nth-child(2)").toHaveAttribute("property-name", "property_2", { |
| 1420 |
message: "Name must have been restored", |
| 1421 |
}); |
| 1422 |
|
| 1423 |
// re-select many2one user |
| 1424 |
await click(".o_property_field:nth-child(2) .o_field_property_open_popover"); |
| 1425 |
await animationFrame(); |
| 1426 |
await changeType("many2one"); |
| 1427 |
await click(".o_field_property_definition_model input"); |
| 1428 |
await contains(".o_field_property_definition_model .ui-menu-item:nth-child(2)").click(); |
| 1429 |
await animationFrame(); |
| 1430 |
const propertyName = queryAttribute(".o_property_field:nth-child(2)", "property-name"); |
| 1431 |
expect(propertyName.endsWith("_html")).toEqual(false); |
| 1432 |
|
| 1433 |
// save (if we do not save, the name will be the same even if |
| 1434 |
// we change the model, because it would be useless to regenerate it again) |
| 1435 |
await closePopover(); |
| 1436 |
|
| 1437 |
// restore the model "User", and check that the name has been restored |
| 1438 |
await contains(".o_property_field:nth-child(2) .o_field_property_open_popover").click(); |
| 1439 |
await contains(".o_field_property_definition_model input").click(); |
| 1440 |
await contains(".o_field_property_definition_model .ui-menu-item:nth-child(2)").click(); |
| 1441 |
await closePopover(); |
| 1442 |
expect(".o_property_field:nth-child(2)").toHaveAttribute("property-name", propertyName); |
| 1443 |
|
| 1444 |
// Change the definition and check that the name stay the same |
| 1445 |
await click(".o_property_field:nth-child(2) .o_field_property_open_popover"); |
| 1446 |
await contains(".o_field_property_definition_kanban input").click(); |
| 1447 |
await closePopover(); |
| 1448 |
expect(".o_property_field:nth-child(2)").toHaveAttribute("property-name", propertyName); |
| 1449 |
|
| 1450 |
// Change the type to "HTML" and verify that the suffix is added |
| 1451 |
await click(".o_property_field:nth-child(2) .o_field_property_open_popover"); |
| 1452 |
await animationFrame(); |
| 1453 |
await changeType("html"); |
| 1454 |
await closePopover(); |
| 1455 |
await animationFrame(); |
| 1456 |
const htmlPropertyName = queryAttribute(".o_property_field:nth-child(2)", "property-name"); |
| 1457 |
expect(htmlPropertyName.endsWith("_html")).toEqual(true); |
| 1458 |
|
| 1459 |
// Restore the selection type, the name should be restored |
| 1460 |
await click(".o_property_field:nth-child(2) .o_field_property_open_popover"); |
| 1461 |
await animationFrame(); |
| 1462 |
await changeType("selection"); |
| 1463 |
await closePopover(); |
| 1464 |
await animationFrame(); |
| 1465 |
expect(".o_property_field:nth-child(2)").toHaveAttribute("property-name", "property_2", { |
| 1466 |
message: "Name must have been restored", |
| 1467 |
}); |
| 1468 |
}); |
| 1469 |
|
| 1470 |
/** |
| 1471 |
* Check the behavior of the properties field in the kanban view. |
| 1472 |
*/ |
| 1473 |
test("properties: kanban view", async () => { |
| 1474 |
await mountView({ |
| 1475 |
type: "kanban", |
| 1476 |
resModel: "partner", |
| 1477 |
arch: /* xml */ ` |
| 1478 |
<kanban> |
| 1479 |
<templates> |
| 1480 |
<t t-name="card"> |
| 1481 |
<field name="company_id"/> <hr/> |
| 1482 |
<field name="display_name"/> <hr/> |
| 1483 |
<field name="properties" widget="properties"/> |
| 1484 |
</t> |
| 1485 |
</templates> |
| 1486 |
</kanban>`, |
| 1487 |
}); |
| 1488 |
|
| 1489 |
// check second card |
| 1490 |
expect(".o_kanban_record:nth-child(2) .o_card_property_field:nth-child(3)").toHaveText( |
| 1491 |
"char value 4" |
| 1492 |
); |
| 1493 |
expect(".o_kanban_record:nth-child(2) .o_card_property_field:nth-child(1)").toHaveText( |
| 1494 |
"char value\nsuffix" |
| 1495 |
); |
| 1496 |
expect(".o_kanban_record:nth-child(2) .o_card_property_field:nth-child(2)").toHaveText( |
| 1497 |
"C" |
| 1498 |
); |
| 1499 |
|
| 1500 |
// check first card |
| 1501 |
expect(".o_kanban_record:nth-child(1) .o_card_property_field").toHaveCount(2); |
| 1502 |
}); |
| 1503 |
|
| 1504 |
test("properties: kanban view with date and datetime property fields", async () => { |
| 1505 |
Partner._records.push({ |
| 1506 |
id: 40, |
| 1507 |
display_name: "fifth partner", |
| 1508 |
properties: { |
| 1509 |
property_1: "2019-01-01", |
| 1510 |
property_2: "2019-01-01 10:00:00", |
| 1511 |
}, |
| 1512 |
company_id: 37, |
| 1513 |
}); |
| 1514 |
ResCompany._records[0].definitions = [ |
| 1515 |
{ |
| 1516 |
name: "property_1", |
| 1517 |
string: "My Date", |
| 1518 |
type: "date", |
| 1519 |
value: "2019-01-01", |
| 1520 |
view_in_cards: true, |
| 1521 |
}, |
| 1522 |
{ |
| 1523 |
name: "property_2", |
| 1524 |
string: "My DateTime", |
| 1525 |
type: "datetime", |
| 1526 |
value: "2019-01-01 10:00:00", |
| 1527 |
view_in_cards: true, |
| 1528 |
}, |
| 1529 |
]; |
| 1530 |
|
| 1531 |
await mountView({ |
| 1532 |
type: "kanban", |
| 1533 |
resModel: "partner", |
| 1534 |
arch: /* xml */ ` |
| 1535 |
<kanban> |
| 1536 |
<templates> |
| 1537 |
<t t-name="card"> |
| 1538 |
<field name="company_id"/> <hr/> |
| 1539 |
<field name="display_name"/> <hr/> |
| 1540 |
<field name="properties" widget="properties"/> |
| 1541 |
</t> |
| 1542 |
</templates> |
| 1543 |
</kanban>`, |
| 1544 |
}); |
| 1545 |
|
| 1546 |
// check fifth card |
| 1547 |
expect(".o_kanban_record:nth-child(5) .o_card_property_field:nth-child(1) span").toHaveText( |
| 1548 |
"01/01/2019" |
| 1549 |
); |
| 1550 |
expect(".o_kanban_record:nth-child(5) .o_card_property_field:nth-child(2) span").toHaveText( |
| 1551 |
"01/01/2019 11:00:00" |
| 1552 |
); |
| 1553 |
}); |
| 1554 |
|
| 1555 |
test("properties: kanban view with multiple sources of properties definitions", async () => { |
| 1556 |
ResCompany._records.push({ |
| 1557 |
id: 38, |
| 1558 |
name: "Company 2", |
| 1559 |
definitions: [ |
| 1560 |
{ |
| 1561 |
name: "property_integer", |
| 1562 |
string: "My Integer", |
| 1563 |
type: "integer", |
| 1564 |
view_in_cards: true, |
| 1565 |
}, |
| 1566 |
], |
| 1567 |
}); |
| 1568 |
Partner._records.push({ |
| 1569 |
id: 10, |
| 1570 |
display_name: "other partner", |
| 1571 |
properties: { |
| 1572 |
property_integer: 1, |
| 1573 |
}, |
| 1574 |
company_id: 38, |
| 1575 |
}); |
| 1576 |
|
| 1577 |
await mountView({ |
| 1578 |
type: "kanban", |
| 1579 |
resModel: "partner", |
| 1580 |
arch: /* xml */ ` |
| 1581 |
<kanban> |
| 1582 |
<templates> |
| 1583 |
<t t-name="card"> |
| 1584 |
<field name="company_id"/> <hr/> |
| 1585 |
<field name="display_name"/> <hr/> |
| 1586 |
<field name="properties" widget="properties"/> |
| 1587 |
</t> |
| 1588 |
</templates> |
| 1589 |
</kanban>`, |
| 1590 |
}); |
| 1591 |
|
| 1592 |
expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(5); |
| 1593 |
expect(queryAllTexts(".o_kanban_record:not(.o_kanban_ghost)")).toEqual([ |
| 1594 |
"Company 1\nfirst partner\nchar value\nsuffix\nB", |
| 1595 |
"Company 1\nsecond partner\nchar value\nsuffix\nC\nchar value 4", |
| 1596 |
"Company 1\nthird partner", |
| 1597 |
"Company 1\nfourth partner", |
| 1598 |
"Company 2\nother partner\nMy Integer\n1", |
| 1599 |
]); |
| 1600 |
}); |
| 1601 |
|
| 1602 |
/** |
| 1603 |
* To check label for int, float, boolean, date and datetime fields. |
| 1604 |
* Also check if border class is applied to boolean field or not. |
| 1605 |
*/ |
| 1606 |
test("properties: kanban view with label and border", async () => { |
| 1607 |
Partner._records.push({ |
| 1608 |
id: 12, |
| 1609 |
display_name: "fifth partner", |
| 1610 |
properties: { |
| 1611 |
property_integer: 12, |
| 1612 |
property_float: 12.2, |
| 1613 |
property_date: "2023-06-05", |
| 1614 |
property_datetime: "2023-06-05 11:05:00", |
| 1615 |
property_checkbox: true, |
| 1616 |
}, |
| 1617 |
company_id: 37, |
| 1618 |
}); |
| 1619 |
ResCompany._records[0].definitions.push( |
| 1620 |
{ |
| 1621 |
name: "property_integer", |
| 1622 |
string: "My Integer", |
| 1623 |
type: "integer", |
| 1624 |
view_in_cards: true, |
| 1625 |
}, |
| 1626 |
{ |
| 1627 |
name: "property_float", |
| 1628 |
string: "My Float", |
| 1629 |
type: "float", |
| 1630 |
view_in_cards: true, |
| 1631 |
}, |
| 1632 |
{ |
| 1633 |
name: "property_date", |
| 1634 |
string: "My Date", |
| 1635 |
type: "date", |
| 1636 |
view_in_cards: true, |
| 1637 |
}, |
| 1638 |
{ |
| 1639 |
name: "property_datetime", |
| 1640 |
string: "My Datetime", |
| 1641 |
type: "datetime", |
| 1642 |
view_in_cards: true, |
| 1643 |
}, |
| 1644 |
{ |
| 1645 |
name: "property_checkbox", |
| 1646 |
string: "My Checkbox", |
| 1647 |
type: "boolean", |
| 1648 |
view_in_cards: true, |
| 1649 |
} |
| 1650 |
); |
| 1651 |
|
| 1652 |
await mountView({ |
| 1653 |
type: "kanban", |
| 1654 |
resModel: "partner", |
| 1655 |
arch: /* xml */ ` |
| 1656 |
<kanban> |
| 1657 |
<templates> |
| 1658 |
<t t-name="card"> |
| 1659 |
<field name="company_id"/> <hr/> |
| 1660 |
<field name="display_name"/> <hr/> |
| 1661 |
<field name="properties" widget="properties"/> |
| 1662 |
</t> |
| 1663 |
</templates> |
| 1664 |
</kanban>`, |
| 1665 |
}); |
| 1666 |
|
| 1667 |
// check for label in integer, float, date and datetime field |
| 1668 |
expect(".o_kanban_record:nth-child(5) .o_card_property_field:nth-child(1) label").toHaveText( |
| 1669 |
"My Integer" |
| 1670 |
); |
| 1671 |
expect(".o_kanban_record:nth-child(5) .o_card_property_field:nth-child(2) label").toHaveText( |
| 1672 |
"My Float" |
| 1673 |
); |
| 1674 |
expect(".o_kanban_record:nth-child(5) .o_card_property_field:nth-child(3) label").toHaveText( |
| 1675 |
"My Date" |
| 1676 |
); |
| 1677 |
expect(".o_kanban_record:nth-child(5) .o_card_property_field:nth-child(4) label").toHaveText( |
| 1678 |
"My Datetime" |
| 1679 |
); |
| 1680 |
|
| 1681 |
//check that label and border class is present for checkbox field |
| 1682 |
expect(".o_kanban_record:nth-child(5) .o_card_property_field:nth-child(5) .border").toHaveCount( |
| 1683 |
1 |
| 1684 |
); |
| 1685 |
expect( |
| 1686 |
".o_kanban_record:nth-child(5) .o_card_property_field:nth-child(5) label:eq(0)" |
| 1687 |
).toHaveText("My Checkbox"); |
| 1688 |
}); |
| 1689 |
|
| 1690 |
test("properties: kanban view without properties", async () => { |
| 1691 |
Partner._records = [ |
| 1692 |
{ |
| 1693 |
id: 40, |
| 1694 |
display_name: "first partner", |
| 1695 |
properties: false, |
| 1696 |
company_id: 37, |
| 1697 |
}, |
| 1698 |
]; |
| 1699 |
await mountView({ |
| 1700 |
type: "kanban", |
| 1701 |
resModel: "partner", |
| 1702 |
arch: /* xml */ ` |
| 1703 |
<kanban> |
| 1704 |
<templates> |
| 1705 |
<t t-name="card"> |
| 1706 |
<field name="company_id"/> <hr/> |
| 1707 |
<field name="display_name"/> <hr/> |
| 1708 |
<field name="properties" widget="properties"/> |
| 1709 |
</t> |
| 1710 |
</templates> |
| 1711 |
</kanban>`, |
| 1712 |
}); |
| 1713 |
expect(".o_kanban_record:eq(0)").toHaveText("Company 1\nfirst partner"); |
| 1714 |
}); |
| 1715 |
|
| 1716 |
/** |
| 1717 |
* Check that the properties are shown when switching view. |
| 1718 |
*/ |
| 1719 |
test.tags("desktop"); |
| 1720 |
test("properties: switch view on desktop", async () => { |
| 1721 |
Partner._views[["kanban", 99]] = /* xml */ `<kanban> |
| 1722 |
<templates> |
| 1723 |
<t t-name="card"> |
| 1724 |
<field name="company_id"/> <hr/> |
| 1725 |
<field name="display_name"/> <hr/> |
| 1726 |
<field name="properties" widget="properties"/> |
| 1727 |
</t> |
| 1728 |
</templates> |
| 1729 |
</kanban>`; |
| 1730 |
Partner._views[["list", 100]] = /* xml */ `<list limit="1"> |
| 1731 |
<field name="display_name"/> |
| 1732 |
<field name="properties"/> |
| 1733 |
</list>`; |
| 1734 |
onRpc("has_group", () => true); |
| 1735 |
await mountWithCleanup(WebClient); |
| 1736 |
await getService("action").doAction({ |
| 1737 |
res_model: "partner", |
| 1738 |
type: "ir.actions.act_window", |
| 1739 |
views: [ |
| 1740 |
[false, "kanban"], |
| 1741 |
[false, "list"], |
| 1742 |
], |
| 1743 |
}); |
| 1744 |
await animationFrame(); |
| 1745 |
await click(".o_switch_view.o_list"); |
| 1746 |
await animationFrame(); |
| 1747 |
expect(".o_optional_columns_dropdown").toHaveCount(1, { |
| 1748 |
message: "Properties should be added as optional columns.", |
| 1749 |
}); |
| 1750 |
}); |
| 1751 |
|
| 1752 |
test.tags("mobile"); |
| 1753 |
test("properties: switch view on mobile", async () => { |
| 1754 |
Partner._views[["kanban", 99]] = /* xml */ `<kanban> |
| 1755 |
<templates> |
| 1756 |
<t t-name="card"> |
| 1757 |
<field name="company_id"/> <hr/> |
| 1758 |
<field name="display_name"/> <hr/> |
| 1759 |
<field name="properties" widget="properties"/> |
| 1760 |
</t> |
| 1761 |
</templates> |
| 1762 |
</kanban>`; |
| 1763 |
Partner._views[["list", 100]] = /* xml */ `<list limit="1"> |
| 1764 |
<field name="display_name"/> |
| 1765 |
<field name="properties"/> |
| 1766 |
</list>`; |
| 1767 |
onRpc("has_group", () => true); |
| 1768 |
await mountWithCleanup(WebClient); |
| 1769 |
await getService("action").doAction({ |
| 1770 |
res_model: "partner", |
| 1771 |
type: "ir.actions.act_window", |
| 1772 |
views: [ |
| 1773 |
[false, "kanban"], |
| 1774 |
[false, "list"], |
| 1775 |
], |
| 1776 |
}); |
| 1777 |
await animationFrame(); |
| 1778 |
await click(".o_cp_switch_buttons .dropdown-toggle"); |
| 1779 |
await animationFrame(); |
| 1780 |
await click(".dropdown-item:contains(List)"); |
| 1781 |
await animationFrame(); |
| 1782 |
expect(".o_optional_columns_dropdown").toHaveCount(1, { |
| 1783 |
message: "Properties should be added as optional columns.", |
| 1784 |
}); |
| 1785 |
}); |
| 1786 |
|
| 1787 |
/** |
| 1788 |
* Test the behavior of the default value. It should be propagated on the property |
| 1789 |
* value only when we create a new property. If the property already exists, and we |
| 1790 |
* change the default value, it should never update the property value. |
| 1791 |
*/ |
| 1792 |
test("properties: default value", async () => { |
| 1793 |
onRpc("has_access", () => true); |
| 1794 |
|
| 1795 |
await mountView({ |
| 1796 |
type: "form", |
| 1797 |
resModel: "partner", |
| 1798 |
resId: 1, |
| 1799 |
arch: /* xml */ ` |
| 1800 |
<form> |
| 1801 |
<sheet> |
| 1802 |
<group> |
| 1803 |
<field name="company_id"/> |
| 1804 |
<field name="properties"/> |
| 1805 |
</group> |
| 1806 |
</sheet> |
| 1807 |
</form>`, |
| 1808 |
actionMenus: {}, |
| 1809 |
}); |
| 1810 |
|
| 1811 |
expect(".o_field_properties").toHaveCount(1); |
| 1812 |
|
| 1813 |
await toggleActionMenu(); |
| 1814 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 1815 |
|
| 1816 |
// add a new property field |
| 1817 |
await click(".o_field_property_add button"); |
| 1818 |
await waitFor(".o_property_field_popover"); |
| 1819 |
|
| 1820 |
// edit the default value and close the popover definition |
| 1821 |
// because we just created the property, the default value should be propagated |
| 1822 |
await click(".o_field_property_definition_value input"); |
| 1823 |
await edit("First Default Value", { confirm: "Enter" }); |
| 1824 |
await animationFrame(); |
| 1825 |
await closePopover(); |
| 1826 |
|
| 1827 |
expect(".o_field_properties .o_property_field:last .o_property_field_value input").toHaveValue( |
| 1828 |
"First Default Value" |
| 1829 |
); |
| 1830 |
|
| 1831 |
// empty the new / existing property value, and re-open the property we created and change the default value |
| 1832 |
// it shouldn't be propagated because it's the second time we open the definition |
| 1833 |
const checkProperty = async (property) => { |
| 1834 |
await click(".o_property_field_value input", { root: property }); |
| 1835 |
await edit(""); |
| 1836 |
await runAllTimers(); |
| 1837 |
await animationFrame(); |
| 1838 |
|
| 1839 |
await click(".o_field_property_open_popover", { root: property }); |
| 1840 |
await runAllTimers(); |
| 1841 |
await animationFrame(); |
| 1842 |
|
| 1843 |
await click(".o_field_property_definition_value input"); |
| 1844 |
await edit("Second Default Value"); |
| 1845 |
await runAllTimers(); |
| 1846 |
await animationFrame(); |
| 1847 |
|
| 1848 |
await closePopover(); |
| 1849 |
|
| 1850 |
expect(queryFirst(".o_property_field_value input", { root: property })).toHaveValue(""); |
| 1851 |
}; |
| 1852 |
await checkProperty(".o_field_properties .o_property_field:last"); |
| 1853 |
const existingProperty = queryFirst(".o_field_properties .o_property_field:nth-child(1)"); |
| 1854 |
await checkProperty(existingProperty); |
| 1855 |
}); |
| 1856 |
|
| 1857 |
test("properties: default value date", async () => { |
| 1858 |
mockDate("2022-01-03T08:00:00"); |
| 1859 |
onRpc("has_access", () => true); |
| 1860 |
await mountView({ |
| 1861 |
type: "form", |
| 1862 |
resModel: "partner", |
| 1863 |
resId: 1, |
| 1864 |
arch: ` |
| 1865 |
<form> |
| 1866 |
<sheet> |
| 1867 |
<group> |
| 1868 |
<field name="company_id"/> |
| 1869 |
<field name="properties"/> |
| 1870 |
</group> |
| 1871 |
</sheet> |
| 1872 |
</form>`, |
| 1873 |
actionMenus: {}, |
| 1874 |
}); |
| 1875 |
expect(".o_field_properties").toHaveCount(1, { message: "The field must be in the view" }); |
| 1876 |
|
| 1877 |
await toggleActionMenu(); |
| 1878 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 1879 |
|
| 1880 |
// add a new date property |
| 1881 |
await click(".o_field_property_add button"); |
| 1882 |
await waitFor(".o_property_field_popover"); |
| 1883 |
await changeType("date"); |
| 1884 |
expect(".o_property_field_popover .o_field_property_definition_type input").toHaveValue( |
| 1885 |
"Date", |
| 1886 |
{ message: "Should have changed the property type" } |
| 1887 |
); |
| 1888 |
// choose a default value and check that it is propagated on the property field |
| 1889 |
await click(".o_field_property_definition_value .o_datetime_input"); |
| 1890 |
await animationFrame(); |
| 1891 |
expect(".o_date_picker").toHaveCount(1); |
| 1892 |
await click(getPickerCell("3")); |
| 1893 |
await animationFrame(); |
| 1894 |
await closePopover(); |
| 1895 |
expect(".o_datetime_input").toHaveValue("01/03/2022", { |
| 1896 |
message: "The default date value should have been propagated", |
| 1897 |
}); |
| 1898 |
// save the form and check that the default value is not reset |
| 1899 |
await click(".o_form_button_save"); |
| 1900 |
await animationFrame(); |
| 1901 |
await click(".o_property_field:nth-last-child(2) .o_field_property_open_popover"); |
| 1902 |
await animationFrame(); |
| 1903 |
expect(".o_property_field_popover .o_field_property_definition_value input").toHaveValue( |
| 1904 |
"01/03/2022" |
| 1905 |
); |
| 1906 |
}); |
| 1907 |
|
| 1908 |
test("properties: suffix", async () => { |
| 1909 |
onRpc("has_access", () => true); |
| 1910 |
|
| 1911 |
await mountView({ |
| 1912 |
type: "form", |
| 1913 |
resModel: "partner", |
| 1914 |
resId: 1, |
| 1915 |
arch: /* xml */ ` |
| 1916 |
<form> |
| 1917 |
<sheet> |
| 1918 |
<group> |
| 1919 |
<field name="company_id"/> |
| 1920 |
<field name="properties"/> |
| 1921 |
</group> |
| 1922 |
</sheet> |
| 1923 |
</form>`, |
| 1924 |
actionMenus: {}, |
| 1925 |
}); |
| 1926 |
|
| 1927 |
expect(".o_field_properties").toHaveCount(1); |
| 1928 |
|
| 1929 |
await toggleActionMenu(); |
| 1930 |
await toggleMenuItem("Edit Properties"); |
| 1931 |
|
| 1932 |
await click(".o_field_property_add button"); |
| 1933 |
await waitFor(".o_property_field_popover"); |
| 1934 |
|
| 1935 |
await click(".o_field_property_definition_suffix input"); |
| 1936 |
await edit("kg", { confirm: "Enter" }); |
| 1937 |
await animationFrame(); |
| 1938 |
await closePopover(); |
| 1939 |
|
| 1940 |
expect(".o_field_properties .o_property_field:last .o_property_field_value_suffix").toHaveText( |
| 1941 |
"kg" |
| 1942 |
); |
| 1943 |
}); |
| 1944 |
|
| 1945 |
/** |
| 1946 |
* check if property field popover closes when clicking on delete property icon. |
| 1947 |
*/ |
| 1948 |
test("properties: close property popover once clicked on delete icon", async () => { |
| 1949 |
onRpc("has_access", () => true); |
| 1950 |
await mountView({ |
| 1951 |
type: "form", |
| 1952 |
resModel: "partner", |
| 1953 |
resId: 3, |
| 1954 |
arch: /* xml */ ` |
| 1955 |
<form> |
| 1956 |
<sheet> |
| 1957 |
<group> |
| 1958 |
<field name="company_id"/> |
| 1959 |
<field name="display_name"/> |
| 1960 |
<field name="properties" widget="properties"/> |
| 1961 |
</group> |
| 1962 |
</sheet> |
| 1963 |
</form>`, |
| 1964 |
actionMenus: {}, |
| 1965 |
}); |
| 1966 |
|
| 1967 |
await toggleActionMenu(); |
| 1968 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 1969 |
|
| 1970 |
// We open the property popover |
| 1971 |
await click(".o_property_field:first-child .o_field_property_open_popover"); |
| 1972 |
await animationFrame(); |
| 1973 |
expect(".o_field_property_definition").toHaveCount(1); |
| 1974 |
|
| 1975 |
// Trying to delete the property should have closed its definition popover |
| 1976 |
// We click on delete button |
| 1977 |
await click(".o_field_property_definition_delete"); |
| 1978 |
await animationFrame(); |
| 1979 |
expect(".o_field_property_definition").toHaveCount(0); |
| 1980 |
}); |
| 1981 |
|
| 1982 |
/** |
| 1983 |
* Check the behavior of the domain (properties with "definition_deleted" should be ignored). |
| 1984 |
* In that case, some properties start without the flag "definition_deleted". |
| 1985 |
*/ |
| 1986 |
test("properties: form view and falsy domain, properties are not empty", async () => { |
| 1987 |
ResCompany._records[0].definitions.splice(1, 1); |
| 1988 |
|
| 1989 |
onRpc("has_access", () => true); |
| 1990 |
await mountView({ |
| 1991 |
type: "form", |
| 1992 |
resModel: "partner", |
| 1993 |
resId: 3, |
| 1994 |
arch: /* xml */ ` |
| 1995 |
<form> |
| 1996 |
<sheet> |
| 1997 |
<group> |
| 1998 |
<field name="company_id"/> |
| 1999 |
<field name="display_name"/> |
| 2000 |
<field name="properties" widget="properties"/> |
| 2001 |
<div class="o_test_properties_not_empty" invisible="not properties"> |
| 2002 |
Properties not empty |
| 2003 |
</div> |
| 2004 |
</group> |
| 2005 |
</sheet> |
| 2006 |
</form>`, |
| 2007 |
actionMenus: {}, |
| 2008 |
}); |
| 2009 |
|
| 2010 |
await toggleActionMenu(); |
| 2011 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 2012 |
|
| 2013 |
expect(".o_test_properties_not_empty").toHaveCount(1); |
| 2014 |
|
| 2015 |
// delete a property, 2 properties left |
| 2016 |
await click(".o_property_field:first-child .o_field_property_open_popover"); |
| 2017 |
await animationFrame(); |
| 2018 |
await click(".o_field_property_definition_delete"); |
| 2019 |
await animationFrame(); |
| 2020 |
await click(".modal-content .btn-primary"); |
| 2021 |
await animationFrame(); |
| 2022 |
expect(".o_test_properties_not_empty").toHaveCount(1); |
| 2023 |
|
| 2024 |
// delete a property, 1 property left |
| 2025 |
await click(".o_property_field:first-child .o_field_property_open_popover"); |
| 2026 |
await animationFrame(); |
| 2027 |
await click(".o_field_property_definition_delete"); |
| 2028 |
await animationFrame(); |
| 2029 |
await click(".modal-content .btn-primary"); |
| 2030 |
await animationFrame(); |
| 2031 |
expect(".o_test_properties_not_empty").toHaveCount(1); |
| 2032 |
|
| 2033 |
// delete a property, no property left |
| 2034 |
|
| 2035 |
await click(".o_property_field:first-child .o_field_property_open_popover"); |
| 2036 |
await animationFrame(); |
| 2037 |
await click(".o_field_property_definition_delete"); |
| 2038 |
await animationFrame(); |
| 2039 |
await click(".modal-content .btn-primary"); |
| 2040 |
await animationFrame(); |
| 2041 |
expect(".o_test_properties_not_empty").toHaveCount(0); |
| 2042 |
}); |
| 2043 |
|
| 2044 |
/** |
| 2045 |
* Check the behavior of the domain (properties with "definition_deleted" should be ignored). |
| 2046 |
* In that case, all properties start with the flag "definition_deleted". |
| 2047 |
*/ |
| 2048 |
test("properties: form view and falsy domain, properties are empty", async () => { |
| 2049 |
ResCompany._records[0].definitions = []; |
| 2050 |
|
| 2051 |
onRpc("has_access", () => true); |
| 2052 |
await mountView({ |
| 2053 |
type: "form", |
| 2054 |
resModel: "partner", |
| 2055 |
resId: 4, |
| 2056 |
arch: /* xml */ ` |
| 2057 |
<form> |
| 2058 |
<sheet> |
| 2059 |
<group> |
| 2060 |
<field name="company_id"/> |
| 2061 |
<field name="display_name"/> |
| 2062 |
<field name="properties" widget="properties"/> |
| 2063 |
<div class="o_test_properties_not_empty" invisible="not properties"> |
| 2064 |
Properties not empty |
| 2065 |
</div> |
| 2066 |
</group> |
| 2067 |
</sheet> |
| 2068 |
</form>`, |
| 2069 |
actionMenus: {}, |
| 2070 |
}); |
| 2071 |
expect(".o_test_properties_not_empty").toHaveCount(0); |
| 2072 |
|
| 2073 |
// create the first property |
| 2074 |
await toggleActionMenu(); |
| 2075 |
await click(".o-dropdown--menu span .fa-cogs"); |
| 2076 |
await animationFrame(); |
| 2077 |
expect(".o_test_properties_not_empty").toHaveCount(1); |
| 2078 |
}); |
| 2079 |
|
| 2080 |
test("properties: discard changes", async () => { |
| 2081 |
onRpc("has_access", () => true); |
| 2082 |
await mountView({ |
| 2083 |
type: "form", |
| 2084 |
resModel: "partner", |
| 2085 |
resId: 1, |
| 2086 |
arch: /* xml */ ` |
| 2087 |
<form> |
| 2088 |
<field name="company_id"/> |
| 2089 |
<field name="properties" widget="properties"/> |
| 2090 |
</form>`, |
| 2091 |
}); |
| 2092 |
expect(".o_property_field:first-child input").toHaveValue("char value"); |
| 2093 |
await contains(".o_property_field:first-child input").edit("char updated"); |
| 2094 |
expect(".o_property_field:first-child input").toHaveValue("char updated"); |
| 2095 |
await clickCancel(); |
| 2096 |
expect(".o_property_field:first-child input").toHaveValue("char value"); |
| 2097 |
}); |
| 2098 |
|
| 2099 |
// --------------------------------------------------- |
| 2100 |
// Test the properties groups |
| 2101 |
// --------------------------------------------------- |
| 2102 |
|
| 2103 |
test.tags("desktop"); |
| 2104 |
test("properties: separators layout", async () => { |
| 2105 |
await makePropertiesGroupView([false, false, false, false]); |
| 2106 |
await toggleActionMenu(); |
| 2107 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 2108 |
await toggleSeparator("property_1", true); |
| 2109 |
expect(getGroups()).toEqual([ |
| 2110 |
[ |
| 2111 |
["PROPERTY 1", "property_gen_2"], |
| 2112 |
["Property 2", "property_2"], |
| 2113 |
["Property 3", "property_3"], |
| 2114 |
], |
| 2115 |
[ |
| 2116 |
// invisible separator to fill the space |
| 2117 |
["", ""], |
| 2118 |
["Property 4", "property_4"], |
| 2119 |
], |
| 2120 |
]); |
| 2121 |
|
| 2122 |
// fold the group |
| 2123 |
await click( |
| 2124 |
".o_field_properties .o_property_group[property-name='property_gen_2']:first-child .o_field_property_group_label" |
| 2125 |
); |
| 2126 |
await animationFrame(); |
| 2127 |
expect(getGroups()).toEqual([ |
| 2128 |
[["PROPERTY 1", "property_gen_2"]], |
| 2129 |
[ |
| 2130 |
["", ""], |
| 2131 |
["Property 4", "property_4"], |
| 2132 |
], |
| 2133 |
]); |
| 2134 |
await click( |
| 2135 |
".o_field_properties .o_property_group[property-name='property_gen_2']:first-child .o_field_property_group_label" |
| 2136 |
); |
| 2137 |
await animationFrame(); |
| 2138 |
await toggleSeparator("property_3", true); |
| 2139 |
expect(getGroups()).toEqual([ |
| 2140 |
[ |
| 2141 |
["PROPERTY 1", "property_gen_2"], |
| 2142 |
["Property 2", "property_2"], |
| 2143 |
], |
| 2144 |
[ |
| 2145 |
["PROPERTY 3", "property_gen_3"], |
| 2146 |
["Property 4", "property_4"], |
| 2147 |
], |
| 2148 |
]); |
| 2149 |
|
| 2150 |
// fold the left group |
| 2151 |
await click(".o_property_group[property-name='property_gen_2'] .o_field_property_group_label"); |
| 2152 |
await animationFrame(); |
| 2153 |
expect(getGroups()).toEqual([ |
| 2154 |
[["PROPERTY 1", "property_gen_2"]], |
| 2155 |
[ |
| 2156 |
["PROPERTY 3", "property_gen_3"], |
| 2157 |
["Property 4", "property_4"], |
| 2158 |
], |
| 2159 |
]); |
| 2160 |
await click(".o_property_group[property-name='property_gen_2'] .o_field_property_group_label"); |
| 2161 |
await animationFrame(); |
| 2162 |
// create 3 new properties |
| 2163 |
await click(".o_field_property_add button"); |
| 2164 |
await animationFrame(); |
| 2165 |
await click(".o_field_property_add button"); |
| 2166 |
await animationFrame(); |
| 2167 |
await click(".o_field_property_add button"); |
| 2168 |
await animationFrame(); |
| 2169 |
await closePopover(); |
| 2170 |
expect(getGroups()).toEqual([ |
| 2171 |
[ |
| 2172 |
["PROPERTY 1", "property_gen_2"], |
| 2173 |
["Property 2", "property_2"], |
| 2174 |
], |
| 2175 |
[ |
| 2176 |
["PROPERTY 3", "property_gen_3"], |
| 2177 |
["Property 4", "property_4"], |
| 2178 |
["Property 5", "property_gen_4"], |
| 2179 |
["Property 6", "property_gen_5"], |
| 2180 |
["Property 7", "property_gen_6"], |
| 2181 |
], |
| 2182 |
]); |
| 2183 |
|
| 2184 |
// Property 3 is not a separator anymore, should split in columns |
| 2185 |
await toggleSeparator("property_gen_3", false); |
| 2186 |
expect(getGroups()).toEqual([ |
| 2187 |
[ |
| 2188 |
["PROPERTY 1", "property_gen_2"], |
| 2189 |
["Property 2", "property_2"], |
| 2190 |
["Property 3", "property_3"], |
| 2191 |
["Property 4", "property_4"], |
| 2192 |
], |
| 2193 |
[ |
| 2194 |
// invisible separator to fill the space |
| 2195 |
["", ""], |
| 2196 |
["Property 5", "property_gen_4"], |
| 2197 |
["Property 6", "property_gen_5"], |
| 2198 |
["Property 7", "property_gen_6"], |
| 2199 |
], |
| 2200 |
]); |
| 2201 |
|
| 2202 |
// Property 1 is not a separator anymore, there's no separator left, |
| 2203 |
// should go back to the original layout |
| 2204 |
await toggleSeparator("property_gen_2", false); |
| 2205 |
expect(getGroups()).toEqual([ |
| 2206 |
[ |
| 2207 |
["", ""], |
| 2208 |
["Property 1", "property_1"], |
| 2209 |
["Property 2", "property_2"], |
| 2210 |
["Property 3", "property_3"], |
| 2211 |
["Property 4", "property_4"], |
| 2212 |
], |
| 2213 |
[ |
| 2214 |
["", ""], |
| 2215 |
["Property 5", "property_gen_4"], |
| 2216 |
["Property 6", "property_gen_5"], |
| 2217 |
["Property 7", "property_gen_6"], |
| 2218 |
], |
| 2219 |
]); |
| 2220 |
}); |
| 2221 |
|
| 2222 |
test("properties: open section by default", async () => { |
| 2223 |
onRpc("has_access", () => true); |
| 2224 |
ResCompany._records[0].definitions = [ |
| 2225 |
{ name: "property_1", string: "Separator 1", type: "separator", fold_by_default: false }, |
| 2226 |
{ name: "property_2", string: "Property 2", type: "char" }, |
| 2227 |
{ name: "property_3", string: "Separator 3", type: "separator" }, |
| 2228 |
{ name: "property_4", string: "Property 4", type: "char" }, |
| 2229 |
]; |
| 2230 |
delete Partner._records[1].properties.property_1; // remove char value |
| 2231 |
|
| 2232 |
await mountView({ |
| 2233 |
type: "form", |
| 2234 |
resModel: "partner", |
| 2235 |
resId: 2, |
| 2236 |
arch: /* xml */ ` |
| 2237 |
<form> |
| 2238 |
<sheet> |
| 2239 |
<group> |
| 2240 |
<field name="company_id"/> |
| 2241 |
<field name="properties" columns="2"/> |
| 2242 |
</group> |
| 2243 |
</sheet> |
| 2244 |
</form>`, |
| 2245 |
actionMenus: {}, |
| 2246 |
}); |
| 2247 |
|
| 2248 |
expect(getGroups()).toEqual([ |
| 2249 |
[ |
| 2250 |
["SEPARATOR 1", "property_1"], |
| 2251 |
["Property 2", "property_2"], |
| 2252 |
], |
| 2253 |
[["SEPARATOR 3", "property_3"]], |
| 2254 |
]); |
| 2255 |
|
| 2256 |
await click("div[property-name='property_1'] .o_field_property_group_label"); |
| 2257 |
await animationFrame(); |
| 2258 |
|
| 2259 |
expect(getGroups()).toEqual([ |
| 2260 |
[["SEPARATOR 1", "property_1"]], |
| 2261 |
[["SEPARATOR 3", "property_3"]], |
| 2262 |
]); |
| 2263 |
}); |
| 2264 |
|
| 2265 |
test.tags("desktop"); |
| 2266 |
test("properties: save separator folded state", async () => { |
| 2267 |
onRpc("web_save", ({ args }) => { |
| 2268 |
expect.step(args[1].properties.map((p) => [p.name, p.value])); |
| 2269 |
}); |
| 2270 |
|
| 2271 |
await makePropertiesGroupView([true, true, true, true]); |
| 2272 |
expect(getGroups()).toEqual([ |
| 2273 |
[["SEPARATOR 1", "property_1"]], |
| 2274 |
[["SEPARATOR 2", "property_2"]], |
| 2275 |
[["SEPARATOR 3", "property_3"]], |
| 2276 |
[["SEPARATOR 4", "property_4"]], |
| 2277 |
]); |
| 2278 |
|
| 2279 |
// return true if the given separator is folded |
| 2280 |
const foldState = (separatorName) => |
| 2281 |
!queryFirst(`div[property-name='${separatorName}'] .o_field_property_label .fa-caret-down`); |
| 2282 |
|
| 2283 |
const assertFolded = (values) => { |
| 2284 |
expect(values.length).toBe(4); |
| 2285 |
expect(foldState("property_1")).toBe(values[0]); |
| 2286 |
expect(foldState("property_2")).toBe(values[1]); |
| 2287 |
expect(foldState("property_3")).toBe(values[2]); |
| 2288 |
expect(foldState("property_4")).toBe(values[3]); |
| 2289 |
}; |
| 2290 |
|
| 2291 |
await click( |
| 2292 |
".o_field_properties .o_property_group[property-name='property_1'] .o_field_property_group_label" |
| 2293 |
); |
| 2294 |
await animationFrame(); |
| 2295 |
assertFolded([true, false, false, false]); |
| 2296 |
|
| 2297 |
await click( |
| 2298 |
".o_field_properties .o_property_group[property-name='property_3'] .o_field_property_group_label" |
| 2299 |
); |
| 2300 |
await animationFrame(); |
| 2301 |
assertFolded([true, false, true, false]); |
| 2302 |
|
| 2303 |
await clickSave(); |
| 2304 |
expect.verifySteps([[ |
| 2305 |
["property_1", true], |
| 2306 |
["property_2", false], |
| 2307 |
["property_3", true], |
| 2308 |
["property_4", false], |
| 2309 |
]]); |
| 2310 |
}); |
| 2311 |
|
| 2312 |
/** |
| 2313 |
* Test the behavior of the properties when we move them inside folded groups |
| 2314 |
*/ |
| 2315 |
test.tags("desktop"); |
| 2316 |
test("properties: separators move properties", async () => { |
| 2317 |
await makePropertiesGroupView([false, true, true, false, true, true, false]); |
| 2318 |
|
| 2319 |
// return true if the given separator is folded |
| 2320 |
const foldState = (separatorName) => |
| 2321 |
!queryFirst(`div[property-name='${separatorName}'] .o_field_property_label .fa-caret-down`); |
| 2322 |
|
| 2323 |
const assertFolded = (values) => { |
| 2324 |
expect(values.length).toBe(4); |
| 2325 |
expect(foldState("property_2")).toBe(values[0]); |
| 2326 |
expect(foldState("property_3")).toBe(values[1]); |
| 2327 |
expect(foldState("property_5")).toBe(values[2]); |
| 2328 |
expect(foldState("property_6")).toBe(values[3]); |
| 2329 |
}; |
| 2330 |
|
| 2331 |
// fold all groups |
| 2332 |
assertFolded([false, false, false, false]); |
| 2333 |
|
| 2334 |
await click("div[property-name='property_2'] .o_field_property_group_label"); |
| 2335 |
await click("div[property-name='property_3'] .o_field_property_group_label"); |
| 2336 |
await click("div[property-name='property_5'] .o_field_property_group_label"); |
| 2337 |
await click("div[property-name='property_6'] .o_field_property_group_label"); |
| 2338 |
await animationFrame(); |
| 2339 |
assertFolded([true, true, true, true]); |
| 2340 |
|
| 2341 |
expect(getGroups()).toEqual([ |
| 2342 |
[ |
| 2343 |
["", ""], |
| 2344 |
["Property 1", "property_1"], |
| 2345 |
], |
| 2346 |
[["SEPARATOR 2", "property_2"]], |
| 2347 |
[["SEPARATOR 3", "property_3"]], |
| 2348 |
[["SEPARATOR 5", "property_5"]], |
| 2349 |
[["SEPARATOR 6", "property_6"]], |
| 2350 |
]); |
| 2351 |
|
| 2352 |
await toggleActionMenu(); |
| 2353 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 2354 |
|
| 2355 |
// move the first property down |
| 2356 |
await click("[property-name='property_1'] .o_field_property_open_popover"); |
| 2357 |
await animationFrame(); |
| 2358 |
await click(".o_field_property_definition .oi-chevron-down"); |
| 2359 |
await animationFrame(); |
| 2360 |
|
| 2361 |
expect(getGroups()).toEqual([ |
| 2362 |
[ |
| 2363 |
["SEPARATOR 2", "property_2"], |
| 2364 |
["Property 1", "property_1"], |
| 2365 |
], |
| 2366 |
[["SEPARATOR 3", "property_3"]], |
| 2367 |
[["SEPARATOR 5", "property_5"]], |
| 2368 |
[["SEPARATOR 6", "property_6"]], |
| 2369 |
]); |
| 2370 |
assertFolded([false, true, true, true]); |
| 2371 |
|
| 2372 |
await click(".o_field_property_definition .oi-chevron-down"); |
| 2373 |
await animationFrame(); |
| 2374 |
expect(getGroups()).toEqual([ |
| 2375 |
[["SEPARATOR 2", "property_2"]], |
| 2376 |
[ |
| 2377 |
["SEPARATOR 3", "property_3"], |
| 2378 |
["Property 1", "property_1"], |
| 2379 |
["Property 4", "property_4"], |
| 2380 |
], |
| 2381 |
[["SEPARATOR 5", "property_5"]], |
| 2382 |
[["SEPARATOR 6", "property_6"]], |
| 2383 |
]); |
| 2384 |
assertFolded([false, false, true, true]); |
| 2385 |
|
| 2386 |
await click(".o_field_property_definition .oi-chevron-down"); |
| 2387 |
await animationFrame(); |
| 2388 |
expect(getGroups()).toEqual([ |
| 2389 |
[["SEPARATOR 2", "property_2"]], |
| 2390 |
[ |
| 2391 |
["SEPARATOR 3", "property_3"], |
| 2392 |
["Property 4", "property_4"], |
| 2393 |
["Property 1", "property_1"], |
| 2394 |
], |
| 2395 |
[["SEPARATOR 5", "property_5"]], |
| 2396 |
[["SEPARATOR 6", "property_6"]], |
| 2397 |
]); |
| 2398 |
assertFolded([false, false, true, true]); |
| 2399 |
|
| 2400 |
await click(".o_field_property_definition .oi-chevron-down"); |
| 2401 |
await animationFrame(); |
| 2402 |
expect(getGroups()).toEqual([ |
| 2403 |
[["SEPARATOR 2", "property_2"]], |
| 2404 |
[ |
| 2405 |
["SEPARATOR 3", "property_3"], |
| 2406 |
["Property 4", "property_4"], |
| 2407 |
], |
| 2408 |
[ |
| 2409 |
["SEPARATOR 5", "property_5"], |
| 2410 |
["Property 1", "property_1"], |
| 2411 |
], |
| 2412 |
[["SEPARATOR 6", "property_6"]], |
| 2413 |
]); |
| 2414 |
assertFolded([false, false, false, true]); |
| 2415 |
|
| 2416 |
// fold property 2 and 3 |
| 2417 |
await closePopover(); |
| 2418 |
await click("div[property-name='property_2'] .o_field_property_group_label"); |
| 2419 |
await animationFrame(); |
| 2420 |
await click("div[property-name='property_3'] .o_field_property_group_label"); |
| 2421 |
await animationFrame(); |
| 2422 |
assertFolded([true, true, false, true]); |
| 2423 |
|
| 2424 |
// move the property up |
| 2425 |
await click("[property-name='property_1'] .o_field_property_open_popover"); |
| 2426 |
await animationFrame(); |
| 2427 |
await click(".o_field_property_definition .oi-chevron-up"); |
| 2428 |
await animationFrame(); |
| 2429 |
expect(getGroups()).toEqual([ |
| 2430 |
[["SEPARATOR 2", "property_2"]], |
| 2431 |
[ |
| 2432 |
["SEPARATOR 3", "property_3"], |
| 2433 |
["Property 4", "property_4"], |
| 2434 |
["Property 1", "property_1"], |
| 2435 |
], |
| 2436 |
[["SEPARATOR 5", "property_5"]], |
| 2437 |
[["SEPARATOR 6", "property_6"]], |
| 2438 |
]); |
| 2439 |
assertFolded([true, false, false, true]); |
| 2440 |
|
| 2441 |
await click(".o_field_property_definition .oi-chevron-up"); |
| 2442 |
await animationFrame(); |
| 2443 |
await click(".o_field_property_definition .oi-chevron-up"); |
| 2444 |
await animationFrame(); |
| 2445 |
expect(getGroups()).toEqual([ |
| 2446 |
[ |
| 2447 |
["SEPARATOR 2", "property_2"], |
| 2448 |
["Property 1", "property_1"], |
| 2449 |
], |
| 2450 |
[ |
| 2451 |
["SEPARATOR 3", "property_3"], |
| 2452 |
["Property 4", "property_4"], |
| 2453 |
], |
| 2454 |
[["SEPARATOR 5", "property_5"]], |
| 2455 |
[["SEPARATOR 6", "property_6"]], |
| 2456 |
]); |
| 2457 |
assertFolded([false, false, false, true]); |
| 2458 |
|
| 2459 |
// now, create a new property, it must unfold the last group |
| 2460 |
await click(".o_field_property_add button"); |
| 2461 |
await animationFrame(); |
| 2462 |
expect(getGroups()).toEqual([ |
| 2463 |
[ |
| 2464 |
["SEPARATOR 2", "property_2"], |
| 2465 |
["Property 1", "property_1"], |
| 2466 |
], |
| 2467 |
[ |
| 2468 |
["SEPARATOR 3", "property_3"], |
| 2469 |
["Property 4", "property_4"], |
| 2470 |
], |
| 2471 |
[["SEPARATOR 5", "property_5"]], |
| 2472 |
[ |
| 2473 |
["SEPARATOR 6", "property_6"], |
| 2474 |
["Property 7", "property_7"], |
| 2475 |
["Property 8", "property_gen_2"], |
| 2476 |
], |
| 2477 |
]); |
| 2478 |
assertFolded([false, false, false, false]); |
| 2479 |
}); |
| 2480 |
|
| 2481 |
test.tags("desktop"); |
| 2482 |
test("properties: separators drag and drop", async () => { |
| 2483 |
// 2 columns view, 5 properties |
| 2484 |
await makePropertiesGroupView([false, false, false, false, false]); |
| 2485 |
expect(getGroups()).toEqual([ |
| 2486 |
[ |
| 2487 |
["", ""], |
| 2488 |
["Property 1", "property_1"], |
| 2489 |
["Property 2", "property_2"], |
| 2490 |
["Property 3", "property_3"], |
| 2491 |
], |
| 2492 |
[ |
| 2493 |
["", ""], |
| 2494 |
["Property 4", "property_4"], |
| 2495 |
["Property 5", "property_5"], |
| 2496 |
], |
| 2497 |
]); |
| 2498 |
|
| 2499 |
const getPropertyHandleElement = (propertyName) => |
| 2500 |
queryFirst(`*[property-name='${propertyName}'] .oi-draggable`); |
| 2501 |
|
| 2502 |
await toggleActionMenu(); |
| 2503 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 2504 |
|
| 2505 |
// if we move properties inside the same column, do not generate the group |
| 2506 |
await contains(getPropertyHandleElement("property_1")).dragAndDrop( |
| 2507 |
getPropertyHandleElement("property_3") |
| 2508 |
); |
| 2509 |
expect(getGroups()).toEqual([ |
| 2510 |
[ |
| 2511 |
["", ""], |
| 2512 |
["Property 2", "property_2"], |
| 2513 |
["Property 3", "property_3"], |
| 2514 |
["Property 1", "property_1"], |
| 2515 |
], |
| 2516 |
[ |
| 2517 |
["", ""], |
| 2518 |
["Property 4", "property_4"], |
| 2519 |
["Property 5", "property_5"], |
| 2520 |
], |
| 2521 |
]); |
| 2522 |
|
| 2523 |
// but if we move a property in a different column, we need to generate the group |
| 2524 |
await contains(getPropertyHandleElement("property_3")).dragAndDrop( |
| 2525 |
getPropertyHandleElement("property_4") |
| 2526 |
); |
| 2527 |
expect(getGroups()).toEqual([ |
| 2528 |
[ |
| 2529 |
// should have generated new separator |
| 2530 |
// to keep the column separation |
| 2531 |
["GROUP 1", "property_gen_2"], |
| 2532 |
["Property 2", "property_2"], |
| 2533 |
["Property 1", "property_1"], |
| 2534 |
], |
| 2535 |
[ |
| 2536 |
["GROUP 2", "property_gen_3"], |
| 2537 |
["Property 3", "property_3"], |
| 2538 |
["Property 4", "property_4"], |
| 2539 |
["Property 5", "property_5"], |
| 2540 |
], |
| 2541 |
]); |
| 2542 |
|
| 2543 |
// fold the first group |
| 2544 |
await click("div[property-name='property_gen_2'] .o_field_property_group_label"); |
| 2545 |
|
| 2546 |
// drag and drop the firth property in the folded group |
| 2547 |
await contains(getPropertyHandleElement("property_5")).dragAndDrop( |
| 2548 |
getPropertyHandleElement("property_gen_2") |
| 2549 |
); |
| 2550 |
// should unfold automatically |
| 2551 |
expect(getGroups()).toEqual([ |
| 2552 |
[ |
| 2553 |
["GROUP 1", "property_gen_2"], |
| 2554 |
["Property 2", "property_2"], |
| 2555 |
["Property 1", "property_1"], |
| 2556 |
["Property 5", "property_5"], |
| 2557 |
], |
| 2558 |
[ |
| 2559 |
["GROUP 2", "property_gen_3"], |
| 2560 |
["Property 3", "property_3"], |
| 2561 |
["Property 4", "property_4"], |
| 2562 |
], |
| 2563 |
]); |
| 2564 |
|
| 2565 |
// drag and drop the first group at the second position |
| 2566 |
await contains(getPropertyHandleElement("property_gen_2")).dragAndDrop( |
| 2567 |
getPropertyHandleElement("property_gen_3") |
| 2568 |
); |
| 2569 |
expect(getGroups()).toEqual([ |
| 2570 |
[ |
| 2571 |
["GROUP 2", "property_gen_3"], |
| 2572 |
["Property 3", "property_3"], |
| 2573 |
["Property 4", "property_4"], |
| 2574 |
], |
| 2575 |
[ |
| 2576 |
["GROUP 1", "property_gen_2"], |
| 2577 |
["Property 2", "property_2"], |
| 2578 |
["Property 1", "property_1"], |
| 2579 |
["Property 5", "property_5"], |
| 2580 |
], |
| 2581 |
]); |
| 2582 |
|
| 2583 |
// move property 3 at the last position of the other group |
| 2584 |
await contains(getPropertyHandleElement("property_3")).dragAndDrop( |
| 2585 |
getPropertyHandleElement("property_gen_2") |
| 2586 |
); |
| 2587 |
expect(getGroups()).toEqual([ |
| 2588 |
[ |
| 2589 |
["GROUP 2", "property_gen_3"], |
| 2590 |
["Property 4", "property_4"], |
| 2591 |
], |
| 2592 |
[ |
| 2593 |
["GROUP 1", "property_gen_2"], |
| 2594 |
["Property 2", "property_2"], |
| 2595 |
["Property 1", "property_1"], |
| 2596 |
["Property 5", "property_5"], |
| 2597 |
["Property 3", "property_3"], |
| 2598 |
], |
| 2599 |
]); |
| 2600 |
|
| 2601 |
// move property 3 at the first position of its group |
| 2602 |
await contains(getPropertyHandleElement("property_3")).dragAndDrop( |
| 2603 |
getPropertyHandleElement("property_2") |
| 2604 |
); |
| 2605 |
expect(getGroups()).toEqual([ |
| 2606 |
[ |
| 2607 |
["GROUP 2", "property_gen_3"], |
| 2608 |
["Property 4", "property_4"], |
| 2609 |
], |
| 2610 |
[ |
| 2611 |
["GROUP 1", "property_gen_2"], |
| 2612 |
["Property 3", "property_3"], |
| 2613 |
["Property 2", "property_2"], |
| 2614 |
["Property 1", "property_1"], |
| 2615 |
["Property 5", "property_5"], |
| 2616 |
], |
| 2617 |
]); |
| 2618 |
}); |
| 2619 |
|
| 2620 |
test("properties: start in edit mode", async () => { |
| 2621 |
onRpc("has_access", () => true); |
| 2622 |
await mountView({ |
| 2623 |
type: "form", |
| 2624 |
resModel: "partner", |
| 2625 |
resId: 1, |
| 2626 |
arch: /* xml */ ` |
| 2627 |
<form> |
| 2628 |
<sheet> |
| 2629 |
<group> |
| 2630 |
<field name="company_id"/> |
| 2631 |
<field name="properties" editMode="True"/> |
| 2632 |
</group> |
| 2633 |
</sheet> |
| 2634 |
</form>`, |
| 2635 |
}); |
| 2636 |
expect(".o_field_property_add button").toHaveCount(1, { |
| 2637 |
message: "The add button must be in the view", |
| 2638 |
}); |
| 2639 |
}); |
| 2640 |
|
| 2641 |
test("properties: no add properties action in cogmenu if no properties field", async () => { |
| 2642 |
await mountView({ |
| 2643 |
type: "form", |
| 2644 |
resModel: "res.users", |
| 2645 |
resId: 1, |
| 2646 |
arch: /* xml */ `<form><field name="name"/></form>`, |
| 2647 |
actionMenus: {}, |
| 2648 |
}); |
| 2649 |
await toggleActionMenu(); |
| 2650 |
expect(".o-dropdown--menu span:contains(Edit Properties)").toHaveCount(0); |
| 2651 |
}); |
| 2652 |
|
| 2653 |
test.tags("desktop"); |
| 2654 |
test("properties: onChange return new properties", async () => { |
| 2655 |
ResCompany._records.push({ |
| 2656 |
id: 38, |
| 2657 |
name: "Company 2", |
| 2658 |
definitions: [ |
| 2659 |
{ |
| 2660 |
name: "property_2_1", |
| 2661 |
string: "My Char", |
| 2662 |
type: "char", |
| 2663 |
view_in_kanban: true, |
| 2664 |
}, |
| 2665 |
], |
| 2666 |
}); |
| 2667 |
Partner._onChanges.company_id = (changes) => { |
| 2668 |
if (changes.company_id === 38) { |
| 2669 |
changes.properties = [ |
| 2670 |
{ |
| 2671 |
name: "property_2_2", |
| 2672 |
string: "My New Char", |
| 2673 |
type: "char", |
| 2674 |
value: "Hello", |
| 2675 |
}, |
| 2676 |
]; |
| 2677 |
} |
| 2678 |
}; |
| 2679 |
onRpc("has_access", () => true); |
| 2680 |
|
| 2681 |
await mountView({ |
| 2682 |
type: "form", |
| 2683 |
resModel: "partner", |
| 2684 |
resId: 1, |
| 2685 |
arch: /* xml */ ` |
| 2686 |
<form> |
| 2687 |
<sheet> |
| 2688 |
<group> |
| 2689 |
<field name="company_id"/> |
| 2690 |
<field name="properties"/> |
| 2691 |
</group> |
| 2692 |
</sheet> |
| 2693 |
</form>`, |
| 2694 |
}); |
| 2695 |
|
| 2696 |
await click("[name='company_id'] input"); |
| 2697 |
await edit("Company 2"); |
| 2698 |
await runAllTimers(); |
| 2699 |
await click(".dropdown-menu li"); |
| 2700 |
await animationFrame(); |
| 2701 |
expect("[name='properties'] .o_property_field").toHaveText("My New Char"); |
| 2702 |
expect("[name='properties'] .o_property_field input").toHaveValue("Hello"); |
| 2703 |
}); |
| 2704 |
|
| 2705 |
test("new property, change record, change property type", async () => { |
| 2706 |
for (const record of Partner._records) { |
| 2707 |
record.properties = {}; |
| 2708 |
} |
| 2709 |
ResCompany._records[0].definitions = []; |
| 2710 |
|
| 2711 |
onRpc("has_access", () => true); |
| 2712 |
|
| 2713 |
await mountView({ |
| 2714 |
type: "form", |
| 2715 |
resModel: "partner", |
| 2716 |
resId: 1, |
| 2717 |
resIds: [1, 2], |
| 2718 |
arch: ` |
| 2719 |
<form> |
| 2720 |
<field name="company_id"/> |
| 2721 |
<field name="properties"/> |
| 2722 |
</form>`, |
| 2723 |
actionMenus: {}, |
| 2724 |
}); |
| 2725 |
|
| 2726 |
await toggleActionMenu(); |
| 2727 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 2728 |
|
| 2729 |
await contains(".o_property_field .o_property_field_value input").edit("aze"); |
| 2730 |
await contains(".o_pager_next").click(); |
| 2731 |
expect(".o_property_field .o_property_field_value input").toHaveValue(""); |
| 2732 |
// Change second record's property type |
| 2733 |
await contains(".o_property_field .o_field_property_open_popover").click(); |
| 2734 |
await changeType("integer"); |
| 2735 |
|
| 2736 |
await contains(".o_pager_previous").click(); |
| 2737 |
expect(".o_property_field .o_property_field_value input").toHaveValue("0"); |
| 2738 |
}); |
| 2739 |
|
| 2740 |
test("property many2one, change property type from many2one to integer", async () => { |
| 2741 |
Partner._records = [ |
| 2742 |
{ |
| 2743 |
id: 1, |
| 2744 |
company_id: 37, |
| 2745 |
display_name: "Pierre", |
| 2746 |
properties: { |
| 2747 |
many_2_one: false, |
| 2748 |
}, |
| 2749 |
}, |
| 2750 |
]; |
| 2751 |
ResCompany._records[0].definitions = [ |
| 2752 |
{ |
| 2753 |
name: "many_2_one", |
| 2754 |
string: "My Many-2-one", |
| 2755 |
type: "many2one", |
| 2756 |
comodel: "partner", |
| 2757 |
domain: false, |
| 2758 |
}, |
| 2759 |
]; |
| 2760 |
|
| 2761 |
onRpc(({ method, model, args }) => { |
| 2762 |
if (["has_access", "has_group"].includes(method)) { |
| 2763 |
return true; |
| 2764 |
} else if (method === "display_name_for" && model === "ir.model") { |
| 2765 |
return [{ model: "partner", display_name: "Partner" }]; |
| 2766 |
} else if (method === "get_available_models" && model === "ir.model") { |
| 2767 |
return [{ model: "partner", display_name: "Partner" }]; |
| 2768 |
} else if (method === "web_save") { |
| 2769 |
const { name, ...propertiesWithoutName } = args[1].properties[0]; |
| 2770 |
expect(name).not.toEqual("many_2_one"); |
| 2771 |
expect(propertiesWithoutName).toEqual({ |
| 2772 |
string: "My Many-2-one", |
| 2773 |
type: "integer", |
| 2774 |
value: 0, |
| 2775 |
definition_changed: true, |
| 2776 |
default: 0, |
| 2777 |
}); |
| 2778 |
} |
| 2779 |
}); |
| 2780 |
|
| 2781 |
await mountView({ |
| 2782 |
type: "form", |
| 2783 |
resModel: "partner", |
| 2784 |
resId: 1, |
| 2785 |
resIds: [1, 2], |
| 2786 |
arch: ` |
| 2787 |
<form> |
| 2788 |
<field name="company_id"/> |
| 2789 |
<field name="properties"/> |
| 2790 |
</form>`, |
| 2791 |
actionMenus: {}, |
| 2792 |
}); |
| 2793 |
|
| 2794 |
await toggleActionMenu(); |
| 2795 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 2796 |
|
| 2797 |
// Change the record's property type |
| 2798 |
await contains(".o_property_field .o_field_property_open_popover").click(); |
| 2799 |
await changeType("integer"); |
| 2800 |
|
| 2801 |
// save |
| 2802 |
await clickSave(); |
| 2803 |
}); |
| 2804 |
|
| 2805 |
test.tags("desktop"); |
| 2806 |
test("properties: moving single property to 2nd group in auto split mode", async () => { |
| 2807 |
await makePropertiesGroupView([false]); |
| 2808 |
await toggleActionMenu(); |
| 2809 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 2810 |
const { moveTo, drop } = await contains(getPropertyHandleElement("property_1")).drag(); |
| 2811 |
const secondGroup = queryFirst(".o_property_group:last-of-type"); |
| 2812 |
await moveTo(secondGroup, "bottom"); |
| 2813 |
await drop(); |
| 2814 |
expect(getGroups()).toEqual([ |
| 2815 |
[["GROUP 1", "property_gen_2"]], |
| 2816 |
[ |
| 2817 |
["GROUP 2", "property_gen_3"], |
| 2818 |
["Property 1", "property_1"], |
| 2819 |
], |
| 2820 |
]); |
| 2821 |
}); |
| 2822 |
|
| 2823 |
test.tags("desktop"); |
| 2824 |
test("properties: moving single property to 1st group", async () => { |
| 2825 |
await makePropertiesGroupView([true, true, false]); |
| 2826 |
await toggleActionMenu(); |
| 2827 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 2828 |
await contains(getPropertyHandleElement("property_3")).dragAndDrop( |
| 2829 |
getPropertyHandleElement("property_1") |
| 2830 |
); |
| 2831 |
expect(getGroups()).toEqual([ |
| 2832 |
[ |
| 2833 |
["SEPARATOR 1", "property_1"], |
| 2834 |
["Property 3", "property_3"], |
| 2835 |
], |
| 2836 |
[["SEPARATOR 2", "property_2"]], |
| 2837 |
]); |
| 2838 |
}); |
| 2839 |
|
| 2840 |
test.tags("desktop"); |
| 2841 |
test("properties: split, moving property from 2nd group to 1st", async () => { |
| 2842 |
await makePropertiesGroupView([true, false, false]); |
| 2843 |
await toggleActionMenu(); |
| 2844 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 2845 |
await contains(getPropertyHandleElement("property_3")).dragAndDrop( |
| 2846 |
getPropertyHandleElement("property_2"), |
| 2847 |
"top" |
| 2848 |
); |
| 2849 |
expect(getGroups()).toEqual([ |
| 2850 |
[ |
| 2851 |
["SEPARATOR 1", "property_1"], |
| 2852 |
["Property 3", "property_3"], |
| 2853 |
["Property 2", "property_2"], |
| 2854 |
], |
| 2855 |
[["GROUP 2", "property_gen_2"]], |
| 2856 |
]); |
| 2857 |
}); |
| 2858 |
|
| 2859 |
test.tags("desktop"); |
| 2860 |
test("properties: split, moving property from 1st group to 2nd", async () => { |
| 2861 |
await makePropertiesGroupView([true, false, false, false, false, false]); |
| 2862 |
await toggleActionMenu(); |
| 2863 |
await toggleMenuItem("Edit Properties"); // Start the edition mode |
| 2864 |
await contains(getPropertyHandleElement("property_3")).dragAndDrop( |
| 2865 |
getPropertyHandleElement("property_6"), |
| 2866 |
"top" |
| 2867 |
); |
| 2868 |
expect(getGroups()).toEqual([ |
| 2869 |
[ |
| 2870 |
["SEPARATOR 1", "property_1"], |
| 2871 |
["Property 2", "property_2"], |
| 2872 |
["Property 4", "property_4"], |
| 2873 |
], |
| 2874 |
[ |
| 2875 |
["GROUP 2", "property_gen_2"], |
| 2876 |
["Property 5", "property_5"], |
| 2877 |
["Property 3", "property_3"], |
| 2878 |
["Property 6", "property_6"], |
| 2879 |
], |
| 2880 |
]); |
| 2881 |
}); |
| 2882 |
|
| 2883 |
test("properties: do not write undefined value", async () => { |
| 2884 |
Partner._records.push({ |
| 2885 |
id: 5000, |
| 2886 |
display_name: "third partner", |
| 2887 |
properties: { |
| 2888 |
property_1: "test", |
| 2889 |
property_2: undefined, |
| 2890 |
}, |
| 2891 |
company_id: 37, |
| 2892 |
}); |
| 2893 |
ResCompany._records[0].definitions = [ |
| 2894 |
{ |
| 2895 |
name: "property_1", |
| 2896 |
string: "Property 1", |
| 2897 |
type: "char", |
| 2898 |
}, |
| 2899 |
{ |
| 2900 |
name: "property_2", |
| 2901 |
string: "Property 2", |
| 2902 |
type: "char", |
| 2903 |
}, |
| 2904 |
]; |
| 2905 |
onRpc(({ method, args }) => { |
| 2906 |
if (method === "has_access") { |
| 2907 |
return true; |
| 2908 |
} |
| 2909 |
if (method === "web_save") { |
| 2910 |
expect.step("web_save"); |
| 2911 |
expect(args[1].properties).toEqual([ |
| 2912 |
{ |
| 2913 |
name: "property_1", |
| 2914 |
string: "Property 1", |
| 2915 |
type: "char", |
| 2916 |
value: "edited", |
| 2917 |
}, |
| 2918 |
{ |
| 2919 |
name: "property_2", |
| 2920 |
string: "Property 2", |
| 2921 |
type: "char", |
| 2922 |
// Value not added here |
| 2923 |
}, |
| 2924 |
]); |
| 2925 |
} |
| 2926 |
}); |
| 2927 |
await mountView({ |
| 2928 |
type: "form", |
| 2929 |
resModel: "partner", |
| 2930 |
resId: 5000, |
| 2931 |
arch: /* xml */ `<form><field name="company_id"/><field name="properties"/></form>`, |
| 2932 |
}); |
| 2933 |
|
| 2934 |
await contains("[property-name=property_1] input").edit("edited"); |
| 2935 |
|
| 2936 |
expect.verifySteps([]); |
| 2937 |
await clickSave(); |
| 2938 |
expect.verifySteps(["web_save"]); |
| 2939 |
}); |
| 2940 |
|
| 2941 |
test("properties: monetary without currency_field", async () => { |
| 2942 |
onRpc("has_access", () => true); |
| 2943 |
|
| 2944 |
await mountView({ |
| 2945 |
type: "form", |
| 2946 |
resModel: "partner", |
| 2947 |
resId: 1, |
| 2948 |
arch: /* xml */ ` |
| 2949 |
<form> |
| 2950 |
<sheet> |
| 2951 |
<group> |
| 2952 |
<field name="company_id"/> |
| 2953 |
<field name="properties"/> |
| 2954 |
</group> |
| 2955 |
</sheet> |
| 2956 |
</form>`, |
| 2957 |
actionMenus: {}, |
| 2958 |
}); |
| 2959 |
expect(".o_field_properties").toHaveCount(1); |
| 2960 |
|
| 2961 |
await toggleActionMenu(); |
| 2962 |
await toggleMenuItem("Edit Properties"); |
| 2963 |
|
| 2964 |
await click(".o_property_field:nth-child(2) .o_field_property_open_popover"); |
| 2965 |
await animationFrame(); |
| 2966 |
|
| 2967 |
await click(".o_field_property_definition_type input"); |
| 2968 |
await animationFrame(); |
| 2969 |
expect(`.o_field_property_definition_type_menu .o-dropdown-item:contains(Monetary) > div.text-muted`).toHaveAttribute("data-tooltip", "Not possible to create monetary field because there is no currency on current model."); |
| 2970 |
}); |
| 2971 |
|
| 2972 |
test("properties: monetary with currency_id", async () => { |
| 2973 |
Partner._fields.currency_id = fields.Many2one({ relation: "res.currency", default: 1 }); |
| 2974 |
|
| 2975 |
onRpc("has_access", () => true); |
| 2976 |
|
| 2977 |
await mountView({ |
| 2978 |
type: "form", |
| 2979 |
resModel: "partner", |
| 2980 |
resId: 1, |
| 2981 |
arch: /* xml */ ` |
| 2982 |
<form> |
| 2983 |
<sheet> |
| 2984 |
<group> |
| 2985 |
<field name="currency_id" invisible="1"/> |
| 2986 |
<field name="company_id"/> |
| 2987 |
<field name="properties"/> |
| 2988 |
</group> |
| 2989 |
</sheet> |
| 2990 |
</form>`, |
| 2991 |
actionMenus: {}, |
| 2992 |
}); |
| 2993 |
expect(".o_field_properties").toHaveCount(1); |
| 2994 |
|
| 2995 |
await toggleActionMenu(); |
| 2996 |
await toggleMenuItem("Edit Properties"); |
| 2997 |
|
| 2998 |
await click(".o_property_field:nth-child(2) .o_field_property_open_popover"); |
| 2999 |
await animationFrame(); |
| 3000 |
|
| 3001 |
await click(".o_field_property_definition_type input"); |
| 3002 |
await animationFrame(); |
| 3003 |
expect(`.o_field_property_definition_type_menu .o-dropdown-item:contains(Monetary) > div:not(.text-muted)`).toHaveCount(1); |
| 3004 |
|
| 3005 |
await contains(`.o_field_property_definition_type_menu .o-dropdown-item:contains(Monetary)`).click(); |
| 3006 |
expect(`.o_field_property_definition_currency_field select`).toHaveText("Currency"); |
| 3007 |
expect(`.o_field_property_definition_currency_field select`).toHaveValue("currency_id"); |
| 3008 |
expect(".o_field_property_definition_value .o_input > span:eq(0)").toHaveText("$"); |
| 3009 |
expect(`.o_field_property_definition_value input`).toHaveValue("0.00"); |
| 3010 |
|
| 3011 |
await closePopover(); |
| 3012 |
expect(".o_property_field:nth-child(2) .o_property_field_value .o_input > span:eq(0)").toHaveText("$"); |
| 3013 |
expect(`.o_property_field:nth-child(2) .o_property_field_value input`).toHaveValue("0.00"); |
| 3014 |
}); |
| 3015 |
|
| 3016 |
test("properties: monetary with multiple currency field", async () => { |
| 3017 |
Partner._fields.another_currency_id = fields.Many2one({ relation: "res.currency", default: 2 }); |
| 3018 |
Partner._fields.currency_id = fields.Many2one({ relation: "res.currency", default: 1 }); |
| 3019 |
|
| 3020 |
onRpc("has_access", () => true); |
| 3021 |
|
| 3022 |
await mountView({ |
| 3023 |
type: "form", |
| 3024 |
resModel: "partner", |
| 3025 |
resId: 1, |
| 3026 |
arch: /* xml */ ` |
| 3027 |
<form> |
| 3028 |
<sheet> |
| 3029 |
<group> |
| 3030 |
<field name="currency_id" invisible="1"/> |
| 3031 |
<field name="another_currency_id" invisible="1"/> |
| 3032 |
<field name="company_id"/> |
| 3033 |
<field name="properties"/> |
| 3034 |
</group> |
| 3035 |
</sheet> |
| 3036 |
</form>`, |
| 3037 |
actionMenus: {}, |
| 3038 |
}); |
| 3039 |
expect(".o_field_properties").toHaveCount(1); |
| 3040 |
|
| 3041 |
await toggleActionMenu(); |
| 3042 |
await toggleMenuItem("Edit Properties"); |
| 3043 |
|
| 3044 |
await click(".o_property_field:nth-child(2) .o_field_property_open_popover"); |
| 3045 |
await animationFrame(); |
| 3046 |
|
| 3047 |
await click(".o_field_property_definition_type input"); |
| 3048 |
await animationFrame(); |
| 3049 |
expect(`.o_field_property_definition_type_menu .o-dropdown-item:contains(Monetary) > div:not(.text-muted)`).toHaveCount(1); |
| 3050 |
|
| 3051 |
await contains(`.o_field_property_definition_type_menu .o-dropdown-item:contains(Monetary)`).click(); |
| 3052 |
expect(`.o_field_property_definition_currency_field select`).toHaveText("Currency\nAnother currency"); |
| 3053 |
expect(`.o_field_property_definition_currency_field select`).toHaveValue("currency_id"); |
| 3054 |
|
| 3055 |
await contains(".o_field_property_definition_currency_field select").select("another_currency_id"); |
| 3056 |
expect(`.o_field_property_definition_currency_field select`).toHaveValue("another_currency_id"); |
| 3057 |
expect(".o_field_property_definition_value .o_input > span:eq(1)").toHaveText("€"); |
| 3058 |
expect(`.o_field_property_definition_value input`).toHaveValue("0.00"); |
| 3059 |
|
| 3060 |
await closePopover(); |
| 3061 |
expect(".o_property_field:nth-child(2) .o_property_field_value .o_input > span:eq(1)").toHaveText("€"); |
| 3062 |
expect(`.o_property_field:nth-child(2) .o_property_field_value input`).toHaveValue("0.00"); |
| 3063 |
}); |