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, }, }, }, RoomsQuery: { rooms: { edges: [ { node: { id: '', slug: '', title: 'some room', entryCount: 3, appearance: 'red', description: 'some description', schoolClass: { id: SELECTED_CLASS_ID, name: 'bla', readOnly: classReadOnly, }, }, }, ], }, }, }); const checkRoomReadOnly = ({editable, readOnly, classReadOnly = false}) => { const operations = getOperations({readOnly, classReadOnly}); cy.mockGraphqlOps({ operations, }); const exist = editable ? 'exist' : 'not.exist'; cy.visit('rooms'); cy.log('visit'); cy.get('.room-widget').should('exist'); cy.getByDataCy('add-room').should(exist); }; describe('Room Team Management - Read only', () => { beforeEach(() => { cy.fakeLogin('nino.teacher', 'test'); cy.server(); cy.viewport('macbook-15'); cy.task('getSchema').then(schema => { cy.mockGraphql({ schema, mocks, }); }); }); 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}); }); });