119 lines
4.8 KiB
TypeScript
119 lines
4.8 KiB
TypeScript
import fuelList from "#components/Ausweis/brennstoffListe.js";
|
|
import { faker } from "@faker-js/faker";
|
|
import { Enums } from "#lib/client/prisma.js";
|
|
|
|
|
|
import "cypress-file-upload"
|
|
import moment from "moment";
|
|
|
|
describe("Verbrauchsausweis erstellen Schritt 1", () => {
|
|
it("erstellt einen neuen Verbrauchsausweis Wohngebäude.", () => {
|
|
cy.task("plz").then(plz => {
|
|
cy.visit("/angebot-anfragen/geg-nachweis-wohnen-anfragen");
|
|
|
|
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']")
|
|
.select(
|
|
faker.number.int({
|
|
min: 1,
|
|
max: [Enums.Ausstellgrund.Modernisierung, Enums.Ausstellgrund.Neubau].length - 1,
|
|
})
|
|
)
|
|
|
|
// 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);
|
|
});
|
|
|
|
// 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 }
|
|
);
|
|
|
|
// Adresse
|
|
cy.get("input[name='adresse']").type(faker.location.streetAddress());
|
|
|
|
// Postleitzahl
|
|
cy.get("input[name='plz']").type(
|
|
plz as string
|
|
);
|
|
|
|
// 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()
|
|
|
|
// 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);
|
|
});
|
|
|
|
// 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: Object.values(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: Object.values(Enums.Heizungsstatus).length,
|
|
min: 1
|
|
}));
|
|
|
|
cy.get("[data-cy='beschreibung']").type(faker.lorem.paragraphs({ min: 2, max: 10 }))
|
|
|
|
// Wärmedämmung Bilder
|
|
cy.get("input[type='file'][name='plaene']").should("have.attr", "type", "file").attachFile("images/daemmung/1.jpeg", { subjectType: "input" }).attachFile("images/daemmung/2.jpeg", { subjectType: "input" });
|
|
cy.get("input[type='file'][name='unterlagen']").should("have.attr", "type", "file").attachFile("images/gebaeude/1.jpeg", { subjectType: "input" }).attachFile("images/daemmung/2.jpeg", { subjectType: "input" });
|
|
|
|
// Jetzt können wir den Verbrauchsausweis erstellen.
|
|
cy.get("form[data-cy='nachweis'] 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 })
|
|
|
|
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 as string);
|
|
cy.get("[data-cy='plz-container']").children().first().click()
|
|
cy.get("input[name='rechnung_email']").should("have.attr", "type", "email").type(email);
|
|
|
|
cy.get("button[data-cy='bestellen']").click();
|
|
|
|
cy.intercept({ method: "PUT", url: "**/api/rechnung/anfordern" }).as("anfordern")
|
|
cy["form:signup"](email, passwort, vorname, nachname)
|
|
cy.wait("@anfordern")
|
|
|
|
cy.url().should("contain", "/einpreisung/success")
|
|
});
|
|
});
|
|
});
|