diff --git a/astro.config.mjs b/astro.config.mjs index af8e2b7b..27e82590 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -17,7 +17,7 @@ export default defineConfig({ output: "server", vite: { optimizeDeps: { - exclude: ["@ibcornelsen/api"] + exclude: ["@ibcornelsen/api", "@ibcornelsen/database"] } }, adapter: node({ diff --git a/cypress.config.ts b/cypress.config.ts index ed29bbe8..5b550f13 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -1,8 +1,17 @@ -import { defineConfig } from 'cypress' +import { defineConfig } from "cypress"; export default defineConfig({ e2e: { - baseUrl: 'http://localhost:3000', - supportFile: false + baseUrl: "http://localhost:3000", + supportFile: false, + viewportHeight: 900, + viewportWidth: 1660, }, -}) \ No newline at end of file + + component: { + devServer: { + framework: "svelte", + bundler: "vite", + }, + }, +}); diff --git a/cypress/e2e/Verbrauchsausweis/index.cy.ts b/cypress/e2e/Verbrauchsausweis/index.cy.ts deleted file mode 100644 index 6c50bf7b..00000000 --- a/cypress/e2e/Verbrauchsausweis/index.cy.ts +++ /dev/null @@ -1,5 +0,0 @@ -describe('The Home page.', () => { - it("successfully loads", () => { - cy.visit("/") - }) -}) \ No newline at end of file diff --git a/cypress/e2e/VerbrauchsausweisWohnen/erstellen.cy.ts b/cypress/e2e/VerbrauchsausweisWohnen/erstellen.cy.ts new file mode 100644 index 00000000..7252d70c --- /dev/null +++ b/cypress/e2e/VerbrauchsausweisWohnen/erstellen.cy.ts @@ -0,0 +1,112 @@ +import fuelList from "#components/Ausweis/fuelList"; +import { faker } from "@faker-js/faker"; +import { Enums } from "@ibcornelsen/database/client"; + +describe("Verbrauchsausweis erstellen Schritt 1", () => { + it("erstellt einen neuen Verbrauchsausweis Wohngebäude.", () => { + cy.visit("/verbrauchsausweis"); + + cy.wait(1000); + + // Wir überprüfen, ob alle Ausstelgründe vorhanden sind, diese sollten genau so viele sein wie in der Datenbank vorhanden sind. + cy.get("input[name='ausstellgrund']") + .should("have.length", Object.values(Enums.Ausstellgrund).length) + .eq( + faker.number.int({ + min: 0, + max: Object.values(Enums.Ausstellgrund).length - 1, + }) + ) + .check(); + + // Jetzt Füllen wir das Baujahr vom Gebäude aus. + cy.get("input[name='baujahr_gebaeude']") + .should("have.attr", "type", "number") + .type( + faker.number.int({ min: 1900, max: 2021 }).toString() + + "{enter}", + { delay: 50 } + ); + + // Jetzt Füllen wir das Baujahr der Heizung aus. + cy.get("input[name='baujahr_heizung']") + .should("have.attr", "type", "number") + .type( + faker.number.int({ min: 1900, max: 2021 }).toString() + + "{enter}", + { delay: 50 } + ); + + // Anzahl Einheiten + cy.get("input[name='einheiten']") + .should("have.attr", "type", "number") + .type(faker.number.int({ min: 1, max: 5 }).toString()); + + // Sanierungsstatus + cy.get("select[name='saniert']").select( + Math.random() > 0.5 ? "true" : "false" + ); + + // Adresse + cy.get("input[name='adresse']").type(faker.location.streetAddress()); + + // Postleitzahl + cy.get("input[name='plz']").type( + faker.location.zipCode({ + format: "#####", + }) + ); + + // TODO: Ort - Dieser wird aus der Datenbank abgefragt, wir müssen also warten, bis der Dropdown da ist. + + // Flaeche + cy.get("input[name='flaeche']") + .should("have.attr", "type", "number") + .type(faker.number.int({ min: 50, max: 1000 }).toString()); + + // Keller + cy.get("select[name='keller']").find("option:not([disabled])").should("have.length", Object.values(Enums.Heizungsstatus).length).parent().select(faker.number.int({ + max: Object.values(Enums.Heizungsstatus).length, + min: 1 + })); + + // Dachgeschoss + cy.get("select[name='dachgeschoss']").find("option:not([disabled])").should("have.length", Object.values(Enums.Heizungsstatus).length).parent().select(faker.number.int({ + max: Object.values(Enums.Heizungsstatus).length, + min: 1 + })); + + // Brennstoff und Einheit 1 + const brennstoffKombo = fuelList[faker.number.int({ min: 0, max: fuelList.length - 1 })]; + + cy.get("select[name='brennstoff_1']").select(brennstoffKombo[0]); + cy.get("select[name='einheit_1']").select(brennstoffKombo[1]); + + // Verbrauchszeitraum + cy.get("select[name='energieverbrauch_zeitraum_monat']").select(faker.number.int({ min: 1, max: 12 }).toString()); + cy.get("select[name='energieverbrauch_zeitraum_jahr']").select(faker.number.int({ min: 2018, max: 2019 }).toString()); + + // Verbrauch + cy.get("input[name='verbrauch_1']").type(faker.number.int({ min: 4000, max: 15000 }).toString()); + cy.get("input[name='verbrauch_2']").type(faker.number.int({ min: 4000, max: 15000 }).toString()); + cy.get("input[name='verbrauch_3']").type(faker.number.int({ min: 4000, max: 15000 }).toString()); + + + const zusaetzlicheHeizquelle = Math.random() > 0.5; + + if (zusaetzlicheHeizquelle) { + cy.get("input[name='zusaetzliche_heizquelle']").check(); + + // Brennstoff und Einheit 2 + const brennstoffKombo2 = fuelList[faker.number.int({ min: 0, max: fuelList.length - 1 })]; + + cy.get("select[name='brennstoff_2']").select(brennstoffKombo2[0]); + cy.get("select[name='einheit_2']").select(brennstoffKombo2[1]); + + // Verbrauch + cy.get("input[name='verbrauch_4']").type(faker.number.int({ min: 4000, max: 15000 }).toString()); + cy.get("input[name='verbrauch_5']").type(faker.number.int({ min: 4000, max: 15000 }).toString()); + cy.get("input[name='verbrauch_6']").type(faker.number.int({ min: 4000, max: 15000 }).toString()); + } + }); +}); diff --git a/cypress/e2e/auth/index.cy.ts b/cypress/e2e/auth/index.cy.ts new file mode 100644 index 00000000..a0bd34f2 --- /dev/null +++ b/cypress/e2e/auth/index.cy.ts @@ -0,0 +1,38 @@ +import { API_ACCESS_TOKEN_COOKIE_NAME, API_REFRESH_TOKEN_COOKIE_NAME } from "#lib/constants"; +import {faker} from "@faker-js/faker"; + +describe('Benutzer Authentifizierung', () => { + // Wir generieren uns einen zufälligen Nutzer + const email = faker.internet.email() + const password = faker.internet.password() + const name = faker.person.firstName() + const surname = faker.person.lastName() + + it("erstellt einen Nutzer und leitet auf die Login Seite weiter", () => { + cy.visit("/auth/signup") + + cy.get('input[name="email"]').type(email) + cy.get('input[name="passwort"]').type(password) + cy.get('input[name="vorname"]').type(name) + cy.get('input[name="name"]').type(surname) + + cy.get('button[type="submit"]').click() + + cy.url().should("include", "/auth/login") + }) + + it("meldet einen Nutzer an und leitet auf die Startseite weiter", () => { + cy.visit("/auth/login") + + cy.get('input[name="email"]').type(email) + cy.get('input[name="passwort"]').type(password) + + cy.get('button[type="submit"]').click() + + cy.url().should("include", "/user") + + // Wir sollten nun einen Access Token und Refresh Token in unseren Cookies sehen. + cy.getCookie(API_ACCESS_TOKEN_COOKIE_NAME).should("exist") + cy.getCookie(API_REFRESH_TOKEN_COOKIE_NAME).should("exist") + }) +}) \ No newline at end of file diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json new file mode 100644 index 00000000..02e42543 --- /dev/null +++ b/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts new file mode 100644 index 00000000..698b01a4 --- /dev/null +++ b/cypress/support/commands.ts @@ -0,0 +1,37 @@ +/// +// *********************************************** +// This example commands.ts shows you how to +// create various custom commands and overwrite +// existing commands. +// +// For more comprehensive examples of custom +// commands please read more here: +// https://on.cypress.io/custom-commands +// *********************************************** +// +// +// -- This is a parent command -- +// Cypress.Commands.add('login', (email, password) => { ... }) +// +// +// -- This is a child command -- +// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) +// +// +// -- This is a dual command -- +// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) +// +// +// -- This will overwrite an existing command -- +// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) +// +// declare global { +// namespace Cypress { +// interface Chainable { +// login(email: string, password: string): Chainable +// drag(subject: string, options?: Partial): Chainable +// dismiss(subject: string, options?: Partial): Chainable +// visit(originalFn: CommandOriginalFn, url: string, options: Partial): Chainable +// } +// } +// } \ No newline at end of file diff --git a/cypress/support/component-index.html b/cypress/support/component-index.html new file mode 100644 index 00000000..ac6e79fd --- /dev/null +++ b/cypress/support/component-index.html @@ -0,0 +1,12 @@ + + + + + + + Components App + + +
+ + \ No newline at end of file diff --git a/cypress/support/component.ts b/cypress/support/component.ts new file mode 100644 index 00000000..e28b7781 --- /dev/null +++ b/cypress/support/component.ts @@ -0,0 +1,39 @@ +// *********************************************************** +// This example support/component.ts is processed and +// loaded automatically before your test files. +// +// This is a great place to put global configuration and +// behavior that modifies Cypress. +// +// You can change the location of this file or turn off +// automatically serving support files with the +// 'supportFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/configuration +// *********************************************************** + +// Import commands.js using ES2015 syntax: +import './commands' + +// Alternatively you can use CommonJS syntax: +// require('./commands') + +import { mount } from 'cypress/svelte' + +// Augment the Cypress namespace to include type definitions for +// your custom command. +// Alternatively, can be defined in cypress/support/component.d.ts +// with a at the top of your spec. +declare global { + namespace Cypress { + interface Chainable { + mount: typeof mount + } + } +} + +Cypress.Commands.add('mount', mount) + +// Example use: +// cy.mount(MyComponent) \ No newline at end of file diff --git a/package.json b/package.json index 06c3eda9..a2d2e244 100644 --- a/package.json +++ b/package.json @@ -58,12 +58,13 @@ "zod": "^3.22.4" }, "devDependencies": { + "@faker-js/faker": "^8.3.1", "@types/body-scroll-lock": "^3.1.2", "@types/js-cookie": "^3.0.6", "@types/uuid": "^9.0.1", "@typescript-eslint/eslint-plugin": "^5.59.6", "@typescript-eslint/parser": "^5.59.6", - "cypress": "^13.6.1", + "cypress": "^13.6.2", "eslint": "~8.15.0", "eslint-config-prettier": "8.1.0", "prettier": "^2.8.8", diff --git a/src/components/Ausweis/Ausweisart.svelte b/src/components/Ausweis/Ausweisart.svelte index 56610d11..03d490e7 100644 --- a/src/components/Ausweis/Ausweisart.svelte +++ b/src/components/Ausweis/Ausweisart.svelte @@ -27,6 +27,7 @@ {#each Object.entries(Enums.Ausstellgrund) as [name, ausstellgrund]}