mattermost-mobile/app/screens/channel_notification_preference/channel_notification_preference.test.js
Dean Whillier fb8238ab0b
[MM-37553] Update default themes (#5648)
* new themes and theme type updates

* update theme processing

port newer functionality from webapp

* update theme UI

including new svg-based thumbnail

* lint fixes

* update snapshots and tests

* update theme tile border approach

* remove unused path component

* remove old variable typo

* remove old variable type from theme type

* lint and snapshot updates

* update snapshots
2021-09-03 10:50:24 -04:00

81 lines
2.6 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {ViewTypes} from '@constants';
import Preferences from '@mm-redux/constants/preferences';
import SectionItem from '@screens/settings/section_item';
import {shallowWithIntlMessages} from '@test/intl-test-helper';
import ChannelNotificationPreference from './channel_notification_preference';
function makeProps(pushNotificationLevel) {
return {
actions: {
updateChannelNotifyProps: jest.fn(),
},
channelId: 'channel_id',
globalNotifyProps: {
push: 'mention',
},
userId: 'user_id',
notifyProps: {
push: pushNotificationLevel,
},
theme: Preferences.THEMES.denim,
};
}
function checkNotificationSelected(pushNotificationLevel, trueIdx) {
const wrapper = shallowWithIntlMessages(
<ChannelNotificationPreference
{...makeProps(pushNotificationLevel)}
/>,
);
const sectionItems = wrapper.find(SectionItem);
expect(sectionItems.exists()).toBe(true);
expect(sectionItems.length).toBe(4);
sectionItems.forEach((sectionItem, idx) => {
expect(sectionItem.prop('selected')).toBe(idx === trueIdx);
});
}
describe('ChannelNotificationPreference', () => {
test('should match snapshot', () => {
const baseProps = makeProps('default');
const wrapper = shallowWithIntlMessages(
<ChannelNotificationPreference {...baseProps}/>,
);
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should have correct setting selected', () => {
checkNotificationSelected(null, 0);
checkNotificationSelected(ViewTypes.NotificationLevels.DEFAULT, 0);
checkNotificationSelected(ViewTypes.NotificationLevels.ALL, 1);
checkNotificationSelected(ViewTypes.NotificationLevels.MENTION, 2);
checkNotificationSelected(ViewTypes.NotificationLevels.NONE, 3);
});
test('should save on click', () => {
const props = makeProps('default');
const wrapper = shallowWithIntlMessages(
<ChannelNotificationPreference {...props}/>,
);
// click on 'Never' -- last item
wrapper.find(SectionItem).at(3).dive().simulate('press');
expect(props.actions.updateChannelNotifyProps).toHaveBeenCalledTimes(1);
expect(props.actions.updateChannelNotifyProps).toBeCalledWith(
props.userId,
props.channelId,
{push: ViewTypes.NotificationLevels.NONE},
);
});
});