diff --git a/app/screens/settings/notification_settings/notification_settings.js b/app/screens/settings/notification_settings/notification_settings.js index 9c832cd07..a878b43ea 100644 --- a/app/screens/settings/notification_settings/notification_settings.js +++ b/app/screens/settings/notification_settings/notification_settings.js @@ -134,12 +134,13 @@ export default class NotificationSettings extends PureComponent { saveNotificationProps = (notifyProps) => { const {currentUser} = this.props; + const prevProps = getNotificationProps(currentUser); const updatedProps = { - ...getNotificationProps(currentUser), + ...prevProps, ...notifyProps, }; - if (!deepEqual(updatedProps, notifyProps)) { + if (!deepEqual(prevProps, notifyProps)) { this.props.actions.updateMe({notify_props: updatedProps}); } }; diff --git a/app/screens/settings/notification_settings/notification_settings.test.js b/app/screens/settings/notification_settings/notification_settings.test.js index 96cacca59..863a966f6 100644 --- a/app/screens/settings/notification_settings/notification_settings.test.js +++ b/app/screens/settings/notification_settings/notification_settings.test.js @@ -9,13 +9,16 @@ import {shallowWithIntl} from 'test/intl-test-helper'; import NotificationSettings from './notification_settings.js'; +import {getNotificationProps} from 'app/utils/notify_props'; + describe('NotificationSettings', () => { + const currentUser = {id: 'current_user_id'}; const baseProps = { actions: { updateMe: jest.fn(), }, componentId: 'component-id', - currentUser: {id: 'current_user_id'}, + currentUser, theme: Preferences.THEMES.default, updateMeRequest: {}, currentUserStatus: 'status', @@ -32,17 +35,22 @@ describe('NotificationSettings', () => { }); test('should include previous notification props when saving new ones', () => { - baseProps.currentUser.notify_props = {previous: 'previous'}; const wrapper = shallowWithIntl( ); const instance = wrapper.instance(); + + const defaultNotifyProps = getNotificationProps(currentUser); + instance.saveNotificationProps(defaultNotifyProps); + expect(baseProps.actions.updateMe).toHaveBeenCalledTimes(0); + const newProps = {new: 'new'}; instance.saveNotificationProps(newProps); + expect(baseProps.actions.updateMe).toHaveBeenCalledTimes(1); expect(baseProps.actions.updateMe).toHaveBeenCalledWith({ notify_props: { - ...baseProps.currentUser.notify_props, + ...defaultNotifyProps, ...newProps, }, });