Finish mutation call for snapshot deletion
Resolves MS-373
This commit is contained in:
parent
3577ca1a2f
commit
03a4217412
|
|
@ -2,6 +2,33 @@ import module from '../../../fixtures/module.minimal';
|
||||||
import {getMinimalMe} from '../../../support/helpers';
|
import {getMinimalMe} from '../../../support/helpers';
|
||||||
import {hasOperationName} from '../../../support/graphql';
|
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) => {
|
const mockUpdateSnapshot = (title) => {
|
||||||
cy.intercept('POST', '/api/graphql', (req) => {
|
cy.intercept('POST', '/api/graphql', (req) => {
|
||||||
if (hasOperationName(req, 'UpdateSnapshot')) {
|
if (hasOperationName(req, 'UpdateSnapshot')) {
|
||||||
|
|
@ -133,10 +160,11 @@ describe('Snapshot', () => {
|
||||||
|
|
||||||
it('Deletes Snapshot', () => {
|
it('Deletes Snapshot', () => {
|
||||||
cy.mockGraphqlOps(operations(true));
|
cy.mockGraphqlOps(operations(true));
|
||||||
|
mockDeleteSnapshot(true);
|
||||||
cy.visit('module/miteinander-reden/snapshots');
|
cy.visit('module/miteinander-reden/snapshots');
|
||||||
cy.getByDataCy('snapshot-entry').should('have.length', 1);
|
cy.getByDataCy('snapshot-entry').should('have.length', 1);
|
||||||
cy.getByDataCy('delete-snapshot-button').click();
|
cy.getByDataCy('delete-snapshot-button').click();
|
||||||
cy.getByDataCy('confirm-button').click();
|
cy.getByDataCy('modal-save-button').click();
|
||||||
cy.getByDataCy('snapshot').should('have.length', 0);
|
cy.getByDataCy('snapshot-entry').should('have.length', 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@
|
||||||
import gql from 'graphql-tag';
|
import gql from 'graphql-tag';
|
||||||
import PenIcon from '@/components/icons/PenIcon';
|
import PenIcon from '@/components/icons/PenIcon';
|
||||||
import TrashIcon from '@/components/icons/TrashIcon';
|
import TrashIcon from '@/components/icons/TrashIcon';
|
||||||
|
import { removeAtIndex } from '@/graphql/immutable-operations';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
|
|
@ -127,11 +128,26 @@
|
||||||
const slug = this.$route.params.slug;
|
const slug = this.$route.params.slug;
|
||||||
const query = SNAPSHOTS_QUERY;
|
const query = SNAPSHOTS_QUERY;
|
||||||
const variables = {
|
const variables = {
|
||||||
slug
|
slug,
|
||||||
};
|
};
|
||||||
const module = store.readQuery({
|
const {module} = store.readQuery({
|
||||||
query,
|
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
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue