Fix broken cypress tests

This commit is contained in:
Ramon Wenger 2020-06-29 17:20:50 +02:00
parent 841b75e0db
commit ae3f990898
4 changed files with 16 additions and 24 deletions

View File

@ -4,7 +4,7 @@ describe('The Login Page', () => {
const password = 'test'; const password = 'test';
cy.visit('/beta-login'); cy.visit('/beta-login');
cy.login(username, password, true); cy.login(username, password, true);
cy.get('body').contains('Neues Wissen erwerben'); cy.assertStartPage();
}); });
it('user sees error message if username is omitted', () => { it('user sees error message if username is omitted', () => {
@ -35,7 +35,6 @@ describe('The Login Page', () => {
}); });
it('logs out then logs in again', () => { it('logs out then logs in again', () => {
const user = 'rahel.cueni'; const user = 'rahel.cueni';
const pw = 'test' const pw = 'test'

View File

@ -1,12 +1,12 @@
describe('Bookmarks', () => { describe('Bookmarks', () => {
beforeEach(() => { beforeEach(() => {
// todo: mock all the graphql queries and mutations // todo: mock all the graphql queries and mutations
cy.exec("python ../server/manage.py prepare_bookmarks_for_cypress"); cy.exec('python ../server/manage.py prepare_bookmarks_for_cypress');
cy.viewport('macbook-15'); cy.viewport('macbook-15');
cy.startGraphQLCapture(); cy.startGraphQLCapture();
cy.login('rahel.cueni', 'test', true); cy.login('rahel.cueni', 'test', true);
cy.get('body').contains('Neues Wissen erwerben'); cy.assertStartPage();
}); });
it('should bookmark content block', () => { it('should bookmark content block', () => {
@ -35,5 +35,4 @@ describe('Bookmarks', () => {
cy.get('[data-cy=modal-save-button]').click(); cy.get('[data-cy=modal-save-button]').click();
}); });
}); });

View File

@ -1,4 +1,4 @@
import { GraphQLError } from "graphql"; import { GraphQLError } from 'graphql';
const schema = require('../fixtures/schema.json'); const schema = require('../fixtures/schema.json');
@ -20,23 +20,21 @@ describe('Email Verifcation', () => {
} }
}); });
cy.login('rahel.cueni', 'test', true) cy.login('rahel.cueni', 'test', true)
cy.get('[data-cy="rooms-link"]').contains('Alle Räume anzeigen'); cy.assertStartPage();
cy.visit('/license-activation'); cy.visit('/license-activation');
cy.redeemCoupon('12345asfd'); cy.redeemCoupon('12345asfd');
cy.get('body').contains('Neues Wissen erwerben'); cy.assertStartPage();
}); });
it('displays error if input is missing', () => { it('displays error if input is missing', () => {
cy.viewport('macbook-15'); cy.viewport('macbook-15');
cy.login('rahel.cueni', 'test', true) cy.login('rahel.cueni', 'test', true)
cy.get('[data-cy="rooms-link"]').contains('Alle Räume anzeigen'); cy.assertStartPage();
cy.visit('/license-activation'); cy.visit('/license-activation');
cy.redeemCoupon(''); cy.redeemCoupon('');
cy.get('[data-cy="coupon-local-errors"]').contains('Coupon ist ein Pflichtfeld.'); cy.get('[data-cy="coupon-local-errors"]').contains('Coupon ist ein Pflichtfeld.');
}); });
it('displays error if coupon input is wrong', () => { it('displays error if coupon input is wrong', () => {
@ -48,12 +46,11 @@ describe('Email Verifcation', () => {
} }
}); });
cy.login('rahel.cueni', 'test', true) cy.login('rahel.cueni', 'test', true)
cy.get('[data-cy="rooms-link"]').contains('Alle Räume anzeigen'); cy.assertStartPage();
cy.visit('/license-activation'); cy.visit('/license-activation');
cy.redeemCoupon('12345asfd'); cy.redeemCoupon('12345asfd');
cy.get('[data-cy="coupon-remote-errors"]').contains('Der angegebene Coupon-Code ist ungültig.'); cy.get('[data-cy="coupon-remote-errors"]').contains('Der angegebene Coupon-Code ist ungültig.');
}); });
it('displays error if an error occures', () => { it('displays error if an error occures', () => {
@ -61,16 +58,14 @@ describe('Email Verifcation', () => {
cy.mockGraphql({ cy.mockGraphql({
schema: schema, schema: schema,
operations: { operations: {
Coupon: new GraphQLError("unknown_error") Coupon: new GraphQLError('unknown_error')
} }
}); });
cy.login('rahel.cueni', 'test', true) cy.login('rahel.cueni', 'test', true)
cy.get('[data-cy="rooms-link"]').contains('Alle Räume anzeigen'); cy.assertStartPage();
cy.visit('/license-activation'); cy.visit('/license-activation');
cy.redeemCoupon('12345asfd'); cy.redeemCoupon('12345asfd');
cy.get('[data-cy="coupon-remote-errors"]').contains('Es ist ein Fehler aufgetreten. Bitte versuchen Sie es nochmals oder kontaktieren Sie den Administrator.'); cy.get('[data-cy="coupon-remote-errors"]').contains('Es ist ein Fehler aufgetreten. Bitte versuchen Sie es nochmals oder kontaktieren Sie den Administrator.');
}); });
}); });

