summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Schippefilt <vsc@odoo.com>2019-03-06 14:02:01 +0100
committerAaron Bohy <aab@odoo.com>2019-03-06 20:07:17 +0100
commit2a2f2cfec25f1789c1f830a7213c24d79d28e62e (patch)
treeb6b5c50c4c3dad8e9a98aa7d5c56cddea3bb9cca
parentff7a82c81babbcf29ae071b7e9247c52f5f71fc4 (diff)
[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>
-rw-r--r--addons/hr_attendance/static/src/js/kiosk_mode.js2
-rw-r--r--addons/hr_attendance/static/src/js/my_attendances.js2
-rw-r--r--addons/hr_attendance/static/tests/hr_attendance_tests.js25
3 files changed, 17 insertions, 12 deletions
diff --git a/addons/hr_attendance/static/src/js/kiosk_mode.js b/addons/hr_attendance/static/src/js/kiosk_mode.js
index cbb84282eff..5370874a1b9 100644
--- a/addons/hr_attendance/static/src/js/kiosk_mode.js
+++ b/addons/hr_attendance/static/src/js/kiosk_mode.js
@@ -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) {
diff --git a/addons/hr_attendance/static/src/js/my_attendances.js b/addons/hr_attendance/static/src/js/my_attendances.js
index b79469596af..5bf9884875d 100644
--- a/addons/hr_attendance/static/src/js/my_attendances.js
+++ b/addons/hr_attendance/static/src/js/my_attendances.js
@@ -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 () {
diff --git a/addons/hr_attendance/static/tests/hr_attendance_tests.js b/addons/hr_attendance/static/tests/hr_attendance_tests.js
index a2bc6d6a6b9..a1cf6955791 100644
--- a/addons/hr_attendance/static/tests/hr_attendance_tests.js
+++ b/addons/hr_attendance/static/tests/hr_attendance_tests.js
@@ -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.');