Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f7685fdb2f | |||
| 609422b5b9 | |||
| 76cf6e7b62 | |||
| cc04b71327 | |||
| 1d5d86d07c | |||
| e2b7131adc | |||
| c2ced7185b |
@@ -251,14 +251,13 @@ jobs:
|
|||||||
DIRECTUS_KEY=${{ secrets.DIRECTUS_KEY || vars.DIRECTUS_KEY }}
|
DIRECTUS_KEY=${{ secrets.DIRECTUS_KEY || vars.DIRECTUS_KEY }}
|
||||||
DIRECTUS_SECRET=${{ secrets.DIRECTUS_SECRET || vars.DIRECTUS_SECRET }}
|
DIRECTUS_SECRET=${{ secrets.DIRECTUS_SECRET || vars.DIRECTUS_SECRET }}
|
||||||
|
|
||||||
# SMTP Config
|
# Mail
|
||||||
SMTP_HOST=${{ secrets.SMTP_HOST || vars.SMTP_HOST }}
|
MAIL_HOST=${{ secrets.SMTP_HOST || vars.SMTP_HOST }}
|
||||||
SMTP_PORT=${{ secrets.SMTP_PORT || vars.SMTP_PORT || '587' }}
|
MAIL_PORT=${{ secrets.SMTP_PORT || vars.SMTP_PORT || '587' }}
|
||||||
SMTP_SECURE=${{ secrets.SMTP_SECURE || vars.SMTP_SECURE || 'false' }}
|
MAIL_USERNAME=${{ secrets.SMTP_USER || vars.SMTP_USER }}
|
||||||
SMTP_USER=${{ secrets.SMTP_USER || vars.SMTP_USER }}
|
MAIL_PASSWORD=${{ secrets.SMTP_PASS || vars.SMTP_PASS }}
|
||||||
SMTP_PASS=${{ secrets.SMTP_PASS || vars.SMTP_PASS }}
|
MAIL_FROM=${{ secrets.SMTP_FROM || vars.SMTP_FROM }}
|
||||||
SMTP_FROM=${{ secrets.SMTP_FROM || vars.SMTP_FROM }}
|
MAIL_RECIPIENTS=${{ secrets.CONTACT_RECIPIENT || vars.CONTACT_RECIPIENT }}
|
||||||
CONTACT_RECIPIENT=${{ secrets.CONTACT_RECIPIENT || vars.CONTACT_RECIPIENT }}
|
|
||||||
|
|
||||||
# Authentication
|
# Authentication
|
||||||
GATEKEEPER_PASSWORD=${{ secrets.GATEKEEPER_PASSWORD || vars.GATEKEEPER_PASSWORD }}
|
GATEKEEPER_PASSWORD=${{ secrets.GATEKEEPER_PASSWORD || vars.GATEKEEPER_PASSWORD }}
|
||||||
@@ -289,7 +288,7 @@ jobs:
|
|||||||
|
|
||||||
echo "${{ secrets.REGISTRY_PASS }}" | docker login registry.infra.mintel.me -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
echo "${{ secrets.REGISTRY_PASS }}" | docker login registry.infra.mintel.me -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
||||||
docker compose -p "${{ needs.prepare.outputs.project_name }}" --env-file ${{ needs.prepare.outputs.env_file }} pull
|
docker compose -p "${{ needs.prepare.outputs.project_name }}" --env-file ${{ needs.prepare.outputs.env_file }} pull
|
||||||
docker compose -p "${{ needs.prepare.outputs.project_name }}" --env-file ${{ needs.prepare.outputs.env_file }} up -d --remove-orphans
|
docker compose -p "${{ needs.prepare.outputs.project_name }}" --env-file ${{ needs.prepare.outputs.env_file }} up -d --wait --remove-orphans
|
||||||
docker system prune -f --filter "until=24h"
|
docker system prune -f --filter "until=24h"
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ ENV NEXT_PUBLIC_TARGET=$NEXT_PUBLIC_TARGET
|
|||||||
ENV DIRECTUS_URL=$DIRECTUS_URL
|
ENV DIRECTUS_URL=$DIRECTUS_URL
|
||||||
ENV NPM_TOKEN=$NPM_TOKEN
|
ENV NPM_TOKEN=$NPM_TOKEN
|
||||||
ENV SENTRY_SUPPRESS_TURBOPACK_WARNING=1
|
ENV SENTRY_SUPPRESS_TURBOPACK_WARNING=1
|
||||||
|
ENV SKIP_RUNTIME_ENV_VALIDATION=true
|
||||||
|
|
||||||
# Enable corepack
|
# Enable corepack
|
||||||
RUN corepack enable
|
RUN corepack enable
|
||||||
@@ -37,13 +38,19 @@ RUN pnpm build
|
|||||||
|
|
||||||
# Production runner image
|
# Production runner image
|
||||||
FROM registry.infra.mintel.me/mintel/runtime:latest AS runner
|
FROM registry.infra.mintel.me/mintel/runtime:latest AS runner
|
||||||
WORKDIR /app
|
# Production environment configuration
|
||||||
|
ENV HOSTNAME="0.0.0.0"
|
||||||
|
ENV PORT=3000
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
# Copy standalone output and static files
|
# Copy standalone output and static files
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
|
# Ensure the cache directory specifically is writeable (Mintel Standard #16)
|
||||||
|
RUN mkdir -p .next/cache && chown -R nextjs:nodejs .next/cache
|
||||||
|
|
||||||
USER nextjs
|
USER nextjs
|
||||||
|
|
||||||
CMD ["node", "server.js"]
|
CMD ["node", "server.js"]
|
||||||
|
|||||||
@@ -71,9 +71,9 @@ export default async function RootLayout({
|
|||||||
params,
|
params,
|
||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
params: { locale: string };
|
params: Promise<{ locale: string }>;
|
||||||
}) {
|
}) {
|
||||||
const { locale } = params;
|
const { locale } = await params;
|
||||||
|
|
||||||
// Validate that the incoming `locale` is supported
|
// Validate that the incoming `locale` is supported
|
||||||
if (locale !== "de") {
|
if (locale !== "de") {
|
||||||
|
|||||||
@@ -47,7 +47,14 @@ export async function POST(req: Request) {
|
|||||||
logger.info("Contact submission saved to Directus");
|
logger.info("Contact submission saved to Directus");
|
||||||
directusSaved = true;
|
directusSaved = true;
|
||||||
} catch (directusError) {
|
} catch (directusError) {
|
||||||
logger.error("Failed to save to Directus", { error: directusError });
|
const errorMessage =
|
||||||
|
directusError instanceof Error
|
||||||
|
? directusError.message
|
||||||
|
: String(directusError);
|
||||||
|
logger.error("Failed to save to Directus", {
|
||||||
|
error: errorMessage,
|
||||||
|
details: directusError,
|
||||||
|
});
|
||||||
services.errors.captureException(directusError, {
|
services.errors.captureException(directusError, {
|
||||||
phase: "directus_save",
|
phase: "directus_save",
|
||||||
});
|
});
|
||||||
@@ -56,19 +63,20 @@ export async function POST(req: Request) {
|
|||||||
|
|
||||||
// 2. Email sending
|
// 2. Email sending
|
||||||
try {
|
try {
|
||||||
|
const { config } = await import("@/lib/config");
|
||||||
const transporter = nodemailer.createTransport({
|
const transporter = nodemailer.createTransport({
|
||||||
host: process.env.SMTP_HOST,
|
host: config.mail.host,
|
||||||
port: parseInt(process.env.SMTP_PORT || "587"),
|
port: config.mail.port,
|
||||||
secure: process.env.SMTP_SECURE === "true",
|
secure: config.mail.port === 465,
|
||||||
auth: {
|
auth: {
|
||||||
user: process.env.SMTP_USER,
|
user: config.mail.user,
|
||||||
pass: process.env.SMTP_PASS,
|
pass: config.mail.pass,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await transporter.sendMail({
|
await transporter.sendMail({
|
||||||
from: process.env.SMTP_FROM,
|
from: config.mail.from,
|
||||||
to: process.env.CONTACT_RECIPIENT || "info@mb-grid-solutions.com",
|
to: config.mail.recipients.join(",") || "info@mb-grid-solutions.com",
|
||||||
replyTo: email,
|
replyTo: email,
|
||||||
subject: `Kontaktanfrage von ${name}`,
|
subject: `Kontaktanfrage von ${name}`,
|
||||||
text: `
|
text: `
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import { Button } from "./Button";
|
|||||||
import { Counter } from "./Counter";
|
import { Counter } from "./Counter";
|
||||||
import { Reveal } from "./Reveal";
|
import { Reveal } from "./Reveal";
|
||||||
import { TechBackground } from "./TechBackground";
|
import { TechBackground } from "./TechBackground";
|
||||||
import { TileGrid } from "./TileGrid";
|
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
@@ -80,7 +79,6 @@ export default function Home() {
|
|||||||
<div className="absolute inset-0 bg-gradient-to-r from-slate-100/80 via-white/90 to-white/40 md:to-transparent" />
|
<div className="absolute inset-0 bg-gradient-to-r from-slate-100/80 via-white/90 to-white/40 md:to-transparent" />
|
||||||
<TechBackground />
|
<TechBackground />
|
||||||
</div>
|
</div>
|
||||||
<TileGrid />
|
|
||||||
|
|
||||||
<div className="container-custom relative z-10">
|
<div className="container-custom relative z-10">
|
||||||
<div className="text-left relative">
|
<div className="text-left relative">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { AnimatePresence, m, LazyMotion, domAnimation } from "framer-motion";
|
import { AnimatePresence, m } from "framer-motion";
|
||||||
import { ArrowUp, Home, Info, Menu, X } from "lucide-react";
|
import { ArrowUp, Home, Info, Menu, X } from "lucide-react";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
import React, { useEffect, useState } from "react";
|
|
||||||
import { m } from "framer-motion";
|
|
||||||
|
|
||||||
export const TileGrid = () => {
|
|
||||||
const [mounted, setMounted] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setMounted(true);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
if (!mounted) return null;
|
|
||||||
|
|
||||||
const rows = 7;
|
|
||||||
const cols = 8;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="absolute inset-0 pointer-events-none overflow-hidden z-[1]">
|
|
||||||
<div className="flex flex-col gap-8 md:gap-12 min-w-[120%] min-h-[120%] -left-[10%] -top-[10%] absolute">
|
|
||||||
{[...Array(rows)].map((_, rowIndex) => (
|
|
||||||
<div
|
|
||||||
key={rowIndex}
|
|
||||||
className="flex gap-8 md:gap-12 justify-center"
|
|
||||||
style={{
|
|
||||||
transform:
|
|
||||||
rowIndex % 2 === 0 ? "translateX(0)" : "translateX(100px)",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{[...Array(cols)].map((_, colIndex) => (
|
|
||||||
<m.div
|
|
||||||
key={`${rowIndex}-${colIndex}`}
|
|
||||||
initial={{ opacity: 0.03 }}
|
|
||||||
animate={{
|
|
||||||
opacity: [0.03, Math.random() > 0.8 ? 0.15 : 0.03, 0.03],
|
|
||||||
scale: [1, Math.random() > 0.8 ? 1.02 : 1, 1],
|
|
||||||
}}
|
|
||||||
transition={{
|
|
||||||
duration: 8 + Math.random() * 8,
|
|
||||||
repeat: Infinity,
|
|
||||||
delay: Math.random() * 15,
|
|
||||||
ease: "easeInOut",
|
|
||||||
}}
|
|
||||||
className="w-32 h-32 md:w-56 md:h-56 bg-white/5 rounded-3xl md:rounded-[3rem] border border-white/10 shadow-[0_8px_32px_0_rgba(31,38,135,0.03)] shrink-0 will-change-transform"
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -27,6 +27,12 @@ services:
|
|||||||
- "traefik.http.middlewares.${PROJECT_NAME}-auth.forwardauth.trustForwardHeader=true"
|
- "traefik.http.middlewares.${PROJECT_NAME}-auth.forwardauth.trustForwardHeader=true"
|
||||||
- "traefik.http.middlewares.${PROJECT_NAME}-auth.forwardauth.authResponseHeaders=X-Auth-User"
|
- "traefik.http.middlewares.${PROJECT_NAME}-auth.forwardauth.authResponseHeaders=X-Auth-User"
|
||||||
- "traefik.docker.network=infra"
|
- "traefik.docker.network=infra"
|
||||||
|
healthcheck:
|
||||||
|
test: [ "CMD", "node", "-e", "fetch('http://127.0.0.1:3000/api/health').then(r => r.ok ? process.exit(0) : process.exit(1)).catch(() => process.exit(1))" ]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
start_period: 30s
|
||||||
|
|
||||||
gatekeeper:
|
gatekeeper:
|
||||||
image: registry.infra.mintel.me/mintel/gatekeeper:latest
|
image: registry.infra.mintel.me/mintel/gatekeeper:latest
|
||||||
|
|||||||
@@ -23,15 +23,21 @@ export async function ensureAuthenticated() {
|
|||||||
if (adminEmail && password) {
|
if (adminEmail && password) {
|
||||||
try {
|
try {
|
||||||
await client.login({ email: adminEmail, password: password });
|
await client.login({ email: adminEmail, password: password });
|
||||||
|
return;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (typeof window === "undefined") {
|
if (typeof window === "undefined") {
|
||||||
getServerAppServices().errors.captureException(e, {
|
getServerAppServices().errors.captureException(e, {
|
||||||
phase: "directus_auth",
|
phase: "directus_auth_fallback",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.error("Failed to authenticate with Directus login fallback:", e);
|
console.error("Failed to authenticate with Directus login fallback:", e);
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
"Missing Directus authentication credentials (token or admin email/password)",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default client;
|
export default client;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ REMOTE_DIR="/home/deploy/sites/${PRJ_ID}.com"
|
|||||||
case $ENV in
|
case $ENV in
|
||||||
testing) PROJECT_NAME="${PRJ_ID}-testing"; ENV_FILE=".env.testing" ;;
|
testing) PROJECT_NAME="${PRJ_ID}-testing"; ENV_FILE=".env.testing" ;;
|
||||||
staging) PROJECT_NAME="${PRJ_ID}-staging"; ENV_FILE=".env.staging" ;;
|
staging) PROJECT_NAME="${PRJ_ID}-staging"; ENV_FILE=".env.staging" ;;
|
||||||
production) PROJECT_NAME="${PRJ_ID}-prod"; ENV_FILE=".env.prod" ;;
|
production) PROJECT_NAME="${PRJ_ID}-production"; ENV_FILE=".env.prod" ;;
|
||||||
*) echo "❌ Invalid environment: $ENV"; exit 1 ;;
|
*) echo "❌ Invalid environment: $ENV"; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@@ -35,8 +35,21 @@ DB_NAME="directus"
|
|||||||
|
|
||||||
echo "🔍 Detecting local database..."
|
echo "🔍 Detecting local database..."
|
||||||
LOCAL_DB_CONTAINER=$(docker compose ps -q directus-db)
|
LOCAL_DB_CONTAINER=$(docker compose ps -q directus-db)
|
||||||
|
|
||||||
if [ -z "$LOCAL_DB_CONTAINER" ]; then
|
if [ -z "$LOCAL_DB_CONTAINER" ]; then
|
||||||
echo "❌ Local directus-db container not found. Is it running? (npm run dev)"
|
# Check if it exists but is stopped
|
||||||
|
LOCAL_DB_EXISTS=$(docker compose ps -a -q directus-db)
|
||||||
|
if [ -n "$LOCAL_DB_EXISTS" ]; then
|
||||||
|
echo "⏳ Local directus-db is stopped. Starting it..."
|
||||||
|
docker compose up -d directus-db
|
||||||
|
# Wait a few seconds for PG to be ready
|
||||||
|
sleep 2
|
||||||
|
LOCAL_DB_CONTAINER=$(docker compose ps -q directus-db)
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$LOCAL_DB_CONTAINER" ]; then
|
||||||
|
echo "❌ Local directus-db container not found. Is it defined in docker-compose.yaml?"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
0
tests/.gitkeep
Normal file
0
tests/.gitkeep
Normal file
@@ -1,97 +0,0 @@
|
|||||||
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.')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
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)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
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(),
|
|
||||||
}),
|
|
||||||
}))
|
|
||||||
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(),
|
||||||
|
}),
|
||||||
|
}));
|
||||||
@@ -13,5 +13,5 @@
|
|||||||
".next/types/**/*.ts",
|
".next/types/**/*.ts",
|
||||||
".next/dev/types/**/*.ts"
|
".next/dev/types/**/*.ts"
|
||||||
],
|
],
|
||||||
"exclude": ["node_modules"]
|
"exclude": ["node_modules", "tests", "tests_bak"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user