summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/relational_fields_tests.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js315
1 files changed, 311 insertions, 4 deletions
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js
index 1a9576edd75..a046e79de6c 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -1150,12 +1150,12 @@ QUnit.module('relational_fields', {
form.destroy();
});
- QUnit.test('list in form: discard newly added element with empty required field', function (assert) {
+ QUnit.test('list in form: discard newly added element with empty required field (default_get)', function (assert) {
// This test simulates discarding a record that has been created with
// one of its required field that is empty. When we discard the changes
// on this empty field, it should not assume that this record should be
// abandonned, since it has been added (even though it is a new record).
- assert.expect(6);
+ assert.expect(8);
var form = createView({
View: FormView,
@@ -1173,7 +1173,7 @@ QUnit.module('relational_fields', {
'</form>',
mockRPC: function (route, args) {
if (args.method === 'default_get') {
- return $.when({p: [[0, 0, {display_name: 'new record', trululu: false}]]});
+ return $.when({ p: [[0, 0, { display_name: 'new record', trululu: false }]] });
}
return this._super.apply(this, arguments);
},
@@ -1181,6 +1181,8 @@ QUnit.module('relational_fields', {
assert.strictEqual($('tr.o_data_row').length, 1,
"should have created the new record in the o2m");
+ assert.strictEqual($('td.o_data_cell').first().text(), "new record",
+ "should have the correct displayed name");
var requiredElement = $('td.o_data_cell.o_required_modifier');
assert.strictEqual(requiredElement.length, 1,
@@ -1194,6 +1196,8 @@ QUnit.module('relational_fields', {
assert.strictEqual($('tr.o_data_row').length, 1,
"should still have the record in the o2m");
+ assert.strictEqual($('td.o_data_cell').first().text(), "new record",
+ "should still have the correct displayed name");
// update selector of required field element
requiredElement = $('td.o_data_cell.o_required_modifier');
@@ -1204,6 +1208,72 @@ QUnit.module('relational_fields', {
form.destroy();
});
+ QUnit.test('list in form: discard newly added element with empty required field (onchange)', function (assert) {
+ assert.expect(8);
+
+ var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY;
+ relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0;
+
+ this.data.partner.onchanges = {
+ product_id: function (obj) {
+ if (obj.product_id === 37) {
+ obj.p = [[0, 0, { display_name: "entry", trululu: false }]];
+ }
+ },
+ trululu: function () {},
+ };
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form>' +
+ '<field name="product_id"/>' +
+ '<field name="p">' +
+ '<tree editable="bottom">' +
+ '<field name="display_name"/>' +
+ '<field name="trululu" required="1"/>' +
+ '</tree>' +
+ '</field>' +
+ '</form>',
+ });
+
+ // check no record in list
+ assert.strictEqual(form.$('.o_data_row').length, 0,
+ "should have no row in the editable list");
+
+ // select product_id to force on_change in editable list
+ form.$('.o_field_widget[name="product_id"] .o_input').click();
+ $('.ui-menu-item').first().click();
+
+ // check that there is a record in the editable list with empty string as required field
+ assert.strictEqual(form.$('.o_data_row').length, 1,
+ "should have a row in the editable list");
+ assert.strictEqual($('td.o_data_cell').first().text(), "entry",
+ "should have the correct displayed name");
+ var requiredField = $('td.o_data_cell.o_required_modifier');
+ assert.strictEqual(requiredField.length, 1,
+ "should have a required field on this record");
+ assert.strictEqual(requiredField.text(), "",
+ "should have empty string in the required field on this record");
+
+ // click on empty required field in editable list record
+ requiredField.click();
+ // click off so that the required field still stay empty
+ $('body').click();
+
+ // record should not be dropped
+ assert.strictEqual(form.$('.o_data_row').length, 1,
+ "should not have droppped record in the editable list");
+ assert.strictEqual($('td.o_data_cell').first().text(), "entry",
+ "should still have the correct displayed name");
+ assert.strictEqual($('td.o_data_cell.o_required_modifier').text(), "",
+ "should still have empty string in the required field");
+
+ relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY;
+ form.destroy();
+ });
+
QUnit.test('list in form: default_get with x2many create', function (assert) {
assert.expect(5);
@@ -4208,7 +4278,6 @@ QUnit.module('relational_fields', {
form.destroy();
});
-
QUnit.test('one2many list (non editable): edition', function (assert) {
assert.expect(12);
@@ -5077,6 +5146,32 @@ QUnit.module('relational_fields', {
form.destroy();
});
+ QUnit.test('one2many and default_get (with date)', function (assert) {
+ assert.expect(1);
+
+ this.data.partner.fields.p.default = [
+ [0, false, {date: '2017-10-08'}],
+ ];
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners">' +
+ '<field name="p">' +
+ '<tree>' +
+ '<field name="date"/>' +
+ '</tree>' +
+ '</field>' +
+ '</form>',
+ });
+
+ assert.strictEqual(form.$('.o_data_cell').text(), '10/08/2017',
+ "should correctly display the date");
+
+ form.destroy();
+ });
+
QUnit.test('one2many and onchange (with integer)', function (assert) {
assert.expect(4);
@@ -8742,6 +8837,53 @@ QUnit.module('relational_fields', {
form.destroy();
});
+ QUnit.test('add a line, edit it and "Save & New"', function (assert) {
+ assert.expect(5);
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form string="Partners">' +
+ '<field name="p">' +
+ '<tree><field name="display_name"/></tree>' +
+ '<form><field name="display_name"/></form>' +
+ '</field>' +
+ '</form>',
+ });
+
+ assert.strictEqual(form.$('.o_data_row').length, 0,
+ "there should be no record in the relation");
+
+ // add a new record
+ form.$('.o_field_x2many_list_row_add a').click();
+ $('.modal .o_field_widget').val('new record').trigger('input');
+ $('.modal .modal-footer .btn-primary:first').click(); // Save & Close
+
+ assert.strictEqual(form.$('.o_data_row .o_data_cell').text(), 'new record',
+ "should display the new record");
+
+ // reopen freshly added record and edit it
+ form.$('.o_data_row .o_data_cell').click();
+ $('.modal .o_field_widget').val('new record edited').trigger('input');
+
+ // save it, and choose to directly create another record
+ $('.modal .modal-footer .btn-primary:nth(1)').click(); // Save & New
+
+ assert.strictEqual($('.modal').length, 1,
+ "the model should still be open");
+ assert.strictEqual($('.modal .o_field_widget').text(), '',
+ "should have cleared the input");
+
+ $('.modal .o_field_widget').val('another new record').trigger('input');
+ $('.modal .modal-footer .btn-primary:first').click(); // Save & Close
+
+ assert.strictEqual(form.$('.o_data_row .o_data_cell').text(),
+ 'new record editedanother new record', "should display the two records");
+
+ form.destroy();
+ });
+
QUnit.module('FieldMany2Many');
QUnit.test('many2many kanban: edition', function (assert) {
@@ -11011,6 +11153,99 @@ QUnit.module('relational_fields', {
QUnit.module('FieldReference');
+ QUnit.test('Reference field in modal readonly mode', function (assert) {
+ assert.expect(4);
+
+ this.data.partner.records[0].p = [2];
+ this.data.partner.records[1].trululu = 1;
+ this.data.partner.records[1].reference = 'product,41';
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners">' +
+ '<field name="reference"/>' +
+ '<field name="p"/>' +
+ '</form>',
+ archs: {
+ 'partner,false,form': '<form><field name="reference"/></form>',
+ 'partner,false,list': '<tree><field name="display_name"/></tree>',
+ },
+ res_id: 1,
+ });
+
+ // Cuurent Form
+ assert.equal(form.$('.o_form_uri.o_field_widget[name=reference]').text(), 'xphone',
+ 'the field reference of the form should have the right value');
+
+ var $cell_o2m = form.$('.o_data_cell');
+ assert.equal($cell_o2m.text(), 'second record',
+ 'the list should have one record');
+
+ $cell_o2m.click();
+
+ // In modal
+ var $modal = $('.modal-dialog.modal-lg');
+ assert.equal($modal.length, 1,
+ 'there should be one modal opened');
+
+ assert.equal($modal.find('.o_form_uri.o_field_widget[name=reference]').text(), 'xpad',
+ 'The field reference in the modal should have the right value');
+
+ $modal.find('.o_form_button_cancel').click();
+
+ form.destroy();
+ });
+
+ QUnit.test('Reference field in modal write mode', function (assert) {
+ assert.expect(5);
+
+ this.data.partner.records[0].p = [2];
+ this.data.partner.records[1].trululu = 1;
+ this.data.partner.records[1].reference = 'product,41';
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners">' +
+ '<field name="reference"/>' +
+ '<field name="p"/>' +
+ '</form>',
+ archs: {
+ 'partner,false,form': '<form><field name="reference"/></form>',
+ 'partner,false,list': '<tree><field name="display_name"/></tree>',
+ },
+ res_id: 1,
+ });
+
+ // current form
+ form.$buttons.find('.o_form_button_edit').click();
+
+ var $fieldRef = form.$('.o_field_widget.o_field_many2one[name=reference]');
+ assert.equal($fieldRef.find('option:selected').text(), 'Product',
+ 'The reference field\'s model should be Product');
+ assert.equal($fieldRef.find('.o_input.ui-autocomplete-input').val(), 'xphone',
+ 'The reference field\'s record should be xphone');
+
+ form.$('.o_data_cell').click();
+
+ // In modal
+ var $modal = $('.modal-dialog.modal-lg');
+ assert.equal($modal.length, 1,
+ 'there should be one modal opened');
+
+ var $fieldRefModal = $modal.find('.o_field_widget.o_field_many2one[name=reference]');
+
+ assert.equal($fieldRefModal.find('option:selected').text(), 'Product',
+ 'The reference field\'s model should be Product');
+ assert.equal($fieldRefModal.find('.o_input.ui-autocomplete-input').val(), 'xpad',
+ 'The reference field\'s record should be xpad');
+
+ form.destroy();
+ });
+
QUnit.test('reference in form view', function (assert) {
assert.expect(15);
@@ -11207,6 +11442,78 @@ QUnit.module('relational_fields', {
form.destroy();
});
+ QUnit.test('one2many with extra field from server not in form', function (assert) {
+ assert.expect(6);
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form string="Partners">' +
+ '<field name="p" >' +
+ '<tree>' +
+ '<field name="datetime"/>' +
+ '<field name="display_name"/>' +
+ '</tree>' +
+ '</field>' +
+ '</form>',
+ res_id: 1,
+ archs: {
+ 'partner,false,form': '<form>' +
+ '<field name="display_name"/>' +
+ '</form>'},
+ mockRPC: function(route, args) {
+ if (route === '/web/dataset/call_kw/partner/write') {
+ args.args[1].p[0][2].datetime = '2018-04-05 12:00:00';
+ }
+ return this._super.apply(this, arguments);
+ }
+ });
+
+ form.$buttons.find('.o_form_button_edit').click();
+
+ var x2mList = form.$('.o_field_x2many_list[name=p]');
+
+ // Add a record in the list
+ x2mList.find('.o_field_x2many_list_row_add a').click();
+
+ var modal = $('.modal-dialog.modal-lg');
+
+ var nameInput = modal.find('input.o_input[name=display_name]');
+ nameInput.val('michelangelo').trigger('input');
+
+ // Save the record in the modal (though it is still virtual)
+ modal.find('.btn-primary').first().click();
+
+ assert.equal(x2mList.find('.o_data_row').length, 1,
+ 'There should be 1 records in the x2m list');
+
+ var newlyAdded = x2mList.find('.o_data_row').eq(0);
+
+ assert.equal(newlyAdded.find('.o_data_cell').first().text(), '',
+ 'The create_date field should be empty');
+ assert.equal(newlyAdded.find('.o_data_cell').eq(1).text(), 'michelangelo',
+ 'The display name field should have the right value');
+
+ // Save the whole thing
+ form.$buttons.find('.o_form_button_save').click();
+
+ x2mList = form.$('.o_field_x2many_list[name=p]');
+
+ // Redo asserts in RO mode after saving
+ assert.equal(x2mList.find('.o_data_row').length, 1,
+ 'There should be 1 records in the x2m list');
+
+ newlyAdded = x2mList.find('.o_data_row').eq(0);
+
+ assert.equal(newlyAdded.find('.o_data_cell').first().text(), '04/05/2018 12:00:00',
+ 'The create_date field should have the right value');
+ assert.equal(newlyAdded.find('.o_data_cell').eq(1).text(), 'michelangelo',
+ 'The display name field should have the right value');
+
+ form.destroy();
+ });
+
QUnit.test('one2many invisible depends on parent field', function (assert) {
assert.expect(4);