diff --git a/client/cypress/fixtures/assignments.json b/client/cypress/fixtures/assignments.json new file mode 100644 index 00000000..7df50fb4 --- /dev/null +++ b/client/cypress/fixtures/assignments.json @@ -0,0 +1,34 @@ +{ + "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" + } +} diff --git a/client/cypress/fixtures/module-geld.json b/client/cypress/fixtures/module-geld.json new file mode 100644 index 00000000..e5a74e69 --- /dev/null +++ b/client/cypress/fixtures/module-geld.json @@ -0,0 +1,82 @@ +{ + "id": "TW9kdWxlTm9kZTozMQ==", + "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": [ + { + "uuid": "df8212ee-3e82-49fa-977e-c4b60789163e", + "note": { + "id": "Tm90ZU5vZGU6Mw==", + "text": "Noch eine Notiz", + "__typename": "NoteNode" + }, + "__typename": "ContentBlockBookmarkNode" + } + ], + "hiddenFor": { + "edges": [], + "__typename": "SchoolClassNodeConnection" + }, + "visibleFor": { + "edges": [], + "__typename": "SchoolClassNodeConnection" + }, + "__typename": "ContentBlockNode" + }, + "__typename": "ContentBlockNodeEdge" + } + ], + "__typename": "ContentBlockNodeConnection" + }, + "__typename": "ChapterNode" + }, + "__typename": "ChapterNodeEdge" + } + ], + "__typename": "ChapterNodeConnection" + } + } diff --git a/client/cypress/fixtures/module.json b/client/cypress/fixtures/module.json new file mode 100644 index 00000000..c41e0bf7 --- /dev/null +++ b/client/cypress/fixtures/module.json @@ -0,0 +1,120 @@ +{ + "id": "TW9kdWxlTm9kZToxNw==", + "title": "Lohn und Budget", + "metaTitle": "Modul 1", + "teaser": "Die Berufsbildung ist ein neuer Lebensabschnit", + "intro": "\nSie stehen am Anfang eines neuen Lebensabschnitts. In Ihrer Rolle als Berufslernende oder Berufslernender haben Sie Verantwortung übernommen.
\nWie 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": { + "note": { + "id": "Tm90ZU5vZGU6Mg==", + "text": "Chapter Chapter", + "__typename": "NoteNode" + }, + "__typename": "ChapterBookmarkNode" + }, + "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": [ + { + "uuid": "df8212ee-3e82-49fa-977e-c4b60789163e", + "note": { + "id": "Tm90ZU5vZGU6Mw==", + "text": "Noch eine Notiz", + "__typename": "NoteNode" + }, + "__typename": "ContentBlockBookmarkNode" + } + ], + "hiddenFor": { + "edges": [], + "__typename": "SchoolClassNodeConnection" + }, + "visibleFor": { + "edges": [], + "__typename": "SchoolClassNodeConnection" + }, + "__typename": "ContentBlockNode" + }, + "__typename": "ContentBlockNodeEdge" + } + ], + "__typename": "ContentBlockNodeConnection" + }, + "__typename": "ChapterNode" + }, + "__typename": "ChapterNodeEdge" + } + ], + "__typename": "ChapterNodeConnection" + } +} diff --git a/client/cypress/fixtures/spell-check.json b/client/cypress/fixtures/spell-check.json new file mode 100644 index 00000000..d2400ac5 --- /dev/null +++ b/client/cypress/fixtures/spell-check.json @@ -0,0 +1,30 @@ +{ + "correct": false, + "results": [ + { + "sentence": "Hir ist ein Feler gewesen", + "offset": 0, + "length": 3, + "affected": "Hir", + "corrected": "Dir", + "__typename": "SpellCheckStepNode" + }, + { + "sentence": "Hir ist ein Feler gewesen", + "offset": 12, + "length": 5, + "affected": "Feler", + "corrected": "Fehler", + "__typename": "SpellCheckStepNode" + }, + { + "sentence": "Hir ist ein Feler gewesen", + "offset": 18, + "length": 7, + "affected": "gewesen", + "corrected": "gewesen.", + "__typename": "SpellCheckStepNode" + } + ], + "__typename": "SpellCheckPayload" +} diff --git a/client/cypress/integration/bookmarks.spec.js b/client/cypress/integration/bookmarks.spec.js index 4ea14296..3ac32dae 100644 --- a/client/cypress/integration/bookmarks.spec.js +++ b/client/cypress/integration/bookmarks.spec.js @@ -1,5 +1,6 @@ describe('Survey', () => { beforeEach(() => { + // todo: mock all the graphql queries and mutations cy.exec("python ../server/manage.py prepare_bookmarks_for_cypress"); cy.viewport('macbook-15'); diff --git a/client/cypress/integration/change-password-spec.js b/client/cypress/integration/change-password-spec.js index 708cb27d..04a204ae 100644 --- a/client/cypress/integration/change-password-spec.js +++ b/client/cypress/integration/change-password-spec.js @@ -7,6 +7,7 @@ describe('Change Password Page', () => { const validationOldWrongMsg = 'Die Eingabe ist falsch'; beforeEach(function () { + // todo: mock all the graphql queries and mutations cy.clearCookies(); cy.visit('/me/profile'); cy.login('rahel.cueni', 'test'); diff --git a/client/cypress/integration/current-module.spec.js b/client/cypress/integration/current-module.spec.js index 8a71570e..079b4f63 100644 --- a/client/cypress/integration/current-module.spec.js +++ b/client/cypress/integration/current-module.spec.js @@ -1,24 +1,82 @@ +const schema = require('../fixtures/schema.json'); +const assignments = require('../fixtures/assignments.json'); +const lohnModule = require('../fixtures/module.json'); +const geldModule = require('../fixtures/module-geld.json'); + describe('Current Module', () => { + before(() => { + cy.server(); + + cy.mockGraphql({ + schema: schema, + // endpoint: '/api/graphql' + operations: { + MeQuery: variables => { + return { + me: { + 'lastModule': { + // 'id': 'TW9kdWxlTm9kZToxNw==', + 'slug': 'lohn-und-budget', + '__typename': 'ModuleNode' + }, + '__typename': 'UserNode', + 'permissions': [] + } + } + }, + AssignmentsQuery: { + assignments + }, + ModulesQuery: variables => { + let module; + if (variables.slug === 'lohn-und-budget') { + module = lohnModule; + } else { + module = geldModule + } + return { + module + } + }, + UpdateLastModule: variables => { + let module; + if (variables.input.id === 'TW9kdWxlTm9kZToxNw==') { + module = lohnModule + } else { + module = geldModule + } + + return { + updateLastModule: { + module, + errors: null, + __typename: 'UpdateLastModulePayload' + } + } + } + } + }); + }); + it('is set correctly', () => { - // cy.route('POST', '/api/graphql/').as('graphQL'); - cy.startGraphQLCapture(); cy.viewport('macbook-15'); - cy.visit('/module/lohn-und-budget'); - cy.login('nico.zickgraf', 'test'); + cy.apolloLogin('nico.zickgraf', 'test'); + cy.visit('/book/topic/geld-und-kauf'); + cy.contains('Modul 1').click(); - cy.get('[data-cy=module-title]').should('contain', 'Lohn und Budget') + cy.get('[data-cy=module-title]').should('contain', 'Lohn und Budget'); - cy.visit('/'); - cy.waitFor('MeQuery'); + cy.get('[data-cy="home-link"]').click(); cy.get('[data-cy="current-module-link"]').click(); - cy.get('[data-cy=module-title]').should('contain', 'Lohn und Budget') + cy.get('[data-cy=module-title]').should('contain', 'Lohn und Budget'); - cy.visit('/module/geld'); - cy.get('[data-cy=module-title]').should('contain', 'Geld') + cy.visit('/book/topic/geld-und-kauf'); + cy.contains('Modul 2').click(); + cy.get('[data-cy=module-title]').should('contain', 'Geld'); cy.get('[data-cy="home-link"]').click(); cy.get('[data-cy="current-module-link"]').click(); cy.get('[data-cy=module-title]').should('contain', 'Geld') }) -}) +}); diff --git a/client/cypress/integration/home-page-logged-in.spec.js b/client/cypress/integration/home-page-logged-in.spec.js index 0a9ab58c..4b846114 100644 --- a/client/cypress/integration/home-page-logged-in.spec.js +++ b/client/cypress/integration/home-page-logged-in.spec.js @@ -1,5 +1,6 @@ describe('The Logged In Home Page', () => { it('successfully loads', () => { + // todo: use graphql login cy.visit('/'); cy.login('test', 'test'); diff --git a/client/cypress/integration/new-project.spec.js b/client/cypress/integration/new-project.spec.js index 778e1d3e..eb7a0799 100644 --- a/client/cypress/integration/new-project.spec.js +++ b/client/cypress/integration/new-project.spec.js @@ -1,8 +1,53 @@ +const schema = require('../fixtures/schema.json'); + describe('New project', () => { it('creates a new project and displays it', () => { + cy.server(); + + cy.mockGraphql({ + schema: schema, + operations: { + ProjectsQuery: { + projects: { + edges: [ + { + node: { + id: 'UHJvamVjdE5vZGU6NjY=', + title: 'Some random title', + appearance: 'blue', + description: 'This description rocks', + slug: 'some-random-title', + objectives: 'Git gud', + final: false, + student: { + firstName: 'Rahel', + lastName: 'Cueni', + id: 'VXNlck5vZGU6NQ==', + avatarUrl: '', + __typename: 'UserNode' + }, + entriesCount: 0, + __typename: 'ProjectNode', + }, + __typename: 'ProjectNodeEdge' + } + ] + } + }, + AddProject: variables => ({ + addProject: { + project: Object.assign({}, variables.input.project), + errors: null, + __typename: 'AddProjectPayload' + } + }) + } + }) + ; + cy.viewport('macbook-15'); + cy.apolloLogin('rahel.cueni', 'test'); cy.visit('/portfolio'); - cy.login('rahel.cueni', 'test'); cy.get('[data-cy=add-project-button]').click(); cy.get('[data-cy=page-form-input-titel]').type('Some random title'); diff --git a/client/cypress/integration/project-entry.spec.js b/client/cypress/integration/project-entry.spec.js index 7da598c9..9792bc8e 100644 --- a/client/cypress/integration/project-entry.spec.js +++ b/client/cypress/integration/project-entry.spec.js @@ -1,11 +1,102 @@ +const schema = require('../fixtures/schema.json'); + describe('Project Entry', () => { beforeEach(() => { - cy.exec("python ../server/manage.py prepare_projects_for_cypress"); - cy.viewport('macbook-15'); - cy.startGraphQLCapture(); - cy.login('rahel.cueni', 'test', true); - cy.get('body').contains('Neues Wissen erwerben'); + cy.apolloLogin('rahel.cueni', 'test'); + + cy.mockGraphql({ + schema: schema, + operations: { + MeQuery: { + me: { + id: 'VXNlck5vZGU6NQ==', + permissions: [] + } + }, + ProjectsQuery: { + projects: { + edges: [{ + node: { + id: 'UHJvamVjdE5vZGU6MzM=', + title: 'Groot', + appearance: 'red', + 'description': 'I am Groot', + 'slug': 'groot', + 'objectives': 'Be Groot\nBe awesome', + 'final': false, + 'student': { + 'firstName': 'Rahel', + 'lastName': 'Cueni', + 'id': 'VXNlck5vZGU6NQ==', + 'avatarUrl': '', + '__typename': 'UserNode' + }, + 'entriesCount': 2, + '__typename': 'ProjectNode' + }, + '__typename': 'ProjectNodeEdge' + }], + '__typename': 'ProjectNodeConnection' + } + }, + ProjectQuery: { + "project": { + "id": "UHJvamVjdE5vZGU6MzY=", + "title": "Groot", + "appearance": "yellow", + "description": "I am Groot", + "slug": "groot", + "objectives": "Be Groot\nBe awesome", + "final": false, + "student": { + "firstName": "Rahel", + "lastName": "Cueni", + "id": "VXNlck5vZGU6NQ==", + "avatarUrl": "", + "__typename": "UserNode" + }, + "entriesCount": 1, + "__typename": "ProjectNode", + "entries": { + "edges": [{ + "node": { + "id": "UHJvamVjdEVudHJ5Tm9kZTo2NQ==", + "activity": "Kill Thanos", + "reflection": "He sucks", + "nextSteps": "Go for the head", + "documentUrl": "", + "__typename": "ProjectEntryNode", + "created": "2020-01-20T15:20:31.262510+00:00" + }, "__typename": "ProjectEntryNodeEdge" + }], "__typename": "ProjectEntryNodeConnection" + } + } + }, + AddProjectEntry: variables => ({ + addProjectEntry: { + projectEntry: Object.assign({}, variables.input.projectEntry, { + created: '2020-01-20T15:26:58.722773+00:00' + }), + errors: null, + __typename: 'AddProjectEntryPayload' + } + }), + UpdateProjectEntry: variables => ({ + updateProjectEntry: { + projectEntry: variables.input.projectEntry, + errors: null, + __typename: 'UpdateProjectEntryPayload' + } + }), + DeleteProjectEntry: { + deleteProjectEntry: { + success: true, + __typename: 'DeleteProjectEntryPayload' + } + } + } + }); }); it('should create a new project entry', () => { @@ -22,7 +113,7 @@ describe('Project Entry', () => { cy.get('[data-cy=text-form-input]').type('Stay with Rocket\nMeet Quill'); }); cy.get('[data-cy=modal-save-button]').click(); - cy.waitFor('AddProjectEntryMutation'); + cy.get('.project-entry:last-of-type').within(() => { cy.get('.project-entry__paragraph:first-of-type').contains('Join the Guardians') }); @@ -39,20 +130,19 @@ describe('Project Entry', () => { cy.get('[data-cy=text-form-input]').clear().type('Defeat Thanos'); }); cy.get('[data-cy=modal-save-button]').click(); - cy.waitFor('UpdateProjectEntry'); cy.get('.project-entry__paragraph:first-of-type').contains('Defeat Thanos'); }); it('should delete the last entry', () => { cy.visit('/portfolio/groot'); - cy.get('.project-entry').should('have.length', 2); + cy.get('.project-entry').should('have.length', 1); cy.get('.project-entry:last-of-type').within(() => { cy.get('[data-cy=project-entry-more]').click(); cy.get('[data-cy=delete-project-entry]').click(); }); - cy.get('.project-entry').should('have.length', 1); + cy.get('.project-entry').should('have.length', 0); }); }); diff --git a/client/cypress/integration/room-page.spec.js b/client/cypress/integration/room-page.spec.js index dfa1d70d..a8206451 100644 --- a/client/cypress/integration/room-page.spec.js +++ b/client/cypress/integration/room-page.spec.js @@ -1,5 +1,7 @@ describe('The Room Page', () => { it('displays new room entry with author name', () => { + // todo: mock all the graphql queries and mutations + cy.viewport('macbook-15'); cy.visit('/room/ein-historisches-festival'); cy.login('rahel.cueni', 'test'); diff --git a/client/cypress/integration/rooms-page.spec.js b/client/cypress/integration/rooms-page.spec.js index 755bc9d0..99604cb4 100644 --- a/client/cypress/integration/rooms-page.spec.js +++ b/client/cypress/integration/rooms-page.spec.js @@ -1,4 +1,5 @@ describe('The Rooms Page', () => { + // todo: mock all the graphql queries and mutations it('goes to the rooms page', () => { cy.visit('/rooms'); cy.login('nico.zickgraf', 'test'); diff --git a/client/cypress/integration/solutions.spec.js b/client/cypress/integration/solutions.spec.js index dfd34b3d..014d4844 100644 --- a/client/cypress/integration/solutions.spec.js +++ b/client/cypress/integration/solutions.spec.js @@ -1,5 +1,8 @@ // todo: reenable with a script that does the mutations, or with a workaround for fetch request checking in cypress describe('Solutions', () => { + // todo: mock all the graphql queries and mutations + // todo: enable again + // // it('does not display the solution at first, then displays them after clicking', () => { // // cy.viewport('macbook-15'); // // cy.login('nico.zickgraf', 'test'); diff --git a/client/cypress/integration/spellcheck.spec.js b/client/cypress/integration/spellcheck.spec.js index c9e0396c..1204528e 100644 --- a/client/cypress/integration/spellcheck.spec.js +++ b/client/cypress/integration/spellcheck.spec.js @@ -1,146 +1,34 @@ const schema = require('../fixtures/schema.json'); +const assignments = require('../fixtures/assignments.json'); +const module = require('../fixtures/module.json'); +const spellCheck = require('../fixtures/spell-check.json'); describe('Spellcheck', () => { - beforeEach(() => { + before(() => { cy.server(); cy.mockGraphql({ schema: schema, // endpoint: '/api/graphql' - }); - }); - - it('should highlight three errors', () => { - let module = { - id: 'TW9kdWxlTm9kZToxNw==', - title: 'Whatevs', - metaTitle: 'Modul 1', - teaser: 'Die Berufsbildung ist ein neuer Lebensabschnit', - intro: '\nSie stehen am Anfang eines neuen Lebensabschnitts. In Ihrer Rolle als Berufslernende oder Berufslernender haben Sie Verantwortung \u00fcbernommen.
\nWie 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': '\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' - }, - 'objectiveGroups': { - 'edges': [], '__typename': 'ObjectiveGroupNodeConnection' - }, - 'chapters': { - 'edges': [{ - 'node': { - 'id': 'Q2hhcHRlck5vZGU6MTg=', - 'title': '1.1 Lehrbeginn', - 'description': 'Wie sieht Ihr Konsumverhalten aus?', - 'bookmark': { - 'note': {'id': 'Tm90ZU5vZGU6Mg==', 'text': 'Chapter Chapter', '__typename': 'NoteNode'}, - '__typename': 'ChapterBookmarkNode' - }, - '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': [{ - 'uuid': 'df8212ee-3e82-49fa-977e-c4b60789163e', - 'note': {'id': 'Tm90ZU5vZGU6Mw==', 'text': 'Noch eine Notiz', '__typename': 'NoteNode'}, - '__typename': 'ContentBlockBookmarkNode' - }], - 'hiddenFor': {'edges': [], '__typename': 'SchoolClassNodeConnection'}, - 'visibleFor': {'edges': [], '__typename': 'SchoolClassNodeConnection'}, - '__typename': 'ContentBlockNode' - }, - '__typename': 'ContentBlockNodeEdge' - }], - '__typename': 'ContentBlockNodeConnection' - }, - '__typename': 'ChapterNode' - }, - '__typename': 'ChapterNodeEdge' - }], - '__typename': 'ChapterNodeConnection' - } - }; - - cy.mockGraphqlOps({ - // endpoint: '/api/graphql', operations: { MeQuery: { me: { permissions: [] } }, + AssignmentsQuery: { + assignments + }, ModulesQuery: { module }, SpellCheck: { - spellCheck: { - correct: false, - results: [{ - sentence: 'Hir ist ein Feler gewesen', - offset: 0, - length: 3, - affected: 'Hir', - corrected: 'Dir', - __typename: 'SpellCheckStepNode' - }, { - sentence: 'Hir ist ein Feler gewesen', - offset: 12, - length: 5, - affected: 'Feler', - corrected: 'Fehler', - __typename: 'SpellCheckStepNode' - }, { - sentence: 'Hir ist ein Feler gewesen', - offset: 18, - length: 7, - affected: 'gewesen', - corrected: 'gewesen.', - __typename: 'SpellCheckStepNode' - }], - __typename: 'SpellCheckPayload' - } + spellCheck } } }); + }); + it('should highlight three errors', () => { cy.apolloLogin('rahel.cueni', 'test'); cy.visit('/module/lohn-und-budget/'); diff --git a/client/cypress/integration/survey.spec.js b/client/cypress/integration/survey.spec.js index c1bd181a..97943eac 100644 --- a/client/cypress/integration/survey.spec.js +++ b/client/cypress/integration/survey.spec.js @@ -1,14 +1,57 @@ +const schema = require('../fixtures/schema.json'); +const module = require('../fixtures/module.json'); + describe('Survey', () => { beforeEach(() => { - cy.exec("python ../server/manage.py prepare_surveys_for_cypress"); + cy.server(); + + cy.mockGraphql({ + schema: schema, + }); cy.viewport('macbook-15'); - cy.startGraphQLCapture(); - cy.login('rahel.cueni', 'test', true); - cy.get('body').contains('Neues Wissen erwerben'); + + cy.apolloLogin('rahel.cueni', 'test'); }); it('should display and fill out the survey', () => { + + let answer = null; + + cy.mockGraphqlOps({ + operations: { + MeQuery: { + me: { + permissions: [] + } + }, + ModuleQuery: variables => ({module}), + SurveyQuery: () => ({ + survey: { + id: 'U3VydmV5Tm9kZTox', + title: 'Test', + data: '{"pages": [{"name": "Seite 1", "elements": [{"name": "Fall 1", "type": "panel", "title": "Fall 1", "elements": [{"name": "A: Max gibt ihr das Geld und muss das Billardspiel absagen.", "type": "text", "placeHolder": "Passende Tugenden erfassen...", "correctAnswer": "Triss"}, {"name": "question2", "type": "text", "title": "B: Max gibt ihr das Geld nicht und geht Billard spielen.", "placeHolder": "Passende Tugenden erfassen...", "correctAnswer": "Jaskier"}], "description": "Max hat Ende Monat noch Fr. 20.\\u2013 \\u00fcbrig, die er gespart hat, um mit seinem besten Kumpel, der ein halbes Jahr im Ausland verweilte, Billard spielen zu gehen. Doch dann bittet ihn seine j\\u00fcngere Schwester um Geld. Sie hat ein unverhofftes Date mit einem jungen Mann, in den sie sich bereits vor Monaten unsterblich verliebt hat. Leider ist ihr Kontostand aber bereits auf Null."}]}, {"name": "Seite 2", "elements": [{"name": "panel1", "type": "panel", "title": "Fall 2", "elements": [{"name": "question1", "type": "text", "title": "A: Silvio bringt seinen Mitfahrer in Sicherheit.", "placeHolder": "Passende Tugenden erfassen...", "correctAnswer": "Yennefer", "useDisplayValuesInTitle": false}, {"name": "question3", "type": "text", "title": "B: Silvio sperrt die Strasse ab.", "placeHolder": "Passende Tugenden erfassen...", "correctAnswer": "Geralt"}], "description": "Auf der Autobahn brennt ein Lastwagen, der jederzeit explodieren kann. Silvio, dem Fahrer, bleiben nur noch wenige Minuten: Entweder bringt er seinen ohnm\\u00e4chtig gewordenen Mitfahrer in Sicherheit oder er sperrt die Strasse ab, die nach wie vor dicht befahren wird."}]}], "completeText": "Abschliessen", "showQuestionNumbers": "off"}', + module: { + id: 'TW9kdWxlTm9kZToxNw==', + __typename: 'ModuleNode' + }, + answer, + __typename: 'SurveyNode' + }, + + }), + UpdateAnswer: variables => { + answer = variables.input.answer; + return { + updateAnswer: { + answer, + __typename: 'UpdateAnswerPayload' + } + } + } + } + }); + cy.visit('/survey/U3VydmV5Tm9kZTox'); cy.get('.survey__panel-title').should('contain', 'Fall 1') @@ -17,15 +60,12 @@ describe('Survey', () => { cy.get('#sq_101i').type('Demut'); cy.get('[value="Speichern & Weiter"]').click(); - //cy.get('.button--primary').click() cy.get('#sq_102i').type('Keuschheit'); cy.get('#sq_103i').type('Geduld'); cy.get('[value=Abschliessen]').click(); - cy.waitFor('UpdateAnswer'); - cy.visit('/survey/U3VydmV5Tm9kZTox'); cy.get('#sq_100i').should('have.value', 'Wohlwollen') diff --git a/client/cypress/support/commands.js b/client/cypress/support/commands.js index c75b0efd..208fac7e 100644 --- a/client/cypress/support/commands.js +++ b/client/cypress/support/commands.js @@ -23,8 +23,11 @@ // // -- This is will overwrite an existing command -- // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) - -import 'cypress-graphql-mock'; +// installed a fork of the original package, because of this issue: +// https://github.com/tgriesser/cypress-graphql-mock/issues/23 +// todo: once above issue is fixed, go back to the original repo -> npm install cypress-graphql-mock +// import 'cypress-graphql-mock'; +import '@iam4x/cypress-graphql-mock'; Cypress.Commands.add('apolloLogin', (username, password) => { const payload = { diff --git a/client/package-lock.json b/client/package-lock.json index 24e4ae86..69308bb2 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -2524,6 +2524,15 @@ "lodash.once": "^4.1.1" } }, + "@iam4x/cypress-graphql-mock": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@iam4x/cypress-graphql-mock/-/cypress-graphql-mock-0.0.1.tgz", + "integrity": "sha512-pi2nNDwX9o+63qbwK4ogUAk5oX2HunclFcQ1YCsTx4DBoAdudfiKUegyqFXrii+wtyDaXUa88UrkrudMMcnCbA==", + "requires": { + "graphql-tools": "^4.0.3", + "tslib": "^1.9.3" + } + }, "@jest/console": { "version": "24.7.1", "resolved": "https://registry.npmjs.org/@jest/console/-/console-24.7.1.tgz", @@ -7244,15 +7253,6 @@ } } }, - "cypress-graphql-mock": { - "version": "0.5.0-alpha.4", - "resolved": "https://registry.npmjs.org/cypress-graphql-mock/-/cypress-graphql-mock-0.5.0-alpha.4.tgz", - "integrity": "sha512-dgsczorpXRyG0Jak0N8RdNcyJv+9FPE1cS9UlKEx8g+JBABZF3mVDjpzksnWDvSAUHGrhD+nHFgtgqMXojQVAw==", - "requires": { - "graphql-tools": "^4.0.3", - "tslib": "^1.9.3" - } - }, "d": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/d/-/d-1.0.0.tgz", @@ -11568,7 +11568,6 @@ "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -11737,7 +11736,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } diff --git a/client/package.json b/client/package.json index ec20a10b..ee872d1e 100644 --- a/client/package.json +++ b/client/package.json @@ -21,6 +21,7 @@ "@babel/preset-env": "^7.5.4", "@babel/preset-stage-2": "^7.0.0", "@babel/runtime": "^7.5.4", + "@iam4x/cypress-graphql-mock": "0.0.1", "apollo-cache-inmemory": "^1.6.5", "apollo-client": "^2.6.8", "apollo-link": "^1.2.13", @@ -37,7 +38,6 @@ "chalk": "^2.0.1", "copy-webpack-plugin": "^4.0.1", "css-loader": "^0.28.0", - "cypress-graphql-mock": "^0.5.0-alpha.4", "debounce": "^1.2.0", "eslint": "^4.15.0", "eslint-config-standard": "^10.2.1", diff --git a/client/src/graphql/gql/mutations/addProject.gql b/client/src/graphql/gql/mutations/addProject.gql index e531c2c6..f3d74545 100644 --- a/client/src/graphql/gql/mutations/addProject.gql +++ b/client/src/graphql/gql/mutations/addProject.gql @@ -1,5 +1,5 @@ #import "../fragments/projectParts.gql" -mutation AddProjectMutation($input: AddProjectInput!){ +mutation AddProject($input: AddProjectInput!){ addProject(input: $input){ project { ...ProjectParts diff --git a/client/src/graphql/gql/mutations/addProjectEntry.gql b/client/src/graphql/gql/mutations/addProjectEntry.gql index 2cd168da..2a98d312 100644 --- a/client/src/graphql/gql/mutations/addProjectEntry.gql +++ b/client/src/graphql/gql/mutations/addProjectEntry.gql @@ -1,5 +1,5 @@ #import "../fragments/projectEntryParts.gql" -mutation AddProjectEntryMutation($input: AddProjectEntryInput!) { +mutation AddProjectEntry($input: AddProjectEntryInput!) { addProjectEntry(input: $input) { projectEntry { ...ProjectEntryParts diff --git a/server/books/schema/mutations/module.py b/server/books/schema/mutations/module.py index de4fde77..15479642 100644 --- a/server/books/schema/mutations/module.py +++ b/server/books/schema/mutations/module.py @@ -43,6 +43,7 @@ class UpdateSolutionVisibility(relay.ClientIDMutation): class UpdateLastModule(relay.ClientIDMutation): class Input: + # todo: use slug here too id = graphene.ID() module = graphene.Field(ModuleNode)