Files
school_compare/nextjs-app/__tests__/components/SchoolCard.test.tsx
T
TudorandClaude Fable 5 4a52735356
PR Checks / Frontend Typecheck + Tests (pull_request) Successful in 10m0s
PR Checks / Backend Smoke (pull_request) Successful in 48s
PR Checks / Build Backend (no push) (pull_request) Successful in 17s
PR Checks / Build Frontend (no push) (pull_request) Successful in 41s
PR Checks / Build Pipeline (no push) (pull_request) Successful in 10s
PR Checks / AI Code Review (Claude) (pull_request) Successful in 24s
feat(sdlc): staging environment + automated staging→prod pipeline
- pr-checks.yml: PR gate — frontend typecheck+jest, backend import smoke,
  image builds (no push), Claude AI review posted as PR comment (severe
  findings block merge)
- deploy.yml (replaces build-and-push.yml): merge to main builds+pushes
  images tagged sha-<sha>/staging, deploys the staging Portainer stack via
  webhook, runs Playwright E2E journeys against staging, then retags the
  verified images :prod (previous kept as :prod-previous) and deploys prod
- docker-compose.portainer.staging.yml: second Portainer stack — :staging
  images, sc_staging_* names, own macvlan IPs, Airflow on 8081; data
  bootstrapped from source via the staging Airflow DAGs
- prod compose now pins :prod instead of :latest (only the promotion step
  moves it; :latest is no longer published)
- e2e/: 6 Playwright journeys (search, postcode, detail, compare, rankings)
  driven by BASE_URL — the promotion gate
- scripts/ci/ai_review.py: Claude review with structured JSON findings
- docs/DEPLOY.md: full SDLC doc incl. one-time setup checklist and rollback
- replaced removed 'next lint' with tsc typecheck; fixed stale jest tests
  (slug URLs, N/A formatting, stable trend, fake-timer setup)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PqGhF93UrpDNvXBLMjJENL
2026-07-03 06:50:40 +01:00

64 lines
2.0 KiB
TypeScript

/**
* SchoolCard Component Tests
*/
import '@testing-library/jest-dom';
import { render, screen, fireEvent } from '@testing-library/react';
import { SchoolCard } from '@/components/SchoolCard';
import type { School } from '@/lib/types';
const mockSchool = {
urn: 100001,
school_name: 'Test Primary School',
local_authority: 'Westminster',
school_type: 'Academy',
address: '123 Test Street',
postcode: 'SW1A 1AA',
latitude: 51.5074,
longitude: -0.1278,
rwm_expected_pct: 75.5,
prev_rwm_expected_pct: 70.0,
} as School;
describe('SchoolCard', () => {
it('renders school information correctly', () => {
render(<SchoolCard school={mockSchool} />);
expect(screen.getByText('Test Primary School')).toBeInTheDocument();
expect(screen.getByText('Westminster')).toBeInTheDocument();
expect(screen.getByText('Academy')).toBeInTheDocument();
expect(screen.getByText('75.5%')).toBeInTheDocument();
});
it('links to school detail page', () => {
render(<SchoolCard school={mockSchool} />);
const link = screen.getByRole('link', { name: /test primary school/i });
expect(link).toHaveAttribute('href', '/school/100001-test-primary-school');
});
it('calls onAddToCompare when the Compare button is clicked', () => {
const mockAddToCompare = jest.fn();
render(<SchoolCard school={mockSchool} onAddToCompare={mockAddToCompare} />);
const addButton = screen.getByText('+ Compare');
fireEvent.click(addButton);
expect(mockAddToCompare).toHaveBeenCalledWith(mockSchool);
expect(mockAddToCompare).toHaveBeenCalledTimes(1);
});
it('does not render the Compare button when handler not provided', () => {
render(<SchoolCard school={mockSchool} />);
expect(screen.queryByText('+ Compare')).not.toBeInTheDocument();
});
it('displays trend indicator for positive change', () => {
render(<SchoolCard school={mockSchool} />);
// Should show upward trend (75.5 > 70.0)
expect(screen.getByTitle('Previous year: 70.0%')).toBeInTheDocument();
});
});