skillbox/client/cypress/integration/frontend/read-only/room-read-only.spec.js

82 lines
1.9 KiB
JavaScript

import mocks from '../../../fixtures/mocks';
const SELECTED_CLASS_ID = 'selectedClassId';
const getOperations = ({readOnly, classReadOnly}) => ({
MeQuery: {
me: {
onboardingVisited: true,
readOnly,
isTeacher: true,
selectedClass: {
id: SELECTED_CLASS_ID,
readOnly: classReadOnly,
},
},
},
RoomEntriesQuery: {
room: {
id: 'roomId',
slug: '',
title: 'room title',
entryCount: 3,
appearance: 'blue',
description: 'room description',
schoolClass: {
id: SELECTED_CLASS_ID,
name: 'selected class',
},
roomEntries: {
edges: [
{
node: {
id: 'entryId',
slug: '',
title: 'entry title',
contents: [],
author: {
id: 'authorId',
firstName: 'first',
lastName: 'last',
avatarUrl: ''
}
},
},
],
},
},
},
});
const checkRoomReadOnly = ({editable, readOnly, classReadOnly = false}) => {
const operations = getOperations({readOnly, classReadOnly});
cy.mockGraphqlOps({
operations,
});
const exist = editable ? 'exist' : 'not.exist';
cy.visit('room/some-room');
cy.get('.room-entry').should('exist');
cy.getByDataCy('add-room-entry-button').should(exist);
cy.getByDataCy('room-actions').should(exist);
};
describe('Room Team Management - Read only', () => {
beforeEach(() => {
cy.setup();
});
it('can edit room', () => {
checkRoomReadOnly({editable: true, readOnly: false});
});
it('can not edit room', () => {
checkRoomReadOnly({editable: false, readOnly: true});
});
it('can not edit room of inactive class', () => {
checkRoomReadOnly({editable: false, readOnly: false, classReadOnly: true});
});
});