[ADD] events tests

bzr revid: xmo@openerp.com-20120705124342-vm0pavyzqfuwa3k5
This commit is contained in:
Xavier Morel 2012-07-05 14:43:42 +02:00
parent 09bf459bbc
commit d968398d15
2 changed files with 40 additions and 2 deletions

View File

@ -208,6 +208,14 @@ $(document).ready(function () {
]
}
}};
},
'/web/dataset/call_kw:read': function (params) {
return {result: [{
id: 1,
a: 'foo',
b: 'bar',
c: 'baz'
}]};
}
});
}
@ -218,10 +226,11 @@ $(document).ready(function () {
counter: 0,
onEvent: function (e) { this.counter++; }
};
var l = new instance.web.ListView(null, ds);
var l = new instance.web.ListView({}, ds);
l.set_editable(true);
l.on('edit:before edit:after', o, o.onEvent);
l.appendTo($fix)
.pipe(l.proxy('reload_content'))
.always(start)
.pipe(function () {
ok(l.options.editable, "should be editable");
@ -234,5 +243,31 @@ $(document).ready(function () {
})
.fail(function (e) { ok(false, e && e.message); });
});
// TODO: test cancelling edition events
asyncTest('edition events: cancelling', 3, function () {
var edit_after = false;
var ds = new instance.web.DataSetStatic(null, 'demo', null, [1]);
var l = new instance.web.ListView({}, ds);
l.set_editable(true);
l.on('edit:before', {}, function (e) {
e.cancel = true;
});
l.on('edit:after', {}, function () {
edit_after = true;
});
l.appendTo($fix)
.pipe(l.proxy('reload_content'))
.always(start)
.pipe(function () {
ok(l.options.editable, "should be editable");
return l.startEdition();
})
// cancelling an event rejects the deferred
.pipe($.Deferred().reject(), function () {
ok(!l.editor.isEditing(), "should not be editing");
ok(!edit_after, "should not have fired the edit:after event");
return $.when();
})
.fail(function (e) { ok(false, e && e.message || e); });
});
});

View File

@ -41,6 +41,9 @@
<script src="/web/static/src/js/view_list_editable.js"></script>
<script src="/web/static/test/testing.js"></script>
<script type="text/javascript">
QUnit.config.testTimeout = 500;
</script>
</head>
<body id="oe" class="openerp">
<h1 id="qunit-header">OpenERP web Test Suite</h1>