fix: lint and build
Some checks failed
Build & Deploy / 🔍 Prepare Environment (push) Successful in 6s
Build & Deploy / 🧪 QA (push) Successful in 1m21s
Build & Deploy / 🏗️ Build (push) Failing after 4m36s
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🔔 Notifications (push) Successful in 2s
Some checks failed
Build & Deploy / 🔍 Prepare Environment (push) Successful in 6s
Build & Deploy / 🧪 QA (push) Successful in 1m21s
Build & Deploy / 🏗️ Build (push) Failing after 4m36s
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🔔 Notifications (push) Successful in 2s
This commit is contained in:
126
tests_bak/contact.test.tsx
Normal file
126
tests_bak/contact.test.tsx
Normal file
@@ -0,0 +1,126 @@
|
||||
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||
import Contact from "../app/kontakt/page";
|
||||
|
||||
// Mock fetch
|
||||
const fetchMock = vi.fn();
|
||||
global.fetch = fetchMock;
|
||||
|
||||
// Mock alert
|
||||
const alertMock = vi.fn();
|
||||
global.alert = alertMock;
|
||||
|
||||
describe("Contact Page", () => {
|
||||
beforeEach(() => {
|
||||
fetchMock.mockClear();
|
||||
alertMock.mockClear();
|
||||
});
|
||||
|
||||
it("renders the contact form correctly", () => {
|
||||
render(<Contact />);
|
||||
|
||||
expect(screen.getByLabelText(/Name \*/i)).toBeInTheDocument();
|
||||
expect(screen.getByLabelText(/Firma/i)).toBeInTheDocument();
|
||||
expect(screen.getByLabelText(/E-Mail \*/i)).toBeInTheDocument();
|
||||
expect(screen.getByLabelText(/Nachricht \*/i)).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("button", { name: /Nachricht senden/i }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("submits the form successfully", async () => {
|
||||
fetchMock.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: async () => ({ success: true }),
|
||||
});
|
||||
|
||||
render(<Contact />);
|
||||
|
||||
fireEvent.change(screen.getByLabelText(/Name \*/i), {
|
||||
target: { value: "John Doe" },
|
||||
});
|
||||
fireEvent.change(screen.getByLabelText(/Firma/i), {
|
||||
target: { value: "Acme Corp" },
|
||||
});
|
||||
fireEvent.change(screen.getByLabelText(/E-Mail \*/i), {
|
||||
target: { value: "john@example.com" },
|
||||
});
|
||||
fireEvent.change(screen.getByLabelText(/Nachricht \*/i), {
|
||||
target: { value: "This is a test message that is long enough." },
|
||||
});
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: /Nachricht senden/i }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
"/api/contact",
|
||||
expect.objectContaining({
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
name: "John Doe",
|
||||
company: "Acme Corp",
|
||||
email: "john@example.com",
|
||||
message: "This is a test message that is long enough.",
|
||||
website: "",
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
expect(screen.getByText(/Nachricht gesendet/i)).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText(/Vielen Dank für Ihre Anfrage/i),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("handles submission errors", async () => {
|
||||
fetchMock.mockResolvedValueOnce({
|
||||
ok: false,
|
||||
json: async () => ({ error: "Server error" }),
|
||||
});
|
||||
|
||||
render(<Contact />);
|
||||
|
||||
fireEvent.change(screen.getByLabelText(/Name \*/i), {
|
||||
target: { value: "John Doe" },
|
||||
});
|
||||
fireEvent.change(screen.getByLabelText(/E-Mail \*/i), {
|
||||
target: { value: "john@example.com" },
|
||||
});
|
||||
fireEvent.change(screen.getByLabelText(/Nachricht \*/i), {
|
||||
target: { value: "This is a test message that is long enough." },
|
||||
});
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: /Nachricht senden/i }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(alertMock).toHaveBeenCalledWith("Fehler: Server error");
|
||||
});
|
||||
});
|
||||
|
||||
it("handles network errors", async () => {
|
||||
fetchMock.mockRejectedValueOnce(new Error("Network error"));
|
||||
|
||||
render(<Contact />);
|
||||
|
||||
fireEvent.change(screen.getByLabelText(/Name \*/i), {
|
||||
target: { value: "John Doe" },
|
||||
});
|
||||
fireEvent.change(screen.getByLabelText(/E-Mail \*/i), {
|
||||
target: { value: "john@example.com" },
|
||||
});
|
||||
fireEvent.change(screen.getByLabelText(/Nachricht \*/i), {
|
||||
target: { value: "This is a test message that is long enough." },
|
||||
});
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: /Nachricht senden/i }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(alertMock).toHaveBeenCalledWith(
|
||||
"Es gab einen Fehler beim Senden Ihrer Nachricht.",
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
27
tests_bak/home.test.tsx
Normal file
27
tests_bak/home.test.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { describe, it, expect } from "vitest";
|
||||
import Home from "../app/page";
|
||||
|
||||
describe("Home Page", () => {
|
||||
it("renders the hero section with correct title", () => {
|
||||
render(<Home />);
|
||||
expect(
|
||||
screen.getByText(/Spezialisierter Partner für Energiekabelprojekte/i),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("contains the CTA button", () => {
|
||||
render(<Home />);
|
||||
const ctaButton = screen.getByRole("link", { name: /Projekt anfragen/i });
|
||||
expect(ctaButton).toBeInTheDocument();
|
||||
expect(ctaButton).toHaveAttribute("href", "/kontakt");
|
||||
});
|
||||
|
||||
it("renders the portfolio section", () => {
|
||||
render(<Home />);
|
||||
expect(screen.getByText(/Unsere Leistungen/i)).toBeInTheDocument();
|
||||
// Use getAllByText because it appears in both hero description and card title
|
||||
const elements = screen.getAllByText(/Technische Beratung/i);
|
||||
expect(elements.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
12
tests_bak/setup.ts
Normal file
12
tests_bak/setup.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import "@testing-library/jest-dom";
|
||||
import { vi } from "vitest";
|
||||
|
||||
// Mock next/navigation
|
||||
vi.mock("next/navigation", () => ({
|
||||
usePathname: () => "/",
|
||||
useRouter: () => ({
|
||||
push: vi.fn(),
|
||||
replace: vi.fn(),
|
||||
prefetch: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
Reference in New Issue
Block a user