diff --git a/client/cypress/integration/frontend/modules/snapshots.spec.js b/client/cypress/integration/frontend/modules/snapshots.spec.js index da66ca67..2cf28352 100644 --- a/client/cypress/integration/frontend/modules/snapshots.spec.js +++ b/client/cypress/integration/frontend/modules/snapshots.spec.js @@ -2,6 +2,33 @@ import module from '../../../fixtures/module.minimal'; import {getMinimalMe} from '../../../support/helpers'; import {hasOperationName} from '../../../support/graphql'; +const mockDeleteSnapshot = (success) => { + cy.intercept('POST', '/api/graphql', (req) => { + if (hasOperationName(req, 'DeleteSnapshot')) { + let result; + if (success) { + result = { + message: 'yay!', + __typename: 'Success' + }; + } else { + result = { + reason: 'Not the owner', + __typename: 'NotOwner' + }; + } + req.reply({ + data: { + deleteSnapshot: { + result + } + }, + }); + + } + }); +}; + const mockUpdateSnapshot = (title) => { cy.intercept('POST', '/api/graphql', (req) => { if (hasOperationName(req, 'UpdateSnapshot')) { @@ -133,10 +160,11 @@ describe('Snapshot', () => { it('Deletes Snapshot', () => { cy.mockGraphqlOps(operations(true)); + mockDeleteSnapshot(true); cy.visit('module/miteinander-reden/snapshots'); cy.getByDataCy('snapshot-entry').should('have.length', 1); cy.getByDataCy('delete-snapshot-button').click(); - cy.getByDataCy('confirm-button').click(); - cy.getByDataCy('snapshot').should('have.length', 0); + cy.getByDataCy('modal-save-button').click(); + cy.getByDataCy('snapshot-entry').should('have.length', 0); }); }); diff --git a/client/src/components/modules/SnapshotListItem.vue b/client/src/components/modules/SnapshotListItem.vue index 62781f87..d8eaed5a 100644 --- a/client/src/components/modules/SnapshotListItem.vue +++ b/client/src/components/modules/SnapshotListItem.vue @@ -51,6 +51,7 @@ import gql from 'graphql-tag'; import PenIcon from '@/components/icons/PenIcon'; import TrashIcon from '@/components/icons/TrashIcon'; + import { removeAtIndex } from '@/graphql/immutable-operations'; export default { props: { @@ -127,11 +128,26 @@ const slug = this.$route.params.slug; const query = SNAPSHOTS_QUERY; const variables = { - slug + slug, }; - const module = store.readQuery({ + const {module} = store.readQuery({ query, - variables + variables, + }); + const index = module.snapshots.findIndex(snapshot => snapshot.id === this.snapshot.id); + const snapshots = removeAtIndex(module.snapshots, index); + + const data = { + module: { + ...module, + snapshots + } + }; + + store.writeQuery({ + query, + variables, + data }); }