From 8bf76a606e4b694d0ad7dfe38e1bc6a48c5e1699 Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Tue, 17 Aug 2021 22:29:13 +0200 Subject: [PATCH] Update some cypress tests --- .../frontend/apply-module-visibility.spec.js | 102 ++++++------- .../frontend/current-module.spec.js | 135 +++++++++--------- .../integration/frontend/snapshots.spec.js | 111 ++++++-------- client/src/pages/module/module.vue | 36 +++-- 4 files changed, 195 insertions(+), 189 deletions(-) diff --git a/client/cypress/integration/frontend/apply-module-visibility.spec.js b/client/cypress/integration/frontend/apply-module-visibility.spec.js index e927364b..a6f4a79c 100644 --- a/client/cypress/integration/frontend/apply-module-visibility.spec.js +++ b/client/cypress/integration/frontend/apply-module-visibility.spec.js @@ -1,58 +1,64 @@ - -import {getModules, getMe} from '../../support/helpers'; -import mocks from '../../fixtures/mocks'; - -const operations = { - MeQuery() { - return getMe({ - schoolClasses: ['FLID2018a', 'Andere Klasse'], - teacher: true, - }); - }, - ModulesQuery: getModules, - UpdateSettings: { - updateSettings: { - success: true, - }, - }, - MySchoolClassQuery: { - me: {}, - }, - UpdateLastModule: { - updateLastModule: { - success: true, - }, - }, - SyncModuleVisibility: { - syncModuleVisibility: { - success: true, - }, - }, -}; +import {getModules, getMinimalMe} from '../../support/helpers'; describe('Apply module visibility', () => { + const schoolClasses = [ + { + name: 'FLID2018a', + id: btoa('SchoolClassNode:1') + }, + { + name: 'Andere Klasse', + id: btoa('SchoolClassNode:2') + }, + ]; + + const {me: minimalMe} = getMinimalMe({}); + const me = { + ...minimalMe, + schoolClasses: { + edges: schoolClasses.map(scn => ({node: scn})) + } + }; +// name: '[\'FLID2018a\', \'Andere Klasse\']' + const operations = { + MeQuery: { + me + }, + ModulesQuery: getModules, + UpdateSettings: { + updateSettings: { + success: true, + }, + }, + MySchoolClassQuery: { + me, + }, + UpdateLastModule: { + updateLastModule: { + success: true, + }, + }, + SyncModuleVisibility: { + syncModuleVisibility: { + success: true, + }, + }, + ModuleDetailsQuery: { + module: { + id: 'some-module-id' + } + } + }; + beforeEach(() => { - cy.server(); - cy.task('getSchema').then(schema => { - cy.mockGraphql({ - schema, - // endpoint: '/api/graphql' - mocks, - operations, - }); - }); + cy.setup(); }); it('clicks through the UI', () => { - // Cypress.config({ - // baseUrl: 'http://localhost:8080', - // }); - cy.viewport('macbook-15'); + cy.mockGraphqlOps({ + operations + }); - // login as teacher - cy.fakeLogin('ross.geller', 'test'); - // cy.apolloLogin('ross.geller', 'test'); - // cy.wait('@gqlBetaLogin'); // go to module cy.visit('/module/lohn-und-budget'); cy.selectClass('Andere Klasse'); diff --git a/client/cypress/integration/frontend/current-module.spec.js b/client/cypress/integration/frontend/current-module.spec.js index 694a2df1..a269f846 100644 --- a/client/cypress/integration/frontend/current-module.spec.js +++ b/client/cypress/integration/frontend/current-module.spec.js @@ -15,23 +15,6 @@ const topics = [ let recentModules = []; -const me = () => { - console.log('getting me'); - return { - lastModule: { - slug: 'lohn-und-budget', - id: 'last-module-id', - }, - lastTopic: { - id: 'VG9waWNOb2RlOjU=', - slug: 'geld-und-kauf', - }, - recentModules: { - edges: recentModules, - }, - }; -}; - const getId = (id) => btoa(`ModuleNode:${id}`); const modules = { @@ -80,54 +63,19 @@ const moduleNodes = Object.values(modules).map(module => ({ })); console.log(moduleNodes); -const getTopic = () => ({ - topic: { - title: 'Geld und Kauf', - id: 'VG9waWNOb2RlOjU=', - teaser: 'Topic 2', - modules: { - edges: moduleNodes, - }, - }, -}); - -const getOperations = () => ({ - MeQuery: { - me: me(), - }, - AssignmentsQuery: { - assignments: [], - }, - ModuleDetailsQuery: variables => ({module: getModuleBySlug(variables.slug)}), - TopicsQuery: { - topics: { - edges: topics.map(topic => ({node: topic})), - }, - }, - Topic: getTopic(), - UpdateLastTopic: () => { - const Topic = getTopic(); - const topic = Topic.topic; - return { - updateLastTopic: { - topic, +const getTopic = () => { + console.info('calling getTopic'); + return { + topic: { + title: 'Geld und Kauf', + id: 'VG9waWNOb2RlOjU=', + teaser: 'Topic 2', + modules: { + edges: moduleNodes, }, - }; - }, - NewsTeasers: { - newsTeasers: { - edges: [], - }, - }, - UpdateLastModule: ({input: {id}}) => { - const lastModule = modules[id]; - return { - updateLastModule: { - lastModule, - }, - }; - }, -}); + } + }; +}; const checkHome = (n, skipHome) => { cy.log(`Checking if home has ${n} teasers`); @@ -147,13 +95,70 @@ const goToModule = (topicTitle, moduleMetaTitle) => { }; describe('Current Module', () => { + const me = { + lastModule: { + slug: 'lohn-und-budget', + id: 'last-module-id', + }, + lastTopic: { + id: 'VG9waWNOb2RlOjU=', + slug: 'geld-und-kauf', + }, + recentModules: { + edges: recentModules, + }, + }; + + const operations = { + MeQuery: { + me, + }, + AssignmentsQuery: { + assignments: [], + }, + ModuleDetailsQuery: variables => { + console.log('calling ModuleDetailsQuery', getModuleBySlug(variables.slug)); + return { + module: getModuleBySlug(variables.slug) + }; + }, + TopicsQuery: { + topics: { + edges: topics.map(topic => ({node: topic})), + }, + }, + Topic: getTopic(), + UpdateLastTopic: () => { + const Topic = getTopic(); + const topic = Topic.topic; + return { + updateLastTopic: { + topic, + }, + }; + }, + NewsTeasers: { + newsTeasers: { + edges: [], + }, + }, + UpdateLastModule: ({input: {id}}) => { + const lastModule = modules[id]; + return { + updateLastModule: { + lastModule, + }, + }; + }, + }; + before(() => { cy.setup(); }); it.skip('is set correctly', () => { cy.mockGraphqlOps({ - operations: getOperations(), + operations, }); cy.visit('/'); diff --git a/client/cypress/integration/frontend/snapshots.spec.js b/client/cypress/integration/frontend/snapshots.spec.js index 3877580d..66c0d34f 100644 --- a/client/cypress/integration/frontend/snapshots.spec.js +++ b/client/cypress/integration/frontend/snapshots.spec.js @@ -1,77 +1,64 @@ import module from '../../fixtures/module.minimal'; -import mocks from '../../fixtures/mocks'; import {getMinimalMe} from '../../support/helpers'; -const operations = isTeacher => ({ - operations: { - MeQuery: getMinimalMe({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', () => { + const operations = isTeacher => ({ + operations: { + MeQuery: getMinimalMe({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 + } + } + }, + }); + beforeEach(() => { - cy.server(); - - cy.task('getSchema').then(schema => { - cy.mockGraphql({ - schema, - mocks, - }); - }); - - cy.viewport('macbook-15'); + cy.setup(); }); 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/'); @@ -80,8 +67,6 @@ describe('Snapshot', () => { }); it('Creates Snapshot', () => { - cy.fakeLogin('ross.geller', 'test'); - cy.mockGraphqlOps(operations(true)); cy.visit('module/miteinander-reden/'); cy.getByDataCy('module-snapshots-button').click(); @@ -93,8 +78,6 @@ describe('Snapshot', () => { }); it('Applies Snapshot', () => { - cy.fakeLogin('ross.geller', 'test'); - cy.mockGraphqlOps(operations(true)); cy.visit('module/miteinander-reden/snapshots'); cy.getByDataCy('snapshot-link').click(); diff --git a/client/src/pages/module/module.vue b/client/src/pages/module/module.vue index a0a8de62..9026258d 100644 --- a/client/src/pages/module/module.vue +++ b/client/src/pages/module/module.vue @@ -1,13 +1,9 @@