fix linting

This commit is contained in:
mahula 2022-09-21 17:13:06 +02:00
parent 2da97bf275
commit aecf84f5ca
20 changed files with 156 additions and 117 deletions

View File

@ -0,0 +1 @@
node_modules

View File

@ -0,0 +1,24 @@
module.exports = {
root: true,
env: {
node: true,
},
parser: "@typescript-eslint/parser",
plugins: ["cypress", "prettier", "@typescript-eslint"],
extends: [
"standard",
"eslint:recommended",
"plugin:prettier/recommended",
"plugin:@typescript-eslint/recommended",
],
rules: {
"no-console": ["error"],
"no-debugger": "error",
"prettier/prettier": [
"error",
{
htmlWhitespaceSensitivity: "ignore",
},
],
},
};

View File

@ -15,10 +15,11 @@ async function setupNodeEvents(
})
);
on('after:run', (results) => {
on("after:run", (results) => {
if (results) {
// results will be undefined in interactive mode
console.log(results.status)
// eslint-disable-next-line no-console
console.log(results.status);
}
});
@ -29,19 +30,20 @@ export default defineConfig({
e2e: {
specPattern: "**/*.feature",
excludeSpecPattern: "*.js",
baseUrl: 'http://localhost:3000',
baseUrl: "http://localhost:3000",
chromeWebSecurity: false,
supportFile: 'cypress/support/index.ts',
supportFile: "cypress/support/index.ts",
viewportHeight: 720,
viewportWidth: 1280,
retries: {
runMode: 2,
openMode: 0
openMode: 0,
},
env: {
backendURL: 'http://localhost:4000',
loginQuery: 'query ($email: String!, $password: String!, $publisherId: Int) {\n login(email: $email, password: $password, publisherId: $publisherId) {\n email\n firstName\n lastName\n language\n klickTipp {\n newsletterState\n __typename\n }\n hasElopage\n publisherId\n isAdmin\n creation\n __typename\n }\n}\n'
backendURL: "http://localhost:4000",
loginQuery:
"query ($email: String!, $password: String!, $publisherId: Int) {\n login(email: $email, password: $password, publisherId: $publisherId) {\n email\n firstName\n lastName\n language\n klickTipp {\n newsletterState\n __typename\n }\n hasElopage\n publisherId\n isAdmin\n creation\n __typename\n }\n}\n",
},
setupNodeEvents
}
})
setupNodeEvents,
},
});

View File

@ -1,11 +1,11 @@
import { When } from "@badeball/cypress-cucumber-preprocessor";
import { ProfilePage } from "../models/ProfilePage";
When("the user fills the password form with:", table => {
When("the user fills the password form with:", (table) => {
table = table.rowsHash();
const profilePage = new ProfilePage();
profilePage.enterOldPassword(table["Old password"]);
profilePage.enterNewPassword(table["New password"]);
profilePage.enterRepeatPassword(table["Repeat new password"]);
cy.get(profilePage.submitNewPasswordBtn).should('be.enabled');
});
cy.get(profilePage.submitNewPasswordBtn).should("be.enabled");
});

View File

@ -2,7 +2,10 @@ import { When } from "@badeball/cypress-cucumber-preprocessor";
import { Toasts } from "../models/Toasts";
When("the user is presented a {string} message", (type: string) => {
const toast = new Toasts();
cy.get(toast.toastTitle).should('contain.text', 'Success');
cy.get(toast.toastMessage).should('contain.text', 'Your password has been changed.');
});
const toast = new Toasts();
cy.get(toast.toastTitle).should("contain.text", "Success");
cy.get(toast.toastMessage).should(
"contain.text",
"Your password has been changed."
);
});

View File

@ -2,8 +2,8 @@ import { And } from "@badeball/cypress-cucumber-preprocessor";
import { ProfilePage } from "../models/ProfilePage";
And("the user opens the change password menu", () => {
const profilePage = new ProfilePage();
cy.get(profilePage.openChangePassword).click();
cy.get(profilePage.newPasswordRepeatInput).should('be.visible');
cy.get(profilePage.submitNewPasswordBtn).should('be.disabled');
});
const profilePage = new ProfilePage();
cy.get(profilePage.openChangePassword).click();
cy.get(profilePage.newPasswordRepeatInput).should("be.visible");
cy.get(profilePage.submitNewPasswordBtn).should("be.disabled");
});

