diff --git a/client/cypress/integration/change-password-spec.js b/client/cypress/integration/change-password-spec.js index 7da2cdb2..708cb27d 100644 --- a/client/cypress/integration/change-password-spec.js +++ b/client/cypress/integration/change-password-spec.js @@ -6,13 +6,17 @@ describe('Change Password Page', () => { const validationErrorMsg = 'Das Passwort muss Grossbuchstaben, Zahlen und Sonderzeichen beinhalten'; const validationOldWrongMsg = 'Die Eingabe ist falsch'; + beforeEach(function () { + cy.clearCookies(); + cy.visit('/me/profile'); + cy.login('rahel.cueni', 'test'); + }); + after(function () { cy.exec("python ../server/manage.py reset_testuser_password rahel.cueni"); }); 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=old-password]').should('have.value', ''); @@ -20,73 +24,46 @@ describe('Change Password Page', () => { }); it('shows errors if old password is not entered', () => { - cy.login('rahel.cueni', 'test'); - cy.visit('/me/profile'); - cy.changePassword('', validNewPassword); cy.get('[data-cy=old-password-local-errors]').should('contain', 'Dein aktuelles Passwort fehlt') }); it('shows errors if new password is not entered', () => { - cy.login('rahel.cueni', 'test'); - cy.visit('/me/profile'); - cy.changePassword(validOldPassword, ''); cy.get('[data-cy=new-password-local-errors]').should('contain', 'Dein neues Passwort fehlt') }); it('shows errors if new password is too short', () => { - cy.login('rahel.cueni', 'test'); - cy.visit('/me/profile'); - cy.changePassword(validOldPassword, 'Abc1!'); cy.get('[data-cy=new-password-local-errors]').should('contain', validationTooShort) }); it('shows errors if new password has no uppercase letter', () => { - cy.login('rahel.cueni', 'test'); - cy.visit('/me/profile'); - cy.changePassword(validOldPassword, 'aabdddedddbc1!'); cy.get('[data-cy=new-password-local-errors]').should('contain', validationErrorMsg) }); it('shows errors if new password has no lowercase letter', () => { - cy.login('rahel.cueni', 'test'); - cy.visit('/me/profile'); - cy.changePassword(validOldPassword, 'ABCDDD334551!'); cy.get('[data-cy=new-password-local-errors]').should('contain', validationErrorMsg) }); it('shows errors if new password has no digit', () => { - cy.login('rahel.cueni', 'test'); - cy.visit('/me/profile'); - cy.changePassword(validOldPassword, 'AbcdEEDE!'); cy.get('[data-cy=new-password-local-errors]').should('contain', validationErrorMsg) }); it('shows errors if new password has no special character', () => { - cy.login('rahel.cueni', 'test'); - cy.visit('/me/profile'); - cy.changePassword(validOldPassword, 'AbcdEEDE09877'); cy.get('[data-cy=new-password-local-errors]').should('contain', validationErrorMsg) }); it('shows errors if old password does not match', () => { - cy.login('rahel.cueni', 'test'); - cy.visit('/me/profile'); - cy.changePassword('test12345', validNewPassword); cy.get('[data-cy=old-password-remote-errors]').should('contain', validationOldWrongMsg) }); it('shows success if change was successful', () => { - cy.login('rahel.cueni', 'test'); - cy.visit('/me/profile'); - cy.changePassword(validOldPassword, validNewPassword); cy.get('[data-cy=password-change-success]').should('contain', 'Dein Password wurde erfolgreich geändert.'); cy.get('[data-cy=old-password]').should('have.value', ''); diff --git a/client/cypress/integration/current-module.spec.js b/client/cypress/integration/current-module.spec.js index 73c77c5b..8a71570e 100644 --- a/client/cypress/integration/current-module.spec.js +++ b/client/cypress/integration/current-module.spec.js @@ -4,8 +4,8 @@ describe('Current Module', () => { cy.startGraphQLCapture(); cy.viewport('macbook-15'); - cy.login('nico.zickgraf', 'test'); cy.visit('/module/lohn-und-budget'); + cy.login('nico.zickgraf', 'test'); cy.get('[data-cy=module-title]').should('contain', 'Lohn und Budget') diff --git a/client/cypress/integration/home-page-logged-in.spec.js b/client/cypress/integration/home-page-logged-in.spec.js index ea7c5aaa..0a9ab58c 100644 --- a/client/cypress/integration/home-page-logged-in.spec.js +++ b/client/cypress/integration/home-page-logged-in.spec.js @@ -1,7 +1,7 @@ describe('The Logged In Home Page', () => { it('successfully loads', () => { - cy.login('test', 'test'); cy.visit('/'); + cy.login('test', 'test'); cy.get('.block-title__title').should('contain', 'Inhalte') }) diff --git a/client/cypress/integration/login-csrf.spec.js b/client/cypress/integration/login-csrf.spec.js deleted file mode 100644 index 4250711e..00000000 --- a/client/cypress/integration/login-csrf.spec.js +++ /dev/null @@ -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') - }) - -}); diff --git a/client/cypress/integration/login-page-spec.js b/client/cypress/integration/login-page-spec.js index ee32a857..7435078d 100644 --- a/client/cypress/integration/login-page-spec.js +++ b/client/cypress/integration/login-page-spec.js @@ -1,15 +1,47 @@ 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 password = 'test'; cy.visit('/'); + cy.login(username, password, true); + cy.get('body').contains('Neues Wissen erwerben'); + }); - cy.get('#id_username').type(username); - cy.get('#id_password').type(`${password}{enter}`); + it('user sees error message if username is omitted', () => { + const username = ''; + const password = 'test'; - cy.getCookie('sessionid').should('exist'); - cy.get('.start-page__header').should('exist') + cy.visit('/'); + 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', () => { // cy.visit('/accounts/login/'); // have to get a csrf token by getting the base page first diff --git a/client/cypress/integration/new-project.spec.js b/client/cypress/integration/new-project.spec.js index 986038b8..778e1d3e 100644 --- a/client/cypress/integration/new-project.spec.js +++ b/client/cypress/integration/new-project.spec.js @@ -1,9 +1,9 @@ describe('New project', () => { it('creates a new project and displays it', () => { cy.viewport('macbook-15'); + cy.visit('/portfolio'); cy.login('rahel.cueni', 'test'); - cy.visit('/portfolio'); 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-beschreibung]').type('This description rocks'); diff --git a/client/cypress/integration/project-entry.spec.js b/client/cypress/integration/project-entry.spec.js index ce687c8f..7da598c9 100644 --- a/client/cypress/integration/project-entry.spec.js +++ b/client/cypress/integration/project-entry.spec.js @@ -4,7 +4,8 @@ describe('Project Entry', () => { cy.viewport('macbook-15'); cy.startGraphQLCapture(); - cy.login('rahel.cueni', 'test'); + cy.login('rahel.cueni', 'test', true); + cy.get('body').contains('Neues Wissen erwerben'); }); it('should create a new project entry', () => { diff --git a/client/cypress/integration/room-page.spec.js b/client/cypress/integration/room-page.spec.js index 038a41d1..dfa1d70d 100644 --- a/client/cypress/integration/room-page.spec.js +++ b/client/cypress/integration/room-page.spec.js @@ -1,9 +1,9 @@ describe('The Room Page', () => { it('displays new room entry with author name', () => { cy.viewport('macbook-15'); + cy.visit('/room/ein-historisches-festival'); cy.login('rahel.cueni', 'test'); - cy.visit('/room/ein-historisches-festival'); cy.get('[data-cy=add-room-entry-button]').click(); cy.get('.add-content-element:first-of-type').click(); cy.get('[data-cy=choose-text-widget]').click(); diff --git a/client/cypress/integration/rooms-page.spec.js b/client/cypress/integration/rooms-page.spec.js index 5f128480..755bc9d0 100644 --- a/client/cypress/integration/rooms-page.spec.js +++ b/client/cypress/integration/rooms-page.spec.js @@ -1,15 +1,16 @@ describe('The Rooms Page', () => { it('goes to the rooms page', () => { + cy.visit('/rooms'); cy.login('nico.zickgraf', 'test'); - cy.visit('/rooms'); cy.get('[data-cy=add-room]').should('exist'); }); + it('add room should not exist for student', () => { + cy.visit('/rooms'); cy.login('rahel.cueni', 'test'); - cy.visit('/rooms'); cy.get('[data-cy=add-room]').should('not.exist'); }); diff --git a/client/cypress/integration/solutions.spec.js b/client/cypress/integration/solutions.spec.js index bf6d9c97..273b6425 100644 --- a/client/cypress/integration/solutions.spec.js +++ b/client/cypress/integration/solutions.spec.js @@ -21,15 +21,15 @@ describe('Solutions', () => { // cy.logout(); cy.viewport('macbook-15'); - cy.login('rahel.cueni', 'test'); cy.visit('/module/lohn-und-budget'); + cy.login('rahel.cueni', 'test'); cy.get('[data-cy=toggle-enable-solutions]') .should('not.exist'); cy.get('[data-cy=solution]').should('not.exist'); cy.logout(); - cy.login('nico.zickgraf', 'test'); cy.visit('/module/lohn-und-budget'); + cy.login('nico.zickgraf', 'test'); cy.get('[data-cy=toggle-enable-solutions]').click(); cy.waitFor('UpdateSolutionVisibility'); // cy.get('[data-cy=toggle-enable-solutions]').within(() => { @@ -40,8 +40,8 @@ describe('Solutions', () => { cy.logout(); - cy.login('rahel.cueni', 'test'); cy.visit('/module/lohn-und-budget'); + cy.login('rahel.cueni', 'test'); // cy.get('[data-cy=solution]').should('exist'); cy.get('[data-cy=solution]').first() .should('contain', 'anzeigen') diff --git a/client/cypress/integration/survey.spec.js b/client/cypress/integration/survey.spec.js index 58a36529..c1bd181a 100644 --- a/client/cypress/integration/survey.spec.js +++ b/client/cypress/integration/survey.spec.js @@ -4,7 +4,8 @@ describe('Survey', () => { cy.viewport('macbook-15'); cy.startGraphQLCapture(); - cy.login('rahel.cueni', 'test'); + cy.login('rahel.cueni', 'test', true); + cy.get('body').contains('Neues Wissen erwerben'); }); it('should display and fill out the survey', () => { diff --git a/client/cypress/support/commands.js b/client/cypress/support/commands.js index 820873dd..faaebc76 100644 --- a/client/cypress/support/commands.js +++ b/client/cypress/support/commands.js @@ -24,26 +24,24 @@ // -- This is will overwrite an existing command -- // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) -Cypress.Commands.add("login", (username, password) => { - cy.request('/') - .its('body') - .then(body => { - console.log(body); - const $html = Cypress.$(body); +Cypress.Commands.add("login", (username, password, visitLogin=false) => { + if (visitLogin) { + cy.visit('/login'); + } - const csrf = $html.find('input[name=csrfmiddlewaretoken]').val(); - console.log(csrf); - cy.loginByCsrf(username, password, csrf) - .then(resp => { - expect(resp.status).to.eq(200); - expect(resp.body).to.include('skillbox'); - }); - }) + if (username != '') { + cy.get('[data-cy=email-input]').type(username); + } + if (password != '') { + cy.get('[data-cy=password-input]').type(password); + } + cy.get('[data-cy=login-button]').click(); }); Cypress.Commands.add("logout", () => { - cy.clearCookies(); + cy.get('[data-cy=user-icon]').click(); + cy.get('[data-cy=logout]').click(); }); Cypress.Commands.add('loginByCsrf', (username, password, csrftoken) => { diff --git a/client/src/App.vue b/client/src/App.vue index 1b99180e..479743b2 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -11,6 +11,7 @@ import SimpleLayout from '@/layouts/SimpleLayout'; import BlankLayout from '@/layouts/BlankLayout'; import FullScreenLayout from '@/layouts/FullScreenLayout'; + import PublicLayout from '@/layouts/PublicLayout'; import Modal from '@/components/Modal'; import MobileNavigation from '@/components/MobileNavigation'; import NewContentBlockWizard from '@/components/content-block-form/NewContentBlockWizard'; @@ -36,6 +37,7 @@ SimpleLayout, BlankLayout, FullScreenLayout, + PublicLayout, Modal, MobileNavigation, NewContentBlockWizard, diff --git a/client/src/components/icons/UserIcon.vue b/client/src/components/icons/UserIcon.vue index 77f3d933..7209e65c 100644 --- a/client/src/components/icons/UserIcon.vue +++ b/client/src/components/icons/UserIcon.vue @@ -1,5 +1,5 @@