Fix TODO and add selector for studio comment capability

This commit is contained in:
Paul Kaplan 2021-04-02 12:43:32 -04:00
parent dc460fffde
commit 8267dcf16a
3 changed files with 20 additions and 5 deletions

View file

@ -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
};

View file

@ -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,

View file

@ -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);
});
});
});