diff options
| author | Vincent Schippefilt <vsc@odoo.com> | 2019-03-06 14:02:32 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2019-03-06 20:07:17 +0100 |
| commit | ab56e637b7f97ddcdbcc9baea99ae097e342409c (patch) | |
| tree | 4cb47da9f7ef89b19d18429220a7507470ec12a9 /addons/web/static/tests/services/notification_service_tests.js | |
| parent | eeed894fd50e477135e1ac9a82f6e98ce063ab90 (diff) | |
[REF] web: 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>
Diffstat (limited to 'addons/web/static/tests/services/notification_service_tests.js')
| -rw-r--r-- | addons/web/static/tests/services/notification_service_tests.js | 126 |
1 files changed, 53 insertions, 73 deletions
diff --git a/addons/web/static/tests/services/notification_service_tests.js b/addons/web/static/tests/services/notification_service_tests.js index 8a10b9f2df9..aed8d2fa847 100644 --- a/addons/web/static/tests/services/notification_service_tests.js +++ b/addons/web/static/tests/services/notification_service_tests.js @@ -41,76 +41,68 @@ QUnit.module('Services', { }, function () { QUnit.module('Notification'); - QUnit.test('Display a simple notification', function (assert) { - var done = assert.async(); + QUnit.test('Display a simple notification', async function (assert) { assert.expect(4); - var view = createView(this.viewParams); + var view = await createView(this.viewParams); view.call('notification', 'notify', { title: 'a', message: 'b', }); + await testUtils.nextMicrotaskTick(); var $notification = $('body .o_notification_manager .o_notification'); assert.strictEqual(_.str.trim($notification.html().replace(/\s+/g, ' ')), "<div class=\"o_notification_title\"> <span role=\"img\" aria-label=\"Notification undefined\" class=\"o_icon fa fa-3x fa-lightbulb-o\" title=\"Notification undefined\"></span> a </div> <div class=\"o_notification_content\">b</div>", "should display notification"); - assert.strictEqual($notification.find('.o_close').length, 0, "should not display the close button in "); - setTimeout(function () { - assert.strictEqual($notification.is(':hidden'), true, "should hide the notification"); - assert.strictEqual($('body .o_notification_manager .o_notification').length, 0, "should destroy the notification"); - view.destroy(); - done(); - }); + assert.containsNone($notification, '.o_close', "should not display the close button in "); + await testUtils.nextTick(); + assert.strictEqual($notification.is(':hidden'), true, "should hide the notification"); + assert.strictEqual($('body .o_notification_manager .o_notification').length, 0, "should destroy the notification"); + view.destroy(); }); - QUnit.test('Display a warning', function (assert) { - var done = assert.async(); + QUnit.test('Display a warning', async function (assert) { assert.expect(1); - var view = createView(this.viewParams); + var view = await createView(this.viewParams); view.call('notification', 'notify', { title: 'a', message: 'b', type: 'warning' }); + await testUtils.nextMicrotaskTick(); var $notification = $('body .o_notification_manager .o_notification'); assert.strictEqual(_.str.trim($notification.html().replace(/\s+/g, ' ')), "<div class=\"o_notification_title\"> <span role=\"img\" aria-label=\"Notification undefined\" class=\"o_icon fa fa-3x fa-exclamation\" title=\"Notification undefined\"></span> a </div> <div class=\"o_notification_content\">b</div>", "should display notification"); view.destroy(); - setTimeout(done); }); - QUnit.test('Display a sticky notification', function (assert) { - var done = assert.async(); + QUnit.test('Display a sticky notification', async function (assert) { assert.expect(3); - var view = createView(this.viewParams); + var view = await createView(this.viewParams); view.call('notification', 'notify', { title: 'a', message: 'b', sticky: true, }); + await testUtils.nextTick(); var $notification = $('body .o_notification_manager .o_notification'); - assert.strictEqual($notification.find('.o_close').length, 1, "should display the close button in notification"); + assert.containsOnce($notification, '.o_close', "should display the close button in notification"); - setTimeout(function () { - assert.strictEqual($notification.is(':hidden'), false, "should not hide the notification automatically"); - testUtils.dom.click($notification.find('.o_close')); - setTimeout(function () { - assert.strictEqual($('body .o_notification_manager .o_notification').length, 0, "should destroy the notification"); - view.destroy(); - done(); - }); - }); + assert.strictEqual($notification.is(':hidden'), false, "should not hide the notification automatically"); + await testUtils.dom.click($notification.find('.o_close')); + assert.strictEqual($('body .o_notification_manager .o_notification').length, + 0, "should destroy the notification"); + view.destroy(); }); - QUnit.test('Display a simple notification with onClose callback when automatically close', function (assert) { - var done = assert.async(); + QUnit.test('Display a simple notification with onClose callback when automatically close', async function (assert) { assert.expect(2); var close = 0; - var view = createView(this.viewParams); + var view = await createView(this.viewParams); view.call('notification', 'notify', { title: 'a', message: 'b', @@ -118,16 +110,14 @@ QUnit.module('Services', { close++; } }); + await testUtils.nextMicrotaskTick(); view.destroy(); assert.strictEqual(close, 0, "should wait to call onClose method once"); - setTimeout(function () { - assert.strictEqual(close, 1, "should call onClose method once"); - done(); - }); + await testUtils.nextTick(); + assert.strictEqual(close, 1, "should call onClose method once"); }); - QUnit.test('Display a sticky notification with onClose callback', function (assert) { - var done = assert.async(); + QUnit.test('Display a sticky notification with onClose callback', async function (assert) { assert.expect(2); testUtils.mock.unpatch(Notification); @@ -135,7 +125,7 @@ QUnit.module('Services', { _autoCloseDelay: 2500, _animationDelay: 0, }); - var view = createView(this.viewParams); + var view = await createView(this.viewParams); var close = 0; view.call('notification', 'notify', { @@ -146,20 +136,17 @@ QUnit.module('Services', { close++; } }); + await testUtils.nextMicrotaskTick(); assert.strictEqual(close, 0, "should wait to call onClose method once"); testUtils.dom.click($('body .o_notification_manager .o_notification .o_close')); - setTimeout(function () { - assert.strictEqual(close, 1, "should call onClose method once"); - view.destroy(); - done(); - }); + assert.strictEqual(close, 1, "should call onClose method once"); + view.destroy(); }); - QUnit.test('Display a question', function (assert) { - var done = assert.async(); + QUnit.test('Display a question', async function (assert) { assert.expect(8); - var view = createView(this.viewParams); + var view = await createView(this.viewParams); function notification (inc) { return { title: 'a' + inc, @@ -187,9 +174,11 @@ QUnit.module('Services', { view.call('notification', 'notify', notification(0)); view.call('notification', 'notify', notification(1)); view.call('notification', 'notify', notification(2)); + await testUtils.nextTick(); var $notification = $('body .o_notification_manager .o_notification'); - assert.strictEqual($notification.eq(0).find('.o_close').length, 1, "should display the close button in notification"); + assert.containsOnce($notification.eq(0), '.o_close', + "should display the close button in notification"); assert.strictEqual(_.str.trim($notification.eq(0).html().replace(/\s+/g, ' ')), "<a aria-label=\"Close\" class=\"fa fa-times o_close\" href=\"#\" title=\"Close\"></a> <div class=\"o_notification_title\"> <span role=\"img\" aria-label=\"Notification undefined\" class=\"o_icon fa fa-3x fa-question-circle-o\" title=\"Notification undefined\"></span> a0 </div> <div class=\"o_notification_content\">b0</div> <div class=\"o_buttons\"> <button class=\"btn btn-primary\" type=\"button\"> <span>accept0</span> </button><button class=\"btn btn-secondary\" type=\"button\"> <span>refuse0</span> </button> </div>", "should display notification"); @@ -198,17 +187,14 @@ QUnit.module('Services', { testUtils.dom.click($notification.find('.o_buttons button:contains(refuse1)')); testUtils.dom.click($notification.eq(2).find('.o_close')); - setTimeout(function () { - assert.strictEqual($notification.is(':hidden'), true, "should hide the notification"); - assert.strictEqual($('body .o_notification_manager .o_notification').length, 0, "should destroy the notification"); - assert.verifySteps(['accept0', 'refuse1', 'close2']); - view.destroy(); - done(); - }); + assert.strictEqual($notification.is(':hidden'), true, "should hide the notification"); + assert.strictEqual($('body .o_notification_manager .o_notification').length, + 0, "should destroy the notification"); + assert.verifySteps(['accept0', 'refuse1', 'close2']); + view.destroy(); }); - QUnit.test('call close notification service', function (assert) { - var done = assert.async(); + QUnit.test('call close notification service', async function (assert) { assert.expect(2); testUtils.mock.unpatch(Notification); @@ -216,7 +202,7 @@ QUnit.module('Services', { _autoCloseDelay: 2500, _animationDelay: 0, }); - var view = createView(this.viewParams); + var view = await createView(this.viewParams); var close = 0; var notificationId0 = view.call('notification', 'notify', { @@ -234,20 +220,18 @@ QUnit.module('Services', { close++; } }); + await testUtils.nextTick(); view.call('notification', 'close', notificationId0); view.call('notification', 'close', notificationId1); + await testUtils.nextTick(); - setTimeout(function () { - assert.strictEqual($('body .o_notification_manager .o_notification').length, 0, "should destroy the notifications"); - assert.strictEqual(close, 2, "should call onClose method twice"); - view.destroy(); - done(); - }); + assert.strictEqual($('body .o_notification_manager .o_notification').length, 0, "should destroy the notifications"); + assert.strictEqual(close, 2, "should call onClose method twice"); + view.destroy(); }); - QUnit.test('Display a custom notification', function (assert) { - var done = assert.async(); + QUnit.test('Display a custom notification', async function (assert) { assert.expect(3); var Custom = Notification.extend({ @@ -263,21 +247,17 @@ QUnit.module('Services', { }, }); - var view = createView(this.viewParams); + var view = await createView(this.viewParams); view.call('notification', 'notify', { Notification: Custom, customParams: true, }); - assert.strictEqual( - $('body .o_notification_manager .o_notification:contains(Custom)').length, 1, + await testUtils.nextMicrotaskTick(); + assert.containsOnce($('body'), '.o_notification_manager .o_notification:contains(Custom)', "should display the notification"); view.destroy(); - setTimeout(function () { - assert.strictEqual( - $('body .o_notification_manager .o_notification').length, 0, - "should destroy the notification"); - done(); - }); + assert.containsNone($('body'), '.o_notification_manager .o_notification', + "should destroy the notification"); }); });}); |
