From 96a52daa80b18d129bd9dbf332c1dd52d062629a Mon Sep 17 00:00:00 2001 From: Pierre Paridans Date: Thu, 22 Aug 2019 09:25:18 +0000 Subject: [PATCH] [REF] web: remove test coverage overlap in mobile test suite The tests in the file `relational_fields_mobile_tests.js` - which is part of the mobile test suite - are actually not specific to mobile. This commit merges those tests asserts into the tests already present in the regular test suite. It ensures that all the existing asserts remains and the actual coverage stays the same. --- .../field_many2many_tests.js | 3 +- .../relational_fields/field_one2many_tests.js | 22 ++- .../fields/relational_fields_mobile_tests.js | 179 ------------------ addons/web/views/webclient_templates.xml | 1 - 4 files changed, 23 insertions(+), 182 deletions(-) delete mode 100644 addons/web/static/tests/fields/relational_fields_mobile_tests.js diff --git a/addons/web/static/tests/fields/relational_fields/field_many2many_tests.js b/addons/web/static/tests/fields/relational_fields/field_many2many_tests.js index ab80fd59983..db0fb3632d3 100644 --- a/addons/web/static/tests/fields/relational_fields/field_many2many_tests.js +++ b/addons/web/static/tests/fields/relational_fields/field_many2many_tests.js @@ -116,7 +116,7 @@ QUnit.module('fields', {}, function () { QUnit.module('FieldMany2Many'); QUnit.test('many2many kanban: edition', async function (assert) { - assert.expect(32); + assert.expect(33); this.data.partner.records[0].timmy = [12, 14]; this.data.partner_type.records.push({ id: 15, display_name: "red", color: 6 }); @@ -250,6 +250,7 @@ QUnit.module('fields', {}, function () { assert.strictEqual($('.modal .modal-footer .o_btn_remove').length, 1, 'There should be a modal having Remove Button'); await testUtils.dom.click($('.modal .modal-footer .o_btn_remove')); + assert.containsNone($('.o_modal'), "modal should have been closed"); assert.strictEqual(form.$('.o_kanban_record:not(.o_kanban_ghost)').length, 5, 'should contain 5 records'); assert.ok(!form.$('.o_kanban_record:contains(silver)').length, diff --git a/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js b/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js index d9bb4a9624b..35b4be9f25e 100644 --- a/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js +++ b/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js @@ -2255,7 +2255,7 @@ QUnit.module('fields', {}, function () { }); QUnit.test('one2many kanban: edition', async function (assert) { - assert.expect(17); + assert.expect(23); this.data.partner.records[0].p = [2]; var form = await createView({ @@ -2286,6 +2286,22 @@ QUnit.module('fields', {}, function () { '' + '', res_id: 1, + mockRPC: function (route, args) { + if (route === '/web/dataset/call_kw/partner/write') { + var commands = args.args[1].p; + assert.strictEqual(commands.length, 2, + 'should have generated two commands'); + assert.strictEqual(commands[0][0], 0, + 'generated command should be ADD WITH VALUES'); + assert.strictEqual(commands[0][2].display_name, "new subrecord 3", + 'value of newly created subrecord should be "new subrecord 3"'); + assert.strictEqual(commands[1][0], 2, + 'generated command should be REMOVE AND DELETE'); + assert.strictEqual(commands[1][1], 2, + 'deleted record id should be 2'); + } + return this._super.apply(this, arguments); + }, }); assert.ok(!form.$('.o_kanban_view .delete_icon').length, @@ -2341,6 +2357,7 @@ QUnit.module('fields', {}, function () { assert.strictEqual($('.modal .modal-footer .o_btn_remove').length, 1, 'There should be a modal having Remove Button'); await testUtils.dom.click($('.modal .modal-footer .o_btn_remove')); + assert.containsNone($('.o_modal'), "modal should have been closed"); assert.strictEqual(form.$('.o_kanban_record:not(.o_kanban_ghost)').length, 3, 'should contain 3 records'); await testUtils.dom.click(form.$('.o_kanban_view .delete_icon:first()')); @@ -2349,6 +2366,9 @@ QUnit.module('fields', {}, function () { 'should contain 1 records'); assert.strictEqual(form.$('.o_kanban_record span:first').text(), 'new subrecord 3', 'the remaining subrecord should be "new subrecord 3"'); + + // save and check that the correct command has been generated + await testUtils.form.clickSave(form); form.destroy(); }); diff --git a/addons/web/static/tests/fields/relational_fields_mobile_tests.js b/addons/web/static/tests/fields/relational_fields_mobile_tests.js deleted file mode 100644 index 640a9298368..00000000000 --- a/addons/web/static/tests/fields/relational_fields_mobile_tests.js +++ /dev/null @@ -1,179 +0,0 @@ -odoo.define('web.relational_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('relational_fields', { - beforeEach: function () { - this.data = { - partner: { - fields: { - display_name: { string: "Displayed name", type: "char" }, - foo: {string: "Foo", type: "char", default: "My little Foo Value"}, - bar: {string: "Bar", type: "boolean", default: true}, - int_field: {string: "int_field", type: "integer", sortable: true}, - qux: {string: "Qux", type: "float", digits: [16,1] }, - p: {string: "one2many field", type: "one2many", relation: 'partner', relation_field: 'trululu'}, - trululu: {string: "Trululu", type: "many2one", relation: 'partner'}, - partner_ids: {string: "many2many field", type: "many2many", relation: 'partner'}, - }, - records: [{ - id: 1, - display_name: "first record", - bar: true, - foo: "yop", - int_field: 10, - qux: 0.44, - p: [], - trululu: 4, - }, { - id: 2, - display_name: "second record", - bar: true, - foo: "blip", - int_field: 9, - qux: 13, - p: [], - trululu: 1, - }, { - id: 4, - display_name: "aaa", - bar: false, - }], - onchanges: {}, - }, - }; - } -}, function () { - - QUnit.module('FieldOne2Many'); - - QUnit.test('one2many kanban: deletion in mobile', async function (assert) { - assert.expect(9); - - this.data.partner.records[0].p = [1, 2]; - var form = await createView({ - View: FormView, - model: 'partner', - data: this.data, - arch: '
' + - '' + - '' + - '' + - '' + - '
' + - '' + - '
' + - '
' + - '
' + - '
' + - '' + - '' + - '' + - '' + - '', - res_id: 1, - mockRPC: function (route, args) { - if (route === '/web/dataset/call_kw/partner/write') { - var commands = args.args[1].p; - assert.strictEqual(commands.length, 2, - 'should have generated two commands'); - assert.ok(commands[0][0] === 4 && commands[0][1] === 2, - 'should have generated the command 2 (DELETE) with id 1'); - assert.ok(commands[1][0] === 2 && commands[1][1] === 1, - 'should have generated the command 2 (DELETE) with id 2'); - } - return this._super.apply(this, arguments); - }, - }); - - assert.containsNone(form, '.o_field_one2many .o-kanban-button-new', - '"Create" button should not be visible in readonly'); - - await testUtils.form.clickEdit(form); - - assert.containsOnce(form, '.o_field_one2many .o-kanban-button-new', - '"Create" button should be visible in edit'); - assert.strictEqual(form.$('.o_kanban_record:not(.o_kanban_ghost)').length, 2, - "should have 2 records"); - - // open and delete record - await testUtils.dom.click(form.$('.oe_kanban_global_click').first()); - assert.strictEqual($('.modal .modal-footer .o_btn_remove').length, 1, - 'there should be a Remove button in the modal footer'); - await testUtils.dom.click($('.modal .modal-footer .o_btn_remove')); - assert.strictEqual($('.o_modal').length, 0, "there shoul be no more modal"); - assert.strictEqual(form.$('.o_kanban_record:not(.o_kanban_ghost)').length, 1, - 'should contain 1 records'); - - // save and check that the correct command has been generated - await testUtils.form.clickSave(form); - form.destroy(); - }); - - QUnit.module('FieldMany2Many'); - - QUnit.test('many2many kanban: deletion in mobile', async function (assert) { - assert.expect(8); - this.data.partner.records[0].partner_ids = [2, 4]; - var form = await createView({ - View: FormView, - model: 'partner', - data: this.data, - arch: '
' + - '' + - '' + - '' + - '' + - '' + - '' + - '
' + - '' + - '
' + - '
' + - '
' + - '
' + - '' + - '' + - '' + - '' + - '', - res_id: 1, - mockRPC: function (route, args) { - if (route === '/web/dataset/call_kw/partner/write') { - var commands = args.args[1].partner_ids; - assert.strictEqual(commands.length, 1, - 'should have generated one commands'); - assert.deepEqual(commands[0], [6, false, [4]] , - 'should properly write ids'); - } - return this._super.apply(this, arguments); - }, - }); - assert.containsNone(form.$('.o_field_many2many .o-kanban-button-new'), - '"Add" button should not be visible in readonly'); - await testUtils.form.clickEdit(form); - assert.containsOnce(form, '.o_field_many2many .o-kanban-button-new', - '"Add" button should be visible in edit'); - assert.containsN(form, '.o_kanban_record:not(.o_kanban_ghost)', 2, - "should have 2 records"); - // open and delete record - await testUtils.dom.click(form.$('.oe_kanban_global_click').first()); - assert.strictEqual($('.modal .modal-footer .o_btn_remove').length, 1, - 'there should be a modal having "Remove" Button'); - await testUtils.dom.click($('.modal .modal-footer .o_btn_remove')); - assert.containsNone($('.o_modal'), "modal should have been closed"); - assert.containsOnce(form, '.o_kanban_record:not(.o_kanban_ghost)', - 'should contain 1 records'); - // save and check that the correct command has been generated - await testUtils.form.clickSave(form); - form.destroy(); - }); -}); -}); -}); diff --git a/addons/web/views/webclient_templates.xml b/addons/web/views/webclient_templates.xml index ca20fba9dc2..69dd425814c 100644 --- a/addons/web/views/webclient_templates.xml +++ b/addons/web/views/webclient_templates.xml @@ -753,7 +753,6 @@ -