diff --git a/client/config/dev.env.js b/client/config/dev.env.js index 287877fd..1b96c3b4 100644 --- a/client/config/dev.env.js +++ b/client/config/dev.env.js @@ -4,4 +4,5 @@ const prodEnv = require('./prod.env') module.exports = merge(prodEnv, { NODE_ENV: '"development"', + VUE_APP_ENABLE_SPELLCHECK: 'true' }); diff --git a/client/cypress.e2e.json b/client/cypress.e2e.json index 288f4ea2..8e6ace33 100644 --- a/client/cypress.e2e.json +++ b/client/cypress.e2e.json @@ -3,8 +3,9 @@ "videoUploadOnPasses": false, "reporter": "junit", "reporterOptions": { - "mochaFile": "cypress/test-reports/cypress-results-[hash].xml", + "mochaFile": "cypress/test-reports/e2e/cypress-results-[hash].xml", "toConsole": true }, + "integrationFolder": "cypress/integration/e2e", "$schema": "https://on.cypress.io/cypress.schema.json" } diff --git a/client/cypress/integration/e2e/email-verification.spec.js b/client/cypress/integration/e2e/email-verification.spec.js index 845c2193..257b940f 100644 --- a/client/cypress/integration/e2e/email-verification.spec.js +++ b/client/cypress/integration/e2e/email-verification.spec.js @@ -1,4 +1,4 @@ -const schema = require('../fixtures/schema_public.json'); +const schema = require('../../fixtures/schema_public.json'); describe('Email Verifcation', () => { beforeEach(() => { @@ -12,7 +12,7 @@ describe('Email Verifcation', () => { operations: { Registration: { registration: { - message: "success", + message: 'success', success: true } }, @@ -24,7 +24,6 @@ describe('Email Verifcation', () => { // user should be logged in at that stage. As the cookie cannot be set at the right time // we just check if the user gets redirected to the login page as we can't log her in cy.url().should('include', 'hello?redirect=%2F'); - }); it('displays error if key is incorrect', () => { @@ -35,7 +34,7 @@ describe('Email Verifcation', () => { operations: { Registration: { registration: { - message: "invalid_key", + message: 'invalid_key', success: false } }, @@ -45,7 +44,6 @@ describe('Email Verifcation', () => { cy.visit('/verify-email?confirmation=abcd1234&id=12'); cy.get('[data-cy="code-nok-msg"]').contains('Der angegebene Verifizierungscode ist ungültig oder abgelaufen.'); cy.get('[data-cy="code-ok-msg"]').should('not.exist'); - }); it('displays error if an error occured', () => { @@ -56,7 +54,7 @@ describe('Email Verifcation', () => { operations: { Registration: { registration: { - message: "unkown_error", + message: 'unkown_error', success: false } }, @@ -65,7 +63,6 @@ describe('Email Verifcation', () => { cy.visit('/verify-email?confirmation=abcd1234&id=12'); cy.get('[data-cy="code-nok-msg"]').contains('Ein Fehler ist aufgetreten. Bitte kontaktieren Sie den Administrator.'); - }); it('forwards to coupon page if user has no valid license', () => { @@ -76,7 +73,7 @@ describe('Email Verifcation', () => { operations: { Registration: { registration: { - message: "no_valid_license", + message: 'no_valid_license', success: false } }, @@ -88,7 +85,5 @@ describe('Email Verifcation', () => { // user should be logged in at that stage. As the cookie cannot be set at the right time // we just check if the user gets redirected to the coupon page as we can't log her in cy.url().should('include', 'hello?redirect=%2Flicense-activation'); - }); - }); diff --git a/client/cypress/integration/e2e/new-student.spec.js b/client/cypress/integration/e2e/new-student.spec.js index f56eb2fa..ba4a5473 100644 --- a/client/cypress/integration/e2e/new-student.spec.js +++ b/client/cypress/integration/e2e/new-student.spec.js @@ -1,3 +1,5 @@ +import {mockUpdateOnboardingProgress} from '../../support/helpers'; + const schema = require('../../fixtures/schema.json'); const me = require('../../fixtures/me.new-student.json'); @@ -9,7 +11,7 @@ describe('New student', () => { schema: schema, }); - cy.fakeLogin('hansli', 'test'); + cy.apolloLogin('hansli', 'test'); const __typename = 'SchoolClassNode'; const name = 'KF1A'; @@ -39,11 +41,7 @@ describe('New student', () => { } } }, - UpdateOnboardingProgress: { - updateOnboardingProgress: { - success: true - } - } + ...mockUpdateOnboardingProgress() } }); diff --git a/client/cypress/integration/frontend/current-module.spec.js b/client/cypress/integration/frontend/current-module.spec.js index d6125860..a73f9a77 100644 --- a/client/cypress/integration/frontend/current-module.spec.js +++ b/client/cypress/integration/frontend/current-module.spec.js @@ -1,4 +1,4 @@ -const schema = require('../../fixtures/schema.json'); +// const schema = require('../../fixtures/schema.json'); const assignments = require('../../fixtures/assignments.json'); const mePayload = require('../../fixtures/me.join-class.json'); const topics = require('../../fixtures/topics.json'); @@ -16,12 +16,66 @@ const topic = { ...Object.values(moduleTeasers).map(module => { return { node: module, - __typename: 'ModuleNodeEdge' + __typename: 'ModuleNodeEdge', }; - }) - ] - } - } + }), + ], + }, + }, +}; + +const me = { + ...mePayload.me, + lastModule: { + // 'id': 'TW9kdWxlTm9kZToxNw==', + 'slug': 'lohn-und-budget', + '__typename': 'ModuleNode', + }, + lastTopic: { + 'id': 'VG9waWNOb2RlOjU=', + 'slug': 'geld-und-kauf', + '__typename': 'TopicNode', + }, + recentModules: { + 'edges': [], + '__typename': 'ModuleNodeConnection', + }, +}; + +const operations = { + MeQuery: variables => { + return { + me: { + ...me, + '__typename': 'UserNode', + 'permissions': [], + }, + }; + }, + AssignmentsQuery: { + assignments, + }, + ModulesQuery: variables => { + return { + module: fullModules[variables.slug], + }; + }, + TopicsQuery: topics, + Topic: topic, + UpdateLastTopic: { + 'updateLastTopic': { + 'topic': topic.topic, + '__typename': 'UpdateLastTopicPayload', + }, + }, + UpdateLastModule: variables => { + return { + updateLastModule: { + lastModule: moduleTeasers[variables.input.id], + __typename: 'UpdateLastModulePayload', + }, + }; + }, }; Cypress.Commands.add('checkHome', (n, skipHome) => { @@ -43,62 +97,20 @@ describe('Current Module', () => { before(() => { cy.server(); - let me = { - ...mePayload.me, - lastModule: { - // 'id': 'TW9kdWxlTm9kZToxNw==', - 'slug': 'lohn-und-budget', - '__typename': 'ModuleNode' - }, - lastTopic: { - 'id': 'VG9waWNOb2RlOjU=', - 'slug': 'geld-und-kauf', - '__typename': 'TopicNode' - }, - recentModules: { - 'edges': [], - '__typename': 'ModuleNodeConnection' - }, - }; - cy.mockGraphql({ - schema: schema, - // endpoint: '/api/graphql' - operations: { - MeQuery: variables => { - return { - me: { - ...me, - '__typename': 'UserNode', - 'permissions': [] - } - }; - }, - AssignmentsQuery: { - assignments - }, - ModulesQuery: variables => { - return { - module: fullModules[variables.slug] - }; - }, - TopicsQuery: topics, - Topic: topic, - UpdateLastTopic: { - 'updateLastTopic': { - 'topic': topic.topic, - '__typename': 'UpdateLastTopicPayload' - } - }, - UpdateLastModule: variables => { - return { - updateLastModule: { - lastModule: moduleTeasers[variables.input.id], - __typename: 'UpdateLastModulePayload' - } - }; - } - } + cy.task('getSchema').then(schema => { + cy.mockGraphql({ + schema, + // endpoint: '/api/graphql' + // mocks, + operations, + }); }); + + // cy.mockGraphql({ + // schema: schema, + // // endpoint: '/api/graphql' + // operations, + // }); }); it('is set correctly', () => { diff --git a/client/cypress/integration/frontend/new-project.spec.js b/client/cypress/integration/frontend/new-project.spec.js index 681c99a6..f71a444e 100644 --- a/client/cypress/integration/frontend/new-project.spec.js +++ b/client/cypress/integration/frontend/new-project.spec.js @@ -1,49 +1,54 @@ -const schema = require('../../fixtures/schema.json'); +// const schema = require('../../fixtures/schema.json'); + +const 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', + }, + ], + }, + }, + MeQuery: {}, + AddProject: variables => ({ + addProject: { + project: Object.assign({}, variables.input.project), + errors: null, + __typename: 'AddProjectPayload', + }, + }), +}; 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.task('getSchema').then(schema => { + cy.mockGraphql({ + schema, + mocks: {}, + operations, + }); + }); cy.viewport('macbook-15'); cy.fakeLogin('rahel.cueni', 'test'); diff --git a/client/cypress/integration/frontend/onboarding.spec.js b/client/cypress/integration/frontend/onboarding.spec.js index f4ab3382..c96ebf82 100644 --- a/client/cypress/integration/frontend/onboarding.spec.js +++ b/client/cypress/integration/frontend/onboarding.spec.js @@ -1,3 +1,5 @@ +import {mockUpdateOnboardingProgress} from '../../support/helpers'; + const schema = require('../../fixtures/schema.json'); const me = require('../../fixtures/me.join-class.json'); @@ -11,7 +13,7 @@ describe('Onboarding', () => { }); it('shows the onboarding steps and finishes them', () => { - cy.apolloLogin('hansli', 'test'); + cy.fakeLogin('hansli', 'test'); cy.mockGraphqlOps({ operations: { @@ -20,7 +22,8 @@ describe('Onboarding', () => { ...me.me, onboardingVisited: false } - } + }, + ...mockUpdateOnboardingProgress() } }); @@ -34,7 +37,7 @@ describe('Onboarding', () => { }); it('shows the onboarding steps and skips them', () => { - cy.apolloLogin('hansli', 'test'); + cy.fakeLogin('hansli', 'test'); cy.mockGraphqlOps({ operations: { @@ -43,7 +46,8 @@ describe('Onboarding', () => { ...me.me, onboardingVisited: false } - } + }, + ...mockUpdateOnboardingProgress() } }); @@ -54,11 +58,12 @@ describe('Onboarding', () => { }); it('does not show the onboarding', () => { - cy.apolloLogin('hansli', 'test'); + cy.fakeLogin('hansli', 'test'); cy.mockGraphqlOps({ operations: { - MeQuery: me + MeQuery: me, + ...mockUpdateOnboardingProgress() } }); diff --git a/client/cypress/integration/frontend/project-entry.spec.js b/client/cypress/integration/frontend/project-entry.spec.js index 68ae7f31..8ac091f8 100644 --- a/client/cypress/integration/frontend/project-entry.spec.js +++ b/client/cypress/integration/frontend/project-entry.spec.js @@ -5,6 +5,7 @@ describe('Project Entry', () => { beforeEach(() => { cy.viewport('macbook-15'); cy.fakeLogin('rahel.cueni', 'test'); + cy.server(); cy.mockGraphql({ schema: schema, diff --git a/client/cypress/integration/frontend/spellcheck.spec.js b/client/cypress/integration/frontend/spellcheck.spec.js index ef5c5b04..c7c1276a 100644 --- a/client/cypress/integration/frontend/spellcheck.spec.js +++ b/client/cypress/integration/frontend/spellcheck.spec.js @@ -1,3 +1,5 @@ +import {mockUpdateLastModule} from '../../support/helpers'; + const schema = require('../../fixtures/schema.json'); const assignments = require('../../fixtures/assignments.json'); const module = require('../../fixtures/module.json'); @@ -23,7 +25,8 @@ describe('Spellcheck', () => { }, SpellCheck: { spellCheck - } + }, + ...mockUpdateLastModule() } }); }); diff --git a/client/cypress/integration/frontend/sync-module-visibility.spec.js b/client/cypress/integration/frontend/sync-module-visibility.spec.js index c62f503d..d69b65b0 100644 --- a/client/cypress/integration/frontend/sync-module-visibility.spec.js +++ b/client/cypress/integration/frontend/sync-module-visibility.spec.js @@ -54,8 +54,8 @@ describe('Apply module visibility', () => { cy.viewport('macbook-15'); // login as teacher - // cy.fakeLogin('nico.zickgraf', 'test'); - cy.apolloLogin('nico.zickgraf', 'test'); + cy.fakeLogin('nico.zickgraf', 'test'); + // cy.apolloLogin('nico.zickgraf', 'test'); // cy.wait('@gqlBetaLogin'); // go to module cy.visit('/module/lohn-und-budget'); diff --git a/client/cypress/support/helpers.js b/client/cypress/support/helpers.js index 2cae9751..bfb2b43a 100644 --- a/client/cypress/support/helpers.js +++ b/client/cypress/support/helpers.js @@ -351,3 +351,23 @@ export const getModules = () => { }, }; }; + +export const mockUpdateOnboardingProgress = () => { + return { + UpdateOnboardingProgress: { + updateOnboardingProgress: { + success: true, + }, + }, + }; +}; + +export const mockUpdateLastModule = () => { + return { + UpdateLastModule: { + updateLastModule: { + lastModule: {} + } + } + }; +}; diff --git a/client/package.json b/client/package.json index 18f2c62c..38d2298f 100644 --- a/client/package.json +++ b/client/package.json @@ -10,8 +10,10 @@ "lint": "eslint --ext .js,.vue src", "fix-lint": "eslint --ext .js,.vue --fix src", "build": "node build/build.js", - "open:cypress": "cypress open", - "test:cypress": "cypress run", + "open:cypress:e2e": "cypress open --config-file cypress.e2e.json", + "open:cypress:frontend": "cypress open --config-file cypress.frontend.json", + "test:cypress:e2e": "cypress run --config-file cypress.e2e.json", + "test:cypress:frontend": "cypress run --config-file cypress.frontend.json", "install:cypress": "cypress install", "test:unit": "jest" },