From 745e94620520cd6edbb7ab98bcb1e264e6523993 Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Sat, 21 Nov 2026 20:15:00 +0100 Subject: [PATCH 1/5] feat: revise the Funding page Lists ELIXIR grants under one ELIXIR programme (data category and filter), titles each card with its programme and logo (ELIXIR, Google Summer of Code), shows the detailed grant type as a subtitle, drops the Grant/GSoC badges, sorts grants by end date, start date and name, and puts the ELIXIR grants stat before the GSoC one, in sentence case. Adds the Google Summer of Code mark (from the GSoC site's logo) as public/gsoc.svg. Refs #214 Co-Authored-By: Claude Opus 5.5 --- public/gsoc.svg | 1 + src/app/funding/page.test.tsx | 60 +++++++++++++++++++ src/app/funding/page.tsx | 99 +++++++++++++++----------------- src/app/listing-filters.test.tsx | 30 +++++----- src/data/data.test.ts | 20 +++++++ src/data/funding.json | 12 ++-- src/lib/funding.test.ts | 85 +++++++++++++++++++++++++++ src/lib/funding.ts | 41 +++++++++++++ 8 files changed, 275 insertions(+), 73 deletions(-) create mode 100644 public/gsoc.svg create mode 100644 src/app/funding/page.test.tsx create mode 100644 src/lib/funding.test.ts create mode 100644 src/lib/funding.ts diff --git a/public/gsoc.svg b/public/gsoc.svg new file mode 100644 index 0000000..d394054 --- /dev/null +++ b/public/gsoc.svg @@ -0,0 +1 @@ + diff --git a/src/app/funding/page.test.tsx b/src/app/funding/page.test.tsx new file mode 100644 index 0000000..21f80f9 --- /dev/null +++ b/src/app/funding/page.test.tsx @@ -0,0 +1,60 @@ +import { render, screen, within } from '@testing-library/react'; +import { describe, expect, it } from 'vitest'; +import funding from '@/data/funding.json'; +import { sortGrants } from '@/lib/funding'; +import FundingPage from './page'; + +const PROGRAMMES = ['ELIXIR', 'Google Summer of Code']; + +// The grant cards, in display order +const cards = () => screen.getAllByRole('article'); + +describe('Funding page', () => { + it('shows the stats in order, capitalized like the rest of the site', () => { + render(); + const labels = screen + .getAllByTestId('stat') + .map((stat) => stat.lastChild?.textContent); + expect(labels).toEqual(['Total grants', 'ELIXIR grants', 'GSoC projects']); + }); + + it('offers one filter per programme', () => { + render(); + const filters = within(screen.getByRole('group', { name: 'Filter' })) + .getAllByRole('button') + .map((button) => button.firstChild?.textContent); + expect(filters).toEqual(PROGRAMMES); + }); + + it('sorts grants by end date, start date and name', () => { + render(); + const titles = cards().map( + (card) => within(card).getByRole('heading', { level: 3 }).textContent, + ); + expect(titles).toEqual(sortGrants(funding).map((grant) => grant.project)); + }); + + it('titles each card with its programme, logo and grant type', () => { + render(); + const sorted = sortGrants(funding); + cards().forEach((card, index) => { + const grant = sorted[index]; + const header = within(card); + expect( + header.getByRole('heading', { level: 4 }).textContent, + grant.project, + ).toBe(grant.category); + expect(header.getByRole('img').getAttribute('alt')).toBe( + `${grant.category} logo`, + ); + const type = card.querySelector('[data-testid="grant-type"]'); + if (grant.category === 'ELIXIR') { + expect(type?.textContent).toBe(grant.funder); + } else { + expect(type).toBeNull(); + } + // The programme is in the title; no badge repeats it + expect(header.queryByText(/^(Grant|GSoC)$/)).toBeNull(); + }); + }); +}); diff --git a/src/app/funding/page.tsx b/src/app/funding/page.tsx index 4efa2c6..5947513 100644 --- a/src/app/funding/page.tsx +++ b/src/app/funding/page.tsx @@ -1,13 +1,12 @@ 'use client'; import { useMemo, useState } from 'react'; +import Image from 'next/image'; import { Award, - Building2, Calendar, HeartHandshake, Search, - Sparkles, Users, X, } from 'lucide-react'; @@ -19,25 +18,19 @@ import { Card } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { AnimatedGridPattern } from '@/components/ui/animated-grid-pattern'; import { checkFilterIds, filterId, matchesAny } from '@/lib/filters'; +import { type Grant, grants, grantType } from '@/lib/funding'; import { useUrlFilters } from '@/lib/use-url-filters'; import { cn } from '@/lib/utils'; -import fundingData from '@/data/funding.json'; +const GSOC = 'Google Summer of Code'; -type FundingItem = { - id: string; - funder: string; - project: string; - recipients: string[]; - startDate: string; - endDate: string; - formattedDuration: string; - category: string; +// The logo of each programme (`category`) +const LOGOS: Record = { + ELIXIR: '/elixir.png', + [GSOC]: '/gsoc.svg', }; -const grants = fundingData as FundingItem[]; - -// One filter per category, in the order the categories first appear +// One filter per programme, in the order the programmes first appear const categoryOptions = checkFilterIds( Array.from(new Set(grants.map((grant) => grant.category))).map( (category) => ({ @@ -69,10 +62,8 @@ export default function FundingPage() { }, [query, selected]); // Stat metrics - const gsocCount = grants.filter((g) => - g.funder.includes('Google Summer of Code'), - ).length; - const elixirCount = grants.filter((g) => g.funder.includes('ELIXIR')).length; + const gsocCount = grants.filter((g) => g.category === GSOC).length; + const elixirCount = grants.filter((g) => g.category === 'ELIXIR').length; return (
@@ -116,9 +107,9 @@ export default function FundingPage() { {/* Stats Bar */}
- - - + + +
@@ -205,42 +196,46 @@ export default function FundingPage() { /* Helper Components */ -function FundingCard({ item }: { item: FundingItem }) { - const isGSoC = item.funder.includes('Google Summer of Code'); +function FundingCard({ item }: { item: Grant }) { + const logo = LOGOS[item.category]; + const type = grantType(item); return ( - + {/* Background Hover Effect */}
- {/* Funder Header Row */} -
-
-
- {isGSoC ? ( - - ) : ( - - )} -
-
-

- {item.funder} -

-
+ {/* Programme: logo, title and detailed grant type. The logo tile + stays white, as the logos are made for light backgrounds. */} +
+
+ {logo && ( + {`${item.category} + )} +
+
+

+ {item.category} +

+ {type && ( +

+ {type} +

+ )}
- - - {isGSoC ? 'GSoC' : 'Grant'} -
{/* Project Title */} @@ -273,7 +268,7 @@ function FundingCard({ item }: { item: FundingItem }) { function Stat({ value, label }: { value: number; label: string }) { return ( -
+
{value}
diff --git a/src/app/listing-filters.test.tsx b/src/app/listing-filters.test.tsx index 7d03aad..dd38daf 100644 --- a/src/app/listing-filters.test.tsx +++ b/src/app/listing-filters.test.tsx @@ -3,6 +3,7 @@ import userEvent from '@testing-library/user-event'; import { afterEach, describe, expect, it, vi } from 'vitest'; import contributors from '@/data/contributor.json'; import funding from '@/data/funding.json'; +import { sortGrants } from '@/lib/funding'; import ContributorsPage from './contributors/page'; import FundingPage from './funding/page'; @@ -28,8 +29,10 @@ const removeFilters = () => screen.queryByRole('button', { name: 'Remove filters' }); describe('Funding page filters', () => { + // Grants in display order + const sorted = sortGrants(funding); const inCategories = (...categories: string[]) => - funding + sorted .filter((grant) => categories.includes(grant.category)) .map((grant) => grant.project); const count = (...categories: string[]) => inCategories(...categories).length; @@ -37,23 +40,23 @@ describe('Funding page filters', () => { const shown = () => screen.getByText(/^Showing \d+ of \d+ project grants\.$/).textContent; - it('lists grants of any selected category', async () => { + it('lists grants of any selected programme', async () => { const user = userEvent.setup(); render(); expect(removeFilters()).toBeNull(); - await user.click(filterButton(/^ELIXIR Services/)); + await user.click(filterButton(/^ELIXIR/)); expect(shown()).toBe( - `Showing ${count('ELIXIR Services')} of ${funding.length} project grants.`, + `Showing ${count('ELIXIR')} of ${funding.length} project grants.`, ); - expect(listedGrants()).toEqual(inCategories('ELIXIR Services')); + expect(listedGrants()).toEqual(inCategories('ELIXIR')); - await user.click(filterButton(/^ELIXIR Platform Tasks/)); + await user.click(filterButton(/^Google Summer of Code/)); expect(shown()).toBe( - `Showing ${count('ELIXIR Services', 'ELIXIR Platform Tasks')} of ${funding.length} project grants.`, + `Showing ${funding.length} of ${funding.length} project grants.`, ); expect(listedGrants()).toEqual( - inCategories('ELIXIR Services', 'ELIXIR Platform Tasks'), + inCategories('ELIXIR', 'Google Summer of Code'), ); await user.click(removeFilters()!); @@ -63,16 +66,13 @@ describe('Funding page filters', () => { }); it('starts with the filters given in the URL', () => { - window.history.replaceState(null, '', '/funding?filter=elixir-services'); + window.history.replaceState(null, '', '/funding?filter=elixir'); render(); expect(shown()).toBe( - `Showing ${count('ELIXIR Services')} of ${funding.length} project grants.`, - ); - expect(listedGrants()).toEqual(inCategories('ELIXIR Services')); - expect(filterButton(/^ELIXIR Services/)).toHaveAttribute( - 'aria-pressed', - 'true', + `Showing ${count('ELIXIR')} of ${funding.length} project grants.`, ); + expect(listedGrants()).toEqual(inCategories('ELIXIR')); + expect(filterButton(/^ELIXIR/)).toHaveAttribute('aria-pressed', 'true'); }); }); diff --git a/src/data/data.test.ts b/src/data/data.test.ts index 6629061..0a5815c 100644 --- a/src/data/data.test.ts +++ b/src/data/data.test.ts @@ -8,6 +8,7 @@ import type { Service, } from '@/components/catalog/types'; import contributors from './contributor.json'; +import funding from './funding.json'; import nodesData from './nodes.json'; import productsData from './product.json'; import { GA4GH_DRIVER_PROJECT_URL } from '@/lib/site'; @@ -116,6 +117,25 @@ describe('nodes.json', () => { ); }); +describe('funding.json', () => { + it('has unique ids', () => { + expect(duplicates(funding.map((grant) => grant.id))).toEqual([]); + }); + + it.each(funding.map((grant) => [grant.project, grant] as const))( + '%s names its programme and dates', + (_, grant) => { + // The programme is the card's title, filter and logo + expect(['ELIXIR', 'Google Summer of Code']).toContain(grant.category); + expect(grant.funder.startsWith(grant.category)).toBe(true); + // ISO dates, as the listing sorts them as text + expect(grant.startDate).toMatch(/^\d{4}-\d{2}-\d{2}$/); + expect(grant.endDate).toMatch(/^\d{4}-\d{2}-\d{2}$/); + expect(grant.startDate <= grant.endDate).toBe(true); + }, + ); +}); + describe('contributor.json', () => { it('only references images that exist', () => { const missing = contributors diff --git a/src/data/funding.json b/src/data/funding.json index 216fbbc..65bb718 100644 --- a/src/data/funding.json +++ b/src/data/funding.json @@ -1,13 +1,13 @@ [ { "id": "1", - "funder": "ELIXIR Commissioned Services: Technology", + "funder": "ELIXIR Commissioned Service: Technology", "project": "24-TECH-Compute", "recipients": ["ELIXIR Compute Platform"], "startDate": "2024-01-01", "endDate": "2026-12-31", "formattedDuration": "1 January 2024 - 31 December 2026", - "category": "ELIXIR Services" + "category": "ELIXIR" }, { "id": "2", @@ -77,7 +77,7 @@ "startDate": "2022-01-01", "endDate": "2023-12-31", "formattedDuration": "1 January 2022 - 31 December 2023", - "category": "ELIXIR Platform Tasks" + "category": "ELIXIR" }, { "id": "9", @@ -117,7 +117,7 @@ "startDate": "2021-06-01", "endDate": "2023-05-31", "formattedDuration": "1 June 2021 - 31 May 2023", - "category": "ELIXIR Implementation Studies" + "category": "ELIXIR" }, { "id": "13", @@ -187,7 +187,7 @@ "startDate": "2019-06-01", "endDate": "2021-05-31", "formattedDuration": "1 June 2019 - 31 May 2021", - "category": "ELIXIR Implementation Studies" + "category": "ELIXIR" }, { "id": "20", @@ -197,7 +197,7 @@ "startDate": "2019-06-01", "endDate": "2021-05-31", "formattedDuration": "1 June 2019 - 31 May 2021", - "category": "ELIXIR Platform Tasks" + "category": "ELIXIR" }, { "id": "21", diff --git a/src/lib/funding.test.ts b/src/lib/funding.test.ts new file mode 100644 index 0000000..d104f03 --- /dev/null +++ b/src/lib/funding.test.ts @@ -0,0 +1,85 @@ +import { describe, expect, it } from 'vitest'; +import { type Grant, grantType, sortGrants } from './funding'; + +const grant = ( + project: string, + startDate: string, + endDate: string, + category = 'ELIXIR', + funder = category, +): Grant => ({ + id: project, + funder, + project, + recipients: [], + startDate, + endDate, + formattedDuration: '', + category, +}); + +describe('sortGrants', () => { + it('orders by end date (newest first)', () => { + const grants = [ + grant('a', '2020-01-01', '2021-01-01'), + grant('b', '2020-01-01', '2023-01-01'), + grant('c', '2020-01-01', '2022-01-01'), + ]; + expect(sortGrants(grants).map((g) => g.project)).toEqual(['b', 'c', 'a']); + }); + + it('then by start date (oldest first)', () => { + const grants = [ + grant('a', '2022-01-01', '2023-01-01'), + grant('b', '2020-01-01', '2023-01-01'), + grant('c', '2021-01-01', '2023-01-01'), + ]; + expect(sortGrants(grants).map((g) => g.project)).toEqual(['b', 'c', 'a']); + }); + + it('then by name (ascending, alphanumerical)', () => { + const grants = [ + grant('Task 10', '2020-01-01', '2023-01-01'), + grant('task 9', '2020-01-01', '2023-01-01'), + grant('Apps', '2020-01-01', '2023-01-01'), + ]; + expect(sortGrants(grants).map((g) => g.project)).toEqual([ + 'Apps', + 'task 9', + 'Task 10', + ]); + }); + + it('leaves its input unchanged', () => { + const grants = [ + grant('a', '2020-01-01', '2021-01-01'), + grant('b', '2020-01-01', '2023-01-01'), + ]; + sortGrants(grants); + expect(grants.map((g) => g.project)).toEqual(['a', 'b']); + }); +}); + +describe('grantType', () => { + it('is the detailed type when it differs from the programme', () => { + expect( + grantType( + grant( + 'a', + '2020-01-01', + '2021-01-01', + 'ELIXIR', + 'ELIXIR Strategic Implementation Study', + ), + ), + ).toBe('ELIXIR Strategic Implementation Study'); + }); + + it('is null when the type is the programme itself', () => { + expect( + grantType( + grant('a', '2020-01-01', '2021-01-01', 'Google Summer of Code'), + ), + ).toBeNull(); + }); +}); diff --git a/src/lib/funding.ts b/src/lib/funding.ts new file mode 100644 index 0000000..3fa466b --- /dev/null +++ b/src/lib/funding.ts @@ -0,0 +1,41 @@ +import fundingData from '@/data/funding.json'; + +// A grant of the Funding page. `category` is the funding programme ("ELIXIR" +// or "Google Summer of Code"): the card's title and filter. `funder` is the +// detailed grant type, e.g. "ELIXIR Strategic Implementation Study", shown +// under the title when it adds to it. +export type Grant = { + id: string; + funder: string; + project: string; + recipients: string[]; + startDate: string; + endDate: string; + formattedDuration: string; + category: string; +}; + +// Dates are ISO 8601 (`YYYY-MM-DD`), so they compare as strings. +const compareText = (a: string, b: string) => + a.localeCompare(b, 'en', { numeric: true, sensitivity: 'base' }); + +/** + * Orders grants by end date (newest first), then by start date (oldest + * first), then by project name (ascending, alphanumerical). Returns a new + * array. + */ +export function sortGrants(grants: readonly T[]): T[] { + return [...grants].sort( + (a, b) => + b.endDate.localeCompare(a.endDate) || + a.startDate.localeCompare(b.startDate) || + compareText(a.project, b.project), + ); +} + +/** The detailed grant type to show under the title, if it adds anything. */ +export function grantType(grant: Grant): string | null { + return grant.funder !== grant.category ? grant.funder : null; +} + +export const grants: Grant[] = sortGrants(fundingData as Grant[]); From bf7dc5c14bbbc721afbb048e9b580b44d0b81714 Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Sat, 21 Nov 2026 20:17:26 +0100 Subject: [PATCH 2/5] docs: describe the funding data format Refs #214 Co-Authored-By: Claude Opus 5.5 --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 9968b6e..05526ea 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,13 @@ Content lives in JSON files under [`src/data/`](src/data/): To change content, edit the relevant file and open a pull request. +In `funding.json`, `category` is the funding programme, `ELIXIR` or +`Google Summer of Code`: it titles the grant's card, sets its logo and is +its filter. `funder` is the detailed grant type, e.g. `ELIXIR Strategic +Implementation Study`, shown under the title unless it equals the +programme. Dates are `YYYY-MM-DD`; grants are listed by end date (newest +first), then start date (oldest first), then name. + The listings (Products, Funding, Contributors) share one filter behaviour ([`src/lib/filters.ts`](src/lib/filters.ts)): several filters can be selected, and an item is listed if it matches any of them. The selection is kept in the From 1662432cc267db42b9d75b99176bcb55289dbb1c Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Sat, 21 Nov 2026 20:53:20 +0100 Subject: [PATCH 3/5] refactor: list funding programmes in one place Keeps the programmes and their logos in PROGRAMMES (src/lib/funding.ts), which sets the order of the filters, so that the order no longer depends on which grant ends last. Tests check that every programme has its logo and that every grant has the fields the card shows. Refs #214 Co-Authored-By: Claude Opus 5.5 --- README.md | 5 ++++- src/app/funding/page.test.tsx | 12 +++--------- src/app/funding/page.tsx | 29 +++++++++++++---------------- src/data/data.test.ts | 13 ++++++++++++- src/lib/funding.ts | 9 ++++++++- 5 files changed, 40 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 05526ea..73ba5b6 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,10 @@ In `funding.json`, `category` is the funding programme, `ELIXIR` or its filter. `funder` is the detailed grant type, e.g. `ELIXIR Strategic Implementation Study`, shown under the title unless it equals the programme. Dates are `YYYY-MM-DD`; grants are listed by end date (newest -first), then start date (oldest first), then name. +first), then start date (oldest first), then name. `formattedDuration` is +the period as shown on the card; keep it in step with the dates. A new +programme needs its logo in `public/` and an entry in `PROGRAMMES` in +[`src/lib/funding.ts`](src/lib/funding.ts). The listings (Products, Funding, Contributors) share one filter behaviour ([`src/lib/filters.ts`](src/lib/filters.ts)): several filters can be selected, diff --git a/src/app/funding/page.test.tsx b/src/app/funding/page.test.tsx index 21f80f9..60f9064 100644 --- a/src/app/funding/page.test.tsx +++ b/src/app/funding/page.test.tsx @@ -1,11 +1,9 @@ import { render, screen, within } from '@testing-library/react'; import { describe, expect, it } from 'vitest'; import funding from '@/data/funding.json'; -import { sortGrants } from '@/lib/funding'; +import { grantType, PROGRAMMES, sortGrants } from '@/lib/funding'; import FundingPage from './page'; -const PROGRAMMES = ['ELIXIR', 'Google Summer of Code']; - // The grant cards, in display order const cards = () => screen.getAllByRole('article'); @@ -23,7 +21,7 @@ describe('Funding page', () => { const filters = within(screen.getByRole('group', { name: 'Filter' })) .getAllByRole('button') .map((button) => button.firstChild?.textContent); - expect(filters).toEqual(PROGRAMMES); + expect(filters).toEqual(PROGRAMMES.map(({ name }) => name)); }); it('sorts grants by end date, start date and name', () => { @@ -48,11 +46,7 @@ describe('Funding page', () => { `${grant.category} logo`, ); const type = card.querySelector('[data-testid="grant-type"]'); - if (grant.category === 'ELIXIR') { - expect(type?.textContent).toBe(grant.funder); - } else { - expect(type).toBeNull(); - } + expect(type?.textContent ?? null).toBe(grantType(grant)); // The programme is in the title; no badge repeats it expect(header.queryByText(/^(Grant|GSoC)$/)).toBeNull(); }); diff --git a/src/app/funding/page.tsx b/src/app/funding/page.tsx index 5947513..e00105b 100644 --- a/src/app/funding/page.tsx +++ b/src/app/funding/page.tsx @@ -18,27 +18,22 @@ import { Card } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { AnimatedGridPattern } from '@/components/ui/animated-grid-pattern'; import { checkFilterIds, filterId, matchesAny } from '@/lib/filters'; -import { type Grant, grants, grantType } from '@/lib/funding'; +import { type Grant, grants, grantType, PROGRAMMES } from '@/lib/funding'; import { useUrlFilters } from '@/lib/use-url-filters'; import { cn } from '@/lib/utils'; -const GSOC = 'Google Summer of Code'; - // The logo of each programme (`category`) -const LOGOS: Record = { - ELIXIR: '/elixir.png', - [GSOC]: '/gsoc.svg', -}; +const LOGOS = Object.fromEntries( + PROGRAMMES.map(({ name, logo }) => [name, logo]), +); -// One filter per programme, in the order the programmes first appear +// One filter per programme, in the order of PROGRAMMES const categoryOptions = checkFilterIds( - Array.from(new Set(grants.map((grant) => grant.category))).map( - (category) => ({ - value: filterId(category), - label: category, - count: grants.filter((grant) => grant.category === category).length, - }), - ), + PROGRAMMES.map(({ name }) => ({ + value: filterId(name), + label: name, + count: grants.filter((grant) => grant.category === name).length, + })), ); const categoryIds = categoryOptions.map((option) => option.value); @@ -62,7 +57,9 @@ export default function FundingPage() { }, [query, selected]); // Stat metrics - const gsocCount = grants.filter((g) => g.category === GSOC).length; + const gsocCount = grants.filter( + (g) => g.category === 'Google Summer of Code', + ).length; const elixirCount = grants.filter((g) => g.category === 'ELIXIR').length; return ( diff --git a/src/data/data.test.ts b/src/data/data.test.ts index 0a5815c..9c13753 100644 --- a/src/data/data.test.ts +++ b/src/data/data.test.ts @@ -8,6 +8,7 @@ import type { Service, } from '@/components/catalog/types'; import contributors from './contributor.json'; +import { PROGRAMMES } from '@/lib/funding'; import funding from './funding.json'; import nodesData from './nodes.json'; import productsData from './product.json'; @@ -118,6 +119,13 @@ describe('nodes.json', () => { }); describe('funding.json', () => { + it.each(PROGRAMMES.map(({ name, logo }) => [name, logo]))( + 'has the logo of %s', + (_, logo) => { + expect(publicFile(logo), logo).toBe(true); + }, + ); + it('has unique ids', () => { expect(duplicates(funding.map((grant) => grant.id))).toEqual([]); }); @@ -126,12 +134,15 @@ describe('funding.json', () => { '%s names its programme and dates', (_, grant) => { // The programme is the card's title, filter and logo - expect(['ELIXIR', 'Google Summer of Code']).toContain(grant.category); + expect(PROGRAMMES.map(({ name }) => name)).toContain(grant.category); expect(grant.funder.startsWith(grant.category)).toBe(true); // ISO dates, as the listing sorts them as text expect(grant.startDate).toMatch(/^\d{4}-\d{2}-\d{2}$/); expect(grant.endDate).toMatch(/^\d{4}-\d{2}-\d{2}$/); expect(grant.startDate <= grant.endDate).toBe(true); + expect(grant.project).toBeTruthy(); + expect(grant.recipients.length).toBeGreaterThan(0); + expect(grant.formattedDuration).toBeTruthy(); }, ); }); diff --git a/src/lib/funding.ts b/src/lib/funding.ts index 3fa466b..0e17ccb 100644 --- a/src/lib/funding.ts +++ b/src/lib/funding.ts @@ -15,7 +15,13 @@ export type Grant = { category: string; }; -// Dates are ISO 8601 (`YYYY-MM-DD`), so they compare as strings. +// The funding programmes (`category`), in the order of the filters, with +// their logos in `public/`. A new programme needs an entry here. +export const PROGRAMMES: readonly { name: string; logo: string }[] = [ + { name: 'ELIXIR', logo: '/elixir.png' }, + { name: 'Google Summer of Code', logo: '/gsoc.svg' }, +]; + const compareText = (a: string, b: string) => a.localeCompare(b, 'en', { numeric: true, sensitivity: 'base' }); @@ -25,6 +31,7 @@ const compareText = (a: string, b: string) => * array. */ export function sortGrants(grants: readonly T[]): T[] { + // Dates are ISO 8601 (`YYYY-MM-DD`), so they compare as strings return [...grants].sort( (a, b) => b.endDate.localeCompare(a.endDate) || From f9ef39ccc33f690bd213ac95f113637d219bdec8 Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Sat, 21 Nov 2026 21:43:04 +0100 Subject: [PATCH 4/5] test: pin the funding stats and filter order Asserts the stat values and the literal filter order, checks that every programme has grants, and documents that a grant type starts with its programme's name. Refs #214 Co-Authored-By: Claude Opus 5.5 --- README.md | 5 +++-- src/app/funding/page.test.tsx | 14 ++++++++++++-- src/app/funding/page.tsx | 2 ++ src/data/data.test.ts | 4 ++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 73ba5b6..37b5dd8 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,9 @@ In `funding.json`, `category` is the funding programme, `ELIXIR` or `Google Summer of Code`: it titles the grant's card, sets its logo and is its filter. `funder` is the detailed grant type, e.g. `ELIXIR Strategic Implementation Study`, shown under the title unless it equals the -programme. Dates are `YYYY-MM-DD`; grants are listed by end date (newest -first), then start date (oldest first), then name. `formattedDuration` is +programme; it starts with the programme's name. Dates are `YYYY-MM-DD`; +grants are listed by end date (newest first), then start date (oldest +first), then name. `formattedDuration` is the period as shown on the card; keep it in step with the dates. A new programme needs its logo in `public/` and an entry in `PROGRAMMES` in [`src/lib/funding.ts`](src/lib/funding.ts). diff --git a/src/app/funding/page.test.tsx b/src/app/funding/page.test.tsx index 60f9064..4257369 100644 --- a/src/app/funding/page.test.tsx +++ b/src/app/funding/page.test.tsx @@ -1,7 +1,7 @@ import { render, screen, within } from '@testing-library/react'; import { describe, expect, it } from 'vitest'; import funding from '@/data/funding.json'; -import { grantType, PROGRAMMES, sortGrants } from '@/lib/funding'; +import { grantType, sortGrants } from '@/lib/funding'; import FundingPage from './page'; // The grant cards, in display order @@ -14,6 +14,16 @@ describe('Funding page', () => { .getAllByTestId('stat') .map((stat) => stat.lastChild?.textContent); expect(labels).toEqual(['Total grants', 'ELIXIR grants', 'GSoC projects']); + const count = (category: string) => + funding.filter((grant) => grant.category === category).length; + const values = screen + .getAllByTestId('stat') + .map((stat) => stat.firstChild?.textContent); + expect(values).toEqual( + [funding.length, count('ELIXIR'), count('Google Summer of Code')].map( + String, + ), + ); }); it('offers one filter per programme', () => { @@ -21,7 +31,7 @@ describe('Funding page', () => { const filters = within(screen.getByRole('group', { name: 'Filter' })) .getAllByRole('button') .map((button) => button.firstChild?.textContent); - expect(filters).toEqual(PROGRAMMES.map(({ name }) => name)); + expect(filters).toEqual(['ELIXIR', 'Google Summer of Code']); }); it('sorts grants by end date, start date and name', () => { diff --git a/src/app/funding/page.tsx b/src/app/funding/page.tsx index e00105b..93d6d91 100644 --- a/src/app/funding/page.tsx +++ b/src/app/funding/page.tsx @@ -57,6 +57,8 @@ export default function FundingPage() { }, [query, selected]); // Stat metrics + // The stats name the two programmes, as the issue for the page asks; + // a new programme gets a filter (PROGRAMMES) but no stat of its own const gsocCount = grants.filter( (g) => g.category === 'Google Summer of Code', ).length; diff --git a/src/data/data.test.ts b/src/data/data.test.ts index 9c13753..45b563c 100644 --- a/src/data/data.test.ts +++ b/src/data/data.test.ts @@ -126,6 +126,10 @@ describe('funding.json', () => { }, ); + it.each(PROGRAMMES.map(({ name }) => [name]))('has grants of %s', (name) => { + expect(funding.some((grant) => grant.category === name)).toBe(true); + }); + it('has unique ids', () => { expect(duplicates(funding.map((grant) => grant.id))).toEqual([]); }); From 000c3ec84d8d7f4ebd34231c4c8fd63a77c8aa2e Mon Sep 17 00:00:00 2001 From: Alex Kanitz Date: Sat, 21 Nov 2026 22:32:43 +0100 Subject: [PATCH 5/5] fix: restrict grants to known programmes Types a grant's category as one of the programmes and checks the data on load, so that a grant of an unknown programme fails the build instead of showing without a logo or filter. The stats use the shared programme names. Addresses Sourcery's review. Refs #214 Co-Authored-By: Claude Opus 5.5 --- src/app/funding/page.tsx | 17 +++++++++------- src/lib/funding.test.ts | 27 +++++++++++++++++++++--- src/lib/funding.ts | 44 +++++++++++++++++++++++++++++++++------- 3 files changed, 71 insertions(+), 17 deletions(-) diff --git a/src/app/funding/page.tsx b/src/app/funding/page.tsx index 93d6d91..1a7b87a 100644 --- a/src/app/funding/page.tsx +++ b/src/app/funding/page.tsx @@ -18,7 +18,14 @@ import { Card } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { AnimatedGridPattern } from '@/components/ui/animated-grid-pattern'; import { checkFilterIds, filterId, matchesAny } from '@/lib/filters'; -import { type Grant, grants, grantType, PROGRAMMES } from '@/lib/funding'; +import { + ELIXIR, + type Grant, + grants, + grantType, + GSOC, + PROGRAMMES, +} from '@/lib/funding'; import { useUrlFilters } from '@/lib/use-url-filters'; import { cn } from '@/lib/utils'; @@ -57,12 +64,8 @@ export default function FundingPage() { }, [query, selected]); // Stat metrics - // The stats name the two programmes, as the issue for the page asks; - // a new programme gets a filter (PROGRAMMES) but no stat of its own - const gsocCount = grants.filter( - (g) => g.category === 'Google Summer of Code', - ).length; - const elixirCount = grants.filter((g) => g.category === 'ELIXIR').length; + const gsocCount = grants.filter((g) => g.category === GSOC).length; + const elixirCount = grants.filter((g) => g.category === ELIXIR).length; return (
diff --git a/src/lib/funding.test.ts b/src/lib/funding.test.ts index d104f03..e558f79 100644 --- a/src/lib/funding.test.ts +++ b/src/lib/funding.test.ts @@ -1,12 +1,18 @@ import { describe, expect, it } from 'vitest'; -import { type Grant, grantType, sortGrants } from './funding'; +import { + checkGrants, + type Grant, + grantType, + type Programme, + sortGrants, +} from './funding'; const grant = ( project: string, startDate: string, endDate: string, - category = 'ELIXIR', - funder = category, + category: Programme = 'ELIXIR', + funder: string = category, ): Grant => ({ id: project, funder, @@ -83,3 +89,18 @@ describe('grantType', () => { ).toBeNull(); }); }); + +describe('checkGrants', () => { + it('accepts grants of known programmes', () => { + const grants = [grant('a', '2020-01-01', '2021-01-01')]; + expect(checkGrants(grants)).toBe(grants); + }); + + it('rejects a grant of an unknown programme', () => { + expect(() => + checkGrants([ + { ...grant('a', '2020-01-01', '2021-01-01'), category: 'Other' }, + ]), + ).toThrow('The grant "a" has the unknown programme "Other"'); + }); +}); diff --git a/src/lib/funding.ts b/src/lib/funding.ts index 0e17ccb..c117b36 100644 --- a/src/lib/funding.ts +++ b/src/lib/funding.ts @@ -1,5 +1,11 @@ import fundingData from '@/data/funding.json'; +export const ELIXIR = 'ELIXIR'; +export const GSOC = 'Google Summer of Code'; + +/** A funding programme: the `category` of a grant. */ +export type Programme = typeof ELIXIR | typeof GSOC; + // A grant of the Funding page. `category` is the funding programme ("ELIXIR" // or "Google Summer of Code"): the card's title and filter. `funder` is the // detailed grant type, e.g. "ELIXIR Strategic Implementation Study", shown @@ -12,14 +18,14 @@ export type Grant = { startDate: string; endDate: string; formattedDuration: string; - category: string; + category: Programme; }; // The funding programmes (`category`), in the order of the filters, with // their logos in `public/`. A new programme needs an entry here. -export const PROGRAMMES: readonly { name: string; logo: string }[] = [ - { name: 'ELIXIR', logo: '/elixir.png' }, - { name: 'Google Summer of Code', logo: '/gsoc.svg' }, +export const PROGRAMMES: readonly { name: Programme; logo: string }[] = [ + { name: ELIXIR, logo: '/elixir.png' }, + { name: GSOC, logo: '/gsoc.svg' }, ]; const compareText = (a: string, b: string) => @@ -30,7 +36,9 @@ const compareText = (a: string, b: string) => * first), then by project name (ascending, alphanumerical). Returns a new * array. */ -export function sortGrants(grants: readonly T[]): T[] { +export function sortGrants< + T extends Pick, +>(grants: readonly T[]): T[] { // Dates are ISO 8601 (`YYYY-MM-DD`), so they compare as strings return [...grants].sort( (a, b) => @@ -41,8 +49,30 @@ export function sortGrants(grants: readonly T[]): T[] { } /** The detailed grant type to show under the title, if it adds anything. */ -export function grantType(grant: Grant): string | null { +export function grantType(grant: { + funder: string; + category: string; +}): string | null { return grant.funder !== grant.category ? grant.funder : null; } -export const grants: Grant[] = sortGrants(fundingData as Grant[]); +/** + * Returns the grants after checking that each names a known programme, so + * that none is listed without its logo and filter. Pages are prerendered, + * so an unknown programme fails the build. + */ +export function checkGrants( + data: readonly (Omit & { category: string })[], +): Grant[] { + const known = new Set(PROGRAMMES.map(({ name }) => name)); + data.forEach(({ project, category }) => { + if (!known.has(category)) { + throw new Error( + `The grant "${project}" has the unknown programme "${category}"`, + ); + } + }); + return data as Grant[]; +} + +export const grants: Grant[] = sortGrants(checkGrants(fundingData));