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.

204 lines
6.3 KiB

  1. /**********************************************************************************
  2. *
  3. * Copyright (c) 2017-2019 MuK IT GmbH.
  4. *
  5. * This file is part of MuK Web Utils
  6. * (see https://mukit.at).
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. **********************************************************************************/
  22. odoo.define('muk_web_utils.tests.fields', function (require) {
  23. "use strict";
  24. var basicFields = require('web.basic_fields');
  25. var concurrency = require('web.concurrency');
  26. var config = require('web.config');
  27. var core = require('web.core');
  28. var FormView = require('web.FormView');
  29. var KanbanView = require('web.KanbanView');
  30. var ListView = require('web.ListView');
  31. var session = require('web.session');
  32. var testUtils = require('web.test_utils');
  33. var field_registry = require('web.field_registry');
  34. var createView = testUtils.createView;
  35. var createAsyncView = testUtils.createAsyncView;
  36. var DebouncedField = basicFields.DebouncedField;
  37. var JournalDashboardGraph = basicFields.JournalDashboardGraph;
  38. var _t = core._t;
  39. QUnit.module('muk_web_utils', {}, function () {
  40. QUnit.module('fields', {
  41. beforeEach: function () {
  42. this.data = {
  43. partner: {
  44. fields: {
  45. display_name: {
  46. string: "Displayed name",
  47. type: "char",
  48. searchable: true
  49. },
  50. short: {
  51. string: "Short",
  52. type: "char",
  53. searchable: true,
  54. trim: true
  55. },
  56. long: {
  57. string: "Long",
  58. string: "txt",
  59. type: "text",
  60. },
  61. document: {
  62. string: "Binary",
  63. type: "binary",
  64. attachment: true,
  65. },
  66. },
  67. records: [{
  68. id: 1,
  69. display_name: "first record",
  70. short: "Short Text",
  71. long: "Super looooooong Text",
  72. document: 'coucou==\n',
  73. }],
  74. },
  75. };
  76. }
  77. }, function () {
  78. QUnit.module('BinaryFileCopy');
  79. QUnit.test('Fields is correctly rendered', function (assert) {
  80. assert.expect(2);
  81. var form = createView({
  82. View: FormView,
  83. model: 'partner',
  84. data: this.data,
  85. arch: (
  86. '<form string="Partners">' +
  87. '<field name="document" widget="copy_binary" filename="short"/>' +
  88. '<field name="short"/>' +
  89. '</form>'
  90. ),
  91. res_id: 1,
  92. });
  93. assert.strictEqual(
  94. form.$('a.o_field_widget[name="document"] > .mk_copy_binary > .mk_copy_button').length,
  95. 1, "the copy button should be visible in readonly mode"
  96. );
  97. form.$buttons.find('.o_form_button_edit').click();
  98. assert.strictEqual(
  99. form.$('a.o_field_widget[name="document"] > .mk_copy_binary').length,
  100. 0, "the copy button shouldn't be visible in edit mode"
  101. );
  102. form.destroy();
  103. });
  104. QUnit.module('CharShare');
  105. QUnit.test('Fields is correctly rendered', function (assert) {
  106. assert.expect(1);
  107. var form = createView({
  108. View: FormView,
  109. model: 'partner',
  110. data: this.data,
  111. arch: (
  112. '<form string="Partners">' +
  113. '<div>' +
  114. '<field name="short" widget="share_char"/>' +
  115. '</div>' +
  116. '</form>'
  117. ),
  118. res_id: 1,
  119. });
  120. assert.strictEqual(
  121. form.$('span.o_field_widget[name="short"] > .mk_share_dropdown.mk_share_char').length,
  122. 1, "the copy button should be visible in readonly mode"
  123. );
  124. form.destroy();
  125. });
  126. QUnit.module('TextShare');
  127. QUnit.test('Fields is correctly rendered', function (assert) {
  128. assert.expect(1);
  129. var form = createView({
  130. View: FormView,
  131. model: 'partner',
  132. data: this.data,
  133. arch: (
  134. '<form string="Partners">' +
  135. '<div>' +
  136. '<field name="long" widget="share_text"/>' +
  137. '</div>' +
  138. '</form>'
  139. ),
  140. res_id: 1,
  141. });
  142. assert.strictEqual(
  143. form.$('span.o_field_widget[name="long"] > .mk_share_dropdown.mk_share_text').length,
  144. 1, "the copy button should be visible in readonly mode"
  145. );
  146. form.destroy();
  147. });
  148. QUnit.module('BinaryFileShare');
  149. QUnit.test('Fields is correctly rendered', function (assert) {
  150. assert.expect(2);
  151. var form = createView({
  152. View: FormView,
  153. model: 'partner',
  154. data: this.data,
  155. arch: (
  156. '<form string="Partners">' +
  157. '<field name="document" widget="share_binary" filename="short"/>' +
  158. '<field name="short"/>' +
  159. '</form>'
  160. ),
  161. res_id: 1,
  162. });
  163. assert.strictEqual(
  164. form.$('a.o_field_widget[name="document"] > .mk_share_dropdown > .mk_share_button').length,
  165. 1, "the share dropdown should be visible in readonly mode"
  166. );
  167. form.$buttons.find('.o_form_button_edit').click();
  168. assert.strictEqual(
  169. form.$('a.o_field_widget[name="document"] > .mk_share_dropdown > .mk_share_button').length,
  170. 0, "the share dropdown shouldn't be visible in edit mode"
  171. );
  172. form.destroy();
  173. });
  174. });
  175. });
  176. });