From 5108fce0ab292f2d9509a12e047bffb3a6b197fd Mon Sep 17 00:00:00 2001 From: Justin Wang Date: Wed, 4 Nov 2026 22:27:16 -0500 Subject: [PATCH 01/16] MSPCA-51: add volunteer helpers, getVolunteer, and useVolunteerId Co-Authored-By: Claude Opus 5.5 --- apps/frontend/src/api/apiClient.ts | 10 ++++ .../src/utils/useVolunteerId.spec.tsx | 27 +++++++++++ apps/frontend/src/utils/useVolunteerId.ts | 12 +++++ apps/frontend/src/utils/volunteer.spec.ts | 47 +++++++++++++++++++ apps/frontend/src/utils/volunteer.ts | 25 ++++++++++ 5 files changed, 121 insertions(+) create mode 100644 apps/frontend/src/utils/useVolunteerId.spec.tsx create mode 100644 apps/frontend/src/utils/useVolunteerId.ts create mode 100644 apps/frontend/src/utils/volunteer.spec.ts create mode 100644 apps/frontend/src/utils/volunteer.ts diff --git a/apps/frontend/src/api/apiClient.ts b/apps/frontend/src/api/apiClient.ts index 4a1c6d739..8355dd3eb 100644 --- a/apps/frontend/src/api/apiClient.ts +++ b/apps/frontend/src/api/apiClient.ts @@ -22,6 +22,12 @@ export interface Animal { restrictions?: string[]; } +export interface Volunteer { + volunteerId: number; + firstName: string; + lastName: string; +} + export interface CreateMatchBody { volunteerId: number; chameleonAnimalId: number; @@ -79,6 +85,10 @@ export class ApiClient { return this.get('/api/animals') as Promise; } + public async getVolunteer(volunteerId: number): Promise { + return this.get(`/api/volunteers/${volunteerId}`) as Promise; + } + public async createMatch(body: CreateMatchBody): Promise { return this.post('/api/matches', body) as Promise; } diff --git a/apps/frontend/src/utils/useVolunteerId.spec.tsx b/apps/frontend/src/utils/useVolunteerId.spec.tsx new file mode 100644 index 000000000..8ffbdb5ff --- /dev/null +++ b/apps/frontend/src/utils/useVolunteerId.spec.tsx @@ -0,0 +1,27 @@ +import { render } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; + +import { useVolunteerId } from './useVolunteerId'; + +const Probe: React.FC = () => {String(useVolunteerId())}; + +const renderAt = (route: string) => + render( + + + , + ); + +describe('useVolunteerId', () => { + it('reads volunteerId from the query string', () => { + expect(renderAt('/x?volunteerId=7').getByText('7')).toBeTruthy(); + }); + + it('returns null when volunteerId is missing', () => { + expect(renderAt('/x').getByText('null')).toBeTruthy(); + }); + + it('returns null when volunteerId is not a valid ID', () => { + expect(renderAt('/x?volunteerId=abc').getByText('null')).toBeTruthy(); + }); +}); diff --git a/apps/frontend/src/utils/useVolunteerId.ts b/apps/frontend/src/utils/useVolunteerId.ts new file mode 100644 index 000000000..3f3a1a809 --- /dev/null +++ b/apps/frontend/src/utils/useVolunteerId.ts @@ -0,0 +1,12 @@ +import { useSearchParams } from 'react-router-dom'; + +import { parseVolunteerId } from './volunteer'; + +/** + * The current volunteer's ID, read from the `?volunteerId=` query param. + * TEMPORARY: replace with the signed-in volunteer once sign-in is implemented. + */ +export const useVolunteerId = (): number | null => { + const [searchParams] = useSearchParams(); + return parseVolunteerId(searchParams.get('volunteerId')); +}; diff --git a/apps/frontend/src/utils/volunteer.spec.ts b/apps/frontend/src/utils/volunteer.spec.ts new file mode 100644 index 000000000..a3c53a837 --- /dev/null +++ b/apps/frontend/src/utils/volunteer.spec.ts @@ -0,0 +1,47 @@ +import { getAvatarColor, getInitials, parseVolunteerId } from './volunteer'; + +describe('getInitials', () => { + it('uses the first letter of each name', () => { + expect(getInitials('Matt', 'Wong')).toBe('MW'); + }); + + it('trims whitespace and uppercases', () => { + expect(getInitials(' anna ', 'lee')).toBe('AL'); + }); + + it('returns an empty string when both names are empty', () => { + expect(getInitials('', '')).toBe(''); + }); + + it('returns a single initial when the last name is empty', () => { + expect(getInitials('Cher', '')).toBe('C'); + }); +}); + +describe('getAvatarColor', () => { + it('maps volunteer IDs onto the palette in order', () => { + expect(getAvatarColor(0)).toBe('purple.avatar'); + expect(getAvatarColor(1)).toBe('blue.blue2'); + }); + + it('wraps around the palette', () => { + expect(getAvatarColor(6)).toBe('purple.avatar'); + }); + + it('is stable for the same volunteer', () => { + expect(getAvatarColor(42)).toBe(getAvatarColor(42)); + }); +}); + +describe('parseVolunteerId', () => { + it('parses a positive integer', () => { + expect(parseVolunteerId('12')).toBe(12); + }); + + it.each([null, '', 'abc', '0', '-3', '1.5', '12abc'])( + 'returns null for %j', + (raw) => { + expect(parseVolunteerId(raw)).toBeNull(); + }, + ); +}); diff --git a/apps/frontend/src/utils/volunteer.ts b/apps/frontend/src/utils/volunteer.ts new file mode 100644 index 000000000..4efda92ba --- /dev/null +++ b/apps/frontend/src/utils/volunteer.ts @@ -0,0 +1,25 @@ +// Avatar background colors, picked by volunteer ID so each volunteer keeps the +// same color. Placeholder palette pending design confirmation. +export const AVATAR_COLORS: readonly string[] = [ + 'purple.avatar', + 'blue.blue2', + 'teal.teal', + 'green.green2', + 'orange.orange3', + 'brown.brown', +]; + +const initial = (name: string): string => name.trim().charAt(0).toUpperCase(); + +export const getInitials = (firstName: string, lastName: string): string => + initial(firstName) + initial(lastName); + +export const getAvatarColor = (volunteerId: number): string => + AVATAR_COLORS[volunteerId % AVATAR_COLORS.length]; + +/** Parses a volunteer ID from a URL value; anything but a positive integer is null. */ +export const parseVolunteerId = (raw: string | null): number | null => { + if (raw === null || !/^\d+$/.test(raw)) return null; + const id = Number(raw); + return id > 0 ? id : null; +}; From f36f43e4288a0d4cfa8da21b5b52d147b6335930 Mon Sep 17 00:00:00 2001 From: Justin Wang Date: Wed, 4 Nov 2026 22:32:23 -0500 Subject: [PATCH 02/16] MSPCA-51: add responsive Navbar component Co-Authored-By: Claude Opus 5.5 --- apps/frontend/src/components/Navbar.spec.tsx | 96 +++++++++++++++++ apps/frontend/src/components/Navbar.tsx | 102 +++++++++++++++++++ apps/frontend/src/testUtils.tsx | 16 +++ 3 files changed, 214 insertions(+) create mode 100644 apps/frontend/src/components/Navbar.spec.tsx create mode 100644 apps/frontend/src/components/Navbar.tsx create mode 100644 apps/frontend/src/testUtils.tsx diff --git a/apps/frontend/src/components/Navbar.spec.tsx b/apps/frontend/src/components/Navbar.spec.tsx new file mode 100644 index 000000000..5fced37bc --- /dev/null +++ b/apps/frontend/src/components/Navbar.spec.tsx @@ -0,0 +1,96 @@ +import { fireEvent, waitFor } from '@testing-library/react'; +import { useNavigate } from 'react-router-dom'; +import type { Mock } from 'vitest'; + +import apiClient, { type Volunteer } from '@api/apiClient'; +import { renderWithProviders } from '../testUtils'; +import Navbar from './Navbar'; + +vi.mock('@api/apiClient', () => ({ + default: { getVolunteer: vi.fn() }, +})); + +const getVolunteer = apiClient.getVolunteer as Mock; + +const volunteer = ( + volunteerId: number, + firstName: string, + lastName: string, +): Volunteer => ({ volunteerId, firstName, lastName }); + +const GoTo: React.FC<{ to: string }> = ({ to }) => { + const navigate = useNavigate(); + return ; +}; + +const avatarText = (container: ReturnType) => + container.getByTestId('navbar-avatar').textContent; + +describe('Navbar', () => { + beforeEach(() => { + getVolunteer.mockReset(); + }); + + it('renders the MSPCA logo', () => { + const view = renderWithProviders(); + expect( + view.getByAltText('MSPCA - Kindness and Care for Animals'), + ).toBeTruthy(); + }); + + it('shows the profile button', () => { + const view = renderWithProviders(); + expect(view.getByRole('button', { name: 'My Profile' })).toBeTruthy(); + }); + + it("shows the volunteer's initials", async () => { + getVolunteer.mockResolvedValue(volunteer(3, 'Matt', 'Wong')); + const view = renderWithProviders(, { route: '/?volunteerId=3' }); + + expect(await view.findByText('MW')).toBeTruthy(); + expect(getVolunteer).toHaveBeenCalledTimes(1); + expect(getVolunteer).toHaveBeenCalledWith(3); + }); + + it('shows a fallback avatar and makes no request without a volunteerId', () => { + const view = renderWithProviders(); + + expect(avatarText(view)).toBe(''); + expect(getVolunteer).not.toHaveBeenCalled(); + }); + + it('shows a fallback avatar when the volunteer request fails', async () => { + getVolunteer.mockRejectedValue(new Error('404')); + const view = renderWithProviders(, { route: '/?volunteerId=9' }); + + await waitFor(() => expect(getVolunteer).toHaveBeenCalledTimes(1)); + expect(avatarText(view)).toBe(''); + }); + + it('ignores a stale response after the volunteerId changes', async () => { + let resolveFirst: (v: Volunteer) => void = () => undefined; + getVolunteer + .mockReturnValueOnce( + new Promise((resolve) => { + resolveFirst = resolve; + }), + ) + .mockResolvedValueOnce(volunteer(2, 'Anna', 'Lee')); + + const view = renderWithProviders( + <> + + + , + { route: '/?volunteerId=1' }, + ); + + fireEvent.click(view.getByText('go')); + expect(await view.findByText('AL')).toBeTruthy(); + + resolveFirst(volunteer(1, 'Matt', 'Wong')); + await new Promise((r) => setTimeout(r, 0)); + + expect(avatarText(view)).toBe('AL'); + }); +}); diff --git a/apps/frontend/src/components/Navbar.tsx b/apps/frontend/src/components/Navbar.tsx new file mode 100644 index 000000000..2b57e390c --- /dev/null +++ b/apps/frontend/src/components/Navbar.tsx @@ -0,0 +1,102 @@ +import { useEffect, useState } from 'react'; +import { chakra, Flex, Image, Text } from '@chakra-ui/react'; + +import apiClient, { type Volunteer } from '@api/apiClient'; +import { useVolunteerId } from '@utils/useVolunteerId'; +import { getAvatarColor, getInitials } from '@utils/volunteer'; +import logo from '../assets/mspca-logo.png'; + +const VolunteerAvatar: React.FC<{ volunteer: Volunteer | null }> = ({ + volunteer, +}) => ( + + {volunteer ? getInitials(volunteer.firstName, volunteer.lastName) : ''} + +); + +/** Site-wide header: MSPCA logo and the current volunteer's profile button. */ +const Navbar: React.FC = () => { + const volunteerId = useVolunteerId(); + const [loaded, setLoaded] = useState(null); + // Only show a volunteer that matches the current URL, so a previous + // volunteer never lingers while the next one loads. + const volunteer = loaded?.volunteerId === volunteerId ? loaded : null; + + useEffect(() => { + if (volunteerId === null) return; + + let cancelled = false; + apiClient + .getVolunteer(volunteerId) + .then((result) => { + if (!cancelled) setLoaded(result); + }) + .catch(() => { + // Unknown volunteer or network error: keep the fallback avatar. + }); + return () => { + cancelled = true; + }; + }, [volunteerId]); + + return ( + + MSPCA - Kindness and Care for Animals + {/* TODO: link to the volunteer profile page once it exists. */} + + + + My Profile + + + + ); +}; + +export default Navbar; diff --git a/apps/frontend/src/testUtils.tsx b/apps/frontend/src/testUtils.tsx new file mode 100644 index 000000000..8c80538c4 --- /dev/null +++ b/apps/frontend/src/testUtils.tsx @@ -0,0 +1,16 @@ +import { render } from '@testing-library/react'; +import { ChakraProvider } from '@chakra-ui/react'; +import { MemoryRouter } from 'react-router-dom'; + +import { system } from './theme'; + +/** Renders `ui` inside the app's Chakra theme and an in-memory router at `route`. */ +export const renderWithProviders = ( + ui: React.ReactElement, + { route = '/' }: { route?: string } = {}, +) => + render( + + {ui} + , + ); From f69239ac7fe2e699715ea1541700a76fcd4c156d Mon Sep 17 00:00:00 2001 From: Justin Wang Date: Wed, 4 Nov 2026 22:33:52 -0500 Subject: [PATCH 03/16] MSPCA-51: render Navbar in shared app layout Co-Authored-By: Claude Opus 5.5 --- apps/frontend/src/app.spec.tsx | 49 ++++++++++++--- apps/frontend/src/app.tsx | 31 ++++++---- apps/frontend/src/containers/404.tsx | 14 ++++- apps/frontend/src/containers/Layout.tsx | 13 ++++ .../frontend/src/pages/AnimalAvailability.tsx | 59 ------------------- 5 files changed, 84 insertions(+), 82 deletions(-) create mode 100644 apps/frontend/src/containers/Layout.tsx diff --git a/apps/frontend/src/app.spec.tsx b/apps/frontend/src/app.spec.tsx index 95caf44df..34a28b1a4 100644 --- a/apps/frontend/src/app.spec.tsx +++ b/apps/frontend/src/app.spec.tsx @@ -1,15 +1,48 @@ import { render } from '@testing-library/react'; +import { ChakraProvider } from '@chakra-ui/react'; +import { createMemoryRouter, RouterProvider } from 'react-router-dom'; -import App from './app'; +import { routes } from './app'; +import { system } from './theme'; -describe('App', () => { - it('should render successfully', () => { - const { baseElement } = render(); - expect(baseElement).toBeTruthy(); +vi.mock('@api/apiClient', () => ({ + default: { + getHello: vi.fn().mockResolvedValue('hello'), + getAnimals: vi.fn().mockResolvedValue([]), + getVolunteer: vi.fn().mockResolvedValue({ + volunteerId: 1, + firstName: 'Matt', + lastName: 'Wong', + }), + }, +})); + +const LOGO_ALT = 'MSPCA - Kindness and Care for Animals'; + +const renderAt = (path: string) => + render( + + + , + ); + +describe('App routes', () => { + it('renders the navbar on the home page', () => { + const view = renderAt('/'); + expect(view.getByAltText(LOGO_ALT)).toBeTruthy(); + expect(view.getByText('Welcome to scaffolding!')).toBeTruthy(); + }); + + it('renders the navbar once on the animal availability page', () => { + const view = renderAt('/animal-availability'); + expect(view.getAllByAltText(LOGO_ALT)).toHaveLength(1); }); - it('should have a greeting as the title', () => { - const { getByText } = render(); - expect(getByText(/Welcome frontend/gi)).toBeTruthy(); + it('shows the navbar and a not-found message on an unknown route', () => { + const view = renderAt('/does-not-exist'); + expect(view.getByAltText(LOGO_ALT)).toBeTruthy(); + expect(view.getByText('Page not found')).toBeTruthy(); }); }); diff --git a/apps/frontend/src/app.tsx b/apps/frontend/src/app.tsx index 3b1620328..a5918676f 100644 --- a/apps/frontend/src/app.tsx +++ b/apps/frontend/src/app.tsx @@ -1,28 +1,33 @@ import { useEffect } from 'react'; -import { createBrowserRouter, RouterProvider } from 'react-router-dom'; +import { + createBrowserRouter, + RouterProvider, + type RouteObject, +} from 'react-router-dom'; import apiClient from '@api/apiClient'; import Root from '@containers/root'; +import Layout from '@containers/Layout'; import NotFound from '@containers/404'; import Test from '@containers/test'; import AnimalAvailability from '@pages/AnimalAvailability'; import { ROUTES } from './routes'; -const router = createBrowserRouter([ +// Every page is a child of Layout so the navbar renders once, above all pages. +export const routes: RouteObject[] = [ { - path: '/', - element: , + element: , errorElement: , + children: [ + { path: '/', element: }, + { path: '/test', element: }, + { path: ROUTES.ANIMAL_AVAILABILITY, element: }, + { path: '*', element: }, + ], }, - { - path: '/test', - element: , - }, - { - path: ROUTES.ANIMAL_AVAILABILITY, - element: , - }, -]); +]; + +const router = createBrowserRouter(routes); export const App: React.FC = () => { useEffect(() => { diff --git a/apps/frontend/src/containers/404.tsx b/apps/frontend/src/containers/404.tsx index d6a08187e..1b5246dd3 100644 --- a/apps/frontend/src/containers/404.tsx +++ b/apps/frontend/src/containers/404.tsx @@ -3,14 +3,24 @@ import { useRouteError } from 'react-router-dom'; import { getErrorMessage } from '@utils/router'; const NotFound: React.FC = () => { - const errorMessage = getErrorMessage(useRouteError()); + const error = useRouteError(); + + // Rendered by the catch-all route for unknown URLs, so there is no error. + if (error == null) { + return ( +
+

Page not found

+

Sorry, we couldn't find the page you're looking for.

+
+ ); + } return (

Oops!

Sorry, an unexpected error has occurred.

- {errorMessage} + {getErrorMessage(error)}

); diff --git a/apps/frontend/src/containers/Layout.tsx b/apps/frontend/src/containers/Layout.tsx new file mode 100644 index 000000000..b43ae1f74 --- /dev/null +++ b/apps/frontend/src/containers/Layout.tsx @@ -0,0 +1,13 @@ +import { Outlet } from 'react-router-dom'; + +import Navbar from '@components/Navbar'; + +/** Shared app shell: the navbar sits above every page. */ +const Layout: React.FC = () => ( + <> + + + +); + +export default Layout; diff --git a/apps/frontend/src/pages/AnimalAvailability.tsx b/apps/frontend/src/pages/AnimalAvailability.tsx index de0f7a22b..8354c8ed3 100644 --- a/apps/frontend/src/pages/AnimalAvailability.tsx +++ b/apps/frontend/src/pages/AnimalAvailability.tsx @@ -4,7 +4,6 @@ import { Button, Flex, Heading, - Image, SimpleGrid, Spinner, Text, @@ -21,63 +20,6 @@ import { type AnimalFilterState, } from '@utils/animals'; import { MOCK_RESTRICTIONS } from '@utils/mockRestrictions'; -import logo from '../assets/mspca-logo.png'; - -const PageHeader: React.FC = () => ( - - MSPCA - Kindness and Care for Animals - - - {/* TODO: use the logged-in volunteer's initials */} - - MW - - - - My Profile - - - -); const AnimalAvailability: React.FC = () => { const [animals, setAnimals] = useState([]); @@ -134,7 +76,6 @@ const AnimalAvailability: React.FC = () => { return ( - Date: Wed, 4 Nov 2026 22:34:49 -0500 Subject: [PATCH 04/16] MSPCA-51: use URL volunteer ID for match requests Co-Authored-By: Claude Opus 5.5 --- .../src/components/AnimalModal.spec.tsx | 62 +++++++++++++++++++ apps/frontend/src/components/AnimalModal.tsx | 11 ++-- 2 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 apps/frontend/src/components/AnimalModal.spec.tsx diff --git a/apps/frontend/src/components/AnimalModal.spec.tsx b/apps/frontend/src/components/AnimalModal.spec.tsx new file mode 100644 index 000000000..0be7d5bda --- /dev/null +++ b/apps/frontend/src/components/AnimalModal.spec.tsx @@ -0,0 +1,62 @@ +import { fireEvent, waitFor } from '@testing-library/react'; +import type { Mock } from 'vitest'; + +import apiClient, { type Animal } from '@api/apiClient'; +import { renderWithProviders } from '../testUtils'; +import AnimalModal from './AnimalModal'; + +vi.mock('@api/apiClient', () => ({ + default: { createMatch: vi.fn() }, +})); + +const createMatch = apiClient.createMatch as Mock; + +const animal = { + animalId: 1, + chameleonAnimalId: 555, + name: 'Biscuit', + age: 2, + sex: 'Male', + breed: ['Beagle'], + weight: 20, + location: 'Boston, MA', + picture: null, + fosterBioMemo: null, +} as Animal; + +const renderModal = (route: string) => + renderWithProviders(, { + route, + }); + +describe('AnimalModal', () => { + beforeEach(() => { + createMatch.mockReset(); + createMatch.mockResolvedValue({}); + }); + + it('requests a match for the volunteer in the URL', async () => { + const view = renderModal('/?volunteerId=5'); + + fireEvent.click(await view.findByRole('button', { name: 'Apply' })); + + await waitFor(() => expect(createMatch).toHaveBeenCalledTimes(1)); + expect(createMatch).toHaveBeenCalledWith({ + volunteerId: 5, + chameleonAnimalId: 555, + additionalComments: undefined, + }); + }); + + it('disables the request without a volunteerId in the URL', async () => { + const view = renderModal('/'); + + const apply = (await view.findByRole('button', { + name: 'Apply', + })) as HTMLButtonElement; + fireEvent.click(apply); + + expect(apply.disabled).toBe(true); + expect(createMatch).not.toHaveBeenCalled(); + }); +}); diff --git a/apps/frontend/src/components/AnimalModal.tsx b/apps/frontend/src/components/AnimalModal.tsx index 658989354..c5eb6be41 100644 --- a/apps/frontend/src/components/AnimalModal.tsx +++ b/apps/frontend/src/components/AnimalModal.tsx @@ -12,13 +12,10 @@ import { import apiClient, { type Animal } from '@api/apiClient'; import { formatAge } from '@utils/animals'; +import { useVolunteerId } from '@utils/useVolunteerId'; import { CalendarIcon, PLACEHOLDER_IMAGE } from './AnimalCard'; import RestrictionTag from './RestrictionTag'; -// TODO: replace with the logged-in volunteer's ID once the frontend has access -// to the current user's profile. -const CURRENT_VOLUNTEER_ID = 1; - interface AnimalModalProps { animal: Animal | null; onClose: () => void; @@ -31,13 +28,16 @@ const AnimalModalBody: React.FC<{ animal: Animal }> = ({ animal }) => { const [submitting, setSubmitting] = useState(false); const [requested, setRequested] = useState(false); const [error, setError] = useState(null); + // TEMPORARY: comes from the URL until sign-in is implemented. + const volunteerId = useVolunteerId(); const handleRequest = async () => { + if (volunteerId === null) return; setSubmitting(true); setError(null); try { await apiClient.createMatch({ - volunteerId: CURRENT_VOLUNTEER_ID, + volunteerId, chameleonAnimalId: animal.chameleonAnimalId, additionalComments: comments.trim() || undefined, }); @@ -262,6 +262,7 @@ const AnimalModalBody: React.FC<{ animal: Animal }> = ({ animal }) => { lineHeight="24px" onClick={handleRequest} loading={submitting} + disabled={volunteerId === null} > Apply From 5156e6adcfec29a1e898ebe990150d9e9524c088 Mon Sep 17 00:00:00 2001 From: Justin Wang Date: Wed, 4 Nov 2026 22:40:32 -0500 Subject: [PATCH 05/16] MSPCA-51: keep navbar on page errors and fix double-height scroll Page render errors are now caught by a nested errorElement under the layout, so the navbar stays visible. The layout is a full-height column and the availability page fills the remaining space instead of 100vh. Co-Authored-By: Claude Opus 5.5 --- apps/frontend/src/app.error.spec.tsx | 44 +++++++++++++++++++ apps/frontend/src/app.tsx | 18 ++++++-- apps/frontend/src/containers/Layout.tsx | 10 +++-- .../frontend/src/pages/AnimalAvailability.tsx | 2 +- 4 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 apps/frontend/src/app.error.spec.tsx diff --git a/apps/frontend/src/app.error.spec.tsx b/apps/frontend/src/app.error.spec.tsx new file mode 100644 index 000000000..6da63a0d8 --- /dev/null +++ b/apps/frontend/src/app.error.spec.tsx @@ -0,0 +1,44 @@ +import { render } from '@testing-library/react'; +import { ChakraProvider } from '@chakra-ui/react'; +import { createMemoryRouter, RouterProvider } from 'react-router-dom'; + +import { routes } from './app'; +import { system } from './theme'; + +vi.mock('@api/apiClient', () => ({ + default: { + getHello: vi.fn().mockResolvedValue('hello'), + getVolunteer: vi.fn().mockResolvedValue({ + volunteerId: 1, + firstName: 'Matt', + lastName: 'Wong', + }), + }, +})); + +// A page that crashes while rendering. +vi.mock('@pages/AnimalAvailability', () => ({ + default: () => { + throw new Error('page exploded'); + }, +})); + +describe('App routes when a page crashes', () => { + it('keeps the navbar above the error message', () => { + vi.spyOn(console, 'error').mockImplementation(() => undefined); + const view = render( + + + , + ); + + expect(view.getByText('page exploded')).toBeTruthy(); + expect( + view.getByAltText('MSPCA - Kindness and Care for Animals'), + ).toBeTruthy(); + }); +}); diff --git a/apps/frontend/src/app.tsx b/apps/frontend/src/app.tsx index a5918676f..27044a10c 100644 --- a/apps/frontend/src/app.tsx +++ b/apps/frontend/src/app.tsx @@ -14,15 +14,25 @@ import AnimalAvailability from '@pages/AnimalAvailability'; import { ROUTES } from './routes'; // Every page is a child of Layout so the navbar renders once, above all pages. +// Page errors are caught by the inner errorElement so the navbar stays put; +// the outer one only catches errors from the layout itself. export const routes: RouteObject[] = [ { element: , errorElement: , children: [ - { path: '/', element: }, - { path: '/test', element: }, - { path: ROUTES.ANIMAL_AVAILABILITY, element: }, - { path: '*', element: }, + { + errorElement: , + children: [ + { path: '/', element: }, + { path: '/test', element: }, + { + path: ROUTES.ANIMAL_AVAILABILITY, + element: , + }, + { path: '*', element: }, + ], + }, ], }, ]; diff --git a/apps/frontend/src/containers/Layout.tsx b/apps/frontend/src/containers/Layout.tsx index b43ae1f74..37c84e7f0 100644 --- a/apps/frontend/src/containers/Layout.tsx +++ b/apps/frontend/src/containers/Layout.tsx @@ -1,13 +1,17 @@ +import { Flex } from '@chakra-ui/react'; import { Outlet } from 'react-router-dom'; import Navbar from '@components/Navbar'; -/** Shared app shell: the navbar sits above every page. */ +/** + * Shared app shell: the navbar sits above every page. The column fills the + * viewport so pages can grow into the remaining height with `flex="1"`. + */ const Layout: React.FC = () => ( - <> + - + ); export default Layout; diff --git a/apps/frontend/src/pages/AnimalAvailability.tsx b/apps/frontend/src/pages/AnimalAvailability.tsx index 8354c8ed3..0b1ba5a01 100644 --- a/apps/frontend/src/pages/AnimalAvailability.tsx +++ b/apps/frontend/src/pages/AnimalAvailability.tsx @@ -75,7 +75,7 @@ const AnimalAvailability: React.FC = () => { ); return ( - + Date: Thu, 5 Nov 2026 23:01:33 -0500 Subject: [PATCH 06/16] MSPCA-51: reject unsafe volunteer IDs and warn on failed volunteer fetch - parseVolunteerId rejects IDs above Number.MAX_SAFE_INTEGER, which previously turned into values like 1e+23 - Navbar logs a console warning when the volunteer request fails - Restore the console.error spy in app.error.spec Co-Authored-By: Claude Opus 5.5 --- apps/frontend/src/app.error.spec.tsx | 11 ++++++++++- apps/frontend/src/components/Navbar.spec.tsx | 7 +++++-- apps/frontend/src/components/Navbar.tsx | 3 ++- apps/frontend/src/utils/volunteer.spec.ts | 18 ++++++++++++------ apps/frontend/src/utils/volunteer.ts | 2 +- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/apps/frontend/src/app.error.spec.tsx b/apps/frontend/src/app.error.spec.tsx index 6da63a0d8..ad9cd7a58 100644 --- a/apps/frontend/src/app.error.spec.tsx +++ b/apps/frontend/src/app.error.spec.tsx @@ -24,8 +24,17 @@ vi.mock('@pages/AnimalAvailability', () => ({ })); describe('App routes when a page crashes', () => { + let consoleError: ReturnType; + + afterEach(() => { + consoleError.mockRestore(); + }); + it('keeps the navbar above the error message', () => { - vi.spyOn(console, 'error').mockImplementation(() => undefined); + // React logs the thrown render error; keep the test output clean. + consoleError = vi + .spyOn(console, 'error') + .mockImplementation(() => undefined); const view = render( { expect(getVolunteer).not.toHaveBeenCalled(); }); - it('shows a fallback avatar when the volunteer request fails', async () => { + it('shows a fallback avatar and warns when the volunteer request fails', async () => { + const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined); getVolunteer.mockRejectedValue(new Error('404')); const view = renderWithProviders(, { route: '/?volunteerId=9' }); - await waitFor(() => expect(getVolunteer).toHaveBeenCalledTimes(1)); + // Waiting for the warning means the rejection has been handled. + await waitFor(() => expect(warn).toHaveBeenCalledTimes(1)); expect(avatarText(view)).toBe(''); + warn.mockRestore(); }); it('ignores a stale response after the volunteerId changes', async () => { diff --git a/apps/frontend/src/components/Navbar.tsx b/apps/frontend/src/components/Navbar.tsx index 2b57e390c..b7cac81d7 100644 --- a/apps/frontend/src/components/Navbar.tsx +++ b/apps/frontend/src/components/Navbar.tsx @@ -47,8 +47,9 @@ const Navbar: React.FC = () => { .then((result) => { if (!cancelled) setLoaded(result); }) - .catch(() => { + .catch((err: unknown) => { // Unknown volunteer or network error: keep the fallback avatar. + console.warn(`Could not load volunteer ${volunteerId}`, err); }); return () => { cancelled = true; diff --git a/apps/frontend/src/utils/volunteer.spec.ts b/apps/frontend/src/utils/volunteer.spec.ts index a3c53a837..1b33017db 100644 --- a/apps/frontend/src/utils/volunteer.spec.ts +++ b/apps/frontend/src/utils/volunteer.spec.ts @@ -38,10 +38,16 @@ describe('parseVolunteerId', () => { expect(parseVolunteerId('12')).toBe(12); }); - it.each([null, '', 'abc', '0', '-3', '1.5', '12abc'])( - 'returns null for %j', - (raw) => { - expect(parseVolunteerId(raw)).toBeNull(); - }, - ); + it.each([ + null, + '', + 'abc', + '0', + '-3', + '1.5', + '12abc', + '99999999999999999999999', + ])('returns null for %j', (raw) => { + expect(parseVolunteerId(raw)).toBeNull(); + }); }); diff --git a/apps/frontend/src/utils/volunteer.ts b/apps/frontend/src/utils/volunteer.ts index 4efda92ba..f827aabc0 100644 --- a/apps/frontend/src/utils/volunteer.ts +++ b/apps/frontend/src/utils/volunteer.ts @@ -21,5 +21,5 @@ export const getAvatarColor = (volunteerId: number): string => export const parseVolunteerId = (raw: string | null): number | null => { if (raw === null || !/^\d+$/.test(raw)) return null; const id = Number(raw); - return id > 0 ? id : null; + return id > 0 && Number.isSafeInteger(id) ? id : null; }; From 0d556332ad0a085e942272de7d9908f0b092f03e Mon Sep 17 00:00:00 2001 From: Justin Wang Date: Mon, 9 Nov 2026 18:50:36 -0500 Subject: [PATCH 07/16] MSPCA-51: remove navbar, modal, and route specs Frontend component tests aren't needed. app.spec.tsx is restored to its original scaffold version. Co-Authored-By: Claude Opus 5.5 --- apps/frontend/src/app.error.spec.tsx | 53 ---------- apps/frontend/src/app.spec.tsx | 49 ++------- .../src/components/AnimalModal.spec.tsx | 62 ------------ apps/frontend/src/components/Navbar.spec.tsx | 99 ------------------- apps/frontend/src/testUtils.tsx | 16 --- 5 files changed, 8 insertions(+), 271 deletions(-) delete mode 100644 apps/frontend/src/app.error.spec.tsx delete mode 100644 apps/frontend/src/components/AnimalModal.spec.tsx delete mode 100644 apps/frontend/src/components/Navbar.spec.tsx delete mode 100644 apps/frontend/src/testUtils.tsx diff --git a/apps/frontend/src/app.error.spec.tsx b/apps/frontend/src/app.error.spec.tsx deleted file mode 100644 index ad9cd7a58..000000000 --- a/apps/frontend/src/app.error.spec.tsx +++ /dev/null @@ -1,53 +0,0 @@ -import { render } from '@testing-library/react'; -import { ChakraProvider } from '@chakra-ui/react'; -import { createMemoryRouter, RouterProvider } from 'react-router-dom'; - -import { routes } from './app'; -import { system } from './theme'; - -vi.mock('@api/apiClient', () => ({ - default: { - getHello: vi.fn().mockResolvedValue('hello'), - getVolunteer: vi.fn().mockResolvedValue({ - volunteerId: 1, - firstName: 'Matt', - lastName: 'Wong', - }), - }, -})); - -// A page that crashes while rendering. -vi.mock('@pages/AnimalAvailability', () => ({ - default: () => { - throw new Error('page exploded'); - }, -})); - -describe('App routes when a page crashes', () => { - let consoleError: ReturnType; - - afterEach(() => { - consoleError.mockRestore(); - }); - - it('keeps the navbar above the error message', () => { - // React logs the thrown render error; keep the test output clean. - consoleError = vi - .spyOn(console, 'error') - .mockImplementation(() => undefined); - const view = render( - - - , - ); - - expect(view.getByText('page exploded')).toBeTruthy(); - expect( - view.getByAltText('MSPCA - Kindness and Care for Animals'), - ).toBeTruthy(); - }); -}); diff --git a/apps/frontend/src/app.spec.tsx b/apps/frontend/src/app.spec.tsx index 34a28b1a4..95caf44df 100644 --- a/apps/frontend/src/app.spec.tsx +++ b/apps/frontend/src/app.spec.tsx @@ -1,48 +1,15 @@ import { render } from '@testing-library/react'; -import { ChakraProvider } from '@chakra-ui/react'; -import { createMemoryRouter, RouterProvider } from 'react-router-dom'; -import { routes } from './app'; -import { system } from './theme'; +import App from './app'; -vi.mock('@api/apiClient', () => ({ - default: { - getHello: vi.fn().mockResolvedValue('hello'), - getAnimals: vi.fn().mockResolvedValue([]), - getVolunteer: vi.fn().mockResolvedValue({ - volunteerId: 1, - firstName: 'Matt', - lastName: 'Wong', - }), - }, -})); - -const LOGO_ALT = 'MSPCA - Kindness and Care for Animals'; - -const renderAt = (path: string) => - render( - - - , - ); - -describe('App routes', () => { - it('renders the navbar on the home page', () => { - const view = renderAt('/'); - expect(view.getByAltText(LOGO_ALT)).toBeTruthy(); - expect(view.getByText('Welcome to scaffolding!')).toBeTruthy(); - }); - - it('renders the navbar once on the animal availability page', () => { - const view = renderAt('/animal-availability'); - expect(view.getAllByAltText(LOGO_ALT)).toHaveLength(1); +describe('App', () => { + it('should render successfully', () => { + const { baseElement } = render(); + expect(baseElement).toBeTruthy(); }); - it('shows the navbar and a not-found message on an unknown route', () => { - const view = renderAt('/does-not-exist'); - expect(view.getByAltText(LOGO_ALT)).toBeTruthy(); - expect(view.getByText('Page not found')).toBeTruthy(); + it('should have a greeting as the title', () => { + const { getByText } = render(); + expect(getByText(/Welcome frontend/gi)).toBeTruthy(); }); }); diff --git a/apps/frontend/src/components/AnimalModal.spec.tsx b/apps/frontend/src/components/AnimalModal.spec.tsx deleted file mode 100644 index 0be7d5bda..000000000 --- a/apps/frontend/src/components/AnimalModal.spec.tsx +++ /dev/null @@ -1,62 +0,0 @@ -import { fireEvent, waitFor } from '@testing-library/react'; -import type { Mock } from 'vitest'; - -import apiClient, { type Animal } from '@api/apiClient'; -import { renderWithProviders } from '../testUtils'; -import AnimalModal from './AnimalModal'; - -vi.mock('@api/apiClient', () => ({ - default: { createMatch: vi.fn() }, -})); - -const createMatch = apiClient.createMatch as Mock; - -const animal = { - animalId: 1, - chameleonAnimalId: 555, - name: 'Biscuit', - age: 2, - sex: 'Male', - breed: ['Beagle'], - weight: 20, - location: 'Boston, MA', - picture: null, - fosterBioMemo: null, -} as Animal; - -const renderModal = (route: string) => - renderWithProviders(, { - route, - }); - -describe('AnimalModal', () => { - beforeEach(() => { - createMatch.mockReset(); - createMatch.mockResolvedValue({}); - }); - - it('requests a match for the volunteer in the URL', async () => { - const view = renderModal('/?volunteerId=5'); - - fireEvent.click(await view.findByRole('button', { name: 'Apply' })); - - await waitFor(() => expect(createMatch).toHaveBeenCalledTimes(1)); - expect(createMatch).toHaveBeenCalledWith({ - volunteerId: 5, - chameleonAnimalId: 555, - additionalComments: undefined, - }); - }); - - it('disables the request without a volunteerId in the URL', async () => { - const view = renderModal('/'); - - const apply = (await view.findByRole('button', { - name: 'Apply', - })) as HTMLButtonElement; - fireEvent.click(apply); - - expect(apply.disabled).toBe(true); - expect(createMatch).not.toHaveBeenCalled(); - }); -}); diff --git a/apps/frontend/src/components/Navbar.spec.tsx b/apps/frontend/src/components/Navbar.spec.tsx deleted file mode 100644 index 2bd42ec02..000000000 --- a/apps/frontend/src/components/Navbar.spec.tsx +++ /dev/null @@ -1,99 +0,0 @@ -import { fireEvent, waitFor } from '@testing-library/react'; -import { useNavigate } from 'react-router-dom'; -import type { Mock } from 'vitest'; - -import apiClient, { type Volunteer } from '@api/apiClient'; -import { renderWithProviders } from '../testUtils'; -import Navbar from './Navbar'; - -vi.mock('@api/apiClient', () => ({ - default: { getVolunteer: vi.fn() }, -})); - -const getVolunteer = apiClient.getVolunteer as Mock; - -const volunteer = ( - volunteerId: number, - firstName: string, - lastName: string, -): Volunteer => ({ volunteerId, firstName, lastName }); - -const GoTo: React.FC<{ to: string }> = ({ to }) => { - const navigate = useNavigate(); - return ; -}; - -const avatarText = (container: ReturnType) => - container.getByTestId('navbar-avatar').textContent; - -describe('Navbar', () => { - beforeEach(() => { - getVolunteer.mockReset(); - }); - - it('renders the MSPCA logo', () => { - const view = renderWithProviders(); - expect( - view.getByAltText('MSPCA - Kindness and Care for Animals'), - ).toBeTruthy(); - }); - - it('shows the profile button', () => { - const view = renderWithProviders(); - expect(view.getByRole('button', { name: 'My Profile' })).toBeTruthy(); - }); - - it("shows the volunteer's initials", async () => { - getVolunteer.mockResolvedValue(volunteer(3, 'Matt', 'Wong')); - const view = renderWithProviders(, { route: '/?volunteerId=3' }); - - expect(await view.findByText('MW')).toBeTruthy(); - expect(getVolunteer).toHaveBeenCalledTimes(1); - expect(getVolunteer).toHaveBeenCalledWith(3); - }); - - it('shows a fallback avatar and makes no request without a volunteerId', () => { - const view = renderWithProviders(); - - expect(avatarText(view)).toBe(''); - expect(getVolunteer).not.toHaveBeenCalled(); - }); - - it('shows a fallback avatar and warns when the volunteer request fails', async () => { - const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined); - getVolunteer.mockRejectedValue(new Error('404')); - const view = renderWithProviders(, { route: '/?volunteerId=9' }); - - // Waiting for the warning means the rejection has been handled. - await waitFor(() => expect(warn).toHaveBeenCalledTimes(1)); - expect(avatarText(view)).toBe(''); - warn.mockRestore(); - }); - - it('ignores a stale response after the volunteerId changes', async () => { - let resolveFirst: (v: Volunteer) => void = () => undefined; - getVolunteer - .mockReturnValueOnce( - new Promise((resolve) => { - resolveFirst = resolve; - }), - ) - .mockResolvedValueOnce(volunteer(2, 'Anna', 'Lee')); - - const view = renderWithProviders( - <> - - - , - { route: '/?volunteerId=1' }, - ); - - fireEvent.click(view.getByText('go')); - expect(await view.findByText('AL')).toBeTruthy(); - - resolveFirst(volunteer(1, 'Matt', 'Wong')); - await new Promise((r) => setTimeout(r, 0)); - - expect(avatarText(view)).toBe('AL'); - }); -}); diff --git a/apps/frontend/src/testUtils.tsx b/apps/frontend/src/testUtils.tsx deleted file mode 100644 index 8c80538c4..000000000 --- a/apps/frontend/src/testUtils.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import { render } from '@testing-library/react'; -import { ChakraProvider } from '@chakra-ui/react'; -import { MemoryRouter } from 'react-router-dom'; - -import { system } from './theme'; - -/** Renders `ui` inside the app's Chakra theme and an in-memory router at `route`. */ -export const renderWithProviders = ( - ui: React.ReactElement, - { route = '/' }: { route?: string } = {}, -) => - render( - - {ui} - , - ); From a538b068a9b3159f1c536ae0f28a51d77c9cd3e4 Mon Sep 17 00:00:00 2001 From: Justin Wang Date: Mon, 9 Nov 2026 19:35:34 -0500 Subject: [PATCH 08/16] MSPCA-51: remove unneeded comments Co-Authored-By: Claude Opus 5.5 --- apps/frontend/src/components/Navbar.tsx | 3 --- apps/frontend/src/utils/volunteer.ts | 1 - 2 files changed, 4 deletions(-) diff --git a/apps/frontend/src/components/Navbar.tsx b/apps/frontend/src/components/Navbar.tsx index 117a35e45..0303988a3 100644 --- a/apps/frontend/src/components/Navbar.tsx +++ b/apps/frontend/src/components/Navbar.tsx @@ -35,8 +35,6 @@ const VolunteerAvatar: React.FC<{ volunteer: Volunteer | null }> = ({ const Navbar: React.FC = () => { const volunteerId = useVolunteerId(); const [loaded, setLoaded] = useState(null); - // Only show a volunteer that matches the current URL, so a previous - // volunteer never lingers while the next one loads. const volunteer = loaded?.volunteerId === volunteerId ? loaded : null; useEffect(() => { @@ -49,7 +47,6 @@ const Navbar: React.FC = () => { if (!cancelled) setLoaded(result); }) .catch((err: unknown) => { - // Unknown volunteer or network error: keep the fallback avatar. console.warn(`Could not load volunteer ${volunteerId}`, err); }); return () => { diff --git a/apps/frontend/src/utils/volunteer.ts b/apps/frontend/src/utils/volunteer.ts index f827aabc0..4b2c6acfe 100644 --- a/apps/frontend/src/utils/volunteer.ts +++ b/apps/frontend/src/utils/volunteer.ts @@ -17,7 +17,6 @@ export const getInitials = (firstName: string, lastName: string): string => export const getAvatarColor = (volunteerId: number): string => AVATAR_COLORS[volunteerId % AVATAR_COLORS.length]; -/** Parses a volunteer ID from a URL value; anything but a positive integer is null. */ export const parseVolunteerId = (raw: string | null): number | null => { if (raw === null || !/^\d+$/.test(raw)) return null; const id = Number(raw); From cb4eaba0844f6793ef9ac180b6ac1849880da7b5 Mon Sep 17 00:00:00 2001 From: Justin Wang Date: Mon, 9 Nov 2026 19:36:47 -0500 Subject: [PATCH 09/16] MSPCA-51: mirror the full GET /volunteers/:id response in Volunteer type Co-Authored-By: Claude Opus 5.5 --- apps/frontend/src/types.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/apps/frontend/src/types.ts b/apps/frontend/src/types.ts index a1c1f8e7a..48d0b03ac 100644 --- a/apps/frontend/src/types.ts +++ b/apps/frontend/src/types.ts @@ -35,8 +35,43 @@ export interface Match { deniedReason: string | null; } +export interface Coordinator { + coordinatorId: number; + firstName: string; + lastName: string; + phone: string; + secondaryPhone: string | null; + email: string; + // 'Boston' | 'Cape Cod' | 'Salem' | 'Nevins Farm' + homebase: string; + active: boolean; + cognitoSub: string; +} + +// Shape returned by GET /volunteers/:volunteerId (coordinator notes excluded) export interface Volunteer { volunteerId: number; firstName: string; lastName: string; + phone: string; + secondaryPhone: string | null; + email: string; + address: string; + city: string; + zipcode: string; + // 'Boston' | 'Cape Cod' | 'Salem' | 'Nevins Farm' + homebase: string; + residentAnimals: string; + notes: string | null; + // Each is 'Dog' | 'Cat' | 'Small Animals' | 'Baby Bottle Animals' | 'Farm Animals' + fosterType: string[]; + animalUpdates: boolean; + // Each is 'Dog' | 'Cat' + completedTrainings: string[]; + mostRecentWaiverSigned: boolean; + // 'Active' | 'Inactive' | 'Pending' + status: string; + cognitoSub: string; + animalPreferences: string[]; + assignedCoordinators: Coordinator[]; } From df4a2f6a4f491a089de859dd05a5dcbccd8f6412 Mon Sep 17 00:00:00 2001 From: Justin Wang Date: Mon, 9 Nov 2026 19:38:51 -0500 Subject: [PATCH 10/16] MSPCA-51: remove comments from types.ts Co-Authored-By: Claude Opus 5.5 --- apps/frontend/src/types.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/apps/frontend/src/types.ts b/apps/frontend/src/types.ts index 48d0b03ac..69319169c 100644 --- a/apps/frontend/src/types.ts +++ b/apps/frontend/src/types.ts @@ -2,20 +2,15 @@ export interface Animal { animalId: number; chameleonAnimalId: string; name: string; - // Whole years of age, e.g. 4 for "4Y5M" ageYear: number; - // Remaining months of age, e.g. 5 for "4Y5M" ageMonth: number; sex: string; - // 'Dog' | 'Cat' | 'Small Animals' | 'Baby Bottle Animals' | 'Farm Animals' species: string; breed: string[]; weight: number; - // 'Boston' | 'Cape Cod' | 'Salem' | 'Nevins Farm' location: string; pictures: string[]; fosterBioMemo: string; - // Restriction tag labels (e.g. 'Dog-Free Home') restrictions: string[]; } @@ -29,7 +24,6 @@ export interface Match { matchId: number; volunteerId: number; chameleonAnimalId: string; - // 'Pending' | 'Active' | 'Complete' | 'Denied' | 'Withdrawn' | 'Canceled' status: string; additionalComments: string | null; deniedReason: string | null; @@ -42,13 +36,11 @@ export interface Coordinator { phone: string; secondaryPhone: string | null; email: string; - // 'Boston' | 'Cape Cod' | 'Salem' | 'Nevins Farm' homebase: string; active: boolean; cognitoSub: string; } -// Shape returned by GET /volunteers/:volunteerId (coordinator notes excluded) export interface Volunteer { volunteerId: number; firstName: string; @@ -59,17 +51,13 @@ export interface Volunteer { address: string; city: string; zipcode: string; - // 'Boston' | 'Cape Cod' | 'Salem' | 'Nevins Farm' homebase: string; residentAnimals: string; notes: string | null; - // Each is 'Dog' | 'Cat' | 'Small Animals' | 'Baby Bottle Animals' | 'Farm Animals' fosterType: string[]; animalUpdates: boolean; - // Each is 'Dog' | 'Cat' completedTrainings: string[]; mostRecentWaiverSigned: boolean; - // 'Active' | 'Inactive' | 'Pending' status: string; cognitoSub: string; animalPreferences: string[]; From e7d44b8fe5f54c695ab4680178c86e16c95e4ce6 Mon Sep 17 00:00:00 2001 From: Justin Wang Date: Mon, 9 Nov 2026 19:40:31 -0500 Subject: [PATCH 11/16] MSPCA-51: restore types.ts comments except the Volunteer shape note Co-Authored-By: Claude Opus 5.5 --- apps/frontend/src/types.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/apps/frontend/src/types.ts b/apps/frontend/src/types.ts index 69319169c..54da53a0f 100644 --- a/apps/frontend/src/types.ts +++ b/apps/frontend/src/types.ts @@ -2,15 +2,20 @@ export interface Animal { animalId: number; chameleonAnimalId: string; name: string; + // Whole years of age, e.g. 4 for "4Y5M" ageYear: number; + // Remaining months of age, e.g. 5 for "4Y5M" ageMonth: number; sex: string; + // 'Dog' | 'Cat' | 'Small Animals' | 'Baby Bottle Animals' | 'Farm Animals' species: string; breed: string[]; weight: number; + // 'Boston' | 'Cape Cod' | 'Salem' | 'Nevins Farm' location: string; pictures: string[]; fosterBioMemo: string; + // Restriction tag labels (e.g. 'Dog-Free Home') restrictions: string[]; } @@ -24,6 +29,7 @@ export interface Match { matchId: number; volunteerId: number; chameleonAnimalId: string; + // 'Pending' | 'Active' | 'Complete' | 'Denied' | 'Withdrawn' | 'Canceled' status: string; additionalComments: string | null; deniedReason: string | null; @@ -36,6 +42,7 @@ export interface Coordinator { phone: string; secondaryPhone: string | null; email: string; + // 'Boston' | 'Cape Cod' | 'Salem' | 'Nevins Farm' homebase: string; active: boolean; cognitoSub: string; @@ -51,13 +58,17 @@ export interface Volunteer { address: string; city: string; zipcode: string; + // 'Boston' | 'Cape Cod' | 'Salem' | 'Nevins Farm' homebase: string; residentAnimals: string; notes: string | null; + // Each is 'Dog' | 'Cat' | 'Small Animals' | 'Baby Bottle Animals' | 'Farm Animals' fosterType: string[]; animalUpdates: boolean; + // Each is 'Dog' | 'Cat' completedTrainings: string[]; mostRecentWaiverSigned: boolean; + // 'Active' | 'Inactive' | 'Pending' status: string; cognitoSub: string; animalPreferences: string[]; From 2d9960884665d3b178236e7dc4ed37dc19bf7fcb Mon Sep 17 00:00:00 2001 From: Justin Wang Date: Tue, 10 Nov 2026 16:09:54 -0500 Subject: [PATCH 12/16] MSPCA-51: remove /test route and Test component Co-Authored-By: Claude Sonnet 5.5 --- apps/frontend/src/app.tsx | 2 -- apps/frontend/src/containers/test.tsx | 12 ------------ 2 files changed, 14 deletions(-) delete mode 100644 apps/frontend/src/containers/test.tsx diff --git a/apps/frontend/src/app.tsx b/apps/frontend/src/app.tsx index 27044a10c..50e2a746b 100644 --- a/apps/frontend/src/app.tsx +++ b/apps/frontend/src/app.tsx @@ -9,7 +9,6 @@ import apiClient from '@api/apiClient'; import Root from '@containers/root'; import Layout from '@containers/Layout'; import NotFound from '@containers/404'; -import Test from '@containers/test'; import AnimalAvailability from '@pages/AnimalAvailability'; import { ROUTES } from './routes'; @@ -25,7 +24,6 @@ export const routes: RouteObject[] = [ errorElement: , children: [ { path: '/', element: }, - { path: '/test', element: }, { path: ROUTES.ANIMAL_AVAILABILITY, element: , diff --git a/apps/frontend/src/containers/test.tsx b/apps/frontend/src/containers/test.tsx deleted file mode 100644 index 28d480422..000000000 --- a/apps/frontend/src/containers/test.tsx +++ /dev/null @@ -1,12 +0,0 @@ -// import { Button } from '@shared/src/components/button'; - -const Test: React.FC = () => { - return ( - <> -
I am test page
- {/* */} - - ); -}; - -export default Test; From ce831585cb8c72e57d62550483846eb501d775ce Mon Sep 17 00:00:00 2001 From: Justin Wang Date: Tue, 10 Nov 2026 16:10:03 -0500 Subject: [PATCH 13/16] MSPCA-51: use Chakra Button in Navbar, inline avatar, drop hover underline Co-Authored-By: Claude Sonnet 5.5 --- apps/frontend/src/components/Navbar.tsx | 56 ++++++++++++------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/apps/frontend/src/components/Navbar.tsx b/apps/frontend/src/components/Navbar.tsx index 0303988a3..6459eccfa 100644 --- a/apps/frontend/src/components/Navbar.tsx +++ b/apps/frontend/src/components/Navbar.tsx @@ -1,5 +1,5 @@ import { useEffect, useState } from 'react'; -import { chakra, Flex, Image, Text } from '@chakra-ui/react'; +import { Button, Flex, Image, Text } from '@chakra-ui/react'; import apiClient from '@api/apiClient'; import type { Volunteer } from '../types'; @@ -7,30 +7,6 @@ import { useVolunteerId } from '@utils/useVolunteerId'; import { getAvatarColor, getInitials } from '@utils/volunteer'; import logo from '../assets/mspca-logo.png'; -const VolunteerAvatar: React.FC<{ volunteer: Volunteer | null }> = ({ - volunteer, -}) => ( - - {volunteer ? getInitials(volunteer.firstName, volunteer.lastName) : ''} - -); - /** Site-wide header: MSPCA logo and the current volunteer's profile button. */ const Navbar: React.FC = () => { const volunteerId = useVolunteerId(); @@ -73,27 +49,47 @@ const Navbar: React.FC = () => { objectFit="contain" /> {/* TODO: link to the volunteer profile page once it exists. */} - - + + {volunteer + ? getInitials(volunteer.firstName, volunteer.lastName) + : ''} + My Profile - +
); }; From ccbde66e97d9503ee8a4f416168e508e852523fb Mon Sep 17 00:00:00 2001 From: Justin Wang Date: Tue, 10 Nov 2026 16:10:09 -0500 Subject: [PATCH 14/16] MSPCA-51: fix app spec so it passes in CI Remove the stale greeting test and stub apiClient so no network call is made. Co-Authored-By: Claude Sonnet 5.5 --- apps/frontend/src/app.spec.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/frontend/src/app.spec.tsx b/apps/frontend/src/app.spec.tsx index 95caf44df..9767fd8ae 100644 --- a/apps/frontend/src/app.spec.tsx +++ b/apps/frontend/src/app.spec.tsx @@ -2,14 +2,13 @@ import { render } from '@testing-library/react'; import App from './app'; +vi.mock('@api/apiClient', () => ({ + default: { getHello: vi.fn().mockResolvedValue('hello') }, +})); + describe('App', () => { it('should render successfully', () => { const { baseElement } = render(); expect(baseElement).toBeTruthy(); }); - - it('should have a greeting as the title', () => { - const { getByText } = render(); - expect(getByText(/Welcome frontend/gi)).toBeTruthy(); - }); }); From dc0299cc7a90e6071b9c405006f3f4029c63b8e1 Mon Sep 17 00:00:00 2001 From: Justin Wang Date: Tue, 10 Nov 2026 16:10:15 -0500 Subject: [PATCH 15/16] MSPCA-51: add frontend test workflow, rename jest workflow to backend_tests Co-Authored-By: Claude Sonnet 5.5 --- .../workflows/{jest.yml => backend_tests.yml} | 4 ++-- .github/workflows/frontend_tests.yml | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) rename .github/workflows/{jest.yml => backend_tests.yml} (92%) create mode 100644 .github/workflows/frontend_tests.yml diff --git a/.github/workflows/jest.yml b/.github/workflows/backend_tests.yml similarity index 92% rename from .github/workflows/jest.yml rename to .github/workflows/backend_tests.yml index 8fb2c7eaa..5beeddace 100644 --- a/.github/workflows/jest.yml +++ b/.github/workflows/backend_tests.yml @@ -1,4 +1,4 @@ -name: Jest run +name: Backend tests on: push: @@ -7,7 +7,7 @@ on: branches: ['**'] jobs: - jest-tests: + backend-tests: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/frontend_tests.yml b/.github/workflows/frontend_tests.yml new file mode 100644 index 000000000..94b82e282 --- /dev/null +++ b/.github/workflows/frontend_tests.yml @@ -0,0 +1,19 @@ +name: Frontend tests + +on: + push: + branches: ['**'] + pull_request: + branches: ['**'] + +jobs: + frontend-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 24.x + cache: 'yarn' + - run: yarn install --frozen-lockfile + - run: npx vitest run --root apps/frontend From fd94b4b30488806fc8d53ece2ac8ae1d56e5c7a0 Mon Sep 17 00:00:00 2001 From: Justin Wang Date: Thu, 12 Nov 2026 18:00:47 -0500 Subject: [PATCH 16/16] MSPCA-51: use Trello label colors for volunteer avatars Per design, avatar colors come from the theme's Trello label palette, so changing those colors in theme.ts updates avatars too. Co-Authored-By: Claude Opus 5.5 --- apps/frontend/src/utils/volunteer.spec.ts | 22 +++++++++++++++++----- apps/frontend/src/utils/volunteer.ts | 17 +++++++---------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/apps/frontend/src/utils/volunteer.spec.ts b/apps/frontend/src/utils/volunteer.spec.ts index 1b33017db..2b9f7c2a2 100644 --- a/apps/frontend/src/utils/volunteer.spec.ts +++ b/apps/frontend/src/utils/volunteer.spec.ts @@ -1,4 +1,10 @@ -import { getAvatarColor, getInitials, parseVolunteerId } from './volunteer'; +import { colors } from '../theme'; +import { + AVATAR_COLORS, + getAvatarColor, + getInitials, + parseVolunteerId, +} from './volunteer'; describe('getInitials', () => { it('uses the first letter of each name', () => { @@ -19,13 +25,19 @@ describe('getInitials', () => { }); describe('getAvatarColor', () => { - it('maps volunteer IDs onto the palette in order', () => { - expect(getAvatarColor(0)).toBe('purple.avatar'); - expect(getAvatarColor(1)).toBe('blue.blue2'); + it('uses the Trello label colors in theme order', () => { + expect(getAvatarColor(0)).toBe('trello.noRestrictions'); + expect(getAvatarColor(1)).toBe('trello.dogFreeHome'); }); it('wraps around the palette', () => { - expect(getAvatarColor(6)).toBe('purple.avatar'); + expect(getAvatarColor(7)).toBe('trello.noRestrictions'); + }); + + it('includes every Trello label color', () => { + expect(AVATAR_COLORS).toEqual( + Object.keys(colors.trello).map((key) => `trello.${key}`), + ); }); it('is stable for the same volunteer', () => { diff --git a/apps/frontend/src/utils/volunteer.ts b/apps/frontend/src/utils/volunteer.ts index 4b2c6acfe..9788f0639 100644 --- a/apps/frontend/src/utils/volunteer.ts +++ b/apps/frontend/src/utils/volunteer.ts @@ -1,13 +1,10 @@ -// Avatar background colors, picked by volunteer ID so each volunteer keeps the -// same color. Placeholder palette pending design confirmation. -export const AVATAR_COLORS: readonly string[] = [ - 'purple.avatar', - 'blue.blue2', - 'teal.teal', - 'green.green2', - 'orange.orange3', - 'brown.brown', -]; +import { colors } from '../theme'; + +// Avatars reuse the Trello label colors, so changing those in theme.ts +// updates avatars too. +export const AVATAR_COLORS: readonly string[] = Object.keys(colors.trello).map( + (key) => `trello.${key}`, +); const initial = (name: string): string => name.trim().charAt(0).toUpperCase();