Update integration tests

This commit is contained in:
Christian Cueni 2019-10-07 15:38:35 +02:00
parent 13e3192776
commit a1954e00c5
12 changed files with 68 additions and 74 deletions

View File

@ -6,13 +6,17 @@ describe('Change Password Page', () => {
const validationErrorMsg = 'Das Passwort muss Grossbuchstaben, Zahlen und Sonderzeichen beinhalten'; const validationErrorMsg = 'Das Passwort muss Grossbuchstaben, Zahlen und Sonderzeichen beinhalten';
const validationOldWrongMsg = 'Die Eingabe ist falsch'; const validationOldWrongMsg = 'Die Eingabe ist falsch';
beforeEach(function () {
cy.logout();
cy.visit('/me/profile');
cy.login('rahel.cueni', 'test');
});
after(function () { after(function () {
cy.exec("python ../server/manage.py reset_testuser_password rahel.cueni"); cy.exec("python ../server/manage.py reset_testuser_password rahel.cueni");
}); });
it('shows an empty form', () => { it('shows an empty form', () => {
cy.login('rahel.cueni', 'test');
cy.visit('/me/profile');
cy.get('[data-cy=password-change-success]').should('not.exist'); cy.get('[data-cy=password-change-success]').should('not.exist');
cy.get('[data-cy=old-password]').should('have.value', ''); cy.get('[data-cy=old-password]').should('have.value', '');
@ -20,73 +24,46 @@ describe('Change Password Page', () => {
}); });
it('shows errors if old password is not entered', () => { it('shows errors if old password is not entered', () => {
cy.login('rahel.cueni', 'test');
cy.visit('/me/profile');
cy.changePassword('', validNewPassword); cy.changePassword('', validNewPassword);
cy.get('[data-cy=old-password-local-errors]').should('contain', 'Dein aktuelles Passwort fehlt') cy.get('[data-cy=old-password-local-errors]').should('contain', 'Dein aktuelles Passwort fehlt')
}); });
it('shows errors if new password is not entered', () => { it('shows errors if new password is not entered', () => {
cy.login('rahel.cueni', 'test');
cy.visit('/me/profile');
cy.changePassword(validOldPassword, ''); cy.changePassword(validOldPassword, '');
cy.get('[data-cy=new-password-local-errors]').should('contain', 'Dein neues Passwort fehlt') cy.get('[data-cy=new-password-local-errors]').should('contain', 'Dein neues Passwort fehlt')
}); });
it('shows errors if new password is too short', () => { it('shows errors if new password is too short', () => {
cy.login('rahel.cueni', 'test');
cy.visit('/me/profile');
cy.changePassword(validOldPassword, 'Abc1!'); cy.changePassword(validOldPassword, 'Abc1!');
cy.get('[data-cy=new-password-local-errors]').should('contain', validationTooShort) cy.get('[data-cy=new-password-local-errors]').should('contain', validationTooShort)
}); });
it('shows errors if new password has no uppercase letter', () => { it('shows errors if new password has no uppercase letter', () => {
cy.login('rahel.cueni', 'test');
cy.visit('/me/profile');
cy.changePassword(validOldPassword, 'aabdddedddbc1!'); cy.changePassword(validOldPassword, 'aabdddedddbc1!');
cy.get('[data-cy=new-password-local-errors]').should('contain', validationErrorMsg) cy.get('[data-cy=new-password-local-errors]').should('contain', validationErrorMsg)
}); });
it('shows errors if new password has no lowercase letter', () => { it('shows errors if new password has no lowercase letter', () => {
cy.login('rahel.cueni', 'test');
cy.visit('/me/profile');
cy.changePassword(validOldPassword, 'ABCDDD334551!'); cy.changePassword(validOldPassword, 'ABCDDD334551!');
cy.get('[data-cy=new-password-local-errors]').should('contain', validationErrorMsg) cy.get('[data-cy=new-password-local-errors]').should('contain', validationErrorMsg)
}); });
it('shows errors if new password has no digit', () => { it('shows errors if new password has no digit', () => {
cy.login('rahel.cueni', 'test');
cy.visit('/me/profile');
cy.changePassword(validOldPassword, 'AbcdEEDE!'); cy.changePassword(validOldPassword, 'AbcdEEDE!');
cy.get('[data-cy=new-password-local-errors]').should('contain', validationErrorMsg) cy.get('[data-cy=new-password-local-errors]').should('contain', validationErrorMsg)
}); });
it('shows errors if new password has no special character', () => { it('shows errors if new password has no special character', () => {
cy.login('rahel.cueni', 'test');
cy.visit('/me/profile');
cy.changePassword(validOldPassword, 'AbcdEEDE09877'); cy.changePassword(validOldPassword, 'AbcdEEDE09877');
cy.get('[data-cy=new-password-local-errors]').should('contain', validationErrorMsg) cy.get('[data-cy=new-password-local-errors]').should('contain', validationErrorMsg)
}); });
it('shows errors if old password does not match', () => { it('shows errors if old password does not match', () => {
cy.login('rahel.cueni', 'test');
cy.visit('/me/profile');
cy.changePassword('test12345', validNewPassword); cy.changePassword('test12345', validNewPassword);
cy.get('[data-cy=old-password-remote-errors]').should('contain', validationOldWrongMsg) cy.get('[data-cy=old-password-remote-errors]').should('contain', validationOldWrongMsg)
}); });
it('shows success if change was successful', () => { it('shows success if change was successful', () => {
cy.login('rahel.cueni', 'test');
cy.visit('/me/profile');
cy.changePassword(validOldPassword, validNewPassword); cy.changePassword(validOldPassword, validNewPassword);
cy.get('[data-cy=password-change-success]').should('contain', 'Dein Password wurde erfolgreich geändert.'); cy.get('[data-cy=password-change-success]').should('contain', 'Dein Password wurde erfolgreich geändert.');
cy.get('[data-cy=old-password]').should('have.value', ''); cy.get('[data-cy=old-password]').should('have.value', '');

View File

@ -4,8 +4,8 @@ describe('Current Module', () => {
cy.startGraphQLCapture(); cy.startGraphQLCapture();
cy.viewport('macbook-15'); cy.viewport('macbook-15');
cy.login('nico.zickgraf', 'test');
cy.visit('/module/lohn-und-budget'); cy.visit('/module/lohn-und-budget');
cy.login('nico.zickgraf', 'test');
cy.get('[data-cy=module-title]').should('contain', 'Lohn und Budget') cy.get('[data-cy=module-title]').should('contain', 'Lohn und Budget')

View File

@ -1,7 +1,7 @@
describe('The Logged In Home Page', () => { describe('The Logged In Home Page', () => {
it('successfully loads', () => { it('successfully loads', () => {
cy.login('test', 'test');
cy.visit('/'); cy.visit('/');
cy.login('test', 'test');
cy.get('.block-title__title').should('contain', 'Inhalte') cy.get('.block-title__title').should('contain', 'Inhalte')
}) })

View File

@ -1,13 +0,0 @@
describe('The Login CSRF Token', () => {
it('403 status without token', () => {
cy.loginByCsrf('some-token')
.its('status')
.should('eq', 403)
});
it('gets token from response body', () => {
cy.login('test', 'test')
})
});

View File

@ -1,15 +1,47 @@
describe('The Login Page', () => { describe('The Login Page', () => {
it('sets auth cookie when logging in via form submission', () => { it('login and redirect to main page', () => {
const username = 'test'; const username = 'test';
const password = 'test'; const password = 'test';
cy.visit('/'); cy.visit('/');
cy.login(username, password, true);
cy.get('body').contains('Neues Wissen erwerben');
});
cy.get('#id_username').type(username); it('user sees error message if username is omitted', () => {
cy.get('#id_password').type(`${password}{enter}`); const username = '';
const password = 'test';
cy.getCookie('sessionid').should('exist'); cy.visit('/');
cy.get('.start-page__header').should('exist') cy.login(username, password);
cy.get('[data-cy=email-local-errors]').contains('ist ein Pflichtfeld');
});
it('user sees error message if password is omitted', () => {
const username = 'test';
const password = '';
cy.visit('/');
cy.login(username, password);
cy.get('[data-cy=password-local-errors]').contains('ist ein Pflichtfeld');
});
it('user sees error message if credentials are invalid', () => {
const username = 'test';
const password = '12345';
cy.visit('/');
cy.login(username, password);
cy.get('[data-cy=login-error]').contains('Die E-Mail oder das Passwort ist falsch. Bitte versuchen Sie nochmals.');
});
it('redirect after login', () => {
const username = 'test';
const password = 'test';
cy.visit('/book/topic/berufliche-grundbildung');
cy.login(username, password);
cy.get('body').contains('Berufliche Grundbildung');
}); });
// it('logs in programmatically without using the UI', () => { // it('logs in programmatically without using the UI', () => {
// cy.visit('/accounts/login/'); // have to get a csrf token by getting the base page first // cy.visit('/accounts/login/'); // have to get a csrf token by getting the base page first

View File

@ -1,9 +1,9 @@
describe('New project', () => { describe('New project', () => {
it('creates a new project and displays it', () => { it('creates a new project and displays it', () => {
cy.viewport('macbook-15'); cy.viewport('macbook-15');
cy.visit('/portfolio');
cy.login('rahel.cueni', 'test'); cy.login('rahel.cueni', 'test');
cy.visit('/portfolio');
cy.get('[data-cy=add-project-button]').click(); cy.get('[data-cy=add-project-button]').click();
cy.get('[data-cy=page-form-input-titel]').type('Some random title'); cy.get('[data-cy=page-form-input-titel]').type('Some random title');
cy.get('[data-cy=page-form-input-beschreibung]').type('This description rocks'); cy.get('[data-cy=page-form-input-beschreibung]').type('This description rocks');

View File

@ -4,7 +4,7 @@ describe('Project Entry', () => {
cy.viewport('macbook-15'); cy.viewport('macbook-15');
cy.startGraphQLCapture(); cy.startGraphQLCapture();
cy.login('rahel.cueni', 'test'); cy.login('rahel.cueni', 'test', true);
}); });
it('should create a new project entry', () => { it('should create a new project entry', () => {

View File

@ -1,9 +1,9 @@
describe('The Room Page', () => { describe('The Room Page', () => {
it('displays new room entry with author name', () => { it('displays new room entry with author name', () => {
cy.viewport('macbook-15'); cy.viewport('macbook-15');
cy.visit('/room/ein-historisches-festival');
cy.login('rahel.cueni', 'test'); cy.login('rahel.cueni', 'test');
cy.visit('/room/ein-historisches-festival');
cy.get('[data-cy=add-room-entry-button]').click(); cy.get('[data-cy=add-room-entry-button]').click();
cy.get('.add-content-element:first-of-type').click(); cy.get('.add-content-element:first-of-type').click();
cy.get('[data-cy=choose-text-widget]').click(); cy.get('[data-cy=choose-text-widget]').click();

View File

@ -1,15 +1,16 @@
describe('The Rooms Page', () => { describe('The Rooms Page', () => {
it('goes to the rooms page', () => { it('goes to the rooms page', () => {
cy.visit('/rooms');
cy.login('nico.zickgraf', 'test'); cy.login('nico.zickgraf', 'test');
cy.visit('/rooms');
cy.get('[data-cy=add-room]').should('exist'); cy.get('[data-cy=add-room]').should('exist');
}); });
it('add room should not exist for student', () => { it('add room should not exist for student', () => {
cy.visit('/rooms');
cy.login('rahel.cueni', 'test'); cy.login('rahel.cueni', 'test');
cy.visit('/rooms');
cy.get('[data-cy=add-room]').should('not.exist'); cy.get('[data-cy=add-room]').should('not.exist');
}); });

View File

@ -21,8 +21,8 @@ describe('Solutions', () => {
// cy.logout(); // cy.logout();
cy.viewport('macbook-15'); cy.viewport('macbook-15');
cy.login('rahel.cueni', 'test');
cy.visit('/module/lohn-und-budget'); cy.visit('/module/lohn-und-budget');
cy.login('rahel.cueni', 'test');
cy.get('[data-cy=toggle-enable-solutions]') cy.get('[data-cy=toggle-enable-solutions]')
.should('not.exist'); .should('not.exist');
cy.get('[data-cy=solution]').should('not.exist'); cy.get('[data-cy=solution]').should('not.exist');
@ -40,8 +40,8 @@ describe('Solutions', () => {
cy.logout(); cy.logout();
cy.login('rahel.cueni', 'test');
cy.visit('/module/lohn-und-budget'); cy.visit('/module/lohn-und-budget');
cy.login('rahel.cueni', 'test');
// cy.get('[data-cy=solution]').should('exist'); // cy.get('[data-cy=solution]').should('exist');
cy.get('[data-cy=solution]').first() cy.get('[data-cy=solution]').first()
.should('contain', 'anzeigen') .should('contain', 'anzeigen')

View File

@ -24,22 +24,19 @@
// -- This is will overwrite an existing command -- // -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
Cypress.Commands.add("login", (username, password) => { Cypress.Commands.add("login", (username, password, visitLogin=false) => {
cy.request('/') if (visitLogin) {
.its('body') cy.visit('/login');
.then(body => { }
console.log(body);
const $html = Cypress.$(body);
const csrf = $html.find('input[name=csrfmiddlewaretoken]').val(); if (username != '') {
console.log(csrf); cy.get('[data-cy=email-input]').type(username);
cy.loginByCsrf(username, password, csrf) }
.then(resp => {
expect(resp.status).to.eq(200);
expect(resp.body).to.include('skillbox');
});
})
if (password != '') {
cy.get('[data-cy=password-input]').type(password);
}
cy.get('[data-cy=login-button]').click();
}); });
Cypress.Commands.add("logout", () => { Cypress.Commands.add("logout", () => {

View File

@ -13,7 +13,7 @@
:class="{ 'sbform-input__input--error': errors.has('email') }" :class="{ 'sbform-input__input--error': errors.has('email') }"
class="change-form__email skillbox-input sbform-input__input" class="change-form__email skillbox-input sbform-input__input"
autocomplete="off" autocomplete="off"
data-cy="email" data-cy="email-input"
/> />
<small <small
v-if="errors.has('email') && submitted" v-if="errors.has('email') && submitted"
@ -38,7 +38,7 @@
:class="{ 'sbform-input__input--error': errors.has('password') }" :class="{ 'sbform-input__input--error': errors.has('password') }"
class="change-form__new skillbox-input sbform-input__input" class="change-form__new skillbox-input sbform-input__input"
autocomplete="off" autocomplete="off"
data-cy="password" data-cy="password-input"
/> />
<small <small
v-if="errors.has('password') && submitted" v-if="errors.has('password') && submitted"
@ -53,9 +53,9 @@
>{{ error }}</small> >{{ error }}</small>
</div> </div>
<div class="sbform-input"> <div class="sbform-input">
<small class="sbform-input__error" v-if="loginError">{{loginError}}</small> <small class="sbform-input__error" data-cy="login-error" v-if="loginError">{{loginError}}</small>
</div> </div>
<button class="button button--primary change-form__submit" data-cy="change-password-button">Anmelden</button> <button class="button button--primary change-form__submit" data-cy="login-button">Anmelden</button>
</form> </form>
</div> </div>
</template> </template>