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.

106 lines
5.2 KiB

  1. //-*- coding: utf-8 -*-
  2. //############################################################################
  3. //
  4. // OpenERP, Open Source Management Solution
  5. // This module copyright (C) 2014 Therp BV (<http://therp.nl>).
  6. //
  7. // This program is free software: you can redistribute it and/or modify
  8. // it under the terms of the GNU Affero General Public License as
  9. // published by the Free Software Foundation, either version 3 of the
  10. // License, or (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU Affero General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU Affero General Public License
  18. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. //
  20. //############################################################################
  21. openerp.testing.section(
  22. 'web_compute_domain_x2many',
  23. function(test)
  24. {
  25. //start OpenERP core tests from web/static/test/form.js
  26. test("basic", function (instance) {
  27. var fields = {
  28. 'a': {value: 3},
  29. 'group_method': {value: 'line'},
  30. 'select1': {value: 'day'},
  31. 'rrule_type': {value: 'monthly'}
  32. };
  33. ok(instance.web.form.compute_domain(
  34. [['a', '=', 3]], fields));
  35. ok(instance.web.form.compute_domain(
  36. [['group_method','!=','count']], fields));
  37. ok(instance.web.form.compute_domain(
  38. [['select1','=','day'], ['rrule_type','=','monthly']], fields));
  39. });
  40. test("or", function (instance) {
  41. var web = {
  42. 'section_id': {value: null},
  43. 'user_id': {value: null},
  44. 'member_ids': {value: null}
  45. };
  46. var domain = ['|', ['section_id', '=', 42],
  47. '|', ['user_id','=',3],
  48. ['member_ids', 'in', [3]]];
  49. ok(instance.web.form.compute_domain(domain, _.extend(
  50. {}, web, {'section_id': {value: 42}})));
  51. ok(instance.web.form.compute_domain(domain, _.extend(
  52. {}, web, {'user_id': {value: 3}})));
  53. ok(instance.web.form.compute_domain(domain, _.extend(
  54. {}, web, {'member_ids': {value: 3}})));
  55. });
  56. test("not", function (instance) {
  57. var fields = {
  58. 'a': {value: 5},
  59. 'group_method': {value: 'line'}
  60. };
  61. ok(instance.web.form.compute_domain(
  62. ['!', ['a', '=', 3]], fields));
  63. ok(instance.web.form.compute_domain(
  64. ['!', ['group_method','=','count']], fields));
  65. });
  66. //end OpenERP core tests
  67. var fields = {
  68. one2many_empty: {value: [], field: {type: 'one2many'}},
  69. one2many_one_entry: {value: [[4, 42, false]], field: {type: 'one2many'}},
  70. one2many_multiple_entries: {value: [[4, 42, false], [4, 43, false]], field: {type: 'one2many'}},
  71. many2many_empty: {value: [[6, false, []]], field: {type: 'many2many'}},
  72. many2many_one_entry: {value: [[6, false, [42]]], field: {type: 'many2many'}},
  73. many2many_multiple_entries: {value: [[6, false, [42, 43]]], field: {type: 'many2many'}},
  74. };
  75. test('legacy behavior', function(instance)
  76. {
  77. var eval = function(expression, fields)
  78. {
  79. expression = instance.web.pyeval.eval('domain', expression, {}, {});
  80. return instance.web.form.compute_domain(expression, fields)
  81. }
  82. ok(eval("[('one2many_empty', '=', [])]", fields), 'empty one2many');
  83. ok(eval("[('many2many_empty', '=', [[6, False, []]])]", fields), 'empty many2many');
  84. });
  85. test('x2many tests', function(instance)
  86. {
  87. var eval = function(expression, fields)
  88. {
  89. expression = instance.web.pyeval.eval('domain', expression, {}, {});
  90. return instance.web.form.compute_domain(expression, fields)
  91. }
  92. ok(!eval("[('one2many_empty', '=', 42)]", fields), 'empty one2many == value');
  93. ok(eval("[('one2many_one_entry', '=', 42)]", fields), 'one2many with one entry == value');
  94. ok(eval("[('one2many_multiple_entries', '=', 42)]", fields), 'one2many with multiple entries == value');
  95. ok(eval("[('one2many_multiple_entries', 'in', [42])]", fields), 'one2many with multiple entries in [value]');
  96. ok(!eval("[('many2many_empty', '=', 42)]", fields), 'empty many2many == value');
  97. ok(eval("[('many2many_one_entry', '=', 42)]", fields), 'many2many with one entry == value');
  98. ok(eval("[('many2many_multiple_entries', '=', 42)]", fields), 'many2many with multiple entries == value');
  99. ok(eval("[('many2many_multiple_entries', 'in', [42])]", fields), 'many2many with multiple entries in [value]');
  100. ok(eval("[('many2many_multiple_entries', 'not in', [44])]", fields), 'many2many with multiple entries not in [value]');
  101. });
  102. });