Add test for room deletion

This commit is contained in:
Ramon Wenger 2021-08-31 18:10:03 +02:00
parent d509b24666
commit 8c5bc36728
2 changed files with 50 additions and 4 deletions

View File

@ -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);
});
});

View File

@ -29,6 +29,7 @@
<popover-link
icon="trash-icon"
text="Löschen"
data-cy="delete-room"
@link-action="deleteRoom()"/>
</li>
</widget-popover>
@ -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
});
},
});
},