summaryrefslogtreecommitdiff
path: root/addons/web/static/tests
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2018-02-12 18:34:43 +0100
committerChristophe Simonis <chs@odoo.com>2018-02-12 18:34:43 +0100
commitadeea2a88db4443b2b426877a28bb1471c2f5db1 (patch)
tree2f43fecc9649947d3061e8c482219fa167b3385a /addons/web/static/tests
parent317f5f11112266128ac2292ecfafcd92cda74fd0 (diff)
parent0f02dcb63918228d48df50f2d5805b7fda25c14a (diff)
[MERGE] forward port branch saas-11.2 up to 0f02dcb6391
Diffstat (limited to 'addons/web/static/tests')
-rw-r--r--addons/web/static/tests/chrome/action_manager_tests.js6
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js4
-rw-r--r--addons/web/static/tests/helpers/test_utils.js132
-rw-r--r--addons/web/static/tests/views/calendar_tests.js58
-rw-r--r--addons/web/static/tests/views/form_tests.js119
-rw-r--r--addons/web/static/tests/views/kanban_tests.js57
-rw-r--r--addons/web/static/tests/views/list_tests.js142
-rw-r--r--addons/web/static/tests/views/pivot_tests.js29
-rw-r--r--addons/web/static/tests/views/view_dialogs_tests.js1
9 files changed, 481 insertions, 67 deletions
diff --git a/addons/web/static/tests/chrome/action_manager_tests.js b/addons/web/static/tests/chrome/action_manager_tests.js
index 23e59b2f03d..1ac0e56b7bd 100644
--- a/addons/web/static/tests/chrome/action_manager_tests.js
+++ b/addons/web/static/tests/chrome/action_manager_tests.js
@@ -1333,6 +1333,7 @@ QUnit.module('ActionManager', {
actions: this.actions,
archs: this.archs,
data: this.data,
+ services: [ReportService],
mockRPC: function (route, args) {
assert.step(args.method || route);
if (route === '/report/check_wkhtmltopdf') {
@@ -1340,7 +1341,6 @@ QUnit.module('ActionManager', {
}
return this._super.apply(this, arguments);
},
- services: [ReportService],
session: {
get_file: function (params) {
assert.step(params.url);
@@ -1373,6 +1373,7 @@ QUnit.module('ActionManager', {
actions: this.actions,
archs: this.archs,
data: this.data,
+ services: [ReportService],
mockRPC: function (route, args) {
assert.step(args.method || route);
if (route === '/report/check_wkhtmltopdf') {
@@ -1380,7 +1381,6 @@ QUnit.module('ActionManager', {
}
return this._super.apply(this, arguments);
},
- services: [ReportService],
session: {
get_file: function (params) {
assert.step(params.url);
@@ -1427,6 +1427,7 @@ QUnit.module('ActionManager', {
actions: this.actions,
archs: this.archs,
data: this.data,
+ services: [ReportService],
mockRPC: function (route, args) {
assert.step(args.method || route);
if (route === '/report/check_wkhtmltopdf') {
@@ -1437,7 +1438,6 @@ QUnit.module('ActionManager', {
}
return this._super.apply(this, arguments);
},
- services: [ReportService],
session: {
get_file: function (params) {
assert.step(params.url); // should not be called
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js
index 0a1fd9128e6..ecedd4c5bc5 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -6271,7 +6271,7 @@ QUnit.module('relational_fields', {
}
if (args.method === 'write') {
assert.deepEqual(args.args[1].timmy, [[6, false, [12]]],
- 'should properly write ids')
+ 'should properly write ids');
}
return this._super.apply(this, arguments);
},
@@ -9354,7 +9354,7 @@ QUnit.module('relational_fields', {
$input = form.$('.o_field_many2manytags span[data-id=13]'); // selects 'red' tag
$input.click(); // opens the colorpicker dropdown
assert.ok(form.$('.o_field_many2manytags span[data-id=13] .o_colorpicker .o_checkbox'), "should have a checkbox in the colorpicker dropdown menu");
-
+
$input.click();
var $checkBox = form.$('.o_field_many2manytags span[data-id=13] .o_colorpicker .o_checkbox input');
assert.notOk($checkBox.is(':checked'), "should have unticked checkbox in colorpicker dropdown menu");
diff --git a/addons/web/static/tests/helpers/test_utils.js b/addons/web/static/tests/helpers/test_utils.js
index d08beffb977..2d8e719ade4 100644
--- a/addons/web/static/tests/helpers/test_utils.js
+++ b/addons/web/static/tests/helpers/test_utils.js
@@ -19,7 +19,6 @@ var core = require('web.core');
var dom = require('web.dom');
var session = require('web.session');
var MockServer = require('web.MockServer');
-var utils = require('web.utils');
var Widget = require('web.Widget');
var DebouncedField = basic_fields.DebouncedField;
@@ -218,6 +217,7 @@ function createAsyncView(params) {
return view.getController(widget).then(function (view) {
// override the view's 'destroy' so that it calls 'destroy' on the widget
// instead, as the widget is the parent of the view and the mockServer.
+ view.__destroy = view.destroy;
view.destroy = function () {
// remove the override to properly destroy the view and its children
// when it will be called the second time (by its parent)
@@ -400,7 +400,7 @@ function addMockEnvironment(widget, params) {
// Dispatch service calls
// Note: some services could call other services at init,
// Which is why we have to init services after that
- var services = {};
+ var services = {ajax: null}; // mocked ajax service already loaded
intercept(widget, 'call_service', function (ev) {
var args, result;
if (ev.data.service === 'ajax') {
@@ -415,36 +415,22 @@ function addMockEnvironment(widget, params) {
}
ev.data.callback(result);
});
- // Instantiate services
- // Note: ensure topological sort of services based on their dependencies
- var sortServices = function (services) {
- // Create nodes (services), with ajax already loaded
- var nodes = { ajax: [] };
- _.each(services, function (Service) {
- nodes[Service.prototype.name] = Service.prototype.dependencies;
+
+ // Deploy services
+ var done = false;
+ while (!done) {
+ var index = _.findIndex(params.services, function (Service) {
+ return !_.some(Service.prototype.dependencies, function (depName) {
+ return !_.has(services, depName);
+ });
});
- var sorted;
- try {
- sorted = utils.topologicalSort(nodes);
- } catch (err) {
- console.warn('topologicalSort Error:', err.message);
- sorted = nodes;
+ if (index !== -1) {
+ var Service = params.services.splice(index, 1)[0];
+ services[Service.prototype.name] = new Service(widget);
+ } else {
+ done = true;
}
- // Remove ajax from sorted
- sorted = _.without(sorted, 'ajax');
- // Sort services based on sorted
- // Note: we convert sorted to an object key=>index for efficiency
- var sortedObj = _.invert(_.object(_.pairs(sorted)));
- sorted = _.sortBy(services, function (Service) {
- return sortedObj[Service.prototype.name];
- });
- return sorted;
- };
- var sortedServices = sortServices(params.services);
- _.each(sortedServices, function (Service) {
- var service = new Service(widget);
- services[service.name] = service;
- });
+ }
intercept(widget, 'load_action', function (event) {
mockServer.performRpc('/web/action/load', {
@@ -680,47 +666,83 @@ function removeSrcAttribute($el, widget) {
var patches = {};
/**
- * Patches a given Class with the given properties.
+ * Patches a given Class or Object with the given properties.
*
- * @param {Class} Klass
+ * @param {Class|Object} target
* @param {Object} props
*/
-function patch (Klass, props) {
+function patch (target, props) {
var patchID = _.uniqueId('patch_');
- Klass.__patchID = patchID;
+ target.__patchID = patchID;
patches[patchID] = {
- Klass: Klass,
+ target: target,
otherPatchedProps: [],
ownPatchedProps: [],
};
- _.each(props, function (value, key) {
- if (Klass.prototype.hasOwnProperty(key)) {
- patches[patchID].ownPatchedProps.push({
- key: key,
- initialValue: Klass.prototype[key],
- });
- } else {
- patches[patchID].otherPatchedProps.push(key);
- }
- });
- Klass.include(props);
+ if (target.prototype) {
+ _.each(props, function (value, key) {
+ if (target.prototype.hasOwnProperty(key)) {
+ patches[patchID].ownPatchedProps.push({
+ key: key,
+ initialValue: target.prototype[key],
+ });
+ } else {
+ patches[patchID].otherPatchedProps.push(key);
+ }
+ });
+ target.include(props);
+ } else {
+ _.each(props, function (value, key) {
+ if (key in target) {
+ var oldValue = target[key];
+ patches[patchID].ownPatchedProps.push({
+ key: key,
+ initialValue: oldValue,
+ });
+ if (typeof value === 'function') {
+ target[key] = function () {
+ var oldSuper = this._super;
+ this._super = oldValue;
+ var result = value.apply(this, arguments);
+ if (oldSuper === undefined) {
+ delete this._super;
+ } else {
+ this._super = oldSuper;
+ }
+ return result;
+ };
+ } else {
+ target[key] = value;
+ }
+ } else {
+ patches[patchID].otherPatchedProps.push(key);
+ target[key] = value;
+ }
+ });
+ }
}
/**
- * Unpatches a given Class.
+ * Unpatches a given Class or Object.
*
- * @param {Class} Klass
+ * @param {Class|Object} target
*/
-function unpatch(Klass) {
- var patchID = Klass.__patchID;
+function unpatch(target) {
+ var patchID = target.__patchID;
var patch = patches[patchID];
_.each(patch.ownPatchedProps, function (p) {
- Klass[p.key] = p.initialValue;
- });
- _.each(patch.otherPatchedProps, function (key) {
- delete Klass.prototype[key];
+ target[p.key] = p.initialValue;
});
+ if (target.prototype) {
+ _.each(patch.otherPatchedProps, function (key) {
+ delete target.prototype[key];
+ });
+ } else {
+ _.each(patch.otherPatchedProps, function (key) {
+ delete target[key];
+ });
+ }
delete patches[patchID];
- delete Klass.__patchID;
+ delete target.__patchID;
}
// Loading static files cannot be properly simulated when their real content is
diff --git a/addons/web/static/tests/views/calendar_tests.js b/addons/web/static/tests/views/calendar_tests.js
index 3bc412910c2..478f53331b4 100644
--- a/addons/web/static/tests/views/calendar_tests.js
+++ b/addons/web/static/tests/views/calendar_tests.js
@@ -5,6 +5,7 @@ var CalendarView = require('web.CalendarView');
var CalendarRenderer = require('web.CalendarRenderer');
var Dialog = require('web.Dialog');
var fieldUtils = require('web.field_utils');
+var mixins = require('web.mixins');
var testUtils = require('web.test_utils');
var session = require('web.session');
@@ -1629,6 +1630,63 @@ QUnit.module('Views', {
calendar.destroy();
});
+ QUnit.test('check if the view destroys all widgets and instances', function (assert) {
+ assert.expect(1);
+
+ var instanceNumber = 0;
+ testUtils.patch(mixins.ParentedMixin, {
+ init: function () {
+ instanceNumber++;
+ return this._super.apply(this, arguments);
+ },
+ destroy: function () {
+ if (!this.isDestroyed()) {
+ instanceNumber--;
+ }
+ return this._super.apply(this, arguments);
+ }
+ });
+
+ var params = {
+ View: CalendarView,
+ model: 'event',
+ data: this.data,
+ arch:
+ '<calendar class="o_calendar_test" '+
+ 'event_open_popup="true" '+
+ 'date_start="start_date" '+
+ 'all_day="allday" '+
+ 'mode="week" '+
+ 'attendee="partner_ids" '+
+ 'color="partner_id">'+
+ '<field name="name"/>'+
+ '<filter name="user_id" avatar_field="image"/>'+
+ '<field name="partner_ids" write_model="filter_partner" write_field="partner_id"/>'+
+ '</calendar>',
+ archs: archs,
+ viewOptions: {
+ initialDate: initialDate,
+ },
+ };
+
+ var calendar = createView(params);
+ calendar.destroy();
+
+ var initialInstanceNumber = instanceNumber;
+ instanceNumber = 0;
+
+ calendar = createView(params);
+
+ // call destroy function of controller to ensure that it correctly destroys everything
+ calendar.__destroy();
+
+ assert.strictEqual(instanceNumber, initialInstanceNumber + 3, "every widget must be destroyed exept the parent");
+
+ calendar.destroy();
+
+ testUtils.unpatch(mixins.ParentedMixin);
+ });
+
QUnit.test('create an event (async dialog) [REQUIRE FOCUS]', function (assert) {
assert.expect(3);
diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js
index 37420e0f076..5b0dd69ddd4 100644
--- a/addons/web/static/tests/views/form_tests.js
+++ b/addons/web/static/tests/views/form_tests.js
@@ -7,6 +7,7 @@ var config = require('web.config');
var core = require('web.core');
var fieldRegistry = require('web.field_registry');
var FormView = require('web.FormView');
+var mixins = require('web.mixins');
var pyeval = require('web.pyeval');
var testUtils = require('web.test_utils');
var widgetRegistry = require('web.widget_registry');
@@ -629,7 +630,7 @@ QUnit.module('Views', {
});
QUnit.test('readonly attrs on fields are re-evaluated on field change', function (assert) {
- assert.expect(3);
+ assert.expect(4);
var form = createView({
View: FormView,
@@ -655,6 +656,9 @@ QUnit.module('Views', {
form.$('.o_field_boolean input').click();
assert.strictEqual(form.$('span[name="foo"]').length, 1,
"the foo field widget should have been rerendered to now be readonly again");
+ form.$('.o_field_boolean input').click();
+ assert.strictEqual(form.$('input[name="foo"]').length, 1,
+ "the foo field widget should have been rerendered to now be editable again");
form.destroy();
});
@@ -6249,6 +6253,41 @@ QUnit.module('Views', {
form.destroy();
});
+ QUnit.test('basic support for widgets', function (assert) {
+ assert.expect(1);
+
+ var MyWidget = Widget.extend({
+ init: function (parent, dataPoint) {
+ this.data = dataPoint.data;
+ },
+ start: function () {
+ this.$el.text(this.data.foo + "!");
+ },
+ updateState: function (dataPoint) {
+ this.$el.text(dataPoint.data.foo + "!");
+ },
+ });
+ widgetRegistry.add('test', MyWidget);
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form string="Partners">' +
+ '<field name="foo"/>' +
+ '<widget name="test"/>' +
+ '</form>',
+ });
+
+ form.$('input[name="foo"]').val("I am alive").trigger('input');
+ assert.strictEqual(form.$('.o_widget').text(), 'I am alive!',
+ "widget should have been updated");
+
+ form.destroy();
+ delete widgetRegistry.map.test;
+ });
+
+
QUnit.test('bounce edit button in readonly mode', function (assert) {
assert.expect(3);
@@ -6360,6 +6399,84 @@ QUnit.module('Views', {
form.destroy();
});
+ QUnit.test('check if the view destroys all widgets and instances', function (assert) {
+ assert.expect(1);
+
+ var instanceNumber = 0;
+ testUtils.patch(mixins.ParentedMixin, {
+ init: function () {
+ instanceNumber++;
+ return this._super.apply(this, arguments);
+ },
+ destroy: function () {
+ if (!this.isDestroyed()) {
+ instanceNumber--;
+ }
+ return this._super.apply(this, arguments);
+ }
+ });
+
+ var params = {
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form string="Partners">' +
+ '<sheet>' +
+ '<field name="display_name"/>' +
+ '<field name="foo"/>' +
+ '<field name="bar"/>' +
+ '<field name="int_field"/>' +
+ '<field name="qux"/>' +
+ '<field name="trululu"/>' +
+ '<field name="timmy"/>' +
+ '<field name="product_id"/>' +
+ '<field name="priority"/>' +
+ '<field name="state"/>' +
+ '<field name="date"/>' +
+ '<field name="datetime"/>' +
+ '<field name="product_ids"/>' +
+ '<field name="p">' +
+ '<tree default_order="foo desc">' +
+ '<field name="display_name"/>' +
+ '<field name="foo"/>' +
+ '</tree>' +
+ '</field>' +
+ '</sheet>' +
+ '</form>',
+ archs: {
+ 'partner,false,form':
+ '<form string="Partner">' +
+ '<sheet>' +
+ '<group>' +
+ '<field name="foo"/>' +
+ '</group>' +
+ '</sheet>' +
+ '</form>',
+ "partner_type,false,list": '<tree><field name="name"/></tree>',
+ 'product,false,list': '<tree><field name="display_name"/></tree>',
+
+ },
+ res_id: 1,
+ };
+
+ var form = createView(params);
+ form.destroy();
+
+ var initialInstanceNumber = instanceNumber;
+ instanceNumber = 0;
+
+ form = createView(params);
+
+ // call destroy function of controller to ensure that it correctly destroys everything
+ form.__destroy();
+
+ assert.strictEqual(instanceNumber, initialInstanceNumber + 3, "every widget must be destroyed exept the parent");
+
+ form.destroy();
+
+ testUtils.unpatch(mixins.ParentedMixin);
+ });
+
QUnit.test('edition in form view on a "noCache" model', function (assert) {
assert.expect(4);
diff --git a/addons/web/static/tests/views/kanban_tests.js b/addons/web/static/tests/views/kanban_tests.js
index 0bea1567d49..f5c31c05c8b 100644
--- a/addons/web/static/tests/views/kanban_tests.js
+++ b/addons/web/static/tests/views/kanban_tests.js
@@ -5,6 +5,7 @@ var KanbanColumnProgressBar = require('web.KanbanColumnProgressBar');
var kanbanExamplesRegistry = require('web.kanban_examples_registry');
var KanbanRenderer = require('web.KanbanRenderer');
var KanbanView = require('web.KanbanView');
+var mixins = require('web.mixins');
var testUtils = require('web.test_utils');
var Widget = require('web.Widget');
var widgetRegistry = require('web.widget_registry');
@@ -3346,6 +3347,62 @@ QUnit.module('Views', {
kanban.destroy();
});
+
+ QUnit.test('check if the view destroys all widgets and instances', function (assert) {
+ assert.expect(1);
+
+ var instanceNumber = 0;
+ testUtils.patch(mixins.ParentedMixin, {
+ init: function () {
+ instanceNumber++;
+ return this._super.apply(this, arguments);
+ },
+ destroy: function () {
+ if (!this.isDestroyed()) {
+ instanceNumber--;
+ }
+ return this._super.apply(this, arguments);
+ }
+ });
+
+ var params = {
+ View: KanbanView,
+ model: 'partner',
+ data: this.data,
+ arch: '<kanban string="Partners">' +
+ '<field name="foo"/>' +
+ '<field name="bar"/>' +
+ '<field name="int_field"/>' +
+ '<field name="qux"/>' +
+ '<field name="product_id"/>' +
+ '<field name="category_ids"/>' +
+ '<field name="state"/>' +
+ '<field name="date"/>' +
+ '<field name="datetime"/>' +
+ '<templates><t t-name="kanban-box">' +
+ '<div><field name="foo"/></div>' +
+ '</t></templates>' +
+ '</kanban>',
+ };
+
+ var kanban = createView(params);
+ kanban.destroy();
+
+ var initialInstanceNumber = instanceNumber;
+ instanceNumber = 0;
+
+ kanban = createView(params);
+
+ // call destroy function of controller to ensure that it correctly destroys everything
+ kanban.__destroy();
+
+ assert.strictEqual(instanceNumber, initialInstanceNumber + 3, "every widget must be destroyed exept the parent");
+
+ kanban.destroy();
+
+ testUtils.unpatch(mixins.ParentedMixin);
+ });
+
});
});
diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js
index cfe00bf9141..4f22945250a 100644
--- a/addons/web/static/tests/views/list_tests.js
+++ b/addons/web/static/tests/views/list_tests.js
@@ -7,6 +7,7 @@ var core = require('web.core');
var basicFields = require('web.basic_fields');
var FormView = require('web.FormView');
var ListView = require('web.ListView');
+var mixins = require('web.mixins');
var testUtils = require('web.test_utils');
var widgetRegistry = require('web.widget_registry');
var Widget = require('web.Widget');
@@ -583,6 +584,40 @@ QUnit.module('Views', {
list.destroy();
});
+ QUnit.test('selection is reset on reload', function (assert) {
+ assert.expect(5);
+
+ var list = createView({
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: '<tree>' +
+ '<field name="foo"/>' +
+ '<field name="int_field" sum="Sum"/>' +
+ '</tree>',
+ });
+
+ assert.strictEqual(list.$('tfoot td:nth(2)').text(), '32',
+ "total should be 32 (no record selected)");
+
+ // select first record
+ var $firstRowSelector = list.$('tbody .o_list_record_selector input').first();
+ $firstRowSelector.click();
+ assert.ok($firstRowSelector.is(':checked'), "first row should be selected");
+ assert.strictEqual(list.$('tfoot td:nth(2)').text(), '10',
+ "total should be 10 (first record selected)");
+
+ // reload
+ list.reload();
+ $firstRowSelector = list.$('tbody .o_list_record_selector input').first();
+ assert.notOk($firstRowSelector.is(':checked'),
+ "first row should no longer be selected");
+ assert.strictEqual(list.$('tfoot td:nth(2)').text(), '32',
+ "total should be 32 (no more record selected)");
+
+ list.destroy();
+ });
+
QUnit.test('aggregates are computed correctly', function (assert) {
assert.expect(4);
@@ -661,6 +696,25 @@ QUnit.module('Views', {
list.destroy();
});
+ QUnit.test('aggregates are formatted according to field widget', function (assert) {
+ assert.expect(1);
+
+ var list = createView({
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: '<tree>' +
+ '<field name="foo"/>' +
+ '<field name="qux" widget="float_time" sum="Sum"/>' +
+ '</tree>',
+ });
+
+ assert.strictEqual(list.$('tfoot td:nth(2)').text(), '19:24',
+ "total should be formatted as a float_time");
+
+ list.destroy();
+ });
+
QUnit.test('groups can be sorted on aggregates', function (assert) {
assert.expect(10);
@@ -1930,7 +1984,7 @@ QUnit.module('Views', {
});
QUnit.test('readonly attrs on fields are re-evaluated on field change', function (assert) {
- assert.expect(7);
+ assert.expect(9);
var list = createView({
View: ListView,
@@ -1964,9 +2018,14 @@ QUnit.module('Views', {
assert.strictEqual(list.$('tbody td.o_readonly_modifier').length, 3,
"the foo field widget parent cell should now be readonly again");
- // Reswitch the cell to editable and save the row
list.$('tbody tr:nth(0) td:nth(2) input').click();
- list.$('thead').click();
+ assert.strictEqual(list.$('tbody tr:nth(0) td:nth(1) > input[name="foo"]').length, 1,
+ "the foo field widget should have been rerendered as editable again");
+ assert.strictEqual(list.$('tbody td.o_readonly_modifier').length, 2,
+ "the foo field widget parent cell should not be readonly again");
+
+ // Click outside to leave edition mode
+ list.$el.click();
assert.strictEqual(list.$('tbody td.o_readonly_modifier').length, 2,
"there should be 2 readonly foo cells in readonly mode");
@@ -2772,6 +2831,28 @@ QUnit.module('Views', {
list.destroy();
});
+ QUnit.test('pressing ESC discard the current line changes (with required)', function (assert) {
+ assert.expect(3);
+
+ var list = createView({
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: '<tree editable="top"><field name="foo" required="1"/></tree>',
+ });
+
+ list.$buttons.find('.o_list_button_add').click();
+
+ list.$('input[name="foo"]').trigger({type: 'keydown', which: $.ui.keyCode.ESCAPE});
+ assert.strictEqual(list.$('tr.o_data_row').length, 4,
+ "should have 4 data row in list");
+ assert.strictEqual(list.$('tr.o_data_row.o_selected_row').length, 0,
+ "no rows should be selected");
+ assert.ok(!list.$buttons.find('.o_list_button_save').is(':visible'),
+ "should not have a visible save button");
+ list.destroy();
+ });
+
QUnit.test('field with password attribute', function (assert) {
assert.expect(2);
@@ -3223,6 +3304,61 @@ QUnit.module('Views', {
list.destroy();
});
+ QUnit.test('check if the view destroys all widgets and instances', function (assert) {
+ assert.expect(1);
+
+ var instanceNumber = 0;
+ testUtils.patch(mixins.ParentedMixin, {
+ init: function () {
+ instanceNumber++;
+ return this._super.apply(this, arguments);
+ },
+ destroy: function () {
+ if (!this.isDestroyed()) {
+ instanceNumber--;
+ }
+ return this._super.apply(this, arguments);
+ }
+ });
+
+ var params = {
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: '<tree string="Partners">' +
+ '<field name="foo"/>' +
+ '<field name="bar"/>' +
+ '<field name="date"/>' +
+ '<field name="int_field"/>' +
+ '<field name="qux"/>' +
+ '<field name="m2o"/>' +
+ '<field name="o2m"/>' +
+ '<field name="m2m"/>' +
+ '<field name="amount"/>' +
+ '<field name="currency_id"/>' +
+ '<field name="datetime"/>' +
+ '<field name="reference"/>' +
+ '</tree>',
+ };
+
+ var list = createView(params);
+ list.destroy();
+
+ var initialInstanceNumber = instanceNumber;
+ instanceNumber = 0;
+
+ list = createView(params);
+
+ // call destroy function of controller to ensure that it correctly destroys everything
+ list.__destroy();
+
+ assert.strictEqual(instanceNumber, initialInstanceNumber + 3, "every widget must be destroyed exept the parent");
+
+ list.destroy();
+
+ testUtils.unpatch(mixins.ParentedMixin);
+ });
+
QUnit.test('list view on a "noCache" model', function (assert) {
assert.expect(8);
diff --git a/addons/web/static/tests/views/pivot_tests.js b/addons/web/static/tests/views/pivot_tests.js
index 94d4bcf36b8..1fcc03ee483 100644
--- a/addons/web/static/tests/views/pivot_tests.js
+++ b/addons/web/static/tests/views/pivot_tests.js
@@ -1,7 +1,6 @@
odoo.define('web.pivot_tests', function (require) {
"use strict";
-var Context = require('web.Context');
var core = require('web.core');
var PivotView = require('web.PivotView');
var testUtils = require('web.test_utils');
@@ -739,7 +738,33 @@ QUnit.module('Views', {
},
});
- $('.o_pivot_download').click();
+ pivot.$buttons.find('.o_pivot_download').click();
+ pivot.destroy();
+ });
+
+ QUnit.test('can download a file without data', function (assert) {
+ assert.expect(1);
+
+ this.data.partner.records = [];
+
+ var pivot = createView({
+ View: PivotView,
+ model: "partner",
+ data: this.data,
+ arch: '<pivot>' +
+ '<field name="date" interval="month" type="col"/>' +
+ '<field name="foo" type="measure"/>' +
+ '</pivot>',
+ session: {
+ get_file: function (args) {
+ assert.strictEqual(args.url, '/web/pivot/export_xls',
+ "should call get_file with correct parameters");
+ args.complete();
+ },
+ },
+ });
+
+ pivot.$buttons.find('.o_pivot_download').click();
pivot.destroy();
});
diff --git a/addons/web/static/tests/views/view_dialogs_tests.js b/addons/web/static/tests/views/view_dialogs_tests.js
index 08ddd2c91c2..014435194f3 100644
--- a/addons/web/static/tests/views/view_dialogs_tests.js
+++ b/addons/web/static/tests/views/view_dialogs_tests.js
@@ -21,7 +21,6 @@ QUnit.module('Views', {
],
},
};
-
},
}, function () {