From e4839df4dbf603b37a2fa3a6f7bfd5dab4e9c81c Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Sun, 14 Mar 2021 21:49:28 +0100 Subject: [PATCH] Fix cypress test --- .../sync-module-visibility.spec.js | 57 +- client/cypress/plugins/index.js | 13 +- client/cypress/support/commands.js | 5 + client/cypress/support/helpers.js | 355 +++++ .../components/modules/ModuleNavigation.vue | 2 +- client/src/pages/module/moduleVisibility.vue | 36 +- client/src/store/index.js | 3 - schema.graphql | 1302 +++++++++++++++++ 8 files changed, 1759 insertions(+), 14 deletions(-) create mode 100644 client/cypress/support/helpers.js create mode 100644 schema.graphql diff --git a/client/cypress/integration/sync-module-visibility.spec.js b/client/cypress/integration/sync-module-visibility.spec.js index b72a89fd..42fafeae 100644 --- a/client/cypress/integration/sync-module-visibility.spec.js +++ b/client/cypress/integration/sync-module-visibility.spec.js @@ -1,9 +1,62 @@ +// import * as schema from '../fixtures/schema.json'; +import {getModules, getMe} from '../support/helpers'; + +const mocks = { + UUID: () => 'Whatever', + GenericStreamFieldType: () => [], +}; + +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', () => { + beforeEach(() => { + cy.server(); + cy.task('getSchema').then(schema => { + cy.mockGraphql({ + schema, + // endpoint: '/api/graphql' + mocks, + operations, + }); + }); + }); + it('needs to be implemented', () => { + Cypress.config({ + baseUrl: 'http://localhost:8080', + }); cy.viewport('macbook-15'); + // login as teacher - cy.login('nico.zickgraf', 'test', true); - cy.wait('@gqlBetaLogin'); + cy.fakeLogin('nico.zickgraf', 'test'); + // cy.login('nico.zickgraf', 'test', true); + // cy.wait('@gqlBetaLogin'); // go to module cy.visit('/module/lohn-und-budget'); cy.selectClass('Andere Klasse'); diff --git a/client/cypress/plugins/index.js b/client/cypress/plugins/index.js index fd170fba..4117cf88 100644 --- a/client/cypress/plugins/index.js +++ b/client/cypress/plugins/index.js @@ -11,7 +11,18 @@ // This function is called when a project is opened or re-opened (e.g. due to // the project's config changing) +import {readFileSync} from 'fs'; +import {resolve} from 'path'; + module.exports = (on, config) => { // `on` is used to hook into various events Cypress emits // `config` is the resolved Cypress config -} + on('task', { + getSchema() { + return readFileSync( + resolve(__dirname, '../../../schema.graphql'), + 'utf8' + ); + } + }); +}; diff --git a/client/cypress/support/commands.js b/client/cypress/support/commands.js index 7ecf5334..f884ba64 100644 --- a/client/cypress/support/commands.js +++ b/client/cypress/support/commands.js @@ -184,3 +184,8 @@ Cypress.Commands.add('selectClass', (schoolClass) => { cy.dataCy('class-selection').click(); cy.dataCy('class-selection-entry').contains(schoolClass).click(); }); + +Cypress.Commands.add('fakeLogin', () => { + cy.log('Logging in (fake)'); + cy.setCookie('loginStatus', 'true'); +}); diff --git a/client/cypress/support/helpers.js b/client/cypress/support/helpers.js new file mode 100644 index 00000000..773dd6eb --- /dev/null +++ b/client/cypress/support/helpers.js @@ -0,0 +1,355 @@ +const getSchoolClassNode = (id, schoolClassName) => ({ + 'id': btoa(`SchoolClassNode:${id}`), + 'name': schoolClassName, + '__typename': 'SchoolClassNode', +}); + +export const getMe = ({schoolClasses, teacher}) => { + let schoolClassNodes = []; + if (schoolClasses) { + for (let i = 0; i < schoolClasses.length; i++) { + schoolClassNodes.push(getSchoolClassNode(i, schoolClasses[i])); + } + } else { + schoolClassNodes.push(getSchoolClassNode(1, 'FLID2018a')); + } + + return { + 'me': { + 'id': 'VXNlck5vZGU6NQ==', + 'pk': 5, + 'username': 'rahel.cueni', + 'email': 'rahel.cueni@skillbox.example', + 'expiryDate': '3596153600', + 'firstName': 'Rahel', + 'lastName': 'Cueni', + 'avatarUrl': '', + 'isTeacher': false, + 'lastModule': { + 'id': 'TW9kdWxlTm9kZToxNw==', + 'slug': 'lohn-und-budget', + '__typename': 'ModuleNode', + }, + 'selectedClass': { + 'id': 'U2Nob29sQ2xhc3NOb2RlOjI=', + '__typename': 'SchoolClassNode', + }, + 'lastTopic': { + 'id': 'VG9waWNOb2RlOjU=', + 'slug': 'geld-und-kauf', + '__typename': 'TopicNode', + }, + 'schoolClasses': { + 'edges': schoolClassNodes.map(scn => ({ + node: scn, + '__typename': 'SchoolClassNodeEdge', + })), + '__typename': 'SchoolClassNodeConnection', + }, + '__typename': 'UserNode', + 'onboardingVisited': true, + 'permissions': teacher ? ['users.can_manage_school_class_content'] : [], + }, + }; +}; + +export const getAssignments = () => { + return { + 'assignments': { + 'edges': [ + { + 'node': { + 'id': 'QXNzaWdubWVudE5vZGU6MQ==', + 'title': 'Ein Auftragstitel', + 'assignment': 'Ein Auftrag', + 'solution': null, + 'submission': { + 'id': 'U3R1ZGVudFN1Ym1pc3Npb25Ob2RlOjE=', + 'text': 'Hir ist ein Feler gewesen', + 'final': false, + 'document': '', + 'submissionFeedback': { + 'id': 'U3VibWlzc2lvbkZlZWRiYWNrTm9kZTox', + 'text': '\ud83d\ude42\ud83d\ude10\ud83e\udd2c\ud83d\udc4d\ud83e\udd22\ud83e\udd22\ud83e\udd22\ud83e\udd22\ud83d\ude2e\ud83e\udd17', + 'teacher': { + 'firstName': 'Nico', + 'lastName': 'Zickgraf', + '__typename': 'UserNode', + }, + '__typename': 'SubmissionFeedbackNode', + }, + '__typename': 'StudentSubmissionNode', + }, + '__typename': 'AssignmentNode', + }, + '__typename': 'AssignmentNodeEdge', + }, + ], + '__typename': 'AssignmentNodeConnection', + }, + }; +}; + +export const getModules = () => { + return { + 'lohn-und-budget': { + 'id': 'TW9kdWxlTm9kZToyOA==', + 'title': 'Lohn und Budget', + 'metaTitle': 'Modul 1', + 'teaser': 'Die Berufsbildung ist ein neuer Lebensabschnit', + 'intro': '\n

