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
This commit is contained in:
parent
04210b8a14
commit
78cbcf1437
2 changed files with 14 additions and 5 deletions
|
|
@ -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});
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue