Files
odoo_source/addons/document/static/tests/document_tests.js
T
qsm-odoo 2c966909e2 [FIX] *: fix some side-effects of https://github.com/odoo/odoo/commit/9de1bc0eef6f5bfaa2a8d745431caa361ae91548
- JS Modals were not correctly built anymore, their .modal-body element
  was duplicated and many without-effect JS lines were introduced (as a
  side effect, the form view design was broken when inside modals)

- Tests were changed to make bugs go unnoticed. For example, the media
  dialog functionnality was entirely broken because the .modal-dialog
  element was not receiving the correct class anymore.

- The JS translation function is _t, not _

- Do not use the <title/> tag as a regular DOM element, it is meant to
  be unique, in the <head/> section

- CSS rules were added to the utils.scss file, which is meant to contain
  functions and mixins, otherwise, the rule is duplicated in every asset

- Some icons were still broken, as missed by https://github.com/odoo/odoo/commit/f90cf060a3cfeb37a67bec83264c0aaab8892b56

- Tests were changed to use [role="dialog"]/footer/header in their
  selectors without any reason, this commit restores some of that to
  avoid rebase conflicts with the BS4 work.

- ...

Note: other elements should still be discussed, like the direct use of
the 'o_form_label' class in views definition... but those do not cause
direct problems.
2018-07-09 11:59:30 +02:00

79 lines
3.0 KiB
JavaScript

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: {hasSidebar: 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();
});
});
});