From 80118dd8a24249e5e008eae1178fccfc9ba68fb4 Mon Sep 17 00:00:00 2001 From: Kirti Choudhary Date: Thu, 19 Oct 2017 16:58:06 +0200 Subject: [IMP] document: added QUnit testcase note: backport 562d467 from saas-11.2 to 11.0 to add a similar test related to #26213 --- addons/document/static/tests/document_tests.js | 78 ++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 addons/document/static/tests/document_tests.js (limited to 'addons/document/static/tests/document_tests.js') diff --git a/addons/document/static/tests/document_tests.js b/addons/document/static/tests/document_tests.js new file mode 100644 index 00000000000..9fd1e7d25ae --- /dev/null +++ b/addons/document/static/tests/document_tests.js @@ -0,0 +1,78 @@ +odoo.define('document.tests', function (require) { + "use strict"; + + var testUtils = require('web.test_utils'); + var FormView = require('web.FormView'); + + var createView = testUtils.createView; + + QUnit.module('DocumentTest', { + beforeEach: function () { + this.data = { + partner: { + fields: { + display_name: { string: "Displayed name", type: "char" } + }, + records: [{ + id: 1, + display_name: "first record", + }] + }, + 'ir.attachment': { + fields: { + type: { string: "Type", type: "char" }, + name: {string: "Name", type: "char"}, + res_id: {string: "ResId", type: "integer"}, + res_model: {string: "ResModel", type: "char"} + }, + records: [{ + id: 1, + type:"binary", + name: "attachment1", + res_id: 1, + res_model: 'partner' + },{ + id: 2, + type:"binary", + name: "attachment2", + res_id: 1, + res_model: 'partner' + }] + } + }; + } + }, function () { + QUnit.module('DocView'); + QUnit.test('documentAttachmentTest', function (assert) { + assert.expect(3); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '
', + res_id: 1, + viewOptions: {sidebar: true}, + mockRPC: function (route, args) { + if (args.method === 'search_read' && args.model === 'ir.attachment') { + return $.when(this.data['ir.attachment'].records); + } + if (route === '/web/dataset/call_kw/ir.attachment/unlink') { + assert.strictEqual(args.args[0], 1, "Should have correct id of the attachment to be deleted"); + } + return this._super.apply(this, arguments); + } + }); + + assert.strictEqual(form.sidebar.$('.o_sidebar_delete_attachment').length, 2, "there should be two attachments"); + form.sidebar.$('.o_sidebar_delete_attachment:eq(0)').click(); + $('.modal-footer .btn-primary').click(); + assert.strictEqual(form.sidebar.$('.o_sidebar_delete_attachment').length, 1, "there should be only one attachment"); + form.destroy(); + }); + }); +}); -- cgit v1.2.3 From ac1e187eea33266095f49a9e1e1ea6b0698be865 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Tue, 7 Aug 2018 17:19:57 +0200 Subject: [FIX] document: no query attachment out of form view Since cce70fd4 the attachment menu is only displayed for form view. But if in another view there is active_ids (eg. selecting record in a list view), we will still make a query to ir.attachment without using the result. Without the code change, the added test would fail when doing a search_read RPC call to ir.attachment model. related to #26213 --- addons/document/static/tests/document_tests.js | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'addons/document/static/tests/document_tests.js') diff --git a/addons/document/static/tests/document_tests.js b/addons/document/static/tests/document_tests.js index 9fd1e7d25ae..cc6f2668fc5 100644 --- a/addons/document/static/tests/document_tests.js +++ b/addons/document/static/tests/document_tests.js @@ -3,6 +3,7 @@ odoo.define('document.tests', function (require) { var testUtils = require('web.test_utils'); var FormView = require('web.FormView'); + var ListView = require('web.ListView'); var createView = testUtils.createView; @@ -16,6 +17,9 @@ odoo.define('document.tests', function (require) { records: [{ id: 1, display_name: "first record", + }, { + id: 2, + display_name: "second record", }] }, 'ir.attachment': { @@ -74,5 +78,34 @@ odoo.define('document.tests', function (require) { assert.strictEqual(form.sidebar.$('.o_sidebar_delete_attachment').length, 1, "there should be only one attachment"); form.destroy(); }); + + QUnit.test('no attachment on list view', function (assert) { + assert.expect(4); + + var list = createView({ + View: ListView, + model: 'partner', + data: this.data, + groupBy: ['display_name'], + viewOptions: {sidebar: true}, + arch: '' + + '' + + '', + mockRPC: function (route, args) { + assert.step(args.model); + return this._super.apply(this, arguments); + } + }); + + // select record then trigger render + list.$('.o_group_header:last').click(); + list.$('.o_data_row input').click(); + list.$('.o_group_header:first').click(); + + assert.verifySteps(['partner', 'partner', 'partner'], + "ir.attachment not called when selecting record in list view"); + + list.destroy(); + }); }); }); -- cgit v1.2.3