Split up frontend only and e2e tests

This commit is contained in:
Ramon Wenger 2021-03-16 15:12:47 +01:00
parent 59f98023d6
commit 337cd8f5ec
12 changed files with 173 additions and 130 deletions

View File

@ -4,4 +4,5 @@ const prodEnv = require('./prod.env')
module.exports = merge(prodEnv, { module.exports = merge(prodEnv, {
NODE_ENV: '"development"', NODE_ENV: '"development"',
VUE_APP_ENABLE_SPELLCHECK: 'true'
}); });

View File

@ -3,8 +3,9 @@
"videoUploadOnPasses": false, "videoUploadOnPasses": false,
"reporter": "junit", "reporter": "junit",
"reporterOptions": { "reporterOptions": {
"mochaFile": "cypress/test-reports/cypress-results-[hash].xml", "mochaFile": "cypress/test-reports/e2e/cypress-results-[hash].xml",
"toConsole": true "toConsole": true
}, },
"integrationFolder": "cypress/integration/e2e",
"$schema": "https://on.cypress.io/cypress.schema.json" "$schema": "https://on.cypress.io/cypress.schema.json"
} }

View File

@ -1,4 +1,4 @@
const schema = require('../fixtures/schema_public.json'); const schema = require('../../fixtures/schema_public.json');
describe('Email Verifcation', () => { describe('Email Verifcation', () => {
beforeEach(() => { beforeEach(() => {
@ -12,7 +12,7 @@ describe('Email Verifcation', () => {
operations: { operations: {
Registration: { Registration: {
registration: { registration: {
message: "success", message: 'success',
success: true 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 // 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 // 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'); cy.url().should('include', 'hello?redirect=%2F');
}); });
it('displays error if key is incorrect', () => { it('displays error if key is incorrect', () => {
@ -35,7 +34,7 @@ describe('Email Verifcation', () => {
operations: { operations: {
Registration: { Registration: {
registration: { registration: {
message: "invalid_key", message: 'invalid_key',
success: false success: false
} }
}, },
@ -45,7 +44,6 @@ describe('Email Verifcation', () => {
cy.visit('/verify-email?confirmation=abcd1234&id=12'); 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-nok-msg"]').contains('Der angegebene Verifizierungscode ist ungültig oder abgelaufen.');
cy.get('[data-cy="code-ok-msg"]').should('not.exist'); cy.get('[data-cy="code-ok-msg"]').should('not.exist');
}); });
it('displays error if an error occured', () => { it('displays error if an error occured', () => {
@ -56,7 +54,7 @@ describe('Email Verifcation', () => {
operations: { operations: {
Registration: { Registration: {
registration: { registration: {
message: "unkown_error", message: 'unkown_error',
success: false success: false
} }
}, },
@ -65,7 +63,6 @@ describe('Email Verifcation', () => {
cy.visit('/verify-email?confirmation=abcd1234&id=12'); 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.'); 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', () => { it('forwards to coupon page if user has no valid license', () => {
@ -76,7 +73,7 @@ describe('Email Verifcation', () => {
operations: { operations: {
Registration: { Registration: {
registration: { registration: {
message: "no_valid_license", message: 'no_valid_license',
success: false 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 // 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 // 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'); cy.url().should('include', 'hello?redirect=%2Flicense-activation');
}); });
}); });

View File

@ -1,3 +1,5 @@
import {mockUpdateOnboardingProgress} from '../../support/helpers';
const schema = require('../../fixtures/schema.json'); const schema = require('../../fixtures/schema.json');
const me = require('../../fixtures/me.new-student.json'); const me = require('../../fixtures/me.new-student.json');
@ -9,7 +11,7 @@ describe('New student', () => {
schema: schema, schema: schema,
}); });
cy.fakeLogin('hansli', 'test'); cy.apolloLogin('hansli', 'test');
const __typename = 'SchoolClassNode'; const __typename = 'SchoolClassNode';
const name = 'KF1A'; const name = 'KF1A';
@ -39,11 +41,7 @@ describe('New student', () => {
} }
} }
}, },
UpdateOnboardingProgress: { ...mockUpdateOnboardingProgress()
updateOnboardingProgress: {
success: true
}
}
} }
}); });

View File

@ -1,4 +1,4 @@
const schema = require('../../fixtures/schema.json'); // const schema = require('../../fixtures/schema.json');
const assignments = require('../../fixtures/assignments.json'); const assignments = require('../../fixtures/assignments.json');
const mePayload = require('../../fixtures/me.join-class.json'); const mePayload = require('../../fixtures/me.join-class.json');
const topics = require('../../fixtures/topics.json'); const topics = require('../../fixtures/topics.json');
@ -16,12 +16,66 @@ const topic = {
...Object.values(moduleTeasers).map(module => { ...Object.values(moduleTeasers).map(module => {
return { return {
node: module, 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) => { Cypress.Commands.add('checkHome', (n, skipHome) => {
@ -43,62 +97,20 @@ describe('Current Module', () => {
before(() => { before(() => {
cy.server(); cy.server();
let me = { cy.task('getSchema').then(schema => {
...mePayload.me, cy.mockGraphql({
lastModule: { schema,
// 'id': 'TW9kdWxlTm9kZToxNw==', // endpoint: '/api/graphql'
'slug': 'lohn-und-budget', // mocks,
'__typename': 'ModuleNode' operations,
}, });
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.mockGraphql({
// schema: schema,
// // endpoint: '/api/graphql'
// operations,
// });
}); });
it('is set correctly', () => { it('is set correctly', () => {

View File

@ -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', () => { describe('New project', () => {
it('creates a new project and displays it', () => { it('creates a new project and displays it', () => {
cy.server(); cy.server();
cy.mockGraphql({ cy.task('getSchema').then(schema => {
schema: schema, cy.mockGraphql({
operations: { schema,
ProjectsQuery: { mocks: {},
projects: { operations,
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.viewport('macbook-15');
cy.fakeLogin('rahel.cueni', 'test'); cy.fakeLogin('rahel.cueni', 'test');

View File

@ -1,3 +1,5 @@
import {mockUpdateOnboardingProgress} from '../../support/helpers';
const schema = require('../../fixtures/schema.json'); const schema = require('../../fixtures/schema.json');
const me = require('../../fixtures/me.join-class.json'); const me = require('../../fixtures/me.join-class.json');
@ -11,7 +13,7 @@ describe('Onboarding', () => {
}); });
it('shows the onboarding steps and finishes them', () => { it('shows the onboarding steps and finishes them', () => {
cy.apolloLogin('hansli', 'test'); cy.fakeLogin('hansli', 'test');
cy.mockGraphqlOps({ cy.mockGraphqlOps({
operations: { operations: {
@ -20,7 +22,8 @@ describe('Onboarding', () => {
...me.me, ...me.me,
onboardingVisited: false onboardingVisited: false
} }
} },
...mockUpdateOnboardingProgress()
} }
}); });
@ -34,7 +37,7 @@ describe('Onboarding', () => {
}); });
it('shows the onboarding steps and skips them', () => { it('shows the onboarding steps and skips them', () => {
cy.apolloLogin('hansli', 'test'); cy.fakeLogin('hansli', 'test');
cy.mockGraphqlOps({ cy.mockGraphqlOps({
operations: { operations: {
@ -43,7 +46,8 @@ describe('Onboarding', () => {
...me.me, ...me.me,
onboardingVisited: false onboardingVisited: false
} }
} },
...mockUpdateOnboardingProgress()
} }
}); });
@ -54,11 +58,12 @@ describe('Onboarding', () => {
}); });
it('does not show the onboarding', () => { it('does not show the onboarding', () => {
cy.apolloLogin('hansli', 'test'); cy.fakeLogin('hansli', 'test');
cy.mockGraphqlOps({ cy.mockGraphqlOps({
operations: { operations: {
MeQuery: me MeQuery: me,
...mockUpdateOnboardingProgress()
} }
}); });

View File

@ -5,6 +5,7 @@ describe('Project Entry', () => {
beforeEach(() => { beforeEach(() => {
cy.viewport('macbook-15'); cy.viewport('macbook-15');
cy.fakeLogin('rahel.cueni', 'test'); cy.fakeLogin('rahel.cueni', 'test');
cy.server();
cy.mockGraphql({ cy.mockGraphql({
schema: schema, schema: schema,

View File

@ -1,3 +1,5 @@
import {mockUpdateLastModule} from '../../support/helpers';
const schema = require('../../fixtures/schema.json'); const schema = require('../../fixtures/schema.json');
const assignments = require('../../fixtures/assignments.json'); const assignments = require('../../fixtures/assignments.json');
const module = require('../../fixtures/module.json'); const module = require('../../fixtures/module.json');
@ -23,7 +25,8 @@ describe('Spellcheck', () => {
}, },
SpellCheck: { SpellCheck: {
spellCheck spellCheck
} },
...mockUpdateLastModule()
} }
}); });
}); });

View File

@ -54,8 +54,8 @@ describe('Apply module visibility', () => {
cy.viewport('macbook-15'); cy.viewport('macbook-15');
// login as teacher // login as teacher
// cy.fakeLogin('nico.zickgraf', 'test'); cy.fakeLogin('nico.zickgraf', 'test');
cy.apolloLogin('nico.zickgraf', 'test'); // cy.apolloLogin('nico.zickgraf', 'test');
// cy.wait('@gqlBetaLogin'); // cy.wait('@gqlBetaLogin');
// go to module // go to module
cy.visit('/module/lohn-und-budget'); cy.visit('/module/lohn-und-budget');

View File

@ -351,3 +351,23 @@ export const getModules = () => {
}, },
}; };
}; };
export const mockUpdateOnboardingProgress = () => {
return {
UpdateOnboardingProgress: {
updateOnboardingProgress: {
success: true,
},
},
};
};
export const mockUpdateLastModule = () => {
return {
UpdateLastModule: {
updateLastModule: {
lastModule: {}
}
}
};
};

View File

@ -10,8 +10,10 @@
"lint": "eslint --ext .js,.vue src", "lint": "eslint --ext .js,.vue src",
"fix-lint": "eslint --ext .js,.vue --fix src", "fix-lint": "eslint --ext .js,.vue --fix src",
"build": "node build/build.js", "build": "node build/build.js",
"open:cypress": "cypress open", "open:cypress:e2e": "cypress open --config-file cypress.e2e.json",
"test:cypress": "cypress run", "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", "install:cypress": "cypress install",
"test:unit": "jest" "test:unit": "jest"
}, },