Sie stehen am Anfang eines neuen Lebensabschnitts. In Ihrer Rolle als Berufslernende oder Berufslernender haben Sie Verantwortung übernommen.

\n

Wie erging es Ihnen am ersten Arbeits- und Schultag?

\n ', + 'slug': 'lohn-und-budget', + 'heroImage': 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==', + 'solutionsEnabled': false, + 'bookmark': { + 'note': null, + '__typename': 'ModuleBookmarkNode', + }, + '__typename': 'ModuleNode', + 'assignments': { + 'edges': [ + { + 'node': { + 'id': 'QXNzaWdubWVudE5vZGU6MQ==', + 'title': 'Ein Auftragstitel', + 'assignment': 'Ein Auftrag', + 'solution': null, + 'submission': { + 'id': 'U3R1ZGVudFN1Ym1pc3Npb25Ob2RlOjE=', + 'text': 'Hir ist ein Feler gewesen', + 'final': false, + 'document': '', + 'submissionFeedback': { + 'id': 'U3VibWlzc2lvbkZlZWRiYWNrTm9kZTox', + 'text': '🙂😐🤬👍🤢🤢🤢🤢😮🤗', + 'teacher': { + 'firstName': 'Nico', + 'lastName': 'Zickgraf', + '__typename': 'UserNode', + }, + '__typename': 'SubmissionFeedbackNode', + }, + '__typename': 'StudentSubmissionNode', + }, + '__typename': 'AssignmentNode', + }, + '__typename': 'AssignmentNodeEdge', + }, + ], + '__typename': 'AssignmentNodeConnection', + }, + 'objectiveGroups': { + 'edges': [], + '__typename': 'ObjectiveGroupNodeConnection', + }, + 'chapters': { + 'edges': [ + { + 'node': { + 'id': 'Q2hhcHRlck5vZGU6MTg=', + 'title': '1.1 Lehrbeginn', + 'description': 'Wie sieht Ihr Konsumverhalten aus?', + 'bookmark': null, + 'contentBlocks': { + 'edges': [ + { + 'node': { + 'id': 'Q29udGVudEJsb2NrTm9kZToxOQ==', + 'slug': 'assignment', + 'title': 'Assignment', + 'type': 'NORMAL', + 'contents': [ + { + 'type': 'assignment', + 'value': { + 'title': 'Ein Auftragstitel', + 'assignment': 'Ein Auftrag', + 'id': 'QXNzaWdubWVudE5vZGU6MQ==', + }, + 'id': 'df8212ee-3e82-49fa-977e-c4b60789163e', + }, + ], + 'userCreated': false, + 'mine': false, + 'bookmarks': [], + 'hiddenFor': { + 'edges': [], + '__typename': 'SchoolClassNodeConnection', + }, + 'visibleFor': { + 'edges': [], + '__typename': 'SchoolClassNodeConnection', + }, + '__typename': 'ContentBlockNode', + }, + '__typename': 'ContentBlockNodeEdge', + }, + ], + '__typename': 'ContentBlockNodeConnection', + }, + '__typename': 'ChapterNode', + }, + '__typename': 'ChapterNodeEdge', + }, + ], + '__typename': 'ChapterNodeConnection', + }, + }, + 'geld': { + 'id': 'TW9kdWxlTm9kZTo0Mg==', + 'title': 'Geld', + 'metaTitle': 'Modul 2', + 'teaser': ' Geld braucht jeder von uns im t\u00e4glichen Leben.', + 'intro': '\n

Jeder B\u00fcrger nutzt es. Nahezu jeden Tag. Kaum ein Tag vergeht, an dem wir nicht mit M\u00fcnzen oder Geldscheinen bezahlen, bargeldlose \u00dcberweisungen t\u00e4tigen oder andere Zahlungsmethoden verwenden. Doch was genau befindet sich da eigentlich in unserem Geldbeutel? Was ist das, was auf unseren Konten liegt und die Bezeichnung Geld tr\u00e4gt?

\n ', + 'slug': 'geld', + 'heroImage': 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==', + 'solutionsEnabled': false, + 'bookmark': null, + '__typename': 'ModuleNode', + 'assignments': { + 'edges': [], + '__typename': 'AssignmentNodeConnection', + }, + 'objectiveGroups': { + 'edges': [], + '__typename': 'ObjectiveGroupNodeConnection', + }, + 'chapters': { + 'edges': [ + { + 'node': { + 'id': 'Q2hhcHRlck5vZGU6MzI=', + 'title': '2.1 Eine Welt ohne Geld?', + 'description': '', + 'bookmark': null, + 'contentBlocks': { + 'edges': [ + { + 'node': { + 'id': 'Q29udGVudEJsb2NrTm9kZToxOQ==', + 'slug': 'assignment', + 'title': 'Assignment', + 'type': 'NORMAL', + 'contents': [ + { + 'type': 'assignment', + 'value': { + 'title': 'Ein Auftragstitel', + 'assignment': 'Ein Auftrag', + 'id': 'QXNzaWdubWVudE5vZGU6MQ==', + }, + 'id': 'df8212ee-3e82-49fa-977e-c4b60789163e', + }, + ], + 'userCreated': false, + 'mine': false, + 'bookmarks': [], + 'hiddenFor': { + 'edges': [], + '__typename': 'SchoolClassNodeConnection', + }, + 'visibleFor': { + 'edges': [], + '__typename': 'SchoolClassNodeConnection', + }, + '__typename': 'ContentBlockNode', + }, + '__typename': 'ContentBlockNodeEdge', + }, + ], + '__typename': 'ContentBlockNodeConnection', + }, + '__typename': 'ChapterNode', + }, + '__typename': 'ChapterNodeEdge', + }, + ], + '__typename': 'ChapterNodeConnection', + }, + }, + 'lerntipps': { + 'id': 'TW9kdWxlTm9kZTo3MA==', + 'title': 'Lerntipps', + 'metaTitle': 'Modul 4', + 'teaser': 'Lerntipps', + 'intro': '\n

Sie stehen am Anfang eines neuen Lebensabschnitts. In Ihrer Rolle als Berufslernende oder Berufslernender haben Sie Verantwortung übernommen.

\n

Wie erging es Ihnen am ersten Arbeits- und Schultag?

\n ', + 'slug': 'lerntipps', + 'heroImage': 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==', + 'solutionsEnabled': false, + 'bookmark': { + 'note': null, + '__typename': 'ModuleBookmarkNode', + }, + '__typename': 'ModuleNode', + 'assignments': { + 'edges': [], + '__typename': 'AssignmentNodeConnection', + }, + 'objectiveGroups': { + 'edges': [], + '__typename': 'ObjectiveGroupNodeConnection', + }, + 'chapters': { + 'edges': [ + { + 'node': { + 'id': 'Q2hhcHRlck5vZGU6MTg=', + 'title': '1.1 Lehrbeginn', + 'description': 'Wie sieht Ihr Konsumverhalten aus?', + 'bookmark': null, + 'contentBlocks': { + 'edges': [], + '__typename': 'ContentBlockNodeConnection', + }, + '__typename': 'ChapterNode', + }, + '__typename': 'ChapterNodeEdge', + }, + ], + '__typename': 'ChapterNodeConnection', + }, + }, + 'random': { + 'id': 'TW9kdWxlTm9kZTo1NA==', + 'title': 'Random', + 'metaTitle': 'Modul 5', + 'teaser': 'Random', + 'intro': '\n

Sie stehen am Anfang eines neuen Lebensabschnitts. In Ihrer Rolle als Berufslernende oder Berufslernender haben Sie Verantwortung übernommen.

\n

Wie erging es Ihnen am ersten Arbeits- und Schultag?

\n ', + 'slug': 'random', + 'heroImage': 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==', + 'solutionsEnabled': false, + 'bookmark': { + 'note': null, + '__typename': 'ModuleBookmarkNode', + }, + '__typename': 'ModuleNode', + 'assignments': { + 'edges': [], + '__typename': 'AssignmentNodeConnection', + }, + 'objectiveGroups': { + 'edges': [], + '__typename': 'ObjectiveGroupNodeConnection', + }, + 'chapters': { + 'edges': [ + { + 'node': { + 'id': 'Q2hhcHRlck5vZGU6MTg=', + 'title': '1.1 Lehrbeginn', + 'description': 'Wie sieht Ihr Konsumverhalten aus?', + 'bookmark': null, + 'contentBlocks': { + 'edges': [], + '__typename': 'ContentBlockNodeConnection', + }, + '__typename': 'ChapterNode', + }, + '__typename': 'ChapterNodeEdge', + }, + ], + '__typename': 'ChapterNodeConnection', + }, + }, + }; +}; diff --git a/client/src/components/modules/ModuleNavigation.vue b/client/src/components/modules/ModuleNavigation.vue index 3ce61f8e..2e8f909c 100644 --- a/client/src/components/modules/ModuleNavigation.vue +++ b/client/src/components/modules/ModuleNavigation.vue @@ -47,7 +47,7 @@ > Snapshots + data-cy="module-snapshots-button">Snapshots schoolClass.id !== this.me.selectedClass.id); }, + slug() { + return this.$route.params.slug; + } }, methods: { @@ -69,15 +74,32 @@ }, sync() { if (this.selectedClassId) { + const slug = this.slug; this.$apollo.mutate({ - mutation: SYNC_VISIBILITY_MUTATION, - variables: { - input: { - module: this.$route.params.slug, - templateSchoolClass: this.selectedClassId, - schoolClass: this.me.selectedClass.id, + mutation: SYNC_VISIBILITY_MUTATION, + variables: { + input: { + module: slug, + templateSchoolClass: this.selectedClassId, + schoolClass: this.me.selectedClass.id, + }, }, + refetchQueries: [ + { + query: MODULE_DETAILS_QUERY, + variables: { + slug, + }, + }, + ], }, + ).then(() => { + this.$router.push({ + name: MODULE_PAGE, + params: { + slug + } + }); }); } }, @@ -86,7 +108,7 @@