View File

@ -2,6 +2,6 @@ import { And } from "@badeball/cypress-cucumber-preprocessor";
import { ProfilePage } from "../models/ProfilePage";
And("the user submits the password form", () => {
const profilePage = new ProfilePage();
profilePage.submitPasswordForm();
});
const profilePage = new ProfilePage();
profilePage.submitPasswordForm();
});

View File

@ -2,14 +2,14 @@
export class LoginPage {
// selectors
emailInput = '#Email-input-field';
passwordInput = '#Password-input-field';
submitBtn = '[type=submit]';
emailHint = '#vee_Email';
passwordHint = '#vee_Password';
emailInput = "#Email-input-field";
passwordInput = "#Password-input-field";
submitBtn = "[type=submit]";
emailHint = "#vee_Email";
passwordHint = "#vee_Password";
goto() {
cy.visit('/');
cy.visit("/");
return this;
}

View File

@ -3,8 +3,8 @@
export class OverviewPage {
navbarName = '[data-test="navbar-item-username"]';
goto() {
cy.visit('/overview');
return this;
}
}
goto() {
cy.visit("/overview");
return this;
}
}

View File

@ -2,17 +2,17 @@
export class ProfilePage {
// selectors
openChangePassword = '[data-test=open-password-change-form]';
oldPasswordInput = '#password-input-field';
newPasswordInput = '#Neues-Passwort-input-field';
newPasswordRepeatInput = '#Neues-Passwort-wiederholen-input-field';
submitNewPasswordBtn = '[data-test=submit-new-password-btn]';
openChangePassword = "[data-test=open-password-change-form]";
oldPasswordInput = "#password-input-field";
newPasswordInput = "#Neues-Passwort-input-field";
newPasswordRepeatInput = "#Neues-Passwort-wiederholen-input-field";
submitNewPasswordBtn = "[data-test=submit-new-password-btn]";
goto() {
cy.visit('/profile');
cy.visit("/profile");
return this;
}
enterOldPassword(password: string) {
cy.get(this.oldPasswordInput).clear().type(password);
return this;

View File

@ -1,17 +1,17 @@
/// <reference types="cypress" />
export class SideNavMenu {
// selectors
profileMenu = '[data-test=profile-menu]';
logoutMenu = '[data-test=logout-menu]';
// selectors
profileMenu = "[data-test=profile-menu]";
logoutMenu = "[data-test=logout-menu]";
openUserProfile() {
cy.get(this.profileMenu).click();
return this;
}
openUserProfile() {
cy.get(this.profileMenu).click();
return this;
}
logout() {
cy.get(this.logoutMenu).click();
return this;
}
}
logout() {
cy.get(this.logoutMenu).click();
return this;
}
}

View File

@ -1,7 +1,7 @@
/// <reference types="cypress" />
export class Toasts {
// selectors
toastTitle = '.gdd-toaster-title';
toastMessage = '.gdd-toaster-body';
}
// selectors
toastTitle = ".gdd-toaster-title";
toastMessage = ".gdd-toaster-body";
}

View File

