diff options
| author | Christophe Simonis <chs@odoo.com> | 2017-06-27 14:19:31 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2017-06-27 14:19:31 +0200 |
| commit | dd43071638773dcb58376b79ec7b1456c8b0454d (patch) | |
| tree | fd7935e2aa93de03fa3fe12507f8ef74405a255e /addons/web/static/tests/fields | |
| parent | 6501184e6294ffb06e24a0ec8e9666b79a80b59a (diff) | |
| parent | 278e478d55209bd958836fde7fe1c82c555180dc (diff) | |
[MERGE] forward port branch saas-16 up to 278e478d552
Diffstat (limited to 'addons/web/static/tests/fields')
3 files changed, 271 insertions, 13 deletions
diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 4b850b26d34..c492537c63f 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -394,7 +394,7 @@ QUnit.module('basic_fields', { QUnit.module('FieldFloat'); QUnit.test('float field when unset', function (assert) { - assert.expect(1); + assert.expect(2); var form = createView({ View: FormView, @@ -408,8 +408,10 @@ QUnit.module('basic_fields', { res_id: 4, }); - assert.ok(form.$('.o_field_widget').hasClass('o_field_empty'), - 'Non-set float field should be recognized as unset.'); + assert.notOk(form.$('.o_field_widget').hasClass('o_field_empty'), + 'Non-set float field should be considered as 0.'); + assert.strictEqual(form.$('.o_field_widget').text(), "0.000", + 'Non-set float field should be considered as 0.'); form.destroy(); }); @@ -536,6 +538,35 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('float widget on monetary field', function (assert) { + assert.expect(1); + + this.data.partner.fields.monetary = {string: "Monetary", type: 'monetary'}; + this.data.partner.records[0].monetary = 9.99; + this.data.partner.records[0].currency_id = 1; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'<form string="Partners">' + + '<sheet>' + + '<field name="monetary" widget="float"/>' + + '<field name="currency_id" invisible="1"/>' + + '</sheet>' + + '</form>', + res_id: 1, + session: { + currencies: _.indexBy(this.data.currency.records, 'id'), + }, + }); + + assert.strictEqual(form.$('.o_field_widget[name=monetary]').text(), '9.99', + 'value should be correctly formatted (with the float formatter)'); + + form.destroy(); + }); + QUnit.module('FieldEmail'); QUnit.test('email field in form view', function (assert) { @@ -1015,7 +1046,7 @@ QUnit.module('basic_fields', { QUnit.module('FieldBinary'); QUnit.test('binary fields are correctly rendered', function (assert) { - assert.expect(9); + assert.expect(16); // save the session function var oldGetFile = session.get_file; @@ -1028,18 +1059,24 @@ QUnit.module('basic_fields', { return $.when(); }; + this.data.partner.records[0].foo = 'coucou.txt'; var form = createView({ View: FormView, model: 'partner', data: this.data, arch: '<form string="Partners">' + - '<field name="document"/>' + + '<field name="document" filename="foo"/>' + + '<field name="foo"/>' + '</form>', res_id: 1, }); assert.strictEqual(form.$('a.o_field_widget[name="document"] > .fa-download').length, 1, "the binary field should be rendered as a downloadable link in readonly"); + assert.strictEqual(form.$('a.o_field_widget[name="document"]').text().trim(), 'coucou.txt', + "the binary field should display the name of the file in the link"); + assert.strictEqual(form.$('.o_field_char').text(), 'coucou.txt', + "the filename field should have the file name as value"); form.$('a.o_field_widget[name="document"]').click(); @@ -1047,12 +1084,15 @@ QUnit.module('basic_fields', { assert.strictEqual(form.$('a.o_field_widget[name="document"] > .fa-download').length, 0, "the binary field should not be rendered as a downloadable link in edit"); - assert.strictEqual(form.$('div.o_field_binary_file[name="document"]').length, 1, - "the binary field should be correctly rendered in edit"); + assert.strictEqual(form.$('div.o_field_binary_file[name="document"] > input').val(), 'coucou.txt', + "the binary field should display the file name in the input edit mode"); assert.strictEqual(form.$('.o_field_binary_file > input').attr('readonly'), 'readonly', "the input should be readonly"); assert.strictEqual(form.$('.o_field_binary_file > .o_clear_file_button').length, 1, "there shoud be a button to clear the file"); + assert.strictEqual(form.$('input.o_field_char').val(), 'coucou.txt', + "the filename field should have the file name as value"); + form.$('.o_field_binary_file > .o_clear_file_button').click(); @@ -1060,6 +1100,16 @@ QUnit.module('basic_fields', { "the input should be hidden"); assert.strictEqual(form.$('.o_field_binary_file > .o_select_file_button:not(.o_hidden)').length, 1, "there shoud be a button to upload the file"); + assert.strictEqual(form.$('input.o_field_char').val(), '', + "the filename field should be empty since we removed the file"); + + form.$buttons.find('.o_form_button_save').click(); + assert.strictEqual(form.$('a.o_field_widget[name="document"] > .fa-download').length, 0, + "the binary field should not render as a downloadable link since we removed the file"); + assert.strictEqual(form.$('a.o_field_widget[name="document"]').text().trim(), '', + "the binary field should not display a filename in the link since we removed the file"); + assert.strictEqual(form.$('.o_field_char').text().trim(), '', + "the filename field should be empty since we removed the file"); form.destroy(); @@ -1926,7 +1976,7 @@ QUnit.module('basic_fields', { QUnit.module('FieldInteger'); QUnit.test('integer field when unset', function (assert) { - assert.expect(1); + assert.expect(2); var form = createView({ View: FormView, @@ -1936,8 +1986,10 @@ QUnit.module('basic_fields', { res_id: 4, }); - assert.ok(form.$('.o_field_widget').hasClass('o_field_empty'), - 'Non-set integer field should be recognized as unset.'); + assert.notOk(form.$('.o_field_widget').hasClass('o_field_empty'), + 'Non-set integer field should be recognized as 0.'); + assert.strictEqual(form.$('.o_field_widget').text(), "0", + 'Non-set integer field should be recognized as 0.'); form.destroy(); }); diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index a1f851eb91f..3bf541b097d 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -199,6 +199,115 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('many2ones in form views with show_adress', function (assert) { + assert.expect(4); + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form string="Partners">' + + '<sheet>' + + '<group>' + + '<field ' + + 'name="trululu" ' + + 'string="custom label" ' + + 'context="{\'search_default_customer\':1, \'show_address\': 1}" ' + + 'options="{\'always_reload\': True}"' + + '/>' + + '</group>' + + '</sheet>' + + '</form>', + mockRPC: function (route, args) { + if (args.method === 'name_get') { + return this._super(route, args).then(function (result) { + result[0][1] += '\nStreet\nCity ZIP'; + return result; + }); + } + return this._super(route, args); + }, + res_id: 1, + }); + + assert.strictEqual($('a.o_form_uri').html(), 'aaa<br>Street<br>City ZIP', + "input should have a multi-line content in readonly due to show_address"); + form.$buttons.find('.o_form_button_edit').click(); + assert.strictEqual(form.$('button.o_external_button:visible').length, 1, + "should have an open record button"); + + form.$('input.o_input').click(); + form.$('input.o_input').trigger($.Event('keyup', { + which: $.ui.keyCode.ESC, + keyCode: $.ui.keyCode.ESC, + })); + + assert.strictEqual(form.$('button.o_external_button:visible').length, 1, + "should still have an open record button"); + form.$('input.o_input').trigger('focusout'); + assert.strictEqual($('.modal button:contains(Create and edit)').length, 0, + "there should not be a quick create modal"); + + form.destroy(); + }); + + QUnit.test('many2ones in form views with search more', function (assert) { + assert.expect(3); + this.data.partner.records.push({ + id: 5, + display_name: "Partner 4", + }, { + id: 6, + display_name: "Partner 5", + }, { + id: 7, + display_name: "Partner 6", + }, { + id: 8, + display_name: "Partner 7", + }, { + id: 9, + display_name: "Partner 8", + }, { + id: 10, + display_name: "Partner 9", + }); + this.data.partner.fields.datetime.searchable = true; + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form string="Partners">' + + '<sheet>' + + '<group>' + + '<field name="trululu"/>' + + '</group>' + + '</sheet>' + + '</form>', + archs: { + 'partner,false,list': '<tree><field name="display_name"/></tree>', + 'partner,false,search': '<search><field name="datetime"/></search>', + }, + res_id: 1, + }); + + form.$buttons.find('.o_form_button_edit').click(); + var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); + form.$('.o_field_many2one input').click(); + $dropdown.find('.o_m2o_dropdown_option:contains(Search)').mouseenter().click(); // Open Search More + + assert.strictEqual($('tr.o_data_row').length, 9, "should display 9 records"); + + $('.o_searchview_more').click(); // Magnifying class for more filters + $('button:contains(Filters)').click(); + $('.o_add_filter').click(); // Add a custom filter, datetime field is selected + assert.strictEqual($('li.o_filter_condition select.o_searchview_extended_prop_field').val(), 'datetime', + "datetime field should be selected"); + $('.o_apply_filter').click(); + + assert.strictEqual($('tr.o_data_row').length, 0, "should display 0 records"); + form.destroy(); + }); + QUnit.test('onchanges on many2ones trigger when editing record in form view', function (assert) { assert.expect(9); @@ -2927,8 +3036,8 @@ QUnit.module('relational_fields', { assert.strictEqual(form.$('.o_data_row').length, 3, "sould have 3 records in one2many list"); - assert.strictEqual(form.$('.o_data_row').text(), "blip1.59yop1.5tototo1.550xphone", - "sould display the record values in one2many list"); + assert.strictEqual(form.$('.o_data_row').text(), "blip1.59yop1.50tototo1.550xphone", + "should display the record values in one2many list"); $('.o_form_button_save').click(); @@ -5153,7 +5262,7 @@ QUnit.module('relational_fields', { }); QUnit.test('widget selection, edition and on many2one field', function (assert) { - assert.expect(15); + assert.expect(18); this.data.partner.onchanges = {product_id: function () {}}; this.data.partner.records[0].product_id = 37; @@ -5178,6 +5287,13 @@ QUnit.module('relational_fields', { }); assert.ok(!form.$('select').length, "should not have a select tag in dom"); + assert.strictEqual(form.$('.o_field_widget[name=product_id]').text(), 'xphone', + "should have rendered the many2one field correctly"); + assert.strictEqual(form.$('.o_field_widget[name=trululu]').text(), '', + "should have rendered the unset many2one field correctly"); + assert.strictEqual(form.$('.o_field_widget[name=color]').text(), 'Red', + "should have rendered the selection field correctly"); + form.$buttons.find('.o_form_button_edit').click(); assert.strictEqual(form.$('select').length, 3, @@ -5811,6 +5927,52 @@ QUnit.module('relational_fields', { form.destroy(); }); + + QUnit.test('name_create in form dialog', function (assert) { + var done = assert.async(); + assert.expect(2); + + var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY; + relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form>' + + '<group>' + + '<field name="p">' + + '<tree>' + + '<field name="bar"/>' + + '</tree>' + + '<form>' + + '<field name="product_id"/>' + + '</form>' + + '</field>' + + '</group>' + + '</form>', + mockRPC: function (route, args) { + if (args.method === 'name_create') { + assert.step('name_create'); + } + return this._super.apply(this, arguments); + }, + }); + + form.$buttons.find('.o_form_button_edit').click(); + form.$('.o_field_x2many_list_row_add a').click(); + var $dropdown = $('.modal .o_field_many2one input').autocomplete('widget'); + $('.modal input').val('new record').trigger('keydown'); + concurrency.delay(0).then(function () { + $dropdown.find('li:first()').click(); // quick create 'new record' + assert.verifySteps(['name_create']); + + relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY; + form.destroy(); + done(); + }); + }); + }); }); }); diff --git a/addons/web/static/tests/fields/upgrade_fields_tests.js b/addons/web/static/tests/fields/upgrade_fields_tests.js new file mode 100644 index 00000000000..babc32b60a8 --- /dev/null +++ b/addons/web/static/tests/fields/upgrade_fields_tests.js @@ -0,0 +1,44 @@ +odoo.define('web.upgrade_fields_tests', function (require) { +"use strict"; + +var FormView = require('web.FormView'); +var testUtils = require('web.test_utils'); + +var createView = testUtils.createView; + +QUnit.module('fields', {}, function () { + +QUnit.module('upgrade_fields', { + beforeEach: function () { + this.data = { + partner: { + fields: { + bar: {string: "Bar", type: "boolean"}, + }, + } + }; + }, +}, function () { + + QUnit.module('UpgradeBoolean'); + + QUnit.test('widget upgrade_boolean in a form view', function (assert) { + assert.expect(1); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form><field name="bar" widget="upgrade_boolean"/></form>', + }); + + form.$('input:checkbox').click(); + assert.strictEqual($('.modal').length, 1, + "the 'Upgrade to Enterprise' dialog should be opened"); + + form.destroy(); + }); + +}); +}); +}); |
