diff options
Diffstat (limited to 'addons/web/static/tests')
| -rw-r--r-- | addons/web/static/tests/chrome/action_manager_tests.js | 27 | ||||
| -rw-r--r-- | addons/web/static/tests/services/notification_service_tests.js | 247 | ||||
| -rw-r--r-- | addons/web/static/tests/views/form_tests.js | 29 | ||||
| -rw-r--r-- | addons/web/static/tests/views/list_tests.js | 13 |
4 files changed, 286 insertions, 30 deletions
diff --git a/addons/web/static/tests/chrome/action_manager_tests.js b/addons/web/static/tests/chrome/action_manager_tests.js index 350bf20a06a..656bc3b8e42 100644 --- a/addons/web/static/tests/chrome/action_manager_tests.js +++ b/addons/web/static/tests/chrome/action_manager_tests.js @@ -2,7 +2,7 @@ odoo.define('web.action_manager_tests', function (require) { "use strict"; var ReportClientAction = require('report.client_action'); - +var NotificationService = require('web.NotificationService'); var AbstractAction = require('web.AbstractAction'); var AbstractStorageService = require('web.AbstractStorageService'); var BasicFields = require('web.basic_fields'); @@ -1770,6 +1770,7 @@ QUnit.module('ActionManager', { assert.step(params.url); params.success(); params.complete(); + return true; }, }, }); @@ -1797,7 +1798,11 @@ QUnit.module('ActionManager', { actions: this.actions, archs: this.archs, data: this.data, - services: [ReportService], + services: [ReportService, NotificationService.extend({ + notify: function (params) { + assert.step(params.type || 'notification'); + } + })], mockRPC: function (route, args) { assert.step(args.method || route); if (route === '/report/check_wkhtmltopdf') { @@ -1810,11 +1815,7 @@ QUnit.module('ActionManager', { assert.step(params.url); params.success(); params.complete(); - }, - }, - intercepts: { - notification: function () { - assert.step('notification'); + return true; }, }, }); @@ -1851,7 +1852,11 @@ QUnit.module('ActionManager', { actions: this.actions, archs: this.archs, data: this.data, - services: [ReportService], + services: [ReportService, NotificationService.extend({ + notify: function (params) { + assert.step(params.type || 'notification'); + } + })], mockRPC: function (route, args) { assert.step(args.method || route); if (route === '/report/check_wkhtmltopdf') { @@ -1865,11 +1870,7 @@ QUnit.module('ActionManager', { session: { get_file: function (params) { assert.step(params.url); // should not be called - }, - }, - intercepts: { - notification: function () { - assert.step('notification'); + return true; }, }, }); diff --git a/addons/web/static/tests/services/notification_service_tests.js b/addons/web/static/tests/services/notification_service_tests.js new file mode 100644 index 00000000000..68227093cea --- /dev/null +++ b/addons/web/static/tests/services/notification_service_tests.js @@ -0,0 +1,247 @@ +odoo.define('web.notification_tests', function (require) { +"use strict"; + +var AbstractView = require('web.AbstractView'); +var Notification = require('web.Notification'); +var NotificationService = require('web.NotificationService'); + +var testUtils = require('web.test_utils'); +var createView = testUtils.createView; + + +QUnit.module('Services', { + beforeEach: function () { + testUtils.patch(Notification, { + _autoCloseDelay: 0, + _animationDelay: 0, + }); + this.viewParams = { + View: AbstractView, + arch: '<fake/>', + data: { + fake_model: { + fields: {}, + record: [], + }, + }, + model: 'fake_model', + services: [NotificationService], + }; + }, + afterEach: function () { + testUtils.unpatch(Notification); + } +}, function () { + QUnit.module('Notification'); + + QUnit.test('Display a simple notification', function (assert) { + var done = assert.async(); + assert.expect(4); + + var view = createView(this.viewParams); + view.call('notification', 'notify', { + title: 'a', + message: 'b', + }); + var $notification = $('body .o_notification_manager .o_notification'); + assert.strictEqual(_.str.trim($notification.html().replace(/\s+/g, ' ')), + "<div class=\"o_notification_title\"> <span class=\"o_icon fa fa-3x fa-lightbulb-o\"></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(); + }); + }); + + QUnit.test('Display a warning', function (assert) { + var done = assert.async(); + assert.expect(1); + + var view = createView(this.viewParams); + view.call('notification', 'notify', { + title: 'a', + message: 'b', + type: 'warning' + }); + var $notification = $('body .o_notification_manager .o_notification'); + assert.strictEqual(_.str.trim($notification.html().replace(/\s+/g, ' ')), + "<div class=\"o_notification_title\"> <span class=\"o_icon fa fa-3x fa-exclamation\"></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(); + assert.expect(3); + + var view = createView(this.viewParams); + view.call('notification', 'notify', { + title: 'a', + message: 'b', + sticky: true, + }); + var $notification = $('body .o_notification_manager .o_notification'); + assert.strictEqual($notification.find('.o_close').length, 1, "should display the close button in notification"); + + setTimeout(function () { + assert.strictEqual($notification.is(':hidden'), false, "should not hide the notification automatically"); + $notification.find('.o_close').click(); + setTimeout(function () { + assert.strictEqual($('body .o_notification_manager .o_notification').length, 0, "should destroy the notification"); + view.destroy(); + done(); + }); + }); + }); + + QUnit.test('Display a simple notification with onClose callback when automatically close', function (assert) { + var done = assert.async(); + assert.expect(2); + + var close = 0; + var view = createView(this.viewParams); + view.call('notification', 'notify', { + title: 'a', + message: 'b', + onClose: function () { + close++; + } + }); + 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(); + }); + }); + + QUnit.test('Display a sticky notification with onClose callback', function (assert) { + var done = assert.async(); + assert.expect(2); + + testUtils.unpatch(Notification); + testUtils.patch(Notification, { + _autoCloseDelay: 2500, + _animationDelay: 0, + }); + var view = createView(this.viewParams); + + var close = 0; + view.call('notification', 'notify', { + title: 'a', + message: 'b', + sticky: true, + onClose: function () { + close++; + } + }); + assert.strictEqual(close, 0, "should wait to call onClose method once"); + $('body .o_notification_manager .o_notification .o_close').click(); + setTimeout(function () { + assert.strictEqual(close, 1, "should call onClose method once"); + view.destroy(); + done(); + }); + }); + + QUnit.test('Display a question', function (assert) { + var done = assert.async(); + assert.expect(8); + + var view = createView(this.viewParams); + function notification (inc) { + return { + title: 'a' + inc, + message: 'b' + inc, + buttons: [ + { + text: 'accept' + inc, + primary: true, + click: function () { + assert.step('accept' + inc); + }, + }, + { + text: 'refuse' + inc, + click: function () { + assert.step('refuse' + inc); + }, + } + ], + onClose: function () { + assert.step('close' + inc); + } + }; + }; + view.call('notification', 'notify', notification(0)); + view.call('notification', 'notify', notification(1)); + view.call('notification', 'notify', notification(2)); + + 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.strictEqual(_.str.trim($notification.eq(0).html().replace(/\s+/g, ' ')), + "<a class=\"fa fa-times o_close\" href=\"#\"></a> <div class=\"o_notification_title\"> <span class=\"o_icon fa fa-3x fa-question-circle-o\"></span> a0 </div> <div class=\"o_notification_content\">b0</div> <div class=\"o_buttons\"> <button type=\"button\" class=\"btn btn-sm btn-primary\"> <span>accept0</span> </button><button type=\"button\" class=\"btn btn-sm btn-default\"> <span>refuse0</span> </button> </div>", + "should display notification"); + + $notification.find('.o_buttons button:contains(accept0)').click(); + $notification.find('.o_buttons button:contains(accept0)').click(); + $notification.find('.o_buttons button:contains(refuse0)').click(); + $notification.eq(0).find('.o_close').click(); + + $notification.find('.o_buttons button:contains(refuse1)').click(); + + $notification.eq(2).find('.o_close').click(); + + 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(); + }); + }); + + QUnit.test('call close notification service', function (assert) { + var done = assert.async(); + assert.expect(2); + + testUtils.unpatch(Notification); + testUtils.patch(Notification, { + _autoCloseDelay: 2500, + _animationDelay: 0, + }); + var view = createView(this.viewParams); + + var close = 0; + var notificationId0 = view.call('notification', 'notify', { + title: 'a', + message: 'b', + onClose: function () { + close++; + } + }); + var notificationId1 = view.call('notification', 'notify', { + title: 'a', + message: 'b', + sticky: true, + onClose: function () { + close++; + } + }); + + view.call('notification', 'close', notificationId0); + view.call('notification', 'close', notificationId1); + + 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(); + }); + }); + +});}); diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index 534fa4fbea9..76c97b10d70 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -8,6 +8,7 @@ var core = require('web.core'); var fieldRegistry = require('web.field_registry'); var FormView = require('web.FormView'); var mixins = require('web.mixins'); +var NotificationService = require('web.NotificationService'); var pyeval = require('web.pyeval'); var testUtils = require('web.test_utils'); var widgetRegistry = require('web.widget_registry'); @@ -2669,13 +2670,17 @@ QUnit.module('Views', { arch: '<form string="Partners">' + '<group><field name="foo"/></group>' + '</form>', - }); - - testUtils.intercept(form, 'warning', function (event) { - assert.strictEqual(event.data.title, 'The following fields are invalid:', - "should have a warning with correct title"); - assert.strictEqual(event.data.message, '<ul><li>Foo</li></ul>', - "should have a warning with correct message"); + services: [NotificationService.extend({ + notify: function (params) { + if (params.type !== 'warning') { + return; + } + assert.strictEqual(params.title, 'The following fields are invalid:', + "should have a warning with correct title"); + assert.strictEqual(params.message, '<ul><li>Foo</li></ul>', + "should have a warning with correct message"); + } + })], }); form.$buttons.find('.o_form_button_save').click(); @@ -4713,11 +4718,11 @@ QUnit.module('Views', { } return result; }, - intercepts: { - warning: function () { - assert.step('warning'); - }, - }, + services: [NotificationService.extend({ + notify: function (params) { + assert.step(params.type); + } + })], }); form.$buttons.find('.o_form_button_edit').click(); diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index c42fbfc4725..fd2f77f068d 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -8,6 +8,7 @@ var basicFields = require('web.basic_fields'); var FormView = require('web.FormView'); var ListView = require('web.ListView'); var mixins = require('web.mixins'); +var NotificationService = require('web.NotificationService'); var testUtils = require('web.test_utils'); var widgetRegistry = require('web.widget_registry'); var Widget = require('web.Widget'); @@ -2095,11 +2096,13 @@ QUnit.module('Views', { '<field name="foo" required="1"/>' + '<field name="bar"/>' + '</tree>', - intercepts: { - warning: function () { - warnings++; - }, - }, + services: [NotificationService.extend({ + notify: function (params) { + if (params.type === 'warning') { + warnings++; + } + } + })], }); // Start first line edition |
