import mocks from '../../../fixtures/mocks'; const SELECTED_CLASS_ID = 'selectedClassId'; const getOperations = ({readOnly}) => ({ MeQuery: { me: { onboardingVisited: true, readOnly, isTeacher: true, selectedClass: { id: SELECTED_CLASS_ID, }, }, }, RoomsQuery: { rooms: { edges: [ { node: { id: '', slug: '', title: 'some room', entryCount: 3, appearance: 'red', description: 'some description', schoolClass: { id: SELECTED_CLASS_ID, name: 'bla', }, }, }, ], }, }, }); Cypress.Commands.add('checkRoomReadOnly', (readOnly) => { cy.mockGraphqlOps({ operations: getOperations({readOnly}), }); const exist = readOnly ? 'not.exist' : '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', () => { cy.checkRoomReadOnly(false); }); it('can not edit room', () => { cy.checkRoomReadOnly(true); }); });