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.');