calendar_tests.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /** @odoo-module **/
  2. import { getFixture } from "@web/../tests/helpers/utils";
  3. import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
  4. let serverData;
  5. let target;
  6. QUnit.module(
  7. "calendar",
  8. {
  9. beforeEach: function () {
  10. target = getFixture();
  11. serverData = {
  12. models: {
  13. event: {
  14. fields: {
  15. partner_ids: {
  16. string: "Partners",
  17. type: "many2many",
  18. relation: "partner",
  19. },
  20. },
  21. records: [
  22. {
  23. id: 14,
  24. partner_ids: [1, 2],
  25. },
  26. ],
  27. },
  28. partner: {
  29. fields: {
  30. name: { string: "Name", type: "char" },
  31. },
  32. records: [
  33. {
  34. id: 1,
  35. name: "Jesus",
  36. },
  37. {
  38. id: 2,
  39. name: "Mahomet",
  40. },
  41. ],
  42. },
  43. },
  44. };
  45. setupViewRegistries();
  46. },
  47. },
  48. function () {
  49. QUnit.test("Many2ManyAttendee: basic rendering", async function (assert) {
  50. await makeView({
  51. type: "form",
  52. resModel: "event",
  53. serverData,
  54. resId: 14,
  55. arch: `
  56. <form>
  57. <field name="partner_ids" widget="many2manyattendee"/>
  58. </form>`,
  59. mockRPC(route, args) {
  60. if (args.method === "get_attendee_detail") {
  61. assert.step(args.method);
  62. assert.strictEqual(
  63. args.model,
  64. "res.partner",
  65. "the method should only be called on res.partner"
  66. );
  67. assert.deepEqual(
  68. args.args[0],
  69. [1, 2],
  70. "the partner ids should be passed as argument"
  71. );
  72. assert.deepEqual(
  73. args.args[1],
  74. [14],
  75. "the event id should be passed as argument"
  76. );
  77. return Promise.resolve([
  78. { id: 1, name: "Jesus", status: "accepted", color: 0 },
  79. { id: 2, name: "Mahomet", status: "tentative", color: 0 },
  80. ]);
  81. }
  82. },
  83. });
  84. assert.hasClass(
  85. target.querySelector('.o_field_widget[name="partner_ids"] div'),
  86. "o_field_tags"
  87. );
  88. assert.containsN(
  89. target,
  90. '.o_field_widget[name="partner_ids"] .badge',
  91. 2,
  92. "there should be 2 tags"
  93. );
  94. const badges = target.querySelectorAll('.o_field_widget[name="partner_ids"] .badge');
  95. assert.strictEqual(
  96. badges[0].textContent.trim(),
  97. "Jesus",
  98. "the tag should be correctly named"
  99. );
  100. assert.hasClass(
  101. badges[0].querySelector("img"),
  102. "o_attendee_border_accepted",
  103. "Jesus should attend the meeting"
  104. );
  105. assert.strictEqual(
  106. badges[1].textContent.trim(),
  107. "Mahomet",
  108. "the tag should be correctly named"
  109. );
  110. assert.hasClass(
  111. badges[1].querySelector("img"),
  112. "o_attendee_border_tentative",
  113. "Mohamet should still confirm his attendance to the meeting"
  114. );
  115. assert.containsOnce(badges[0], "img", "should have img tag");
  116. assert.hasAttrValue(
  117. badges[0].querySelector("img"),
  118. "data-src",
  119. "/web/image/partner/1/avatar_128",
  120. "should have correct avatar image"
  121. );
  122. assert.verifySteps(["get_attendee_detail"]);
  123. });
  124. }
  125. );