From 217ef59f1c31ff4bac7e35112f7ecdaa328c50bb Mon Sep 17 00:00:00 2001 From: Farhan Munshi <3207297+fm2munsh@users.noreply.github.com> Date: Mon, 16 Mar 2020 11:29:13 -0400 Subject: [PATCH] [MM-23271] Check canAddReaction permission inside of render reactions (#4032) * MM-23271 check canAddReaction when creating in reactions component * MM-23271 Fixing linting --- .../__snapshots__/reactions.test.js.snap | 289 ++++++++++++++++++ app/components/reactions/reactions.js | 4 +- app/components/reactions/reactions.test.js | 47 +++ 3 files changed, 338 insertions(+), 2 deletions(-) create mode 100644 app/components/reactions/__snapshots__/reactions.test.js.snap create mode 100644 app/components/reactions/reactions.test.js diff --git a/app/components/reactions/__snapshots__/reactions.test.js.snap b/app/components/reactions/__snapshots__/reactions.test.js.snap new file mode 100644 index 000000000..5e9a4d9ba --- /dev/null +++ b/app/components/reactions/__snapshots__/reactions.test.js.snap @@ -0,0 +1,289 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Reactions should match snapshot 1`] = ` + + + + + + + + +`; + +exports[`Reactions should match snapshot with canAddReaction = false 1`] = ` + + + + + +`; diff --git a/app/components/reactions/reactions.js b/app/components/reactions/reactions.js index 1a1d3dd1e..508e6efff 100644 --- a/app/components/reactions/reactions.js +++ b/app/components/reactions/reactions.js @@ -133,7 +133,7 @@ export default class Reactions extends PureComponent { }; render() { - const {position, reactions, canAddMoreReactions} = this.props; + const {position, reactions, canAddMoreReactions, canAddReaction} = this.props; const styles = getStyleSheet(this.props.theme); if (!reactions) { @@ -141,7 +141,7 @@ export default class Reactions extends PureComponent { } let addMoreReactions = null; - if (canAddMoreReactions) { + if (canAddReaction && canAddMoreReactions) { addMoreReactions = ( { + const baseProps = { + actions: { + addReaction: jest.fn(), + getReactionsForPost: jest.fn(), + removeReaction: jest.fn(), + }, + canAddReaction: true, + canAddMoreReactions: true, + canRemoveReaction: true, + currentUserId: 'current-user-id', + position: 'right', + postId: 'post-id', + reactions: { + 'current-user-id-frowning_face': {create_at: 1, emoji_name: 'frowning_face', post_id: 'post-id', user_id: 'current-user-id'}, + 'current-user-id-grinning': {create_at: 1, emoji_name: 'grinning', post_id: 'post-id', user_id: 'current-user-id'}, + 'current-user-id-sweat': {create_at: 1, emoji_name: 'sweat', post_id: 'post-id', user_id: 'current-user-id'}, + }, + theme: Preferences.THEMES.default, + + }; + + test('should match snapshot', () => { + const wrapper = shallow(); + expect(wrapper.getElement()).toMatchSnapshot(); + }); + + test('should match snapshot with canAddReaction = false', () => { + const wrapper = shallow( + , + ); + expect(wrapper.getElement()).toMatchSnapshot(); + }); +});