diff --git a/client/cypress/integration/frontend/read-only/room-read-only.spec.js b/client/cypress/integration/frontend/read-only/room-read-only.spec.js index 7715fde3..1f2f22c7 100644 --- a/client/cypress/integration/frontend/read-only/room-read-only.spec.js +++ b/client/cypress/integration/frontend/read-only/room-read-only.spec.js @@ -14,25 +14,36 @@ const getOperations = ({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, + 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: '' + } }, }, - }, - ], + ], + }, }, }, }); @@ -45,10 +56,9 @@ const checkRoomReadOnly = ({editable, readOnly, classReadOnly = false}) => { }); 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.visit('room/some-room'); + cy.get('.room-entry').should('exist'); + cy.getByDataCy('add-room-entry-button').should(exist); }; describe('Room Team Management - Read only', () => { diff --git a/client/cypress/integration/frontend/read-only/rooms-read-only.spec.js b/client/cypress/integration/frontend/read-only/rooms-read-only.spec.js new file mode 100644 index 00000000..5f24c15f --- /dev/null +++ b/client/cypress/integration/frontend/read-only/rooms-read-only.spec.js @@ -0,0 +1,78 @@ +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 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); +}; + +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', () => { + 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}); + }); +}); diff --git a/client/src/pages/room.vue b/client/src/pages/room.vue index d1feecce..f204f337 100644 --- a/client/src/pages/room.vue +++ b/client/src/pages/room.vue @@ -14,7 +14,7 @@