From 1c71c24ea05f0e937dfd1d857e329d0fa2f0e0dc Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Wed, 26 Feb 2020 12:48:30 +0100 Subject: [PATCH] Change redirect for new student, also add new test --- client/cypress/fixtures/me.new-student.json | 19 ++++++++++ .../cypress/integration/new-student.spec.js | 38 +++++++++++++++++++ client/src/main.js | 4 +- 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 client/cypress/fixtures/me.new-student.json create mode 100644 client/cypress/integration/new-student.spec.js diff --git a/client/cypress/fixtures/me.new-student.json b/client/cypress/fixtures/me.new-student.json new file mode 100644 index 00000000..0568b0ab --- /dev/null +++ b/client/cypress/fixtures/me.new-student.json @@ -0,0 +1,19 @@ +{ + "me": { + "id": "VXNlck5vZGU6NQ==", + "pk": 5, + "username": "hansli", + "email": "hansli@skillbox.example", + "firstName": "Hansli", + "lastName": "Alleini", + "avatarUrl": "", + "lastModule": null, + "selectedClass": null, + "schoolClasses": { + "edges": [], + "__typename": "SchoolClassNodeConnection" + }, + "__typename": "UserNode", + "permissions": [] + } +} diff --git a/client/cypress/integration/new-student.spec.js b/client/cypress/integration/new-student.spec.js new file mode 100644 index 00000000..873c0d93 --- /dev/null +++ b/client/cypress/integration/new-student.spec.js @@ -0,0 +1,38 @@ +const schema = require('../fixtures/schema.json'); +const me = require('../fixtures/me.new-student.json'); + +describe('New student', () => { + it('shows "Enter Code" page and adds the user to a class', () => { + + cy.server(); + + cy.mockGraphql({ + schema: schema, + }); + + + cy.apolloLogin('hansli', 'test'); + + cy.mockGraphqlOps({ + operations: { + MeQuery: me, + JoinClass: { + joinClass: { + success: true, + schoolClass: { + id: "U2Nob29sQ2xhc3NOb2RlOjI=", + name: "KF1A", + __typename: "SchoolClassNode" + } + } + } + } + }); + + cy.visit('/'); + cy.get('[data-cy=join-class-title]').should('contain', 'Zugangscode'); + cy.get('[data-cy=input-class-code]').type('XXXX'); + cy.get('[data-cy=join-class]').click(); + cy.get('[data-cy=class-list-title]').should('contain', 'Klassenliste'); + }); +}); diff --git a/client/src/main.js b/client/src/main.js index 63336b3e..9136bc69 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -151,8 +151,8 @@ router.beforeEach(async (to, from, next) => { return } - if (to.name !== 'noClass' && loginRequired(to) && await redirectStudentsWithoutClass()) { - next({name: 'noClass'}) + if (to.name !== 'join-class' && loginRequired(to) && await redirectStudentsWithoutClass()) { + next({name: 'join-class'}) return }