section_one2many_field_tests.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /** @odoo-module */
  2. import { getFixture } from "@web/../tests/helpers/utils";
  3. import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
  4. QUnit.module("SectionOneToManyField", (hooks) => {
  5. let serverData;
  6. let target;
  7. hooks.beforeEach(() => {
  8. target = getFixture();
  9. serverData = {
  10. models: {
  11. partner: {
  12. fields: { lines: { type: "one2many", relation: "lines_sections" } },
  13. records: [
  14. {
  15. id: 1,
  16. lines: [1, 2],
  17. },
  18. ],
  19. },
  20. lines_sections: {
  21. fields: {
  22. display_type: { type: "char" },
  23. title: { type: "char", string: "Title" },
  24. int: { type: "number", string: "integer" },
  25. },
  26. records: [
  27. {
  28. id: 1,
  29. display_type: "line_section",
  30. title: "firstSectionTitle",
  31. int: 4,
  32. },
  33. {
  34. id: 2,
  35. display_type: false,
  36. title: "recordTitle",
  37. int: 5,
  38. },
  39. ],
  40. },
  41. },
  42. };
  43. setupViewRegistries();
  44. });
  45. QUnit.test("basic rendering", async (assert) => {
  46. await makeView({
  47. type: "form",
  48. resModel: "partner",
  49. resId: 1,
  50. serverData,
  51. arch: `
  52. <form>
  53. <field name="lines" widget="section_one2many">
  54. <tree>
  55. <field name="display_type" invisible="1" />
  56. <field name="title" />
  57. <field name="int" />
  58. </tree>
  59. </field>
  60. </form>
  61. `,
  62. });
  63. assert.containsOnce(target, ".o_field_x2many .o_list_renderer table.o_section_list_view");
  64. assert.containsN(target, ".o_data_row", 2);
  65. const rows = target.querySelectorAll(".o_data_row");
  66. assert.hasClass(rows[0], "o_is_line_section fw-bold");
  67. assert.doesNotHaveClass(rows[1], "o_is_line_section fw-bold");
  68. assert.strictEqual(rows[0].textContent, "firstSectionTitle");
  69. assert.strictEqual(rows[1].textContent, "recordTitle5");
  70. assert.strictEqual(rows[0].querySelector("td[name=title]").getAttribute("colspan"), "3");
  71. assert.strictEqual(rows[1].querySelector("td[name=title]").getAttribute("colspan"), null);
  72. assert.containsOnce(target, ".o_list_record_remove");
  73. assert.containsNone(target, ".o_is_line_section .o_list_record_remove");
  74. });
  75. });