Highlight und neue ID

This commit is contained in:
Moritz Utcke
2025-03-25 14:01:13 -03:00
parent 84a3a2dd39
commit 5d66eb10ca
89 changed files with 1650 additions and 601 deletions

View File

@@ -0,0 +1,282 @@
import fuelList from "#components/Ausweis/brennstoffListe.js";
import { faker } from "@faker-js/faker";
import "cypress-file-upload"
import moment from "moment";
import { Aufnahme, Enums, Objekt, VerbrauchsausweisWohnen } from "#lib/client/prisma.js";
describe("Verbrauchsausweis für Wohngebäude bearbeiten", async () => {
it("bearbeitet einen bereits existierenden Verbrauchsausweis für Wohngebäude", () => {
cy.task("verbrauchsausweisWohnen", {
where: {
ausgestellt: false,
bestellt: false
},
include: {
aufnahme: {
include: {
objekt: true
}
},
benutzer: true
}
}).then((ausweis: VerbrauchsausweisWohnen & { aufnahme: Aufnahme & { objekt: Objekt } }) => {
cy.visit(`/energieausweis-erstellen/verbrauchsausweis-wohngebaeude?id=${ausweis.id}`);
cy.wait(2000);
// Wir überprüfen, ob alle Ausstelgründe vorhanden sind, diese sollten genau so viele sein wie in der Datenbank vorhanden sind.
cy.get("select[data-cy='ausstellgrund']")
.find("option:selected").should("have.value", ausweis.ausstellgrund)
// Jetzt Füllen wir das Baujahr vom Gebäude aus.
cy.get("input[name='baujahr_gebaeude']")
.should("have.value", ausweis.aufnahme.baujahr_gebaeude[0])
// Jetzt Füllen wir das Baujahr der Heizung aus.
cy.get("input[name='baujahr_heizung']")
.should("have.value", ausweis.aufnahme.baujahr_heizung[0])
// Anzahl Einheiten
cy.get("input[name='einheiten']")
.should("have.value", ausweis.aufnahme.einheiten)
// Sanierungsstatus
cy.get("select[name='saniert']").find("option:selected").should("have.value", ausweis.aufnahme.saniert)
// Adresse
cy.get("input[name='adresse']").should("have.value", ausweis.aufnahme.objekt.adresse);
// 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.
cy.get("[data-cy='plz-container']").find("button").first().click()
// Flaeche
cy.get("input[name='flaeche']")
.should("have.attr", "type", "number")
.type(faker.number.int({ min: 50, max: 1000 }).toString());
// Nutzflaeche
cy.get("input[name='nutzflaeche']")
.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", (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length).parent().select(faker.number.int({
max: (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length,
min: 1
}));
// Dachgeschoss
cy.get("select[name='dachgeschoss']").find("option:not([disabled])").should("have.length", (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length).parent().select(faker.number.int({
max: (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as 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]);
let availableDates = [];
const startDate = moment()
.subtract(4, "years")
.subtract(6, "months");
const endDate = moment().subtract(3, "years");
for (let m = moment(startDate); m.isBefore(endDate); m.add(1, "month")) {
availableDates.push({
year: m.year(),
month: m.month(),
});
}
// Verbrauchszeitraum
cy.get("select[name='energieverbrauch_zeitraum_jahr']").select(availableDates[0].year.toString());
cy.get("select[name='energieverbrauch_zeitraum_monat']").select(availableDates[0].month.toString());
// Verbrauch
cy.get("input[name='verbrauch_1']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true });
cy.get("input[name='verbrauch_2']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true });
cy.get("input[name='verbrauch_3']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true });
const zusaetzlicheHeizquelle = Math.random() > 0.5;
if (zusaetzlicheHeizquelle) {
cy.get("[data-cy='zusaetzliche_heizquelle']").check();
// Brennstoff und Einheit 2
const brennstoffKombo2 = fuelList[faker.number.int({ min: 0, max: fuelList.length - 1 })];
cy.get("[data-cy='brennstoff_2']").select(brennstoffKombo2[0], { force: true });
cy.get("[data-cy='einheit_2']").select(brennstoffKombo2[1], { force: true });
// Verbrauch
cy.get("input[name='verbrauch_4']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true });
cy.get("input[name='verbrauch_5']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true });
cy.get("input[name='verbrauch_6']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true });
}
// Warmwasser enthalten und bekannt
const warmwasserEnthalten = Math.random() > 0.5;
const anteilBekannt = Math.random() > 0.5;
if (warmwasserEnthalten) {
cy.get("input[name='warmwasser_enthalten']").check();
if (anteilBekannt) {
// Der Anteil ist bekannt, wir müssen ihn also angeben.
cy.get("input[name='warmwasser_anteil_bekannt']").check();
cy.get("input[name='anteil_warmwasser_1']").type(faker.number.int({ min: 0, max: 50 }).toString());
if (zusaetzlicheHeizquelle) {
// Zusätzliche Heizquelle existiert, also müssen wir auch hier den Anteil angeben.
cy.get("input[name='anteil_warmwasser_2']").type(faker.number.int({ min: 0, max: 50 }).toString(), {force: true});
}
}
}
// Alternative Energieversorgungssysteme
if (Math.random() > 0.5) cy.get("input[name='alternative_heizung']").check();
if (Math.random() > 0.5) cy.get("input[name='alternative_warmwasser']").check();
if (Math.random() > 0.5) cy.get("input[name='alternative_lueftung']").check();
if (Math.random() > 0.5) cy.get("input[name='alternative_kuehlung']").check();
// Gebäudetyp
cy.get("select[name='gebaeudetyp']").then(($dropdown) => {
const options = $dropdown.find('option');
// Select the option at the random index
cy.get("select[name='gebaeudetyp']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string);
});
// Gebäudeteil
cy.get("select[name='gebaeudeteil']").then(($dropdown) => {
const options = $dropdown.find('option');
// Select the option at the random index
cy.get("select[name='gebaeudeteil']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string);
});
// Lüftung
cy.get("select[name='lueftung']").then(($dropdown) => {
const options = $dropdown.find('option');
// Select the option at the random index
cy.get("select[name='lueftung']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string);
});
// Kühlung
cy.get("select[name='kuehlung']").then(($dropdown) => {
const options = $dropdown.find('option');
// Select the option at the random index
cy.get("select[name='kuehlung']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string, { force: true });
});
// Leerstand
cy.get("input[name='leerstand']").should("have.attr", "type", "number").type(faker.number.int({ min: 0, max: 30 }).toString());
// Heizungsanlage Daten
if (Math.random() > 0.5) cy.get("[data-cy='zentralheizung']").check();
if (Math.random() > 0.5) cy.get("[data-cy='einzelofen']").check();
if (Math.random() > 0.5) cy.get("[data-cy='durchlauf_erhitzer']").check();
if (Math.random() > 0.5) cy.get("[data-cy='standard_kessel']").check();
if (Math.random() > 0.5) cy.get("[data-cy='solarsystem_warmwasser']").check();
if (Math.random() > 0.5) cy.get("[data-cy='waermepumpe']").check();
if (Math.random() > 0.5) cy.get("[data-cy='niedertemperatur_kessel']").check();
if (Math.random() > 0.5) cy.get("[data-cy='brennwert_kessel']").check();
if (Math.random() > 0.5) cy.get("[data-cy='warmwasser_rohre_gedaemmt']").check();
if (Math.random() > 0.5) cy.get("[data-cy='heizungsrohre_gedaemmt']").check();
if (Math.random() > 0.5) cy.get("[data-cy='zirkulation']").check();
// if (Math.random() > 0.5) cy.get("[data-cy='raum_temperatur_regler']").check();
// Heizungsanlage Bilder
cy.get("input[name='heizung_image']").should("have.attr", "type", "file").attachFile("images/heizungsanlage/1.jpeg", { subjectType: "input" });
cy.get("input[name='heizung_image']").should("have.attr", "type", "file").attachFile("images/heizungsanlage/2.jpeg", { subjectType: "input" });
// Fenster Daten
if (Math.random() > 0.5) cy.get("input[name='einfach_verglasung']").check();
if (Math.random() > 0.5) cy.get("input[name='doppel_verglasung']").check();
if (Math.random() > 0.5) cy.get("input[name='isolier_verglasung']").check();
if (Math.random() > 0.5) cy.get("input[name='dreifach_verglasung']").check();
if (Math.random() > 0.5) cy.get("input[name='fenster_dicht']").check();
if (Math.random() > 0.5) cy.get("input[name='fenster_teilweise_undicht']").check();
if (Math.random() > 0.5) cy.get("input[name='tueren_dicht']").check();
if (Math.random() > 0.5) cy.get("input[name='tueren_undicht']").check();
if (Math.random() > 0.5) cy.get("input[name='rolllaeden_kaesten_gedaemmt']").check();
// Fenster Bilder
cy.get("input[name='fenster_image']").should("have.attr", "type", "file").attachFile("images/fenster/1.jpeg", { subjectType: "input" });
cy.get("input[name='fenster_image']").should("have.attr", "type", "file").attachFile("images/fenster/2.jpeg", { subjectType: "input" });
// Wärmedämmung Daten
if (Math.random() > 0.5) cy.get("input[name='aussenwand_gedaemmt']").check();
if (Math.random() > 0.5) cy.get("input[name='keller_wand_gedaemmt']").check();
if (Math.random() > 0.5) cy.get("input[name='keller_decke_gedaemmt']").check();
if (Math.random() > 0.5) cy.get("input[name='dachgeschoss_gedaemmt']").check();
if (Math.random() > 0.5) cy.get("input[name='oberste_geschossdecke_gedaemmt']").check();
if (Math.random() > 0.5) cy.get("input[name='oberste_geschossdecke_min_12cm_gedaemmt']").check();
// Wärmedämmung Bilder
cy.get("input[name='daemmung_image']").should("have.attr", "type", "file").attachFile("images/daemmung/1.jpeg", { subjectType: "input" });
cy.get("input[name='daemmung_image']").should("have.attr", "type", "file").attachFile("images/daemmung/2.jpeg", { subjectType: "input" });
// Gebäude Bild
cy.get("input[name='gebaeude_image']").should("have.attr", "type", "file").attachFile("images/gebaeude/1.jpeg", { subjectType: "input" });
// Jetzt können wir den Verbrauchsausweis erstellen.
cy.get("form[data-cy='ausweis'] button[data-cy='weiter']").click({ force: true });
cy.url().should("contain", "/kundendaten");
const email = faker.internet.email();
const passwort = "test1234";
const vorname = faker.person.firstName();
const nachname = faker.person.lastName();
const telefon = faker.phone.number()
const strasse = faker.location.streetAddress({ useFullAddress: true })
const plz = faker.location.zipCode("#####")
cy.get("input[name='vorname']").should("have.attr", "type", "text").type(vorname);
cy.get("input[name='name']").should("have.attr", "type", "text").type(nachname);
cy.get("input[name='telefon']").should("have.attr", "type", "text").type(telefon);
// Rechnung
cy.get("input[name='rechnung_empfaenger']").should("have.attr", "type", "text").type(`${vorname} ${nachname}`);
cy.get("input[name='rechnung_strasse']").should("have.attr", "type", "text").type(strasse);
cy.get("input[name='rechnung_plz']").should("have.attr", "type", "text").type(plz);
cy.get("[data-cy='plz-container']").children().first().click()
cy.get("input[name='rechnung_email']").should("have.attr", "type", "email").type(email);
cy.get("[data-cy='paypal']").click()
cy.get("button[data-cy='bestellen']").click();
cy.get("a[data-cy='registrieren']").should("be.visible").click();
// Wir sind jetzt registriert und können uns nun einloggen.
// Die Email sollte automatisch eingetragen sein, da wir uns gerade registriert haben.
cy.get("form[name='signup'] input[name='vorname']").should("be.visible").should("have.attr", "type", "text").type(vorname);
cy.get("form[name='signup'] input[name='nachname']").should("be.visible").should("have.attr", "type", "text").type(nachname);
cy.get("form[name='signup'] input[name='email']").should("be.visible").should("have.attr", "type", "email").should("contain.value", email);
cy.get("form[name='signup'] input[name='passwort']").should("be.visible").should("have.attr", "type", "password").type(passwort);
cy.intercept({ method: "PUT", url: "**/api/user" }).as("signup")
cy.get("form[name='signup'] button[type='submit']").click();
cy.wait("@signup")
cy.get("form[name='login'] button[type='submit']").click();
cy.origin('https://www.mollie.com', () => {
// Jetzt sind wir auf der Mollie Seite, dort wählen wir den "paid" status aus
cy.get("input[type='radio'][name='final_state'][value='paid']").check();
// Da wird unser Test fehlschlagen, da die localhost domain von Mollie aus nicht erreichbar ist.
})
})
});
});