describe('Room Team Management - Read only', () => { const SELECTED_CLASS_ID = 'selectedClassId'; const getOperations = ({ readOnly, classReadOnly }) => ({ MeQuery: { me: { readOnly, isTeacher: true, selectedClass: { id: SELECTED_CLASS_ID, readOnly: classReadOnly, }, }, }, RoomsQuery: { rooms: [ { id: '', slug: 'some-room', title: 'some room', entryCount: 3, appearance: 'red', description: 'some description', schoolClass: { id: SELECTED_CLASS_ID, name: 'bla', }, }, ], }, }); const checkRoomsReadOnly = ({ 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); cy.getByDataCy('widget-footer').should(exist); }; beforeEach(() => { cy.setup(); }); it('can edit room', () => { checkRoomsReadOnly({ editable: true, readOnly: false }); }); it('can not edit room', () => { checkRoomsReadOnly({ editable: false, readOnly: true }); }); it('can not edit room of inactive class', () => { checkRoomsReadOnly({ editable: false, readOnly: false, classReadOnly: true }); }); });