Update some cypress tests

This commit is contained in:
Ramon Wenger 2021-08-17 22:29:13 +02:00
parent 23a3c3ca6e
commit 8bf76a606e
4 changed files with 195 additions and 189 deletions

View File

@ -1,58 +1,64 @@
import {getModules, getMinimalMe} from '../../support/helpers';
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,
},
},
};
describe('Apply module visibility', () => { 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(() => { beforeEach(() => {
cy.server(); cy.setup();
cy.task('getSchema').then(schema => {
cy.mockGraphql({
schema,
// endpoint: '/api/graphql'
mocks,
operations,
});
});
}); });
it('clicks through the UI', () => { it('clicks through the UI', () => {
// Cypress.config({ cy.mockGraphqlOps({
// baseUrl: 'http://localhost:8080', operations
// }); });
cy.viewport('macbook-15');
// login as teacher
cy.fakeLogin('ross.geller', 'test');
// cy.apolloLogin('ross.geller', 'test');
// cy.wait('@gqlBetaLogin');
// go to module // go to module
cy.visit('/module/lohn-und-budget'); cy.visit('/module/lohn-und-budget');
cy.selectClass('Andere Klasse'); cy.selectClass('Andere Klasse');

View File

@ -15,23 +15,6 @@ const topics = [
let recentModules = []; 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 getId = (id) => btoa(`ModuleNode:${id}`);
const modules = { const modules = {
@ -80,54 +63,19 @@ const moduleNodes = Object.values(modules).map(module => ({
})); }));
console.log(moduleNodes); console.log(moduleNodes);
const getTopic = () => ({ const getTopic = () => {
topic: { console.info('calling getTopic');
title: 'Geld und Kauf', return {
id: 'VG9waWNOb2RlOjU=', topic: {
teaser: 'Topic 2', title: 'Geld und Kauf',
modules: { id: 'VG9waWNOb2RlOjU=',
edges: moduleNodes, 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,
}, },
}; }
}, };
NewsTeasers: { };
newsTeasers: {
edges: [],
},
},
UpdateLastModule: ({input: {id}}) => {
const lastModule = modules[id];
return {
updateLastModule: {
lastModule,
},
};
},
});
const checkHome = (n, skipHome) => { const checkHome = (n, skipHome) => {
cy.log(`Checking if home has ${n} teasers`); cy.log(`Checking if home has ${n} teasers`);
@ -147,13 +95,70 @@ const goToModule = (topicTitle, moduleMetaTitle) => {
}; };
describe('Current Module', () => { 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(() => { before(() => {
cy.setup(); cy.setup();
}); });
it.skip('is set correctly', () => { it.skip('is set correctly', () => {
cy.mockGraphqlOps({ cy.mockGraphqlOps({
operations: getOperations(), operations,
}); });
cy.visit('/'); cy.visit('/');

View File

@ -1,77 +1,64 @@
import module from '../../fixtures/module.minimal'; import module from '../../fixtures/module.minimal';
import mocks from '../../fixtures/mocks';
import {getMinimalMe} from '../../support/helpers'; 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', () => { 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(() => { beforeEach(() => {
cy.server(); cy.setup();
cy.task('getSchema').then(schema => {
cy.mockGraphql({
schema,
mocks,
});
});
cy.viewport('macbook-15');
}); });
it('Menu is visible for teacher', () => { it('Menu is visible for teacher', () => {
cy.fakeLogin('ross.geller', 'test');
cy.mockGraphqlOps(operations(true)); cy.mockGraphqlOps(operations(true));
cy.visit('module/miteinander-reden/'); cy.visit('module/miteinander-reden/');
cy.getByDataCy('snapshot-menu').should('be.visible'); cy.getByDataCy('snapshot-menu').should('be.visible');
}); });
it('Menu is not visible for student', () => { it('Menu is not visible for student', () => {
cy.fakeLogin('rachel.green', 'test');
cy.mockGraphqlOps(operations(false)); cy.mockGraphqlOps(operations(false));
cy.visit('module/miteinander-reden/'); cy.visit('module/miteinander-reden/');
@ -80,8 +67,6 @@ describe('Snapshot', () => {
}); });
it('Creates Snapshot', () => { it('Creates Snapshot', () => {
cy.fakeLogin('ross.geller', 'test');
cy.mockGraphqlOps(operations(true)); cy.mockGraphqlOps(operations(true));
cy.visit('module/miteinander-reden/'); cy.visit('module/miteinander-reden/');
cy.getByDataCy('module-snapshots-button').click(); cy.getByDataCy('module-snapshots-button').click();
@ -93,8 +78,6 @@ describe('Snapshot', () => {
}); });
it('Applies Snapshot', () => { it('Applies Snapshot', () => {
cy.fakeLogin('ross.geller', 'test');
cy.mockGraphqlOps(operations(true)); cy.mockGraphqlOps(operations(true));
cy.visit('module/miteinander-reden/snapshots'); cy.visit('module/miteinander-reden/snapshots');
cy.getByDataCy('snapshot-link').click(); cy.getByDataCy('snapshot-link').click();

View File

@ -1,13 +1,9 @@
<template> <template>
<div v-if="module.id"> <module
<module :module="module"
:module="module" @editNote="editNote"
v-if="module.id" @addNote="addNote"
@editNote="editNote" @bookmark="bookmark"/>
@addNote="addNote"
@bookmark="bookmark"/>
</div>
</template> </template>
<script> <script>
@ -37,6 +33,16 @@
}; };
}, },
created() {
this.$log.debug('**** module.vue created ****');
this.$log.debug(`||| module id ${this.module.id} |||`);
this.updateLastVisitedModule(this.module.id);
},
mounted() {
this.$log.debug('**** module.vue mounted ****');
this.$log.debug(`||| module id ${this.module.id} |||`);
},
apollo: { apollo: {
module() { module() {
return { return {
@ -47,9 +53,10 @@
update(data) { update(data) {
return this.$getRidOfEdges(data).module || {}; return this.$getRidOfEdges(data).module || {};
}, },
result({data: {module: {id}}}) { // result({data: {module: {id}}}) {
this.updateLastVisitedModule(id); // // this.$log.debug(`=== updating result for module ${id} ===`);
}, // // this.updateLastVisitedModule(id);
// },
fetchPolicy: 'cache-first', fetchPolicy: 'cache-first',
}; };
}, },
@ -60,10 +67,15 @@
methods: { methods: {
updateLastVisitedModule(moduleId) { updateLastVisitedModule(moduleId) {
this.$log.debug(`updating last visited module for module ${moduleId}`);
if (!moduleId) { if (!moduleId) {
this.$log.warn('no module id'); this.$log.warn('no module id');
return; return;
} }
if (this.me.lastModule.id === moduleId) {
this.$log.debug('same module already set as last module');
return;
}
this.$apollo.mutate({ this.$apollo.mutate({
mutation: UPDATE_LAST_MODULE_MUTATION, mutation: UPDATE_LAST_MODULE_MUTATION,
variables: { variables: {