This rev. is the first part (out of 3) of the refactoring of the
ActionManager and ViewManager layer of the webclient.
The main changes are:
- there is no ViewManager anymore, its work is now handled by the
ActionManager itself, but isolated in a specific file ; this
eases a lot of things, as the breadcrumbs handling for example.
- the ActionManager code is converted to the new coding principles
and guidelines ; mainly, children widgets communicate with it by
triggering events up, and not by function calls anymore.
- the ActionManager layer is now testable, and a lot of tests have
already been written.
- the code in other addons has been adapted consequently.
What's coming next:
- introduce the 'AbstractAction' Widget, and make client actions
and view controllers inherit from it ; this widget will
implement a common API that could be used uniformly by the
ActionManager (e.g. restore(), canBeLeft(), renderButtons(),
getTitle()...).
- move the ControlPanel handling from the ActionManager to the
AbstractAction.
79 lines
3.0 KiB
JavaScript
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();
|
|
});
|
|
});
|
|
});
|