diff options
Diffstat (limited to 'addons/web/static/tests/views/form_tests.js')
| -rw-r--r-- | addons/web/static/tests/views/form_tests.js | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index 7ed63d3bece..ab304e62ebc 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -5013,5 +5013,147 @@ QUnit.module('Views', { form.destroy(); }); + + QUnit.test('readonly fields are not sent when saving', function (assert) { + assert.expect(6); + + // define an onchange on display_name to check that the value of readonly + // fields is correctly sent for onchanges + this.data.partner.onchanges = { + display_name: function () {}, + p: function () {}, + }; + var checkOnchange = false; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form string="Partners">' + + '<field name="p">' + + '<tree>' + + '<field name="display_name"/>' + + '</tree>' + + '<form string="Partners">' + + '<field name="display_name"/>' + + '<field name="foo" attrs="{\'readonly\': [[\'display_name\', \'=\', \'readonly\']]}"/>' + + '</form>' + + '</field>' + + '</form>', + mockRPC: function (route, args) { + if (checkOnchange && args.method === 'onchange') { + if (args.args[2] === 'display_name') { // onchange on field display_name + assert.strictEqual(args.args[1].foo, 'foo value', + "readonly fields value should be sent for onchanges"); + } else { // onchange on field p + assert.deepEqual(args.args[1].p, [ + [0, false, {display_name: 'readonly', foo: 'foo value'}] + ], "readonly fields value should be sent for onchanges"); + } + } + if (args.method === 'create') { + assert.deepEqual(args.args[0], { + p: [[0, false, {display_name: 'readonly'}]] + }, "should not have sent the value of the readonly field"); + } + return this._super.apply(this, arguments); + }, + }); + + form.$('.o_field_x2many_list_row_add a').click(); + assert.strictEqual($('.modal input.o_field_widget[name=foo]').length, 1, + 'foo should be editable'); + checkOnchange = true; + $('.modal .o_field_widget[name=foo]').val('foo value').trigger('input'); + $('.modal .o_field_widget[name=display_name]').val('readonly').trigger('input'); + assert.strictEqual($('.modal span.o_field_widget[name=foo]').length, 1, + 'foo should be readonly'); + $('.modal .modal-footer .btn-primary').click(); // close the modal + checkOnchange = false; + + form.$('.o_data_row').click(); // re-open previous record + assert.strictEqual($('.modal .o_field_widget[name=foo]').text(), 'foo value', + "the edited value should have been kept"); + $('.modal .modal-footer .btn-primary').click(); // close the modal + + form.$buttons.find('.o_form_button_save').click(); // save the record + + form.destroy(); + }); + + QUnit.test('id is False in evalContext for new records', function (assert) { + assert.expect(2); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form string="Partners">' + + '<field name="id"/>' + + '<field name="foo" attrs="{\'readonly\': [[\'id\', \'=\', False]]}"/>' + + '</form>', + }); + + assert.ok(form.$('.o_field_widget[name=foo]').hasClass('o_readonly_modifier'), + "foo should be readonly in 'Create' mode"); + + form.$buttons.find('.o_form_button_save').click(); + form.$buttons.find('.o_form_button_edit').click(); + + assert.notOk(form.$('.o_field_widget[name=foo]').hasClass('o_readonly_modifier'), + "foo should not be readonly anymore"); + + form.destroy(); + }); + + QUnit.test('delete a duplicated record', function (assert) { + assert.expect(5); + + var newRecordID; + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form string="Partners">' + + '<field name="display_name"/>' + + '</form>', + res_id: 1, + viewOptions: {sidebar: true}, + mockRPC: function (route, args) { + if (args.method === 'search_read' && args.model === 'ir.attachment') { + // rpcs done by the sidebar + return $.when([]); + } + var result = this._super.apply(this, arguments); + if (args.method === 'copy') { + return result.then(function (id) { + newRecordID = id; + return id; + }); + } + if (args.method === 'unlink') { + assert.deepEqual(args.args[0], [newRecordID], + "should delete the newly created record"); + } + return result; + }, + }); + + form.sidebar.$('a:contains(Duplicate)').click(); // duplicate record 1 + assert.strictEqual(form.$('.o_form_editable').length, 1, + "form should be in edit mode"); + assert.strictEqual(form.$('.o_field_widget').val(), 'first record (copy)', + "duplicated record should have correct name"); + form.$buttons.find('.o_form_button_save').click(); // save duplicated record + + form.sidebar.$('a:contains(Delete)').click(); // delete duplicated record + assert.strictEqual($('.modal').length, 1, "should have opened a confirm dialog"); + $('.modal .modal-footer .btn-primary').click(); // confirm + + assert.strictEqual(form.$('.o_field_widget').text(), 'first record', + "should have come back to previous record"); + + form.destroy(); + }); }); }); |
