summaryrefslogtreecommitdiff
path: root/addons/web/static/tests
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2017-08-10 17:01:05 +0200
committerChristophe Simonis <chs@odoo.com>2017-08-10 17:01:05 +0200
commit48b2ce60ed12b9b0f3aaa0322465504798bd154e (patch)
tree0ac2c53a78f678ad4701943eb9eab6a4c8f5ff48 /addons/web/static/tests
parent298eaca4d1e268c43185e9c1dd6d6973e02d9b57 (diff)
parent85571bb78c9acc4e867cc3b480be9236a756fc22 (diff)
[MERGE] forward port branch saas-16 up to 85571bb78c9
Diffstat (limited to 'addons/web/static/tests')
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js251
-rw-r--r--addons/web/static/tests/views/basic_model_tests.js59
-rw-r--r--addons/web/static/tests/views/calendar_tests.js42
-rw-r--r--addons/web/static/tests/views/form_tests.js15
-rw-r--r--addons/web/static/tests/views/list_tests.js14
5 files changed, 366 insertions, 15 deletions
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js
index 0ad9aa2a416..29f8666455a 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -922,6 +922,140 @@ QUnit.module('relational_fields', {
});
});
+ QUnit.test('list in form: create with one2many with many2one', function (assert) {
+ assert.expect(1);
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form>' +
+ '<sheet>' +
+ '<field name="p">' +
+ '<tree editable="bottom">' +
+ '<field name="display_name"/>' +
+ '<field name="trululu"/>' +
+ '</tree>' +
+ '</field>' +
+ '</sheet>' +
+ '</form>',
+ mockRPC: function (route, args) {
+ if (args.method === 'default_get') {
+ return $.when({p: [[0, 0, {display_name: 'new record'}]]});
+ } else if (args.method === 'name_get') {
+ // This should not be called at all and thus is not accounted for
+ // in the assert.expect. If this is called, you broke this test.
+ assert.notOk(_.str.startsWith(args.args[0][0], 'virtual_'),
+ "should not call name_get for the m2o inside o2m which has no value");
+ }
+ return this._super.apply(this, arguments);
+ },
+ });
+
+ assert.strictEqual($('td.o_data_cell:first').text(), 'new record',
+ "should have created the new record in the o2m with the correct name");
+
+ form.destroy();
+ });
+
+ QUnit.test('list in form: default_get with x2many create', function (assert) {
+ assert.expect(3);
+
+ this.data.partner.onchanges.timmy = function (obj) {
+ assert.deepEqual(
+ obj.timmy,
+ [
+ [6, false, []],
+ [0, false, {display_name: 'brandon is the new timmy', name: 'brandon'}]
+ ],
+ "should have properly created the x2many command list");
+ obj.int_field = obj.timmy.length;
+ };
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form>' +
+ '<sheet>' +
+ '<field name="timmy">' +
+ '<tree editable="bottom">' +
+ '<field name="display_name"/>' +
+ '</tree>' +
+ '</field>' +
+ '<field name="int_field"/>' +
+ '</sheet>' +
+ '</form>',
+ mockRPC: function (route, args) {
+ if (args.method === 'default_get') {
+ return $.when({timmy: [[0, 0, {display_name: 'brandon is the new timmy', name: 'brandon'}]]});
+ }
+ return this._super.apply(this, arguments);
+ },
+ });
+
+ assert.strictEqual($('td.o_data_cell:first').text(), 'brandon is the new timmy',
+ "should have created the new record in the m2m with the correct name");
+ assert.strictEqual($('input.o_field_integer').val(), '2',
+ "should have called and executed the onchange properly");
+
+ form.destroy();
+ });
+
+ QUnit.test('list in form: call button in sub view', function (assert) {
+ assert.expect(6);
+
+ this.data.partner.records[0].p = [2];
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form>' +
+ '<sheet>' +
+ '<field name="p">' +
+ '<tree editable="bottom">' +
+ '<field name="product_id"/>' +
+ '</tree>' +
+ '</field>' +
+ '</sheet>' +
+ '</form>',
+ res_id: 1,
+ mockRPC: function (route, args) {
+ if (route === '/web/dataset/call_kw/product/get_formview_id') {
+ return $.when(false);
+ }
+ return this._super.apply(this, arguments);
+ },
+ intercepts: {
+ execute_action: function (event) {
+ assert.strictEqual(event.data.env.model, 'product',
+ 'should call with correct model in env');
+ assert.strictEqual(event.data.env.currentID, 37,
+ 'should call with correct currentID in env');
+ assert.deepEqual(event.data.env.resIDs, [37],
+ 'should call with correct resIDs in env');
+ },
+ },
+ archs: {
+ 'product,false,form': '<form string="Partners">' +
+ '<header>' +
+ '<button name="action" type="action" string="Just do it !"/>' +
+ '<button name="object" type="object" string="Just don\'t do it !"/>' +
+ '<field name="display_name"/>' +
+ '</header>' +
+ '</form>',
+ },
+ });
+
+ form.$buttons.find('.o_form_button_edit').click();
+ form.$('td.o_data_cell:first').click(); // edit first one2many line
+ form.$('.o_external_button').click(); // open product sub view in modal
+ $('button:contains("Just do it !")').click(); // click on action button
+ $('button:contains("Just don\'t do it !")').click(); // click on object button
+
+ form.destroy();
+ });
+
QUnit.test('autocompletion in a many2one, in form view with a domain', function (assert) {
assert.expect(1);
@@ -1418,6 +1552,115 @@ QUnit.module('relational_fields', {
form.destroy();
});
+ QUnit.test('many2one in one2many: domain updated by an onchange', function (assert) {
+ assert.expect(3);
+
+ this.data.partner.onchanges = {
+ trululu: function () {},
+ };
+
+ var domain = [];
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form>' +
+ '<field name="p">' +
+ '<tree editable="bttom">' +
+ '<field name="trululu"/>' +
+ '</tree>' +
+ '</field>' +
+ '</form>',
+ res_id: 1,
+ mockRPC: function (route, args) {
+ if (args.method === 'onchange') {
+ return $.when({
+ domain: {
+ trululu: domain,
+ },
+ });
+ }
+ if (args.method === 'name_search') {
+ assert.deepEqual(args.kwargs.args, domain,
+ "sent domain should be correct");
+ }
+ return this._super(route, args);
+ },
+ viewOptions: {
+ mode: 'edit',
+ },
+ });
+
+ // add a first row with a specific domain for the m2o
+ domain = [['id', 'in', [10]]]; // domain for subrecord 1
+ form.$('.o_field_x2many_list_row_add a').click(); // triggers the onchange
+ form.$('.o_field_widget[name=trululu] input').click(); // triggers the name_search
+
+ // add a second row with another domain for the m2o
+ domain = [['id', 'in', [5]]]; // domain for subrecord 2
+ form.$('.o_field_x2many_list_row_add a').click(); // triggers the onchange
+ form.$('.o_field_widget[name=trululu] input').click(); // triggers the name_search
+
+ // check again the first row to ensure that the domain hasn't change
+ domain = [['id', 'in', [10]]]; // domain for subrecord 1 should have been kept
+ form.$('.o_data_row:first .o_data_cell').click();
+ form.$('.o_field_widget[name=trululu] input').click(); // triggers the name_search
+
+ form.destroy();
+ });
+
+ QUnit.test('updating a many2one from a many2many', function (assert) {
+ assert.expect(4);
+
+ this.data.turtle.records[1].turtle_trululu = 1;
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form string="Partners">' +
+ '<group>' +
+ '<field name="turtles">' +
+ '<tree editable="bottom">' +
+ '<field name="display_name"/>' +
+ '<field name="turtle_trululu"/>' +
+ '</tree>' +
+ '</field>' +
+ '</group>' +
+ '</form>',
+ res_id: 1,
+ archs: {
+ 'partner,false,form': '<form string="Trululu"><field name="display_name"/></form>',
+ },
+ mockRPC: function (route, args) {
+ if (args.method === 'get_formview_id') {
+ assert.deepEqual(args.args[0], [1], "should call get_formview_id with correct id");
+ return $.when(false);
+ }
+ return this._super(route, args);
+ },
+ });
+
+ // Opening the modal
+ form.$buttons.find('.o_form_button_edit').click();
+ form.$('.o_data_row td:contains(first record)').click();
+ form.$('.o_external_button').click();
+ assert.strictEqual($('.modal').length, 1,
+ "should have one modal in body");
+
+ // Changing the 'trululu' value
+ $('.modal input[name="display_name"]').val('test').trigger('input');
+ $('.modal button.btn-primary').click();
+
+ // Test whether the value has changed
+ assert.strictEqual($('.modal').length, 0,
+ "the modal should be closed");
+ assert.equal(form.$('.o_data_cell:contains(test)').text(), 'test',
+ "the partner name should have been updated to 'test'");
+
+ form.destroy();
+ });
+
QUnit.module('FieldOne2Many');
QUnit.test('one2many basic properties', function (assert) {
@@ -3847,9 +4090,9 @@ QUnit.module('relational_fields', {
res_id: 1,
intercepts: {
execute_action: function (event) {
- assert.deepEqual(event.data.res_ids, [2],
+ assert.deepEqual(event.data.env.currentID, 2,
'should call with correct id');
- assert.strictEqual(event.data.model, 'partner',
+ assert.strictEqual(event.data.env.model, 'partner',
'should call with correct model');
assert.strictEqual(event.data.action_data.name, 'method_name',
"should call correct method");
@@ -3891,9 +4134,9 @@ QUnit.module('relational_fields', {
res_id: 1,
intercepts: {
execute_action: function (event) {
- assert.deepEqual(event.data.res_ids, [2],
+ assert.deepEqual(event.data.env.currentID, 2,
'should call with correct id');
- assert.strictEqual(event.data.model, 'partner',
+ assert.strictEqual(event.data.env.model, 'partner',
'should call with correct model');
assert.strictEqual(event.data.action_data.name, 'method_name',
"should call correct method");
diff --git a/addons/web/static/tests/views/basic_model_tests.js b/addons/web/static/tests/views/basic_model_tests.js
index 53577d90e40..8c23fc4f97c 100644
--- a/addons/web/static/tests/views/basic_model_tests.js
+++ b/addons/web/static/tests/views/basic_model_tests.js
@@ -956,6 +956,30 @@ QUnit.module('Views', {
model.destroy();
});
+ QUnit.test('group on date field with magic grouping method', function (assert) {
+ assert.expect(1);
+
+ this.params.fieldNames = ['foo'];
+ this.params.groupedBy = ['date:month'];
+ this.params.res_id = undefined;
+
+ var model = createModel({
+ Model: BasicModel,
+ data: this.data,
+ mockRPC: function (route, args) {
+ if (args.method === 'read_group') {
+ assert.deepEqual(args.kwargs.fields, ['foo', 'date'],
+ "should have correctly trimmed the magic grouping info from the field name");
+ }
+ return this._super.apply(this, arguments);
+ },
+ });
+
+ model.load(this.params);
+ model.destroy();
+ });
+
+
QUnit.test('read group when grouped by a selection field', function (assert) {
assert.expect(5);
@@ -1949,4 +1973,39 @@ QUnit.module('Views', {
model.destroy();
});
+ QUnit.test('reload a new record', function (assert) {
+ assert.expect(6);
+
+ this.params.context = {};
+ this.params.fieldNames = ['product_id', 'category', 'product_ids'];
+ this.params.res_id = undefined;
+ this.params.type = 'record';
+
+ var model = createModel({
+ Model: BasicModel,
+ data: this.data,
+ mockRPC: function (route, args) {
+ assert.step(args.method);
+ return this._super(route, args);
+ },
+ });
+
+ model.load(this.params).then(function (recordID) {
+ model.reload(recordID).then(function (recordID) {
+ assert.verifySteps(['default_get', 'default_get'],
+ "two default_get RPCs should have been done");
+ var record = model.get(recordID);
+ assert.strictEqual(record.data.product_id, false,
+ "m2o default value should be false");
+ assert.deepEqual(record.data.product_ids.data, [],
+ "o2m default should be []");
+ assert.deepEqual(record.data.category.data, [],
+ "m2m default should be []");
+ });
+ });
+
+ model.destroy();
+ });
+
+
});});
diff --git a/addons/web/static/tests/views/calendar_tests.js b/addons/web/static/tests/views/calendar_tests.js
index 31b1babc9b3..6aa01daac5a 100644
--- a/addons/web/static/tests/views/calendar_tests.js
+++ b/addons/web/static/tests/views/calendar_tests.js
@@ -789,7 +789,7 @@ QUnit.module('Views', {
assert.strictEqual($event1Avatars.find('span').length, 0,
"should not have a span for more attendees since there is only one");
- var $event2Avatars = calendar.$('.fc-event:contains(All the day) .o_calendar_avatars');
+ var $event2Avatars = calendar.$('.fc-event:contains(All day) .o_calendar_avatars');
assert.strictEqual($event2Avatars.find('img').length, 3, "should have 3 avatars");
assert.strictEqual($event2Avatars.find('span').text(), '+2',
"should indicate there are 2 more attendees that we don't show");
@@ -1034,6 +1034,46 @@ QUnit.module('Views', {
"should display 5 events");
calendar.destroy();
});
+
+ QUnit.test('events starting at midnight', function (assert) {
+ assert.expect(2);
+
+ var calendar = createView({
+ View: CalendarView,
+ model: 'event',
+ data: this.data,
+ arch: '<calendar mode="week" date_start="start"/>',
+ viewOptions: {
+ initialDate: initialDate,
+ },
+ });
+
+ // Click on Tuesday 12am
+ var $view = $('#qunit-fixture').contents();
+ $view.prependTo('body');
+ var top = calendar.$('.fc-axis:contains(12am)').offset().top + 5;
+ var left = calendar.$('.fc-day:eq(2)').offset().left + 5;
+ try {
+ testUtils.triggerPositionalMouseEvent(left, top, "mousedown");
+ testUtils.triggerPositionalMouseEvent(left, top, "mouseup");
+ } catch (e) {
+ calendar.destroy();
+ $view.remove();
+ throw new Error('The test failed to simulate a click on the screen.' +
+ 'Your screen is probably too small or your dev tools are open.');
+ }
+ assert.ok($('.modal-dialog.modal-sm').length,
+ "should open the quick create dialog");
+
+ // Creating the event
+ $('.modal-body input:first').val('new event in quick create').trigger('input');
+ $('.modal button.btn:contains(Create)').trigger('click').trigger('click');
+ assert.strictEqual(calendar.$('.fc-event:contains(new event in quick create)').length, 1,
+ "should display the new record");
+
+ calendar.destroy();
+ $view.remove();
+ });
});
});
diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js
index 7eed1a2d100..26d15e33c2a 100644
--- a/addons/web/static/tests/views/form_tests.js
+++ b/addons/web/static/tests/views/form_tests.js
@@ -903,7 +903,7 @@ QUnit.module('Views', {
testUtils.intercept(form, 'execute_action', function (event) {
assert.strictEqual(event.data.action_data.name, "post",
"should trigger execute_action with correct method name");
- assert.deepEqual(event.data.res_ids, [2], "should have correct id in event data");
+ assert.deepEqual(event.data.env.currentID, 2, "should have correct id in event data");
event.data.on_success();
event.data.on_closed();
});
@@ -956,7 +956,7 @@ QUnit.module('Views', {
testUtils.intercept(form, 'execute_action', function (event) {
assert.step('execute_action');
- assert.deepEqual(event.data.res_ids, [resID],
+ assert.deepEqual(event.data.env.currentID, resID,
"execute action should be done on correct record id");
event.data.on_success();
event.data.on_closed();
@@ -1006,7 +1006,7 @@ QUnit.module('Views', {
testUtils.intercept(form, 'execute_action', function (event) {
assert.step('execute_action');
- assert.deepEqual(event.data.res_ids, [resID],
+ assert.deepEqual(event.data.env.currentID, resID,
"execute action should be done on correct record id");
event.data.on_success();
event.data.on_closed();
@@ -3597,8 +3597,9 @@ QUnit.module('Views', {
},
intercepts: {
execute_action: function (e) {
- assert.deepEqual(e.data.action_data.context, {test: 2},
- "button context should have been evaluated and given to the action, without previous context");
+ assert.deepEqual(e.data.action_data.context, {
+ 'test': 2
+ }, "button context should have been evaluated and given to the action, with magicc without previous context");
},
},
});
@@ -3631,8 +3632,8 @@ QUnit.module('Views', {
},
intercepts: {
execute_action: function (e) {
- assert.deepEqual(e.data.action_data.context, {},
- "button context should have been evaluated and given to the action, without previous context");
+ assert.deepEqual(e.data.action_data.context, {
+ }, "button context should have been evaluated and given to the action, with magic keys but without previous context");
},
},
});
diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js
index f0370ac7cf8..2247a64fa3c 100644
--- a/addons/web/static/tests/views/list_tests.js
+++ b/addons/web/static/tests/views/list_tests.js
@@ -984,7 +984,7 @@ QUnit.module('Views', {
});
QUnit.test('list view, editable, without data', function (assert) {
- assert.expect(9);
+ assert.expect(11);
this.data.foo.records = [];
@@ -998,6 +998,7 @@ QUnit.module('Views', {
'<field name="date"/>' +
'<field name="m2o"/>' +
'<field name="foo"/>' +
+ '<button type="object" icon="fa-plus-square" name="method"/>' +
'</tree>',
viewOptions: {
action: {
@@ -1033,7 +1034,14 @@ QUnit.module('Views', {
assert.strictEqual(list.$('tbody tr:eq(0) td:eq(1)').text().trim(), "",
"the date field td should not have any content");
+ assert.strictEqual(list.$('.o_list_button button').prop('disabled'), true,
+ "buttons should be disabled while the record is not yet created");
+
list.$buttons.find('.o_list_button_save').click();
+
+ assert.strictEqual(list.$('.o_list_button button').prop('disabled'), false,
+ "buttons should not be disabled once the record is created");
+
list.destroy();
});
@@ -1163,9 +1171,9 @@ QUnit.module('Views', {
},
intercepts: {
execute_action: function (event) {
- assert.deepEqual(event.data.res_ids, [1],
+ assert.deepEqual(event.data.env.currentID, 1,
'should call with correct id');
- assert.strictEqual(event.data.model, 'foo',
+ assert.strictEqual(event.data.env.model, 'foo',
'should call with correct model');
assert.strictEqual(event.data.action_data.name, 'button_action',
"should call correct method");