@ -1,39 +1,38 @@
import jwtDecode from 'jwt-decode'
import jwtDecode from "jwt-decode";
Cypress.Commands.add('login', (email, password) => {
Cypress.LocalStorage.clear
cy.request({
method: 'POST',
url: Cypress.env('backendURL'),
body: {
"operationName": null,
"variables": {
"email": email,
"password": password
},
"query": Cypress.env('loginQuery')
}
})
.then(async (response) => {
const token = response.headers.token
let tokenTime
Cypress.Commands.add("login", (email, password) => {
cy.clearLocalStorage("vuex");
// to avoid JWT InvalidTokenError, the decoding of the token is wrapped
// in a try-catch block (see
// https://github.com/auth0/jwt-decode/issues/65#issuecomment-395493807)
try {
tokenTime = jwtDecode(token).exp
} catch (tokenDecodingError) {
cy.log('JWT decoding error: ', tokenDecodingError)
}
cy.request({
method: "POST",
url: Cypress.env("backendURL"),
body: {
operationName: null,
variables: {
email: email,
password: password,
},
query: Cypress.env("loginQuery"),
},
}).then(async (response) => {
const token = response.headers.token;
let tokenTime;
let vuexToken = {
token : token,
tokenTime : tokenTime
};
// to avoid JWT InvalidTokenError, the decoding of the token is wrapped
// in a try-catch block (see
// https://github.com/auth0/jwt-decode/issues/65#issuecomment-395493807)
try {
tokenTime = jwtDecode(token).exp;
} catch (tokenDecodingError) {
cy.log("JWT decoding error: ", tokenDecodingError);
}
cy.visit('/')
window.localStorage.setItem('vuex', JSON.stringify(vuexToken))
})
})
const vuexToken = {
token: token,
tokenTime: tokenTime,
};
cy.visit("/");
window.localStorage.setItem("vuex", JSON.stringify(vuexToken));
});
});

View File

@ -1,11 +1,14 @@
/* eslint-disable @typescript-eslint/no-namespace */
/* eslint-disable @typescript-eslint/no-explicit-any */
/// <reference types="cypress" />
import './e2e';
import "./e2e";
declare global {
namespace Cypress {
interface Chainable<Subject> {
login(email: string, password: string): Chainable<any>
}
namespace Cypress {
interface Chainable<Subject> {
login(email: string, password: string): Chainable<any>;
}
}
}
}

View File

@ -2,4 +2,4 @@ import { Given } from "@badeball/cypress-cucumber-preprocessor";
Given("the browser navigates to page {string}", (page: string) => {
cy.visit(page);
});
});

View File

@ -2,7 +2,10 @@ import { Then } from "@badeball/cypress-cucumber-preprocessor";
import { Toasts } from "../../e2e/models/Toasts";
Then("the user cannot login", () => {
const toast = new Toasts();
cy.get(toast.toastTitle).should('contain.text', 'Fehler!'); // 'Error!'
cy.get(toast.toastMessage).should('contain.text', 'Kein Benutzer mit diesen Anmeldedaten.'); // 'No user with this credentials.'
const toast = new Toasts();
cy.get(toast.toastTitle).should("contain.text", "Fehler!"); // 'Error!'
cy.get(toast.toastMessage).should(
"contain.text",
"Kein Benutzer mit diesen Anmeldedaten."
); // 'No user with this credentials.'
});

View File

@ -1,5 +1,8 @@
import { Given } from "@badeball/cypress-cucumber-preprocessor";
Given("the user is logged in as {string} {string}", (email: string, password: string) => {
Given(
"the user is logged in as {string} {string}",
(email: string, password: string) => {
cy.login(email, password);
});
}
);

View File

@ -2,9 +2,7 @@ import { Then } from "@badeball/cypress-cucumber-preprocessor";
import { OverviewPage } from "../../e2e/models/OverviewPage";
Then("the user is logged in with username {string}", (username: string) => {
const overviewPage = new OverviewPage();
cy.url().should('include', '/overview')
cy.get(overviewPage.navbarName).should('contain', username);
const overviewPage = new OverviewPage();
cy.url().should("include", "/overview");
cy.get(overviewPage.navbarName).should("contain", username);
});

View File

@ -2,6 +2,6 @@ import { Then } from "@badeball/cypress-cucumber-preprocessor";
import { SideNavMenu } from "../../e2e/models/SideNavMenu";
Then("the user logs out", () => {
const sideNavMenu = new SideNavMenu;
sideNavMenu.logout();
});
const sideNavMenu = new SideNavMenu();
sideNavMenu.logout();
});

View File

@ -1,9 +1,12 @@
import { When } from "@badeball/cypress-cucumber-preprocessor";
import { LoginPage } from "../../e2e/models/LoginPage";
When("the user submits the credentials {string} {string}", (email: string, password: string) => {
const loginPage = new LoginPage;
When(
"the user submits the credentials {string} {string}",
(email: string, password: string) => {
const loginPage = new LoginPage();
loginPage.enterEmail(email);
loginPage.enterPassword(password);
loginPage.submitLogin();
});
}
);