From a8d3635d7b3b056a69b3eab977b622e86596c42c Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Thu, 25 Mar 2021 20:49:36 +0100 Subject: [PATCH] Update frontend cypress tests --- .../integration/frontend/onboarding.spec.js | 7 +- .../frontend/project-entry.spec.js | 194 +++++++++--------- .../integration/frontend/school-class.spec.js | 17 +- .../integration/frontend/spellcheck.spec.js | 46 +++-- .../integration/frontend/survey.spec.js | 7 +- 5 files changed, 141 insertions(+), 130 deletions(-) diff --git a/client/cypress/integration/frontend/onboarding.spec.js b/client/cypress/integration/frontend/onboarding.spec.js index c96ebf82..ce6b14e5 100644 --- a/client/cypress/integration/frontend/onboarding.spec.js +++ b/client/cypress/integration/frontend/onboarding.spec.js @@ -1,14 +1,15 @@ import {mockUpdateOnboardingProgress} from '../../support/helpers'; -const schema = require('../../fixtures/schema.json'); const me = require('../../fixtures/me.join-class.json'); describe('Onboarding', () => { beforeEach(() => { cy.server(); - cy.mockGraphql({ - schema: schema, + cy.task('getSchema').then(schema => { + cy.mockGraphql({ + schema, + }); }); }); diff --git a/client/cypress/integration/frontend/project-entry.spec.js b/client/cypress/integration/frontend/project-entry.spec.js index 8ac091f8..d6ce642b 100644 --- a/client/cypress/integration/frontend/project-entry.spec.js +++ b/client/cypress/integration/frontend/project-entry.spec.js @@ -1,5 +1,96 @@ -const schema = require('../../fixtures/schema.json'); -const me = require('../../fixtures/me.new-student.json'); + +const operations = { + MeQuery: { + me: { + id: 'VXNlck5vZGU6NQ==', + onboardingVisited: true, + 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', + }, + }, +}; describe('Project Entry', () => { beforeEach(() => { @@ -7,100 +98,11 @@ describe('Project Entry', () => { cy.fakeLogin('rahel.cueni', 'test'); cy.server(); - cy.mockGraphql({ - schema: schema, - operations: { - MeQuery: { - me: { - id: 'VXNlck5vZGU6NQ==', - onboardingVisited: true, - 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' - } - } - } + cy.task('getSchema').then(schema => { + cy.mockGraphql({ + schema, + operations, + }); }); }); diff --git a/client/cypress/integration/frontend/school-class.spec.js b/client/cypress/integration/frontend/school-class.spec.js index 2c7059b1..7aee4693 100644 --- a/client/cypress/integration/frontend/school-class.spec.js +++ b/client/cypress/integration/frontend/school-class.spec.js @@ -1,4 +1,3 @@ -const schema = require('../../fixtures/schema.json'); const me = require('../../fixtures/me.join-class.json'); const selectedClass = require('../../fixtures/selected-school-class.json'); @@ -6,8 +5,10 @@ describe('Class Management', () => { beforeEach(() => { cy.server(); - cy.mockGraphql({ - schema: schema, + cy.task('getSchema').then(schema => { + cy.mockGraphql({ + schema, + }); }); cy.viewport('macbook-15'); @@ -104,7 +105,7 @@ describe('Class Management', () => { }); cy.visit('/me/my-class'); - cy.get('[data-cy=school-class-member]').should('have.length', 2); + cy.get('[data-cy=group-list-member]').should('have.length', 2); cy.get('[data-cy=remove-from-class]').should('have.length', 0); cy.get('[data-cy=add-to-class]').should('have.length', 0); }); @@ -187,8 +188,10 @@ describe('Teacher Class Management', () => { beforeEach(() => { cy.server(); - cy.mockGraphql({ - schema: schema, + cy.task('getSchema').then(schema => { + cy.mockGraphql({ + schema, + }); }); cy.viewport('macbook-15'); @@ -232,7 +235,7 @@ describe('Teacher Class Management', () => { cy.get('[data-cy=edit-group-name-link]').click(); cy.get('[data-cy=edit-name-input] input').type('{selectall}{backspace}').type(className); cy.get('[data-cy=modal-save-button]').click(); - cy.get('[data-cy=school-class-name]').should('contain', className); + cy.get('[data-cy=group-list-name]').should('contain', className); }); // // fixme: cache misbehaves with mequery, but only for test diff --git a/client/cypress/integration/frontend/spellcheck.spec.js b/client/cypress/integration/frontend/spellcheck.spec.js index c7c1276a..adeb0495 100644 --- a/client/cypress/integration/frontend/spellcheck.spec.js +++ b/client/cypress/integration/frontend/spellcheck.spec.js @@ -1,33 +1,37 @@ import {mockUpdateLastModule} from '../../support/helpers'; -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'); +const operations = { + MeQuery: { + me: { + permissions: [], + onboardingVisited: true, + }, + }, + AssignmentsQuery: { + assignments, + }, + ModulesQuery: { + module, + }, + SpellCheck: { + spellCheck, + }, + ...mockUpdateLastModule(), +}; + describe('Spellcheck', () => { before(() => { cy.server(); - cy.mockGraphql({ - schema: schema, - operations: { - MeQuery: { - me: { - permissions: [], - onboardingVisited: true - } - }, - AssignmentsQuery: { - assignments - }, - ModulesQuery: { - module - }, - SpellCheck: { - spellCheck - }, - ...mockUpdateLastModule() - } + + cy.task('getSchema').then(schema => { + cy.mockGraphql({ + schema, + operations, + }); }); }); diff --git a/client/cypress/integration/frontend/survey.spec.js b/client/cypress/integration/frontend/survey.spec.js index ab0e0c3f..aa02a211 100644 --- a/client/cypress/integration/frontend/survey.spec.js +++ b/client/cypress/integration/frontend/survey.spec.js @@ -1,12 +1,13 @@ -const schema = require('../../fixtures/schema.json'); const module = require('../../fixtures/module.json'); describe('Survey', () => { beforeEach(() => { cy.server(); - cy.mockGraphql({ - schema: schema, + cy.task('getSchema').then(schema => { + cy.mockGraphql({ + schema, + }); }); cy.viewport('macbook-15');