2021-03-23 15:19:01 -04:00
|
|
|
import {
|
|
|
|
getInitialState as getInitialStudioState,
|
|
|
|
selectCanEditInfo,
|
2021-04-02 12:43:32 -04:00
|
|
|
selectCanAddProjects,
|
2021-04-08 10:36:56 -04:00
|
|
|
selectShowCommentComposer,
|
|
|
|
selectCanDeleteComment,
|
|
|
|
selectCanDeleteCommentWithoutConfirm,
|
|
|
|
selectCanReportComment,
|
|
|
|
selectCanRestoreComment
|
2021-03-23 15:19:01 -04:00
|
|
|
} from '../../../src/redux/studio';
|
|
|
|
|
|
|
|
import {
|
|
|
|
getInitialState as getInitialSessionState
|
|
|
|
} from '../../../src/redux/session';
|
|
|
|
|
2021-04-02 12:33:18 -04:00
|
|
|
import {sessions, studios} from '../../helpers/state-fixtures.json';
|
2021-03-23 15:19:01 -04:00
|
|
|
|
2021-04-08 10:36:56 -04:00
|
|
|
let state;
|
2021-03-23 15:19:01 -04:00
|
|
|
|
2021-04-08 10:36:56 -04:00
|
|
|
const setStateByRole = (role) => {
|
|
|
|
switch (role) {
|
|
|
|
case 'admin':
|
|
|
|
state.session = sessions.user1Admin;
|
|
|
|
break;
|
|
|
|
case 'curator':
|
|
|
|
state.studio = studios.isCurator;
|
|
|
|
state.session = sessions.user1Social;
|
|
|
|
break;
|
|
|
|
case 'manager':
|
|
|
|
state.studio = studios.isManager;
|
|
|
|
state.session = sessions.user1Social;
|
|
|
|
break;
|
|
|
|
case 'creator':
|
|
|
|
state.studio = studios.creator1;
|
|
|
|
state.session = sessions.user1Social;
|
|
|
|
break;
|
|
|
|
case 'logged in':
|
|
|
|
state.session = sessions.user1Social;
|
|
|
|
break;
|
|
|
|
case 'unconfirmed':
|
|
|
|
state.session = sessions.user1;
|
|
|
|
break;
|
|
|
|
case 'logged out': // Default state set in beforeEach
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Error('Unknown user role in test: ' + role);
|
|
|
|
}
|
|
|
|
};
|
2021-03-23 15:19:01 -04:00
|
|
|
|
2021-04-08 10:36:56 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
state = {
|
|
|
|
session: getInitialSessionState(),
|
|
|
|
studio: getInitialStudioState()
|
|
|
|
};
|
|
|
|
});
|
2021-03-23 15:19:01 -04:00
|
|
|
|
2021-04-08 10:36:56 -04:00
|
|
|
describe('studio info', () => {
|
|
|
|
describe('can edit studio info', () => {
|
|
|
|
test.each([
|
|
|
|
['admin', true],
|
|
|
|
['curator', false],
|
|
|
|
['manager', true],
|
|
|
|
['creator', true],
|
|
|
|
['logged in', false],
|
|
|
|
['unconfirmed', false],
|
|
|
|
['logged out', false]
|
|
|
|
])('%s: %s', (role, expected) => {
|
|
|
|
setStateByRole(role);
|
|
|
|
expect(selectCanEditInfo(state)).toBe(expected);
|
2021-03-23 15:19:01 -04:00
|
|
|
});
|
2021-04-08 10:36:56 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('studio projects', () => {
|
|
|
|
describe('can add project, not open to all', () => {
|
|
|
|
test.each([
|
|
|
|
['admin', false],
|
|
|
|
['curator', true],
|
|
|
|
['manager', true],
|
|
|
|
['creator', true],
|
|
|
|
['logged in', false],
|
|
|
|
['unconfirmed', false],
|
|
|
|
['logged out', false]
|
|
|
|
])('%s: %s', (role, expected) => {
|
|
|
|
setStateByRole(role);
|
|
|
|
expect(selectCanAddProjects(state)).toBe(expected);
|
2021-03-23 15:19:01 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-08 10:36:56 -04:00
|
|
|
describe('can add project, open to all', () => {
|
|
|
|
test.each([
|
|
|
|
['logged in', true],
|
|
|
|
['unconfirmed', false],
|
|
|
|
['logged out', false]
|
|
|
|
])('%s: %s', (role, expected) => {
|
|
|
|
setStateByRole(role);
|
|
|
|
state.studio.openToAll = true;
|
|
|
|
expect(selectCanAddProjects(state)).toBe(expected);
|
2021-03-23 15:19:01 -04:00
|
|
|
});
|
2021-04-08 10:36:56 -04:00
|
|
|
});
|
|
|
|
});
|
2021-03-23 15:19:01 -04:00
|
|
|
|
2021-04-08 10:36:56 -04:00
|
|
|
describe('studio comments', () => {
|
|
|
|
describe('showing comment composer', () => {
|
|
|
|
test.each([
|
|
|
|
['logged in', true],
|
|
|
|
['unconfirmed', false],
|
|
|
|
['logged out', false]
|
|
|
|
])('%s: %s', (role, expected) => {
|
|
|
|
setStateByRole(role);
|
|
|
|
expect(selectShowCommentComposer(state)).toBe(expected);
|
2021-03-23 15:19:01 -04:00
|
|
|
});
|
2021-04-08 10:36:56 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('can report comment', () => {
|
|
|
|
test.each([
|
|
|
|
['logged in', true],
|
|
|
|
['unconfirmed', false],
|
|
|
|
['logged out', false]
|
|
|
|
])('%s: %s', (role, expected) => {
|
|
|
|
setStateByRole(role);
|
|
|
|
expect(selectCanReportComment(state)).toBe(expected);
|
2021-03-23 15:19:01 -04:00
|
|
|
});
|
2021-04-08 10:36:56 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('can delete comment', () => {
|
|
|
|
test.each([
|
|
|
|
['admin', true],
|
|
|
|
['curator', false],
|
|
|
|
['manager', false],
|
|
|
|
['creator', false],
|
|
|
|
['logged in', false],
|
|
|
|
['unconfirmed', false],
|
|
|
|
['logged out', false]
|
|
|
|
])('%s: %s', (role, expected) => {
|
|
|
|
setStateByRole(role);
|
|
|
|
expect(selectCanDeleteComment(state)).toBe(expected);
|
2021-03-23 15:19:01 -04:00
|
|
|
});
|
2021-04-08 10:36:56 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('can delete comment without confirmation', () => {
|
|
|
|
test.each([
|
|
|
|
['admin', true],
|
|
|
|
['curator', false],
|
|
|
|
['manager', false],
|
|
|
|
['creator', false],
|
|
|
|
['logged in', false],
|
|
|
|
['unconfirmed', false],
|
|
|
|
['logged out', false]
|
|
|
|
])('%s: %s', (role, expected) => {
|
|
|
|
setStateByRole(role);
|
|
|
|
expect(selectCanDeleteCommentWithoutConfirm(state)).toBe(expected);
|
2021-03-23 15:19:01 -04:00
|
|
|
});
|
|
|
|
});
|
2021-04-02 12:43:32 -04:00
|
|
|
|
2021-04-08 10:36:56 -04:00
|
|
|
describe('can restore a comment', () => {
|
|
|
|
test.each([
|
|
|
|
['admin', true],
|
|
|
|
['curator', false],
|
|
|
|
['manager', false],
|
|
|
|
['creator', false],
|
|
|
|
['logged in', false],
|
|
|
|
['unconfirmed', false],
|
|
|
|
['logged out', false]
|
|
|
|
])('%s: %s', (role, expected) => {
|
|
|
|
setStateByRole(role);
|
|
|
|
expect(selectCanRestoreComment(state)).toBe(expected);
|
2021-04-02 12:43:32 -04:00
|
|
|
});
|
|
|
|
});
|
2021-03-23 15:19:01 -04:00
|
|
|
});
|