summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/widgets/notification_alert
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/mail/static/src/widgets/notification_alert
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/mail/static/src/widgets/notification_alert')
-rw-r--r--addons/mail/static/src/widgets/notification_alert/notification_alert.js45
-rw-r--r--addons/mail/static/src/widgets/notification_alert/notification_alert_tests.js103
2 files changed, 148 insertions, 0 deletions
diff --git a/addons/mail/static/src/widgets/notification_alert/notification_alert.js b/addons/mail/static/src/widgets/notification_alert/notification_alert.js
new file mode 100644
index 00000000..27055cd7
--- /dev/null
+++ b/addons/mail/static/src/widgets/notification_alert/notification_alert.js
@@ -0,0 +1,45 @@
+odoo.define('mail/static/src/widgets/notification_alert/notification_alert.js', function (require) {
+"use strict";
+
+const components = {
+ NotificationAlert: require('mail/static/src/components/notification_alert/notification_alert.js'),
+};
+
+const { ComponentWrapper, WidgetAdapterMixin } = require('web.OwlCompatibility');
+
+const Widget = require('web.Widget');
+const widgetRegistry = require('web.widget_registry');
+
+class NotificationAlertWrapper extends ComponentWrapper {}
+
+// -----------------------------------------------------------------------------
+// Display Notification alert on user preferences form view
+// -----------------------------------------------------------------------------
+const NotificationAlert = Widget.extend(WidgetAdapterMixin, {
+ /**
+ * @override
+ */
+ init() {
+ this._super(...arguments);
+ this.component = undefined;
+ },
+ /**
+ * @override
+ */
+ async start() {
+ await this._super(...arguments);
+
+ this.component = new NotificationAlertWrapper(
+ this,
+ components.NotificationAlert,
+ {}
+ );
+ await this.component.mount(this.el);
+ },
+});
+
+widgetRegistry.add('notification_alert', NotificationAlert);
+
+return NotificationAlert;
+
+});
diff --git a/addons/mail/static/src/widgets/notification_alert/notification_alert_tests.js b/addons/mail/static/src/widgets/notification_alert/notification_alert_tests.js
new file mode 100644
index 00000000..20297c85
--- /dev/null
+++ b/addons/mail/static/src/widgets/notification_alert/notification_alert_tests.js
@@ -0,0 +1,103 @@
+odoo.define('mail/static/src/widgets/notification_alert/notification_alert_tests.js', function (require) {
+'use strict';
+
+const { afterEach, beforeEach, start } = require('mail/static/src/utils/test_utils.js');
+
+const FormView = require('web.FormView');
+
+QUnit.module('mail', {}, function () {
+QUnit.module('widgets', {}, function () {
+QUnit.module('notification_alert', {}, function () {
+QUnit.module('notification_alert_tests.js', {
+ beforeEach() {
+ beforeEach(this);
+
+ this.start = async params => {
+ let { widget } = await start(Object.assign({
+ data: this.data,
+ hasView: true,
+ // View params
+ View: FormView,
+ model: 'mail.message',
+ arch: `
+ <form>
+ <widget name="notification_alert"/>
+ </form>
+ `,
+ }, params));
+ this.widget = widget;
+ };
+ },
+ afterEach() {
+ afterEach(this);
+ },
+});
+
+QUnit.skip('notification_alert widget: display blocked notification alert', async function (assert) {
+ // FIXME: Test should work, but for some reasons OWL always flags the
+ // component as not mounted, even though it is in the DOM and it's state
+ // is good for rendering... task-227947
+ assert.expect(1);
+
+ await this.start({
+ env: {
+ browser: {
+ Notification: {
+ permission: 'denied',
+ },
+ },
+ },
+ });
+
+ assert.containsOnce(
+ document.body,
+ '.o_notification_alert',
+ "Blocked notification alert should be displayed"
+ );
+});
+
+QUnit.test('notification_alert widget: no notification alert when granted', async function (assert) {
+ assert.expect(1);
+
+ await this.start({
+ env: {
+ browser: {
+ Notification: {
+ permission: 'granted',
+ },
+ },
+ },
+ });
+
+ assert.containsNone(
+ document.body,
+ '.o_notification_alert',
+ "Blocked notification alert should not be displayed"
+ );
+});
+
+QUnit.test('notification_alert widget: no notification alert when default', async function (assert) {
+ assert.expect(1);
+
+ await this.start({
+ env: {
+ browser: {
+ Notification: {
+ permission: 'default',
+ },
+ },
+ },
+ });
+
+ assert.containsNone(
+ document.body,
+ '.o_notification_alert',
+ "Blocked notification alert should not be displayed"
+ );
+});
+
+});
+});
+});
+
+});