Finish mutation call for snapshot deletion

Resolves MS-373
This commit is contained in:
Ramon Wenger 2022-06-15 11:52:38 +02:00
parent 3577ca1a2f
commit 03a4217412
2 changed files with 49 additions and 5 deletions

View File

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

View File

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