From 5cb64810cd1d20f6ff132507e0010d9d79b148e9 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Wed, 12 Apr 2017 14:54:03 +0800 Subject: [PATCH] FIX: Changing notification level in topic footer buttons was not updating timeline. --- .../topic-notifications-button.js.es6 | 8 ++-- .../components/topic-timeline.js.es6 | 2 +- .../discourse/lib/keyboard-shortcuts.js.es6 | 8 ++-- .../widgets/topic-notifications-button.js.es6 | 2 +- .../topic-notifications-button-test.js.es6 | 45 +++++++++++++++++++ 5 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 test/javascripts/acceptance/topic-notifications-button-test.js.es6 diff --git a/app/assets/javascripts/discourse/components/topic-notifications-button.js.es6 b/app/assets/javascripts/discourse/components/topic-notifications-button.js.es6 index e39f45fd9b8..b53717855de 100644 --- a/app/assets/javascripts/discourse/components/topic-notifications-button.js.es6 +++ b/app/assets/javascripts/discourse/components/topic-notifications-button.js.es6 @@ -9,12 +9,14 @@ export default MountWidget.extend({ }, @observes('topic.details.notification_level') - _triggerRerender() { - this.queueRerender(); + _triggerEvent() { + this.appEvents.trigger('topic-notifications-button:changed', { + type: 'notification', id: this.get('topic.details.notification_level') + }); }, didInsertElement() { this._super(); - this.dispatch('topic-notifications-button:keyboard-trigger', 'topic-notifications-button'); + this.dispatch('topic-notifications-button:changed', 'topic-notifications-button'); } }); diff --git a/app/assets/javascripts/discourse/components/topic-timeline.js.es6 b/app/assets/javascripts/discourse/components/topic-timeline.js.es6 index eaa065857cb..e2b493e45e2 100644 --- a/app/assets/javascripts/discourse/components/topic-timeline.js.es6 +++ b/app/assets/javascripts/discourse/components/topic-timeline.js.es6 @@ -79,6 +79,6 @@ export default MountWidget.extend(Docking, { } this.dispatch('topic:current-post-scrolled', 'timeline-scrollarea'); - this.dispatch('topic-notifications-button:keyboard-trigger', 'topic-notifications-button'); + this.dispatch('topic-notifications-button:changed', 'topic-notifications-button'); } }); diff --git a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 index 15372b27ad6..8a598edbca9 100644 --- a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 +++ b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 @@ -196,19 +196,19 @@ export default { }, setTrackingToMuted(event) { - this.appEvents.trigger('topic-notifications-button:keyboard-trigger', {type: 'notification', id: 0, event}); + this.appEvents.trigger('topic-notifications-button:changed', {type: 'notification', id: 0, event}); }, setTrackingToRegular(event) { - this.appEvents.trigger('topic-notifications-button:keyboard-trigger', {type: 'notification', id: 1, event}); + this.appEvents.trigger('topic-notifications-button:changed', {type: 'notification', id: 1, event}); }, setTrackingToTracking(event) { - this.appEvents.trigger('topic-notifications-button:keyboard-trigger', {type: 'notification', id: 2, event}); + this.appEvents.trigger('topic-notifications-button:changed', {type: 'notification', id: 2, event}); }, setTrackingToWatching(event) { - this.appEvents.trigger('topic-notifications-button:keyboard-trigger', {type: 'notification', id: 3, event}); + this.appEvents.trigger('topic-notifications-button:changed', {type: 'notification', id: 3, event}); }, sendToTopicListItemView(action) { diff --git a/app/assets/javascripts/discourse/widgets/topic-notifications-button.js.es6 b/app/assets/javascripts/discourse/widgets/topic-notifications-button.js.es6 index 9c9f0cec7cb..4bf84e56316 100644 --- a/app/assets/javascripts/discourse/widgets/topic-notifications-button.js.es6 +++ b/app/assets/javascripts/discourse/widgets/topic-notifications-button.js.es6 @@ -88,7 +88,7 @@ export default createWidget('topic-notifications-button', { return this.attrs.topic.get('details').updateNotifications(id); }, - topicNotificationsButtonKeyboardTrigger(msg) { + topicNotificationsButtonChanged(msg) { switch(msg.type) { case 'notification': this.notificationLevelChanged(msg.id); diff --git a/test/javascripts/acceptance/topic-notifications-button-test.js.es6 b/test/javascripts/acceptance/topic-notifications-button-test.js.es6 new file mode 100644 index 00000000000..bc01ada8b34 --- /dev/null +++ b/test/javascripts/acceptance/topic-notifications-button-test.js.es6 @@ -0,0 +1,45 @@ +import { acceptance } from "helpers/qunit-helpers"; +acceptance("Topic Notifications button", { + loggedIn: true, + setup() { + const response = object => { + return [ + 200, + { "Content-Type": "application/json" }, + object + ]; + }; + + server.post('/t/280/notifications', () => { // eslint-disable-line no-undef + return response({}); + }); + } +}); + +test("Share Popup", () => { + visit("/t/internationalization-localization/280"); + + const notificationOptions = "#topic-footer-buttons .notification-options"; + + andThen(() => { + ok( + exists(`${notificationOptions} .tracking`), + "it should display the notification options button in the topic's footer" + ); + }); + + click(`${notificationOptions} .tracking`); + click(`${notificationOptions} .dropdown-menu .watching`); + + andThen(() => { + ok( + exists(`${notificationOptions} .watching`), + "it should display the right notification level" + ); + + ok( + exists(".timeline-footer-controls .notification-options .watching"), + 'it should display the right notification level in topic timeline' + ); + }); +});