skillbox/client/cypress/integration/frontend/snapshots.spec.js

110 lines
2.6 KiB
JavaScript

import getMe from '../../fixtures/me.minimal';
import module from '../../fixtures/module.minimal';
import mocks from '../../fixtures/mocks';
const operations = isTeacher => ({
operations: {
MeQuery: {
me: getMe(isTeacher),
},
ModuleDetailsQuery: {
module,
},
CreateSnapshot: {
createSnapshot: {
snapshot: {
id: '',
title: '',
created: '',
creator: '',
},
success: true,
},
},
ModuleSnapshotsQuery: {
module: {
...module,
snapshots: [
{
id: 'snapshot-id',
title: 'title',
created: '2020-01-01',
mine: true,
shared: false,
creator: 'me',
},
],
},
},
SnapshotDetail: {
snapshot: {
chapters: [],
module: {}
}
},
ApplySnapshot: {
applySnapshot: {
success: true
}
}
},
});
describe('Snapshot', () => {
beforeEach(() => {
cy.server();
cy.task('getSchema').then(schema => {
cy.mockGraphql({
schema,
mocks,
});
});
cy.viewport('macbook-15');
});
it('Menu is visible for teacher', () => {
cy.fakeLogin('ross.geller', 'test');
cy.mockGraphqlOps(operations(true));
cy.visit('module/miteinander-reden/');
cy.getByDataCy('snapshot-menu').should('be.visible');
});
it('Menu is not visible for student', () => {
cy.fakeLogin('rachel.green', 'test');
cy.mockGraphqlOps(operations(false));
cy.visit('module/miteinander-reden/');
cy.getByDataCy('module-title').should('be.visible');
cy.getByDataCy('snapshot-menu').should('not.exist');
});
it('Creates Snapshot', () => {
cy.fakeLogin('ross.geller', 'test');
cy.mockGraphqlOps(operations(true));
cy.visit('module/miteinander-reden/');
cy.getByDataCy('module-snapshots-button').click();
cy.getByDataCy('create-snapshot-button').click();
cy.getByDataCy('show-all-snapshots-button').click();
cy.getByDataCy('snapshot-list').should('exist').within(() => {
cy.get('.snapshots__snapshot').should('have.length', 1);
});
});
it('Applies Snapshot', () => {
cy.fakeLogin('ross.geller', 'test');
cy.mockGraphqlOps(operations(true));
cy.visit('module/miteinander-reden/snapshots');
cy.getByDataCy('snapshot-link').click();
cy.getByDataCy('apply-checkbox').click();
cy.getByDataCy('apply-button').click();
cy.getByDataCy('module-title').should('exist');
cy.getByDataCy('snapshot-header').should('not.exist');
});
});