<NME> notification_settings.test.js
<BEF> // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import React from 'react';

import Preferences from '@mm-redux/constants/preferences';
import {shallowWithIntl} from '@test/intl-test-helper';
import {getNotificationProps} from '@utils/notify_props';

import NotificationSettings from './notification_settings.js';

describe('NotificationSettings', () => {
    const baseProps = {
        actions: {
            updateMe: jest.fn(),
        },
        componentId: 'component-id',
        currentUser: {id: 'current_user_id'},
        theme: Preferences.THEMES.default,
        updateMeRequest: {},
        currentUserStatus: 'status',
    };

    test('should match snapshot', () => {
        const wrapper = shallowWithIntl(
            <NotificationSettings {...baseProps}/>,
        );

        expect(wrapper.instance()).toMatchSnapshot();
    });

    });

    test('should include previous notification props when saving new ones', () => {
        baseProps.currentUser.notify_props = {previous: 'previous'};
        const wrapper = shallowWithIntl(
            <NotificationSettings {...baseProps}/>
        );

        const instance = wrapper.instance();
        const newProps = {new: 'new'};
        instance.saveNotificationProps(newProps);
        expect(baseProps.actions.updateMe).toHaveBeenCalledWith({
            notify_props: {
                ...baseProps.currentUser.notify_props,
                ...newProps,
            },
        });
        const newProps = {new: 'new'};
        instance.saveNotificationProps(newProps);
        expect(baseProps.actions.updateMe).toHaveBeenCalledTimes(1);
        expect(baseProps.actions.updateMe).toHaveBeenCalledWith({
            notify_props: {
                ...defaultNotifyProps,
                ...newProps,
            },
        });
    });
});

<MSG> MM-19966 Fixed Notification Settings (#3535)

* MM-19966 Fixed Notification Settings

Fixed the save functionality for props. There was a change to combine notification settings that then did a deep comparison on two like objects. This change makes the comparison of the newly changed notification props and the previous props.

* Fix unit test

<DFF> @@ -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(
             <NotificationSettings {...baseProps}/>
         );
 
         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,
             },
         });

{'addition_count': 11, 'commit_subject': 'MM-19966 Fixed Notification Settings (#3535)', 'deletion_count': 3, 'file_extension': '.js', 'lang': 'test', 'license': 'apache-2.0', 'repo_name': 'mattermost/mattermost-mobile'}