authentication feature

fixed a problem in login component
This commit is contained in:
Ulf Gebhardt 2021-04-10 11:47:00 +02:00
parent 169b220aa1
commit c52dceddf2
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD
16 changed files with 91 additions and 54 deletions

View File

@ -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"

View File

@ -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))
});

View File

@ -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);
});

View File

@ -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);
});

View File

@ -0,0 +1,5 @@
import { Then } from "cypress-cucumber-preprocessor/steps";
Then("I am on page {string}", page => {
cy.location("pathname").should("contain", page);
});

View File

@ -0,0 +1,6 @@
import { When } from "cypress-cucumber-preprocessor/steps";
When("I click submit", () => {
cy.get("button[name=submit]")
.click();
});

View File

@ -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);
});

View File

@ -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();
});

View File

@ -0,0 +1,6 @@
import { When } from "cypress-cucumber-preprocessor/steps";
When('I refresh the page', () => {
cy.visit('/')
.reload();
});

View File

@ -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);
});

View File

@ -1,5 +0,0 @@
import { When } from "cypress-cucumber-preprocessor/steps";
When("I wait for {int} milliseconds", ms => {
cy.wait(ms)
});

View File

@ -0,0 +1,6 @@
const loginCredentials = {
email: "peterpan@example.org",
password: "1234"
}
export default loginCredentials

View File

@ -0,0 +1,7 @@
const narrator = {
id: 'id-of-peter-pan',
name: "Peter Pan",
slug: "peter-pan",
}
export default narrator

View File

@ -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("/")
});

View File

@ -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}.`)
}
},
},
}