diff options
| author | Kirti Choudhary <kic@odoo.com> | 2017-10-19 16:58:06 +0200 |
|---|---|---|
| committer | Nicolas Lempereur <nle@odoo.com> | 2018-08-17 15:33:40 +0200 |
| commit | 80118dd8a24249e5e008eae1178fccfc9ba68fb4 (patch) | |
| tree | 76a8ebf4034008cd8fc50ca910ef5b7c4682ec05 /addons/document | |
| parent | 9f1534ee8cbc92897b46cf75dc81bfa66037c423 (diff) | |
[IMP] document: added QUnit testcase
note: backport 562d467 from saas-11.2 to 11.0 to add a similar test
related to #26213
Diffstat (limited to 'addons/document')
| -rw-r--r-- | addons/document/static/tests/document_tests.js | 78 | ||||
| -rw-r--r-- | addons/document/views/document_templates.xml | 6 |
2 files changed, 84 insertions, 0 deletions
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: '<form string="Partners">' + + '<sheet>' + + '<field name="display_name"/>' + + '</sheet>' + + '</form>', + 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(); + }); + }); +}); diff --git a/addons/document/views/document_templates.xml b/addons/document/views/document_templates.xml index abb2d13f2fc..1b7b999fdd1 100644 --- a/addons/document/views/document_templates.xml +++ b/addons/document/views/document_templates.xml @@ -5,4 +5,10 @@ <script type="text/javascript" src="/document/static/src/js/document.js"></script> </xpath> </template> + + <template id="qunit_suite" name="document tests" inherit_id="web.qunit_suite"> + <xpath expr="//script[last()]" position="after"> + <script type="text/javascript" src="/document/static/tests/document_tests.js"/> + </xpath> + </template> </odoo> |
