From 8267dcf16a6f3b1983a996f746a710ce65640df7 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Fri, 2 Apr 2021 12:43:32 -0400 Subject: [PATCH] Fix TODO and add selector for studio comment capability --- src/redux/studio.js | 6 +++++- src/views/studio/studio-comments.jsx | 6 +++--- test/unit/redux/studio.test.js | 13 ++++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/redux/studio.js b/src/redux/studio.js index cb3ad4a5a..ae1ffa2e5 100644 --- a/src/redux/studio.js +++ b/src/redux/studio.js @@ -133,6 +133,9 @@ const selectCanAddProjects = state => isCurator(state) || (selectIsSocial(state) && state.studio.openToAll); +// This isn't "canComment" since they could be muted, but comment composer handles that +const selectShowCommentComposer = state => selectIsSocial(state); + module.exports = { getInitialState, studioReducer, @@ -144,5 +147,6 @@ module.exports = { // Selectors selectCanEditInfo, - selectCanAddProjects + selectCanAddProjects, + selectShowCommentComposer }; diff --git a/src/views/studio/studio-comments.jsx b/src/views/studio/studio-comments.jsx index c9c04634f..71fffe122 100644 --- a/src/views/studio/studio-comments.jsx +++ b/src/views/studio/studio-comments.jsx @@ -9,6 +9,8 @@ import ComposeComment from '../preview/comment/compose-comment.jsx'; import TopLevelComment from '../preview/comment/top-level-comment.jsx'; import studioCommentActions from '../../redux/studio-comment-actions.js'; +import {selectShowCommentComposer} from '../../redux/studio.js'; + const StudioComments = ({ comments, getTopLevelComments, @@ -81,9 +83,7 @@ export default connect( comments: state.comments.comments, moreCommentsToLoad: state.comments.moreCommentsToLoad, replies: state.comments.replies, - - // TODO permissions like this to a selector for testing - shouldShowCommentComposer: !!state.session.session.user // is logged in + shouldShowCommentComposer: selectShowCommentComposer(state) }), { getTopLevelComments: studioCommentActions.getTopLevelComments, diff --git a/test/unit/redux/studio.test.js b/test/unit/redux/studio.test.js index 59562b92b..f859c29dd 100644 --- a/test/unit/redux/studio.test.js +++ b/test/unit/redux/studio.test.js @@ -1,7 +1,8 @@ import { getInitialState as getInitialStudioState, selectCanEditInfo, - selectCanAddProjects + selectCanAddProjects, + selectShowCommentComposer } from '../../../src/redux/studio'; import { @@ -75,4 +76,14 @@ describe('studio selectors', () => { expect(selectCanAddProjects(state)).toBe(false); }); }); + + describe('studio comments', () => { + test('show comment composer only for social users', () => { + expect(selectShowCommentComposer(state)).toBe(false); + state.session = sessions.user1; + expect(selectShowCommentComposer(state)).toBe(false); + state.session = sessions.user1Social; + expect(selectShowCommentComposer(state)).toBe(true); + }); + }); });