Initialize HemHub project foundation
This commit is contained in:
21
frontend/src/App.test.tsx
Normal file
21
frontend/src/App.test.tsx
Normal file
@ -0,0 +1,21 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { afterEach, expect, test, vi } from 'vitest'
|
||||
import App from './App'
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
test('visar sidans rubrik', () => {
|
||||
vi.spyOn(globalThis, 'fetch').mockResolvedValue(
|
||||
new Response(JSON.stringify({ status: 'UP' }), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
}),
|
||||
)
|
||||
|
||||
render(<App />)
|
||||
|
||||
expect(screen.getByRole('heading', { name: 'HemHub' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
48
frontend/src/App.tsx
Normal file
48
frontend/src/App.tsx
Normal file
@ -0,0 +1,48 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
type HealthResponse = {
|
||||
status: string
|
||||
}
|
||||
|
||||
function App() {
|
||||
const [backendStatus, setBackendStatus] = useState<string | null>(null)
|
||||
const [hasError, setHasError] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
const loadHealth = async () => {
|
||||
try {
|
||||
const response = await fetch('/api/health')
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Backend svarade med status ${response.status}`)
|
||||
}
|
||||
|
||||
const health = (await response.json()) as HealthResponse
|
||||
setBackendStatus(health.status)
|
||||
} catch {
|
||||
setHasError(true)
|
||||
}
|
||||
}
|
||||
|
||||
void loadHealth()
|
||||
}, [])
|
||||
|
||||
let statusMessage = 'Kontrollerar backend…'
|
||||
|
||||
if (hasError) {
|
||||
statusMessage = 'Backend kunde inte nås'
|
||||
} else if (backendStatus) {
|
||||
statusMessage = `Backend: ${backendStatus}`
|
||||
}
|
||||
|
||||
return (
|
||||
<main>
|
||||
<h1>HemHub</h1>
|
||||
<p>Frontend har startat.</p>
|
||||
<p aria-live="polite">{statusMessage}</p>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
|
||||
11
frontend/src/main.tsx
Normal file
11
frontend/src/main.tsx
Normal file
@ -0,0 +1,11 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import App from './App'
|
||||
import './styles.css'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
||||
|
||||
23
frontend/src/styles.css
Normal file
23
frontend/src/styles.css
Normal file
@ -0,0 +1,23 @@
|
||||
:root {
|
||||
font-family: system-ui, sans-serif;
|
||||
color: #1f2937;
|
||||
background: #f3f4f6;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
main {
|
||||
max-width: 40rem;
|
||||
margin: 6rem auto;
|
||||
padding: 2rem;
|
||||
border-radius: 0.75rem;
|
||||
background: white;
|
||||
box-shadow: 0 0.25rem 1rem rgb(0 0 0 / 8%);
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
2
frontend/src/test/setup.ts
Normal file
2
frontend/src/test/setup.ts
Normal file
@ -0,0 +1,2 @@
|
||||
import '@testing-library/jest-dom/vitest'
|
||||
|
||||
1
frontend/src/vite-env.d.ts
vendored
Normal file
1
frontend/src/vite-env.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
||||
Reference in New Issue
Block a user