mattermost-mobile/app/screens/channel_notification_preference/channel_notification_preference.test.js
Jyoti Patel b6920770f1
[GH-15185][MM-5973] Add Channel Settings > Notification Preferences. (#4730)
* Add Channel Settings > Notification Preferences.

Fixes #15185

* Make newly added strings mmjstool compatible.

mmjstool seems to be looking for specific patterns in AST like called with
`formatMessage` and `t()` [1]. Looks like `t()` is just for that purpose.

[1]: a83581379d/mmjstool/src/i18n_extract.js (L97):L100

* Pass only required props to NotificationPreference & ChannelNotificationPreference.

* Fix style issues/nits from code review.

* Use radio button for channel notifications on android, and checkmarks on iOS.

Also changes style according to figma spec.

* Fix missing prop error.

For some reason, `npm run fix` didn't catch this. But `npm run check` did during CircleCI.

* Fix missing i18n strings by passing strings through `t()`.

mmjstool really needs to be smarter to understand these types of cases.

* Address comments from UX code review.

* Remove remnant from merge conflict.

* Fix UI in iOS landscape mode.

* Use SafeArea view for ios landscape view

* Use paddingHorizontal for SafeArea view for iOS landscape mode
2020-09-12 00:53:29 -03:00

69 lines
2.3 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 {shallowWithIntl} from 'test/intl-test-helper';
import ChannelNotificationPreference from './channel_notification_preference';
function makeProps(pushNotificationLevel) {
return {
actions: {
updateChannelNotifyProps: jest.fn(),
},
channelId: 'channel_id',
userId: 'user_id',
notifyProps: {
push: pushNotificationLevel,
},
theme: Preferences.THEMES.default,
isLandscape: false,
};
}
function checkNotificationSelected(pushNotificationLevel, trueIdx) {
const wrapper = shallowWithIntl(
<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 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 = shallowWithIntl(
<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},
);
});
});