From c52dceddf24cff2bc59d850dfd12e2964ace1230 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 10 Apr 2021 11:47:00 +0200 Subject: [PATCH] authentication feature fixed a problem in login component --- cypress/integration/Authentication.feature | 13 +++---- .../Authentication/given_I_am_logged_in.js | 13 +++++++ .../given_I_have_an_user_account.js | 7 ++++ .../then_I_am_logged_in_as_{string}.js | 6 +++ .../then_I_am_on_page_{string}.js | 5 +++ .../Authentication/when_I_click_submit.js | 6 +++ .../when_I_fill_in_my_credentials.js | 11 ++++++ .../Authentication/when_I_log_out.js | 8 ++++ .../Authentication/when_I_refresh_the_page.js | 6 +++ .../when_I_visit_the_{string}_page.js | 0 cypress/integration/common/.steps.js | 38 ------------------- .../when_I_wait_for_{int}_milliseconds.js | 5 --- cypress/integration/data/loginCredentials.js | 6 +++ cypress/integration/data/narrator.js | 7 ++++ cypress/support/commands.js | 2 +- webapp/pages/login.vue | 12 +++++- 16 files changed, 91 insertions(+), 54 deletions(-) create mode 100644 cypress/integration/Authentication/given_I_am_logged_in.js create mode 100644 cypress/integration/Authentication/given_I_have_an_user_account.js create mode 100644 cypress/integration/Authentication/then_I_am_logged_in_as_{string}.js create mode 100644 cypress/integration/Authentication/then_I_am_on_page_{string}.js create mode 100644 cypress/integration/Authentication/when_I_click_submit.js create mode 100644 cypress/integration/Authentication/when_I_fill_in_my_credentials.js create mode 100644 cypress/integration/Authentication/when_I_log_out.js create mode 100644 cypress/integration/Authentication/when_I_refresh_the_page.js rename cypress/integration/{common => Authentication}/when_I_visit_the_{string}_page.js (100%) delete mode 100644 cypress/integration/common/when_I_wait_for_{int}_milliseconds.js create mode 100644 cypress/integration/data/loginCredentials.js create mode 100644 cypress/integration/data/narrator.js diff --git a/cypress/integration/Authentication.feature b/cypress/integration/Authentication.feature index 22e2668a8..50bb8e938 100644 --- a/cypress/integration/Authentication.feature +++ b/cypress/integration/Authentication.feature @@ -8,19 +8,16 @@ Feature: Authentication Scenario: Log in When I visit the "login" page - And I fill in my email and password combination + And I fill in my credentials And I click submit - And I wait for 50000 milliseconds - Then I can click on my profile picture in the top right corner - And I wait for 50000 milliseconds - And I can see my name "Peter Lustig" in the dropdown menu + Then I am logged in as "Peter Pan" Scenario: Refresh and stay logged in Given I am logged in When I refresh the page - Then I am still logged in + Then I am logged in as "Peter Pan" Scenario: Log out Given I am logged in - When I log out through the menu in the top right corner - Then I see the login screen again + When I log out + Then I am on page "login" diff --git a/cypress/integration/Authentication/given_I_am_logged_in.js b/cypress/integration/Authentication/given_I_am_logged_in.js new file mode 100644 index 000000000..e0412971d --- /dev/null +++ b/cypress/integration/Authentication/given_I_am_logged_in.js @@ -0,0 +1,13 @@ +import { Given } from "cypress-cucumber-preprocessor/steps"; +import narrator from "../data/narrator"; + +Given("I am logged in", () => { + cy.neode() + .first("User", { name: narrator.name }) + .then(user => { + return new Cypress.Promise((resolve, reject) => { + return user.toJson().then((user) => resolve(user)) + }) + }) + .then(user => cy.login(user)) +}); \ No newline at end of file diff --git a/cypress/integration/Authentication/given_I_have_an_user_account.js b/cypress/integration/Authentication/given_I_have_an_user_account.js new file mode 100644 index 000000000..776a7752c --- /dev/null +++ b/cypress/integration/Authentication/given_I_have_an_user_account.js @@ -0,0 +1,7 @@ +import { Given } from "cypress-cucumber-preprocessor/steps"; +import narrator from '../data/narrator' +import loginCredentials from '../data/loginCredentials' + +Given("I have an user account", () => { + cy.factory().build("user", narrator, loginCredentials); +}); \ No newline at end of file diff --git a/cypress/integration/Authentication/then_I_am_logged_in_as_{string}.js b/cypress/integration/Authentication/then_I_am_logged_in_as_{string}.js new file mode 100644 index 000000000..c516fbb92 --- /dev/null +++ b/cypress/integration/Authentication/then_I_am_logged_in_as_{string}.js @@ -0,0 +1,6 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("I am logged in as {string}", name => { + cy.get(".avatar-menu").click(); + cy.get(".avatar-menu-popover").contains(name); +}); \ No newline at end of file diff --git a/cypress/integration/Authentication/then_I_am_on_page_{string}.js b/cypress/integration/Authentication/then_I_am_on_page_{string}.js new file mode 100644 index 000000000..219e181b7 --- /dev/null +++ b/cypress/integration/Authentication/then_I_am_on_page_{string}.js @@ -0,0 +1,5 @@ +import { Then } from "cypress-cucumber-preprocessor/steps"; + +Then("I am on page {string}", page => { + cy.location("pathname").should("contain", page); +}); \ No newline at end of file diff --git a/cypress/integration/Authentication/when_I_click_submit.js b/cypress/integration/Authentication/when_I_click_submit.js new file mode 100644 index 000000000..c8578da8f --- /dev/null +++ b/cypress/integration/Authentication/when_I_click_submit.js @@ -0,0 +1,6 @@ +import { When } from "cypress-cucumber-preprocessor/steps"; + +When("I click submit", () => { + cy.get("button[name=submit]") + .click(); +}); \ No newline at end of file diff --git a/cypress/integration/Authentication/when_I_fill_in_my_credentials.js b/cypress/integration/Authentication/when_I_fill_in_my_credentials.js new file mode 100644 index 000000000..e0d90e744 --- /dev/null +++ b/cypress/integration/Authentication/when_I_fill_in_my_credentials.js @@ -0,0 +1,11 @@ +import { When } from "cypress-cucumber-preprocessor/steps"; +import loginCredentials from '../data/loginCredentials' + +When("I fill in my credentials", () => { + cy.get("input[name=email]") + .trigger("focus") + .type(loginCredentials.email) + .get("input[name=password]") + .trigger("focus") + .type(loginCredentials.password); +}); \ No newline at end of file diff --git a/cypress/integration/Authentication/when_I_log_out.js b/cypress/integration/Authentication/when_I_log_out.js new file mode 100644 index 000000000..fcb3437ed --- /dev/null +++ b/cypress/integration/Authentication/when_I_log_out.js @@ -0,0 +1,8 @@ +import { When } from "cypress-cucumber-preprocessor/steps"; + +When("I log out", () => { + cy.get(".avatar-menu").click(); + cy.get(".avatar-menu-popover") + .find('a[href="/logout"]') + .click(); +}); \ No newline at end of file diff --git a/cypress/integration/Authentication/when_I_refresh_the_page.js b/cypress/integration/Authentication/when_I_refresh_the_page.js new file mode 100644 index 000000000..1ac655cb4 --- /dev/null +++ b/cypress/integration/Authentication/when_I_refresh_the_page.js @@ -0,0 +1,6 @@ +import { When } from "cypress-cucumber-preprocessor/steps"; + +When('I refresh the page', () => { + cy.visit('/') + .reload(); +}); \ No newline at end of file diff --git a/cypress/integration/common/when_I_visit_the_{string}_page.js b/cypress/integration/Authentication/when_I_visit_the_{string}_page.js similarity index 100% rename from cypress/integration/common/when_I_visit_the_{string}_page.js rename to cypress/integration/Authentication/when_I_visit_the_{string}_page.js diff --git a/cypress/integration/common/.steps.js b/cypress/integration/common/.steps.js index d557112d5..a54d54afa 100644 --- a/cypress/integration/common/.steps.js +++ b/cypress/integration/common/.steps.js @@ -23,19 +23,6 @@ const annoyingParams = { password: "1234", }; -Given("I am logged in", () => { - cy.neode() - .first("User", { - name: narratorParams.name - }) - .then(user => { - return new Cypress.Promise((resolve, reject) => { - return user.toJson().then((user) => resolve(user)) - }) - }) - .then(user => cy.login(user)) -}); - Given("I log in as {string}", name => { cy.logout() cy.neode() @@ -143,31 +130,6 @@ Given("I am on the {string} page", page => { cy.openPage(page); }); -When(/(?:when )?I refresh the page/, () => { - cy.visit('/') - .reload(); -}); - -When("I log out through the menu in the top right corner", () => { - cy.get(".avatar-menu").click(); - cy.get(".avatar-menu-popover") - .find('a[href="/logout"]') - .click(); -}); - -Then("I can see my name {string} in the dropdown menu", () => { - cy.get(".avatar-menu-popover").should("contain", narratorParams.name); -}); - -Then("I see the login screen again", () => { - cy.location("pathname").should("contain", "/login"); -}); - -Then("I am still logged in", () => { - cy.get(".avatar-menu").click(); - cy.get(".avatar-menu-popover").contains(narratorParams.name); -}); - When("I select {string} in the language menu", name => { cy.switchLanguage(name, true); }); diff --git a/cypress/integration/common/when_I_wait_for_{int}_milliseconds.js b/cypress/integration/common/when_I_wait_for_{int}_milliseconds.js deleted file mode 100644 index 95d064ed9..000000000 --- a/cypress/integration/common/when_I_wait_for_{int}_milliseconds.js +++ /dev/null @@ -1,5 +0,0 @@ -import { When } from "cypress-cucumber-preprocessor/steps"; - -When("I wait for {int} milliseconds", ms => { - cy.wait(ms) -}); \ No newline at end of file diff --git a/cypress/integration/data/loginCredentials.js b/cypress/integration/data/loginCredentials.js new file mode 100644 index 000000000..939295511 --- /dev/null +++ b/cypress/integration/data/loginCredentials.js @@ -0,0 +1,6 @@ +const loginCredentials = { + email: "peterpan@example.org", + password: "1234" +} + +export default loginCredentials diff --git a/cypress/integration/data/narrator.js b/cypress/integration/data/narrator.js new file mode 100644 index 000000000..e9eaff3d0 --- /dev/null +++ b/cypress/integration/data/narrator.js @@ -0,0 +1,7 @@ +const narrator = { + id: 'id-of-peter-pan', + name: "Peter Pan", + slug: "peter-pan", +} + +export default narrator diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 2d7573dda..46099a937 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -53,7 +53,7 @@ Cypress.Commands.add("switchLanguage", (name, force) => { Cypress.Commands.add("login", user => { const token = encode(user) - cy.setCookie('human-connection-token', token) + cy.setCookie('ocelot-social-token', token) .visit("/") }); diff --git a/webapp/pages/login.vue b/webapp/pages/login.vue index d7548706c..f8ccd3afe 100644 --- a/webapp/pages/login.vue +++ b/webapp/pages/login.vue @@ -25,9 +25,17 @@ export default { } }, methods: { - handleSuccess() { + async handleSuccess() { this.$i18n.set(this.user.locale || 'en') - this.$router.replace(this.$route.query.path || '/') + + try { + await this.$router.replace(this.$route.query.path || '/') + } catch (err) { + //throw new Error(`Problem handling something: ${err}.`); + // TODO this is causing trouble - most likely due to double redirect on terms&conditions + console.log(`Problem handling something: ${err}.`) + } + }, }, }