You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
5.5 KiB

  1. odoo.define('muk_web_utils.tests.fields', function (require) {
  2. "use strict";
  3. var basicFields = require('web.basic_fields');
  4. var concurrency = require('web.concurrency');
  5. var config = require('web.config');
  6. var core = require('web.core');
  7. var FormView = require('web.FormView');
  8. var KanbanView = require('web.KanbanView');
  9. var ListView = require('web.ListView');
  10. var session = require('web.session');
  11. var testUtils = require('web.test_utils');
  12. var field_registry = require('web.field_registry');
  13. var createView = testUtils.createView;
  14. var createAsyncView = testUtils.createAsyncView;
  15. var DebouncedField = basicFields.DebouncedField;
  16. var JournalDashboardGraph = basicFields.JournalDashboardGraph;
  17. var _t = core._t;
  18. QUnit.module('muk_web_utils', {}, function () {
  19. QUnit.module('fields', {
  20. beforeEach: function () {
  21. this.data = {
  22. partner: {
  23. fields: {
  24. display_name: {
  25. string: "Displayed name",
  26. type: "char",
  27. searchable: true
  28. },
  29. short: {
  30. string: "Short",
  31. type: "char",
  32. searchable: true,
  33. trim: true
  34. },
  35. long: {
  36. string: "Long",
  37. string: "txt",
  38. type: "text",
  39. },
  40. document: {
  41. string: "Binary",
  42. type: "binary",
  43. attachment: true,
  44. },
  45. },
  46. records: [{
  47. id: 1,
  48. display_name: "first record",
  49. short: "Short Text",
  50. long: "Super looooooong Text",
  51. document: 'coucou==\n',
  52. }],
  53. },
  54. };
  55. }
  56. }, function () {
  57. QUnit.module('BinaryFileCopy');
  58. QUnit.test('Fields is correctly rendered', function (assert) {
  59. assert.expect(2);
  60. var form = createView({
  61. View: FormView,
  62. model: 'partner',
  63. data: this.data,
  64. arch: (
  65. '<form string="Partners">' +
  66. '<field name="document" widget="copy_binary" filename="short"/>' +
  67. '<field name="short"/>' +
  68. '</form>'
  69. ),
  70. res_id: 1,
  71. });
  72. assert.strictEqual(
  73. form.$('a.o_field_widget[name="document"] > .mk_copy_binary > .mk_copy_button').length,
  74. 1, "the copy button should be visible in readonly mode"
  75. );
  76. form.$buttons.find('.o_form_button_edit').click();
  77. assert.strictEqual(
  78. form.$('a.o_field_widget[name="document"] > .mk_copy_binary').length,
  79. 0, "the copy button shouldn't be visible in edit mode"
  80. );
  81. form.destroy();
  82. });
  83. QUnit.module('CharShare');
  84. QUnit.test('Fields is correctly rendered', function (assert) {
  85. assert.expect(1);
  86. var form = createView({
  87. View: FormView,
  88. model: 'partner',
  89. data: this.data,
  90. arch: (
  91. '<form string="Partners">' +
  92. '<div>' +
  93. '<field name="short" widget="share_char"/>' +
  94. '</div>' +
  95. '</form>'
  96. ),
  97. res_id: 1,
  98. });
  99. assert.strictEqual(
  100. form.$('span.o_field_widget[name="short"] > .mk_share_dropdown.mk_share_char').length,
  101. 1, "the copy button should be visible in readonly mode"
  102. );
  103. form.destroy();
  104. });
  105. QUnit.module('TextShare');
  106. QUnit.test('Fields is correctly rendered', function (assert) {
  107. assert.expect(1);
  108. var form = createView({
  109. View: FormView,
  110. model: 'partner',
  111. data: this.data,
  112. arch: (
  113. '<form string="Partners">' +
  114. '<div>' +
  115. '<field name="long" widget="share_text"/>' +
  116. '</div>' +
  117. '</form>'
  118. ),
  119. res_id: 1,
  120. });
  121. assert.strictEqual(
  122. form.$('span.o_field_widget[name="long"] > .mk_share_dropdown.mk_share_text').length,
  123. 1, "the copy button should be visible in readonly mode"
  124. );
  125. form.destroy();
  126. });
  127. QUnit.module('BinaryFileShare');
  128. QUnit.test('Fields is correctly rendered', function (assert) {
  129. assert.expect(2);
  130. var form = createView({
  131. View: FormView,
  132. model: 'partner',
  133. data: this.data,
  134. arch: (
  135. '<form string="Partners">' +
  136. '<field name="document" widget="share_binary" filename="short"/>' +
  137. '<field name="short"/>' +
  138. '</form>'
  139. ),
  140. res_id: 1,
  141. });
  142. assert.strictEqual(
  143. form.$('a.o_field_widget[name="document"] > .mk_share_dropdown > .mk_share_button').length,
  144. 1, "the share dropdown should be visible in readonly mode"
  145. );
  146. form.$buttons.find('.o_form_button_edit').click();
  147. assert.strictEqual(
  148. form.$('a.o_field_widget[name="document"] > .mk_share_dropdown > .mk_share_button').length,
  149. 0, "the share dropdown shouldn't be visible in edit mode"
  150. );
  151. form.destroy();
  152. });
  153. });
  154. });
  155. });