View File

@ -29,7 +29,6 @@
// import 'cypress-graphql-mock'; // import 'cypress-graphql-mock';
import '@iam4x/cypress-graphql-mock'; import '@iam4x/cypress-graphql-mock';
Cypress.Commands.add('apolloLogin', (username, password) => { Cypress.Commands.add('apolloLogin', (username, password) => {
const payload = { const payload = {
'operationName': 'BetaLogin', 'operationName': 'BetaLogin',
@ -47,12 +46,10 @@ Cypress.Commands.add('apolloLogin', (username, password) => {
url: '/api/graphql-public/', url: '/api/graphql-public/',
body: payload body: payload
}); });
}); });
// todo: replace with apollo call // todo: replace with apollo call
Cypress.Commands.add("login", (username, password, visitLogin = false) => { Cypress.Commands.add('login', (username, password, visitLogin = false) => {
if (visitLogin) { if (visitLogin) {
cy.visit('/beta-login'); cy.visit('/beta-login');
} }
@ -67,7 +64,7 @@ Cypress.Commands.add("login", (username, password, visitLogin = false) => {
cy.get('[data-cy=login-button]').click(); cy.get('[data-cy=login-button]').click();
}); });
Cypress.Commands.add("logout", () => { Cypress.Commands.add('logout', () => {
cy.get('[data-cy=user-icon]').click(); cy.get('[data-cy=user-icon]').click();
cy.get('[data-cy=logout]').click(); cy.get('[data-cy=logout]').click();
}); });
@ -122,7 +119,6 @@ Cypress.Commands.add('enterPassword', (password) => {
}); });
Cypress.Commands.add('register', (prefix, firstname, lastname, street, city, postcode, password, passwordConfirmation, acceptTerms) => { Cypress.Commands.add('register', (prefix, firstname, lastname, street, city, postcode, password, passwordConfirmation, acceptTerms) => {
let selection = prefix === 1 ? 'Herr' : 'Frau'; let selection = prefix === 1 ? 'Herr' : 'Frau';
cy.get('[data-cy="prefix-selection"]').select(selection); cy.get('[data-cy="prefix-selection"]').select(selection);
@ -153,7 +149,7 @@ Cypress.Commands.add('register', (prefix, firstname, lastname, street, city, pos
if (acceptTerms) { if (acceptTerms) {
cy.get('[data-cy="acceptedTerms-input"] > input').first().check({force: true}).then(() => { cy.get('[data-cy="acceptedTerms-input"] > input').first().check({force: true}).then(() => {
cy.get('[data-cy="acceptedTerms-input"] > input:checkbox').should('be.checked'); cy.get('[data-cy="acceptedTerms-input"] > input:checkbox').should('be.checked');
});; }); ;
} }
cy.get('[data-cy="passwordConfirmation-input"]').type(passwordConfirmation); cy.get('[data-cy="passwordConfirmation-input"]').type(passwordConfirmation);
@ -167,3 +163,6 @@ Cypress.Commands.add('redeemCoupon', coupon => {
cy.get('[data-cy="coupon-button"]').click(); cy.get('[data-cy="coupon-button"]').click();
}) })
Cypress.Commands.add('assertStartPage', () => {
cy.get('[data-cy=start-modules-list]').should('exist');
});