[TEST] saving of record being edited, improve RPC mocking to allow dispatch on ORM method name

bzr revid: xmo@openerp.com-20120704132822-3p4h1c6cyr0qvn2x
This commit is contained in:
Xavier Morel 2012-07-04 15:28:22 +02:00
parent 9c6f8c5335
commit 25284686f3
3 changed files with 75 additions and 5 deletions

View File

@ -232,7 +232,9 @@ openerp.web.list_editable = function (instance) {
event = event || {}; event = event || {};
this.trigger(event_name + ':before', event); this.trigger(event_name + ':before', event);
if (event.cancel) { if (event.cancel) {
return $.Deferred().reject(); return $.Deferred().reject({
message: _.str.sprintf("Event %s:before cancelled",
event_name)});
} }
return $.when(action.apply(this.editor, args || [])).then(function () { return $.when(action.apply(this.editor, args || [])).then(function () {
self.trigger.apply(self, [event_name + ':after'] self.trigger.apply(self, [event_name + ':after']
@ -424,7 +426,8 @@ openerp.web.list_editable = function (instance) {
var record = this.record; var record = this.record;
this.record = null; this.record = null;
if (!this.form.can_be_discarded()) { if (!this.form.can_be_discarded()) {
return $.Deferred().reject().promise(); return $.Deferred().reject({
message: "The form's data can not be discarded"}).promise();
} }
this.form.do_hide(); this.form.do_hide();
return $.when(record); return $.when(record);

View File

@ -37,4 +37,66 @@ $(document).ready(function () {
"should use default form type"); "should use default form type");
}); });
}); });
asyncTest('toggle-edition-new', function () {
instance.connection.responses['/web/dataset/call_kw:create'] = function () {
return { result: 42 };
};
instance.connection.responses['/web/dataset/call_kw:read'] = function () {
return { result: [{
id: 42,
a: false,
b: false,
c: false
}]};
};
var e = new instance.web.list.Editor({
do_warn: function (e) {
warning = e;
},
dataset: new instance.web.DataSetSearch(),
isPrependOnCreate: function () { return false; },
editionView: function () {
return {
arch: {
tag: 'form',
attrs: {
version: '7.0',
'class': 'oe_form_container'
},
children: [
{tag: 'field', attrs: {name: 'a'}},
{tag: 'field', attrs: {name: 'b'}},
{tag: 'field', attrs: {name: 'c'}}
]
},
fields: {
a: {type: 'char'},
b: {type: 'char'},
c: {type: 'char'}
}
};
}
});
var counter = 0;
var warning = null;
e.appendTo($fix)
.pipe(function () {
return e.edit(null, function () {
++counter;
});
})
.pipe(function (form) {
ok(e.isEditing(), "editor is now editing");
equal(counter, 3, "all fields have been configured");
strictEqual(form, e.form);
return e.save();
})
.always(start)
.fail(function (error) { ok(false, error && error.message); })
.done(function (record) {
ok(!warning, "should have received no warning");
ok(!e.isEditing(), "should have stopped editing");
equal(record.id, 42, "should have newly created id");
})
});
}); });

View File

@ -55,11 +55,16 @@ openerp.testing = (function () {
var connection = instance.connection; var connection = instance.connection;
connection.responses = responses || {}; connection.responses = responses || {};
connection.rpc_function = function (url, payload) { connection.rpc_function = function (url, payload) {
if (!(url.url in this.responses)) { var fn = this.responses[url.url + ':' + payload.params.method]
|| this.responses[url.url];
if (!fn) {
return $.Deferred().reject({}, 'failed', return $.Deferred().reject({}, 'failed',
_.str.sprintf("Url %s not found in mock responses", url.url)).promise(); _.str.sprintf("Url %s not found in mock responses, with arguments %s",
url.url, JSON.stringify(payload.params))
).promise();
} }
return $.when(this.responses[url.url](payload)); return $.when(fn(payload));
}; };
}, },
/** /**