MM-30101 Match channel specific global notification preference (#4935)
* MM-30101 Match channel specific global notification preference * Avoid crash if globalNotifyProps is undefined
This commit is contained in:
parent
a819f63d99
commit
e57bcfdaba
7 changed files with 33 additions and 8 deletions
|
|
@ -23,7 +23,7 @@ export default class ChannelNotificationPreferenceAndroid extends ChannelNotific
|
|||
label: intl.formatMessage({
|
||||
id: element.id,
|
||||
defaultMessage: element.defaultMessage,
|
||||
}),
|
||||
}, element.labelValues),
|
||||
value: element.value,
|
||||
checked: element.checked,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ export default class ChannelNotificationPreferenceIos extends ChannelNotificatio
|
|||
<FormattedText
|
||||
id={item.id}
|
||||
defaultMessage={item.defaultMessage}
|
||||
values={item.labelValues}
|
||||
/>
|
||||
)}
|
||||
action={this.handlePress}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ 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 {shallowWithIntlMessages} from 'test/intl-test-helper';
|
||||
import ChannelNotificationPreference from './channel_notification_preference';
|
||||
|
||||
function makeProps(pushNotificationLevel) {
|
||||
|
|
@ -15,6 +15,9 @@ function makeProps(pushNotificationLevel) {
|
|||
updateChannelNotifyProps: jest.fn(),
|
||||
},
|
||||
channelId: 'channel_id',
|
||||
globalNotifyProps: {
|
||||
push: 'mention',
|
||||
},
|
||||
userId: 'user_id',
|
||||
notifyProps: {
|
||||
push: pushNotificationLevel,
|
||||
|
|
@ -25,7 +28,7 @@ function makeProps(pushNotificationLevel) {
|
|||
}
|
||||
|
||||
function checkNotificationSelected(pushNotificationLevel, trueIdx) {
|
||||
const wrapper = shallowWithIntl(
|
||||
const wrapper = shallowWithIntlMessages(
|
||||
<ChannelNotificationPreference
|
||||
{...makeProps(pushNotificationLevel)}
|
||||
/>,
|
||||
|
|
@ -52,7 +55,7 @@ describe('ChannelNotificationPreference', () => {
|
|||
|
||||
test('should save on click', () => {
|
||||
const props = makeProps('default');
|
||||
const wrapper = shallowWithIntl(
|
||||
const wrapper = shallowWithIntlMessages(
|
||||
<ChannelNotificationPreference {...props}/>,
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ export default class ChannelNotificationPreferenceBase extends PureComponent {
|
|||
updateChannelNotifyProps: PropTypes.func.isRequired,
|
||||
}),
|
||||
channelId: PropTypes.string.isRequired,
|
||||
globalNotifyProps: PropTypes.object.isRequired,
|
||||
isLandscape: PropTypes.bool.isRequired,
|
||||
notifyProps: PropTypes.object.isRequired,
|
||||
theme: PropTypes.object.isRequired,
|
||||
|
|
@ -35,25 +36,33 @@ export default class ChannelNotificationPreferenceBase extends PureComponent {
|
|||
}
|
||||
|
||||
getItems = () => {
|
||||
const {formatMessage} = this.context.intl;
|
||||
const {globalNotifyProps} = this.props;
|
||||
const {notificationLevel} = this.state;
|
||||
const defaultNotificationLevel = formatMessage({id: `channel_header.notificationPreference.${globalNotifyProps?.push.toLowerCase()}`});
|
||||
|
||||
return [{
|
||||
id: t('channel_notifications.preference.global_default'),
|
||||
defaultMessage: 'Global default (Mentions)',
|
||||
defaultMessage: 'Global default ({notifyLevel})',
|
||||
labelValues: {notifyLevel: defaultNotificationLevel},
|
||||
value: ViewTypes.NotificationLevels.DEFAULT,
|
||||
checked: notificationLevel === ViewTypes.NotificationLevels.DEFAULT,
|
||||
}, {
|
||||
id: t('channel_notifications.preference.all_activity'),
|
||||
defaultMessage: 'For all activity',
|
||||
labelValues: undefined,
|
||||
value: ViewTypes.NotificationLevels.ALL,
|
||||
checked: notificationLevel === ViewTypes.NotificationLevels.ALL,
|
||||
}, {
|
||||
id: t('channel_notifications.preference.only_mentions'),
|
||||
defaultMessage: 'Only mentions and direct messages',
|
||||
labelValues: undefined,
|
||||
value: ViewTypes.NotificationLevels.MENTION,
|
||||
checked: notificationLevel === ViewTypes.NotificationLevels.MENTION,
|
||||
}, {
|
||||
id: t('channel_notifications.preference.never'),
|
||||
defaultMessage: 'Never',
|
||||
labelValues: undefined,
|
||||
value: ViewTypes.NotificationLevels.NONE,
|
||||
checked: notificationLevel === ViewTypes.NotificationLevels.NONE,
|
||||
}];
|
||||
|
|
|
|||
|
|
@ -4,16 +4,17 @@
|
|||
import {bindActionCreators} from 'redux';
|
||||
import {connect} from 'react-redux';
|
||||
import {updateChannelNotifyProps} from '@mm-redux/actions/channels';
|
||||
import {getCurrentUser} from '@mm-redux/selectors/entities/users';
|
||||
import {getTheme} from '@mm-redux/selectors/entities/preferences';
|
||||
import {isLandscape} from 'app/selectors/device';
|
||||
|
||||
import ChannelNotificationPreference from './channel_notification_preference';
|
||||
|
||||
function mapStateToProps(state) {
|
||||
const theme = getTheme(state);
|
||||
return {
|
||||
theme,
|
||||
globalNotifyProps: getCurrentUser(state)?.notify_props,
|
||||
isLandscape: isLandscape(state),
|
||||
theme: getTheme(state),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@
|
|||
"channel_notifications.ignoreChannelMentions.settings": "Ignore @channel, @here, @all",
|
||||
"channel_notifications.muteChannel.settings": "Mute channel",
|
||||
"channel_notifications.preference.all_activity": "For all activity",
|
||||
"channel_notifications.preference.global_default": "Global default (Mentions)",
|
||||
"channel_notifications.preference.global_default": "Global default ({notifyLevel})",
|
||||
"channel_notifications.preference.header": "Send Notifications",
|
||||
"channel_notifications.preference.never": "Never",
|
||||
"channel_notifications.preference.only_mentions": "Only mentions and direct messages",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import React from 'react';
|
|||
import {IntlProvider, intlShape} from 'react-intl';
|
||||
import {mount, shallow} from 'enzyme';
|
||||
|
||||
import {getTranslations} from '@i18n';
|
||||
|
||||
const intlProvider = new IntlProvider({locale: 'en'}, {});
|
||||
const {intl} = intlProvider.getChildContext();
|
||||
|
||||
|
|
@ -14,6 +16,15 @@ export function shallowWithIntl(node, {context} = {}) {
|
|||
});
|
||||
}
|
||||
|
||||
export function shallowWithIntlMessages(node, {context} = {}) {
|
||||
const provider = new IntlProvider({locale: 'en', messages: getTranslations('en')}, {});
|
||||
const {intl: intlWithMessages} = provider.getChildContext();
|
||||
|
||||
return shallow(React.cloneElement(node, {intl: intlWithMessages}), {
|
||||
context: Object.assign({}, context, {intl: intlWithMessages}),
|
||||
});
|
||||
}
|
||||
|
||||
export function mountWithIntl(node, {context, childContextTypes} = {}) {
|
||||
return mount(React.cloneElement(node, {intl}), {
|
||||
context: Object.assign({}, context, {intl}),
|
||||
|
|
|
|||
Loading…
Reference in a new issue