From 8c5bc367289d2c2fa29ffcdcdc88799148bbfbb2 Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Tue, 31 Aug 2021 18:10:03 +0200 Subject: [PATCH] Add test for room deletion --- .../frontend/rooms/room-page.spec.js | 42 +++++++++++++++++++ client/src/components/rooms/RoomActions.vue | 12 ++++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/client/cypress/integration/frontend/rooms/room-page.spec.js b/client/cypress/integration/frontend/rooms/room-page.spec.js index 499e73d0..a031d976 100644 --- a/client/cypress/integration/frontend/rooms/room-page.spec.js +++ b/client/cypress/integration/frontend/rooms/room-page.spec.js @@ -131,4 +131,46 @@ describe('The Room Page', () => { cy.get('.change-visibility__radio--selected').should('have.length', 1).should('contain', 'eigenen Beiträge'); checkRadioButton(); }); + + it('deletes the room and goes back to the overview', () => { + const roomToDelete = { + id: 'room-to-delete', + roomEntries: { + edges: [] + } + }; + const otherRoom = { + id: 'otherRoom' + }; + let rooms = [roomToDelete, otherRoom]; + const operations = { + MeQuery: getMinimalMe({}), + RoomsQuery() { + return { + rooms: { + edges: rooms.map(room => ({node: room})) + } + }; + }, + RoomEntriesQuery: { + room: roomToDelete + }, + DeleteRoom: { + deleteRoom: { + success: true + } + } + }; + cy.mockGraphqlOps({ + operations + }); + + cy.visit(`/rooms`); + cy.getByDataCy('room-widget').should('have.length', 2); + cy.getByDataCy('room-widget').first().click(); + cy.getByDataCy('toggle-room-actions-menu').click(); + cy.getByDataCy('delete-room').click(); + cy.url().should('include', 'rooms'); + cy.getByDataCy('room-widget').should('have.length', 1); + }); }); diff --git a/client/src/components/rooms/RoomActions.vue b/client/src/components/rooms/RoomActions.vue index 02cc58e5..bd218098 100644 --- a/client/src/components/rooms/RoomActions.vue +++ b/client/src/components/rooms/RoomActions.vue @@ -29,6 +29,7 @@ @@ -47,6 +48,7 @@ import TrashIcon from '@/components/icons/TrashIcon'; import EyeIcon from '@/components/icons/EyeIcon'; import PopoverLink from '@/components/ui/PopoverLink'; + import {ROOMS_PAGE} from '@/router/room.names'; export default { props: { @@ -80,22 +82,24 @@ this.showMenu = !this.showMenu; }, deleteRoom() { - const theId = this.id; this.$apollo.mutate({ mutation: DELETE_ROOM_MUTATION, variables: { input: { - id: theId, + id: this.id, }, }, - update(store, {data: {deleteRoom: {success}}}) { + update: (store, {data: {deleteRoom: {success}}}) => { if (success) { const data = store.readQuery({query: ROOMS_QUERY}); if (data) { - data.rooms.edges.splice(data.rooms.edges.findIndex(edge => edge.node.id === theId), 1); + data.rooms.edges.splice(data.rooms.edges.findIndex(edge => edge.node.id === this.id), 1); store.writeQuery({query: ROOMS_QUERY, data}); } } + this.$router.push({ + name: ROOMS_PAGE + }); }, }); },