[REF] hr_attendance: adapt code after jQuery update

Part of task 1896658

Co-authored-by: Aaron Bohy <aab@odoo.com>
Co-authored-by: Christophe Matthieu <chm@odoo.com>
Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Co-authored-by: David Monjoie <dmo@odoo.com>
Co-authored-by: Martin Geubelle <mge@odoo.com>
Co-authored-by: svs-odoo <svs@odoo.com>
Co-authored-by: Vincent Schippefilt <vsc@odoo.com>
This commit is contained in:
Vincent Schippefilt
2019-03-06 20:07:17 +01:00
committed by Aaron Bohy
co-authored by Aaron Bohy Christophe Matthieu Mathieu Duckerts-Antoine David Monjoie Martin Geubelle svs-odoo
parent ff7a82c81b
commit 2a2f2cfec2
3 changed files with 17 additions and 12 deletions
@@ -31,7 +31,7 @@ var KioskMode = AbstractAction.extend({
});
// Make a RPC call every day to keep the session alive
self._interval = window.setInterval(this._callServer.bind(this), (60*60*1000*24));
return $.when(def, this._super.apply(this, arguments));
return Promise.all([def, this._super.apply(this, arguments)]);
},
_onBarcodeScanned: function(barcode) {
@@ -25,7 +25,7 @@ var MyAttendances = AbstractAction.extend({
self.employee = res.length && res[0];
});
return $.when(def, this._super.apply(this, arguments));
return Promise.all([def, this._super.apply(this, arguments)]);
},
update_attendance: function () {
@@ -53,7 +53,7 @@ QUnit.module('HR Attendance', {
}, function () {
QUnit.module('My attendances (client action)');
QUnit.test('simple rendering', function (assert) {
QUnit.test('simple rendering', async function (assert) {
assert.expect(1);
var $target = $('#qunit-fixture');
@@ -64,7 +64,7 @@ QUnit.module('HR Attendance', {
uid: 1,
},
});
clientAction.appendTo($target);
await clientAction.appendTo($target);
assert.strictEqual(clientAction.$('.o_hr_attendance_kiosk_mode h1').text(), 'Employee A',
"should have rendered the client action without crashing");
@@ -72,7 +72,7 @@ QUnit.module('HR Attendance', {
clientAction.destroy();
});
QUnit.test('Attendance Kiosk Mode Test', function (assert) {
QUnit.test('Attendance Kiosk Mode Test', async function (assert) {
assert.expect(2);
var $target = $('#qunit-fixture');
@@ -89,12 +89,12 @@ QUnit.module('HR Attendance', {
if (args.method === 'attendance_scan' && args.model === 'hr.employee') {
rpcCount++;
return $.when(self.data['hr.employee'].records[0]);
return Promise.resolve(self.data['hr.employee'].records[0]);
}
return this._super(route, args);
},
});
clientAction.appendTo($target);
await clientAction.appendTo($target);
core.bus.trigger('barcode_scanned', 1);
core.bus.trigger('barcode_scanned', 1);
assert.strictEqual(rpcCount, 1, 'RPC call should have been done only once.');
@@ -105,7 +105,7 @@ QUnit.module('HR Attendance', {
clientAction.destroy();
});
QUnit.test('Attendance Greeting Message Test', function (assert) {
QUnit.test('Attendance Greeting Message Test', async function (assert) {
assert.expect(10);
var $target = $('#qunit-fixture');
@@ -113,7 +113,7 @@ QUnit.module('HR Attendance', {
var rpcCount = 0;
var clientActions = [];
function createGreetingMessage (target, barcode){
async function createGreetingMessage (target, barcode){
var action = {
attendance: {
check_in: "2018-09-20 13:41:13",
@@ -138,18 +138,19 @@ QUnit.module('HR Attendance', {
as functional flow.
*/
createGreetingMessage (target, args.args[0]);
return $.when({action: action});
return Promise.resolve({action: action});
}
return this._super(route, args);
},
});
clientAction.appendTo(target);
await clientAction.appendTo(target);
clientActions.push(clientAction);
}
// init - mock coming from kiosk
createGreetingMessage ($target, 1);
await createGreetingMessage ($target, 1);
await testUtils.nextMicrotaskTick();
assert.strictEqual(clientActions.length, 1, 'Number of clientAction must = 1.');
core.bus.trigger('barcode_scanned', 1);
@@ -161,15 +162,19 @@ QUnit.module('HR Attendance', {
assert.strictEqual(rpcCount, 0, 'RPC call should not have been done.');
core.bus.trigger('barcode_scanned', 2);
await testUtils.nextTick();
assert.strictEqual(clientActions.length, 2, 'Number of clientActions must = 2.');
assert.strictEqual(rpcCount, 1, 'RPC call should have been done only once.');
core.bus.trigger('barcode_scanned', 2);
await testUtils.nextMicrotaskTick();
assert.strictEqual(clientActions.length, 2, 'Number of clientActions must = 2.');
assert.strictEqual(rpcCount, 1, 'RPC call should have been done only once.');
core.bus.trigger('barcode_scanned', 1);
await testUtils.nextTick();
assert.strictEqual(clientActions.length, 3, 'Number of clientActions must = 3.');
core.bus.trigger('barcode_scanned', 1);
await testUtils.nextMicrotaskTick();
assert.strictEqual(clientActions.length, 3, 'Number of clientActions must = 3.');
assert.strictEqual(rpcCount, 2, 'RPC call should have been done only twice.');