Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 11 additions & 103 deletions web/src/components/AidGuideSections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { C, MODULE_COLORS } from '../lib/designTokens'
import { fetchAllGuarantees, type AidGuarantee, type GuaranteeList } from '../lib/aidColleges'
import { formatCollegeDate, parseIsoDay } from '../data/applicationDeadlines'
import { US_STATES } from '../lib/fafsaData'
import { SecLabel } from './moduleUI'
import { EdvifiCan, ExtLink, GuideIntro as Intro, GuideItem as Item, GuideRow, SecLabel } from './moduleUI'
import {
AID_FACTS_AS_OF,
guaranteeLabel,
Expand Down Expand Up @@ -56,40 +56,6 @@ const SANS = "'Outfit',sans-serif"

export type AidGuideDestination = 'fafsa' | 'scholarships' | 'scholarship-search'

const Chevron = () => (
<svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M6 4l4 4-4 4"/></svg>
)

const ExtLink = ({ href, children, color = MC }: { href: string; children: ReactNode; color?: string }) => (
<a href={href} target="_blank" rel="noopener noreferrer" style={{ fontFamily: SANS, fontSize: 12, fontWeight: 600, color, textDecoration: 'none', whiteSpace: 'nowrap' }}>
{children} ↗
</a>
)

/** One entry inside an open row: name and figure on top, the explanation under it. */
const Item = ({ title, figure, children, links, color = MC, chip }: {
title: string
figure?: string
children: ReactNode
links?: ReactNode
color?: string
/** Render the title as a colored chip instead of bold text. */
chip?: boolean
}) => (
<div style={{ display: 'flex', gap: 12, alignItems: 'flex-start', padding: '10px 0', borderBottom: `1px solid ${C.border}` }}>
<div style={{ flex: 1, minWidth: 0 }}>
<div style={{ fontFamily: SANS, fontSize: 13, lineHeight: 1.4 }}>
{chip
? <span style={{ display: 'inline-block', fontWeight: 700, fontSize: 12, color, background: `${color}15`, border: `1px solid ${color}30`, padding: '1px 9px', borderRadius: 99 }}>{title}</span>
: <span style={{ fontWeight: 700, color: C.text }}>{title}</span>}
{figure && <span style={{ fontWeight: 600, color }}> · {figure}</span>}
</div>
<div style={{ fontFamily: SANS, fontSize: 12, color: C.textMuted, lineHeight: 1.5, marginTop: 2 }}>{children}</div>
</div>
{links && <div style={{ display: 'flex', gap: 10, flexShrink: 0, paddingTop: 1 }}>{links}</div>}
</div>
)

const ProgramItem = ({ p, color }: { p: AidProgram; color: string }) => (
<Item
title={p.name}
Expand All @@ -107,64 +73,6 @@ const GuaranteeItem = ({ g }: { g: AidGuarantee }) => (
</Item>
)

/** "Edvifi can ___" — one line at the foot of a row, pointing at the tool that does it. */
const EdvifiCan = ({ can, cta, onClick, color = MC }: { can: string; cta: string; onClick: () => void; color?: string }) => (
// A quiet tinted strip rather than a banner: it should read as the next step,
// not as an ad, but still be the first thing the eye lands on at the bottom.
<div style={{ display: 'flex', alignItems: 'center', gap: 12, flexWrap: 'wrap', marginTop: 12, padding: '10px 12px', borderRadius: 9, background: `${color}10`, border: `1px solid ${color}2E`, fontFamily: SANS, fontSize: 13, color: C.text }}>
<span style={{ flex: '1 1 220px', display: 'flex', alignItems: 'center', gap: 10 }}>
<span aria-hidden="true" style={{ width: 28, height: 28, borderRadius: 7, flexShrink: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', background: C.surface, border: `1px solid ${color}26` }}>
<img src="/logos/logo-color.png" alt="" style={{ width: 18, height: 18, objectFit: 'contain' }} />
</span>
<span style={{ lineHeight: 1.45 }}><strong style={{ color: C.text, fontWeight: 700 }}>Edvifi</strong> can {can}</span>
</span>
<button onClick={onClick} style={{ flexShrink: 0, padding: '7px 13px', borderRadius: 8, border: 'none', background: color, color: '#fff', cursor: 'pointer', fontFamily: SANS, fontSize: 12, fontWeight: 600 }}>
{cta} →
</button>
</div>
)

/** A collapsible row in the same shape as the checklist sections below it. */
const Row = ({ kind, title, summary, tag, open, onToggle, children }: {
kind: keyof typeof ROWS
title: string
summary: string
tag?: string
open: boolean
onToggle: () => void
children: ReactNode
}) => {
const { color, icon } = ROWS[kind]
const [hover, setHover] = useState(false)
const edge = open || hover ? `${color}45` : C.border
return (
// Longhands only. Mixing the `border` shorthand with `borderLeft` lets React
// re-apply the shorthand on toggle and wipe the colored edge.
<div style={{ marginBottom: 10, borderStyle: 'solid', borderWidth: '1px 1px 1px 3px', borderColor: `${edge} ${edge} ${edge} ${color}`, transition: 'border-color 0.15s ease', borderRadius: 10, overflow: 'hidden', background: C.surface }}>
<button
onClick={onToggle}
onMouseEnter={() => setHover(true)}
onMouseLeave={() => setHover(false)}
aria-expanded={open}
style={{ display: 'flex', alignItems: 'center', width: '100%', padding: '11px 14px', background: open || hover ? `${color}0D` : C.surface, transition: 'background 0.15s ease', border: 'none', borderBottom: open ? `1px solid ${color}25` : 'none', cursor: 'pointer', gap: 12, textAlign: 'left' }}
>
<span aria-hidden="true" style={{ width: 32, height: 32, borderRadius: 8, flexShrink: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', color, background: `${color}18` }}>{icon}</span>
<span style={{ flex: 1, minWidth: 0 }}>
<span style={{ display: 'block', fontFamily: SANS, fontSize: 13.5, fontWeight: 700, color: C.text }}>{title}</span>
<span style={{ display: 'block', fontFamily: SANS, fontSize: 12, color: C.textMuted, marginTop: 1 }}>{summary}</span>
</span>
{tag && <span style={{ flexShrink: 0, fontFamily: SANS, fontSize: 11, fontWeight: 700, color, background: `${color}18`, padding: '3px 9px', borderRadius: 99 }}>{tag}</span>}
<span style={{ transform: open ? 'rotate(90deg)' : 'rotate(0)', transition: 'transform 0.15s ease', color: open || hover ? color : C.textMuted, display: 'flex', flexShrink: 0 }}><Chevron /></span>
</button>
{open && <div style={{ padding: '2px 16px 12px' }}>{children}</div>}
</div>
)
}

const Intro = ({ children }: { children: ReactNode }) => (
<p style={{ fontFamily: SANS, fontSize: 12.5, color: C.text, lineHeight: 1.55, margin: '10px 0 4px' }}>{children}</p>
)

export type GuideRowId = 'big' | 'uni' | 'state' | 'types'

interface Props {
Expand Down Expand Up @@ -209,13 +117,13 @@ export default function AidGuideSections({ homeState, yourSchools, listFailed, o
<div>
<SecLabel>Know your aid</SecLabel>

<Row kind="big" title="The big programs" summary="Pell Grant, QuestBridge, ROTC and the GI Bill" open={open === 'big'} onToggle={() => toggle('big')}>
<GuideRow {...ROWS.big} title="The big programs" summary="Pell Grant, QuestBridge, ROTC and the GI Bill" open={open === 'big'} onToggle={() => toggle('big')}>
{MAJOR_PROGRAMS.map((p) => <ProgramItem key={p.id} p={p} color={ROWS.big.color} />)}
<EdvifiCan color={ROWS.big.color} can="walk you through the FAFSA, which is how you get considered for Pell." cta="Start FAFSA prep" onClick={() => onGoTo('fafsa')} />
</Row>
</GuideRow>

<Row
kind="uni"
<GuideRow
{...ROWS.uni}
title="Your schools’ own aid applications"
summary={listFailed
? 'Couldn’t check your schools just now. Your list is saved'
Expand Down Expand Up @@ -244,10 +152,10 @@ export default function AidGuideSections({ homeState, yourSchools, listFailed, o
</>
)}
</details>
</Row>
</GuideRow>

<Row
kind="state"
<GuideRow
{...ROWS.state}
title="State grants"
summary={homeGrant ? `${homeGrant.name} for ${homeGrant.stateName} residents`
: homeName ? `Where to find ${homeName}’s aid`
Expand All @@ -271,12 +179,12 @@ export default function AidGuideSections({ homeState, yourSchools, listFailed, o
</details>
) : otherGrants.map(grantItem)}
<EdvifiCan color={ROWS.state.color} can="line up the FAFSA priority date for every school on your list." cta="See my schools’ dates" onClick={() => onGoTo('scholarships')} />
</Row>
</GuideRow>

<Row kind="types" title="Five kinds of scholarships" summary="Merit, need, institutional, national and specialized" open={open === 'types'} onToggle={() => toggle('types')}>
<GuideRow {...ROWS.types} title="Five kinds of scholarships" summary="Merit, need, institutional, national and specialized" open={open === 'types'} onToggle={() => toggle('types')}>
{SCHOLARSHIP_CATEGORIES.map((c) => <Item key={c.id} title={c.name} chip color={CATEGORY_COLOR[c.id] ?? ROWS.types.color}>{c.description} {c.example}.</Item>)}
<EdvifiCan color={ROWS.types.color} can="match you with scholarships that fit your profile." cta="Find my matches" onClick={() => onGoTo('scholarship-search')} />
</Row>
</GuideRow>

<p style={{ fontFamily: SANS, fontSize: 11, color: C.textMuted, margin: '2px 0 0' }}>
Amounts are for {AID_FACTS_AS_OF} and change every year. Confirm on the official site.
Expand Down
59 changes: 59 additions & 0 deletions web/src/components/ApplicationGuideSections.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { describe, it, expect, vi } from 'vitest'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import ApplicationGuideSections, { ApplicationRounds } from './ApplicationGuideSections'
import type { ApplicationEntry } from '../data/applicationsChecklist'

vi.mock('../lib/supabase', () => ({ supabase: {} }))

const app = (name: string, over: Partial<ApplicationEntry> = {}): ApplicationEntry => ({
collegeId: `test-${name}`, name, category: 'reach', deadlineType: 'RD', status: 'not-started', ...over,
})
const apps = [
app('Duke', { deadlineType: 'ED', customDeadline: '2099-11-01', applicationFeeCents: 8500 }),
app('UNC', { customDeadline: '2099-01-15', applicationFeeCents: 0 }),
app('Elon', { customDeadline: '2099-01-10', applicationFeeCents: 6000 }),
app('Wake Tech', { deadlineType: 'Rolling', institutionType: '2yr' }),
app('Rice', { deadlineType: 'EA', status: 'submitted', applicationFeeCents: 7500 }),
]

describe('ApplicationRounds', () => {
it('places the schools still to send in each round', async () => {
const onSeeSchools = vi.fn()
render(<ApplicationRounds apps={apps} gradeStartIdx={null} onSeeSchools={onSeeSchools} />)
expect(screen.getByText('Applying early to 1 school: Duke, Nov 1, 2099')).toBeInTheDocument()
expect(screen.getByText('2 schools in Regular Decision; Elon is first, Jan 10, 2099; 1 more is rolling')).toBeInTheDocument()
await userEvent.click(screen.getByRole('button', { name: /^Regular Decision/ }))
expect(onSeeSchools).toHaveBeenCalledOnce()
})

it('points an empty list at Discover', () => {
render(<ApplicationRounds apps={[]} gradeStartIdx={null} onSeeSchools={() => {}} />)
expect(screen.getAllByText('Add schools in Discover to see where yours fall')).toHaveLength(2)
})

it('says an early application is in rather than missing', () => {
render(<ApplicationRounds apps={apps.filter((a) => a.name !== 'Duke')} gradeStartIdx={null} onSeeSchools={() => {}} />)
expect(screen.getByText('Your early application is in')).toBeInTheDocument()
})
})

describe('ApplicationGuideSections', () => {
it('sums up the list and opens onto Application 101', async () => {
const onRead = vi.fn()
render(<ApplicationGuideSections apps={apps} onRead={onRead} onSeeSchools={() => {}} />)
// Rice is in, so its fee is off the bill; Wake Tech has none on file.
expect(screen.getByText('Your list: $145 for 2 schools, 1 free, 1 not on file')).toBeInTheDocument()
expect(screen.getByText('On your list: 1 ED, 1 EA, 2 RD, 1 rolling')).toBeInTheDocument()

await userEvent.click(screen.getByRole('button', { name: /^Application rounds/ }))
expect(screen.getByText('2 on your list', { exact: false })).toBeInTheDocument()
await userEvent.click(screen.getByRole('button', { name: /Should I apply ED/ }))
expect(onRead).toHaveBeenCalledWith('as-2')
})

it('leaves fees general until one is on file', () => {
render(<ApplicationGuideSections apps={[app('Elon'), app('Duke')]} onRead={() => {}} onSeeSchools={() => {}} />)
expect(screen.getByText('Many schools are free, and a waiver covers the rest for many families')).toBeInTheDocument()
})
})
Loading
Loading