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
45 changes: 39 additions & 6 deletions web/src/components/ApplicationStatusTab.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState } from 'react'
import { describe, it, expect, vi } from 'vitest'
import { render, screen, within, fireEvent } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import ApplicationStatusTab from './ApplicationStatusTab'
import ApplicationStatusTab, { ALL_SCHOOLS } from './ApplicationStatusTab'
import { setSharedTask, tasksForEntry } from '../data/applicationTasks'
import type { ApplicationEntry } from '../data/applicationsChecklist'

Expand All @@ -24,7 +24,10 @@ const APPS = [

/** A school's row in the list (the timeline has its own button per school). */
const schoolRow = (name: string) =>
screen.getAllByRole('button', { name: new RegExp(name) }).find((b) => b.classList.contains('ast-row'))!
screen.queryAllByRole('button', { name: new RegExp(name) }).find((b) => b.classList.contains('ast-row'))!

/** The rows sit one level in from the landing summary. */
const goToList = () => userEvent.click(screen.getByRole('button', { name: /See all \d+ schools?/ }))

// A task with no date shows an "Add date" button, not an empty input: an
// empty date box is a blank square that says nothing about what it is for.
Expand Down Expand Up @@ -53,15 +56,24 @@ const renderTab = (apps = APPS, initialOpenId: string | null = null) => {
}

describe('ApplicationStatusTab', () => {
it('shows a summary, the shared tasks and one row per school', () => {
it('lands on a summary: status, next up and the shared tasks', () => {
renderTab()
expect(screen.getByRole('heading', { level: 2 })).toHaveTextContent('Your applications')
expect(screen.getByRole('button', { name: /1 to submit/ })).toBeInTheDocument()
expect(screen.getByText('Shared across your list')).toBeInTheDocument()
expect(screen.getByText('Request teacher recommendations')).toBeInTheDocument()
expect(screen.getByRole('button', { name: /^Next up: Alpha College/ })).toBeInTheDocument()
// The rows themselves are one level in.
expect(schoolRow('Alpha College')).toBeUndefined()
expect(screen.getByRole('button', { name: /See all 2 schools/ })).toBeInTheDocument()
})

it('shows one row per school once the list is opened', async () => {
renderTab()
await goToList()
expect(screen.getByRole('heading', { level: 2 })).toHaveTextContent('Your schools')
expect(schoolRow('Alpha College')).toBeInTheDocument()
expect(schoolRow('Beta University')).toBeInTheDocument()
expect(screen.getByRole('button', { name: /^Next up: Alpha College/ })).toBeInTheDocument()
// Per-school tasks stay on the school page.
expect(screen.queryByText('Draft the supplemental essay(s)')).not.toBeInTheDocument()
})
Expand All @@ -74,16 +86,18 @@ describe('ApplicationStatusTab', () => {

it('opens a school page with its own checklist, and goes back', async () => {
renderTab()
await goToList()
await userEvent.click(schoolRow('Alpha College'))
expect(screen.getByRole('heading', { name: 'Alpha College' })).toBeInTheDocument()
expect(screen.getByText('Draft the supplemental essay(s)')).toBeInTheDocument()
expect(screen.getAllByText('Shared with 1 other school').length).toBeGreaterThan(0)
await userEvent.click(screen.getByText('← All applications'))
expect(screen.getByText('Shared across your list')).toBeInTheDocument()
expect(schoolRow('Alpha College')).toBeInTheDocument()
})

it('routes a shared task ticked on a school page to every school', async () => {
const { onSetShared, onUpdate } = renderTab()
await goToList()
await userEvent.click(schoolRow('Alpha College'))
const row = screen.getByText('Request teacher recommendations').parentElement!
await userEvent.click(row.querySelector('button')!)
Expand Down Expand Up @@ -111,20 +125,30 @@ describe('ApplicationStatusTab', () => {

it('filters the school list from the status strip', async () => {
renderTab([app('sc-1', 'Alpha College'), app('sc-2', 'Beta University', { status: 'accepted' })])
await goToList()
await userEvent.click(screen.getByRole('button', { name: /1 accepted/ }))
expect(schoolRow('Beta University')).toBeInTheDocument()
expect(schoolRow('Alpha College')).toBeUndefined()
await userEvent.click(screen.getByText('Show all'))
expect(schoolRow('Alpha College')).toBeInTheDocument()
})

it('opens straight onto the full list when routed there', () => {
// What the module passes for "See all", and what a refresh on
// #/dashboard/application-tracking/status/all restores.
renderTab(APPS, ALL_SCHOOLS)
expect(screen.getByRole('heading', { level: 2 })).toHaveTextContent('Your schools')
expect(schoolRow('Alpha College')).toBeInTheDocument()
})

it('opens straight onto a school when asked to', () => {
renderTab(APPS, 'sc-2')
expect(screen.getByRole('heading', { name: 'Beta University' })).toBeInTheDocument()
})

it('edits category and round from the school page', async () => {
const { onUpdate } = renderTab()
await goToList()
await userEvent.click(schoolRow('Alpha College'))
await userEvent.selectOptions(screen.getByRole('combobox', { name: 'Reach, target or likely' }), 'reach')
expect(onUpdate).toHaveBeenCalledWith('sc-1', { category: 'reach' })
Expand All @@ -134,15 +158,17 @@ describe('ApplicationStatusTab', () => {

it('removes a school only after confirming', async () => {
const { onRemove } = renderTab()
await goToList()
await userEvent.click(schoolRow('Alpha College'))
await userEvent.click(screen.getByText('Remove from my list'))
expect(onRemove).not.toHaveBeenCalled()
await userEvent.click(screen.getByRole('button', { name: 'Remove' }))
expect(onRemove).toHaveBeenCalledWith('sc-1')
})

it('sorts schools still to submit ahead of decided ones', () => {
it('sorts schools still to submit ahead of decided ones', async () => {
renderTab([app('sc-2', 'Beta University', { status: 'accepted' }), app('sc-1', 'Alpha College')])
await goToList()
const rows = screen.getAllByRole('button', { name: /Alpha College|Beta University/ }).filter((b) => b.classList.contains('ast-row'))
expect(rows.map((r) => r.textContent?.match(/Alpha College|Beta University/)?.[0])).toEqual(['Alpha College', 'Beta University'])
})
Expand All @@ -159,6 +185,7 @@ describe('ApplicationStatusTab', () => {
const saved = app('sc-1', 'Alpha College', { deadlineType: 'RD' })
const withTasks = { ...saved, tasks: tasksForEntry(saved) }
const { onUpdate } = renderTab([withTasks])
await goToList()
await userEvent.click(schoolRow('Alpha College'))
await userEvent.selectOptions(screen.getByRole('combobox', { name: 'Application round' }), 'ED')
const fields = onUpdate.mock.calls.at(-1)![1]
Expand All @@ -168,6 +195,7 @@ describe('ApplicationStatusTab', () => {

it('dates a per-school task on that school, and a shared task on every school', async () => {
const { onUpdate, onSetSharedDue } = renderTab()
await goToList()
await userEvent.click(schoolRow('Alpha College'))
const essayBox = await openDateBox('Draft the supplemental essay(s)')
fireEvent.focus(essayBox)
Expand All @@ -192,6 +220,7 @@ describe('ApplicationStatusTab', () => {

it('saves the date box once typing settles, not each in-between value', async () => {
const { onUpdate } = renderTab()
await goToList()
await userEvent.click(schoolRow('Alpha College'))
const box = await openDateBox('Draft the supplemental essay(s)')
onUpdate.mockClear()
Expand All @@ -211,6 +240,7 @@ describe('ApplicationStatusTab', () => {
const saved = app('sc-1', 'Alpha College')
const withDue = { ...saved, tasks: tasksForEntry(saved).map((t) => (t.id === 'essays' ? { ...t, due: '2026-10-12' } : t)) }
const { onUpdate } = renderTab([withDue])
await goToList()
await userEvent.click(schoolRow('Alpha College'))
const box = await openSavedDate('Draft the supplemental essay(s)')
fireEvent.focus(box)
Expand All @@ -222,6 +252,7 @@ describe('ApplicationStatusTab', () => {

it('saves the student\'s own deadline from the school page, and clears it when the round changes', async () => {
const { onUpdate } = renderTab()
await goToList()
await userEvent.click(schoolRow('Alpha College'))
await userEvent.click(screen.getByRole('button', { name: "Add a due date for this school's deadline" }))
const box = screen.getByLabelText("Due date for this school's deadline")
Expand All @@ -239,6 +270,7 @@ describe('ApplicationStatusTab', () => {
app('sc-2', 'Beta University', { category: 'reach' }),
app('sc-3', 'Gamma Institute', { category: 'reach' }),
])
await goToList()
await userEvent.click(screen.getByRole('button', { name: 'Category' }))
// Group headings (bold), not the category label inside each row.
const headings = screen.getAllByText(/^(Reach|Target|Likely|No category)$/).filter((el) => el.tagName === 'B').map((el) => el.textContent)
Expand All @@ -251,6 +283,7 @@ describe('ApplicationStatusTab', () => {
const saved = app('sc-1', 'Alpha College')
const withDue = { ...saved, tasks: tasksForEntry(saved).map((t) => (t.id === 'essays' ? { ...t, due: '2026-10-12' } : t)) }
const { onUpdate } = renderTab([withDue])
await goToList()
await userEvent.click(schoolRow('Alpha College'))
const box = await openSavedDate('Draft the supplemental essay(s)')
fireEvent.focus(box)
Expand Down
55 changes: 46 additions & 9 deletions web/src/components/ApplicationStatusTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ const STAGES: Array<{ key: StageKey; label: string; color: string; statuses: App
{ key: 'withdrawn', label: 'withdrawn', color: '#7A6D5C', statuses: ['withdrawn'] },
]

/** The open-item id that means "the whole school list" rather than one school.
* It shares the slot a collegeId uses, so the list gets URL state and a Back
* step for free. Ids are `sc-<scorecard_id>` or a slug and the school lookup
* runs first, so only a school whose slug is literally "all" could shadow it. */
export const ALL_SCHOOLS = 'all'

const MS_PER_DAY = 86400000
const daysUntil = (d: Date, now: Date) => Math.ceil((d.getTime() - now.getTime()) / MS_PER_DAY)

Expand Down Expand Up @@ -258,7 +264,7 @@ export default function ApplicationStatusTab({
deadline={deadlineFor.get(openApp.collegeId) ?? null}
daysLeft={daysFor(openApp)}
sharedCounts={sharedCounts}
onBack={() => onOpen(null)}
onBack={() => onOpen(ALL_SCHOOLS)}
onStatus={(s) => setStatus(openApp, s)}
onCategory={(category) => onUpdate(openApp.collegeId, { category })}
onDeadlineType={(deadlineType) => {
Expand All @@ -279,6 +285,10 @@ export default function ApplicationStatusTab({
}


// openId is null on the landing summary, ALL_SCHOOLS on the full list, and
// a collegeId on one school's page (handled above).
const showList = openId === ALL_SCHOOLS

const stages = STAGES.map((st) => ({ ...st, n: apps.filter((a) => st.statuses.includes(a.status)).length })).filter((st) => st.n > 0)
const activeFilter = stages.find((st) => st.key === filter) ?? null

Expand Down Expand Up @@ -313,10 +323,18 @@ export default function ApplicationStatusTab({

return (
<motion.div ref={topRef} initial={{ opacity: 0 }} animate={{ opacity: 1 }} transition={{ duration: 0.25, ease: EASE_OUT }} style={{ padding: '24px 28px 32px', maxWidth: 1200 }}>
{showList && (
<button
onClick={() => onOpen(null)}
style={{ background: 'none', border: 'none', padding: 0, marginBottom: 12, cursor: 'pointer', fontFamily: font, fontSize: 13, fontWeight: 600, color: MC }}
>
← Your applications
</button>
)}
<header style={{ display: 'flex', alignItems: 'flex-end', justifyContent: 'space-between', gap: 20, flexWrap: 'wrap' }}>
<div style={{ flex: '1 1 320px', minWidth: 0 }}>
<h2 style={{ fontFamily: "'Young Serif',serif", fontSize: 30, fontWeight: 400, color: C.text, margin: 0, lineHeight: 1.2 }}>
Your applications
{showList ? 'Your schools' : 'Your applications'}
</h2>
{/* status strip — each count filters the school list below */}
{stages.length > 0 && (
Expand All @@ -326,7 +344,7 @@ export default function ApplicationStatusTab({
return (
<button
key={st.key}
onClick={() => setFilter(on ? null : st.key)}
onClick={() => { setFilter(on ? null : st.key); if (!showList) onOpen(ALL_SCHOOLS) }}
aria-pressed={on}
className="ast-chip"
style={{ display: 'inline-flex', alignItems: 'center', gap: 6, padding: '3px 8px', borderRadius: 99, border: `1px solid ${on ? `${st.color}40` : 'transparent'}`, background: on ? `${st.color}14` : undefined, cursor: 'pointer', fontFamily: font, fontSize: 12.5, color: on ? st.color : C.textMuted }}
Expand All @@ -340,7 +358,7 @@ export default function ApplicationStatusTab({
)}
</div>

{next && nextApp && nextDays != null && (
{!showList && next && nextApp && nextDays != null && (
<button
onClick={() => onOpen(nextApp.collegeId)}
className="ast-card"
Expand All @@ -364,14 +382,14 @@ export default function ApplicationStatusTab({
)}
</header>

{timeline.length > 0 && (
{!showList && timeline.length > 0 && (
<section style={{ marginTop: 24 }}>
<DeadlineTimeline items={timeline} now={now} onSelect={onOpen} />
</section>
)}

{/* shared tasks */}
{shared.length > 0 && (
{!showList && shared.length > 0 && (
<section style={{ marginTop: 30 }}>
<div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: 12, flexWrap: 'wrap', marginBottom: 10 }}>
<SecLabel style={{ marginBottom: 0 }}>Shared across your list</SecLabel>
Expand All @@ -385,13 +403,18 @@ export default function ApplicationStatusTab({
</section>
)}

{/* schools */}
{/* schools — one level in from the landing summary */}
{showList && (
<section style={{ marginTop: 28 }}>
<div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: 12, flexWrap: 'wrap', marginBottom: 10 }}>
{/* The heading above already says "Your schools", so this line only
earns its place when a filter is narrowing what is below it. */}
<span style={{ display: 'inline-flex', alignItems: 'baseline', gap: 10 }}>
<SecLabel style={{ marginBottom: 0 }}>{activeFilter ? `Your schools · ${activeFilter.label}` : 'Your schools'}</SecLabel>
{activeFilter && (
<button onClick={() => setFilter(null)} style={{ background: 'none', border: 'none', padding: 0, cursor: 'pointer', fontFamily: font, fontSize: 12, fontWeight: 600, color: MC }}>Show all</button>
<>
<SecLabel style={{ marginBottom: 0 }}>{activeFilter.label}</SecLabel>
<button onClick={() => setFilter(null)} style={{ background: 'none', border: 'none', padding: 0, cursor: 'pointer', fontFamily: font, fontSize: 12, fontWeight: 600, color: MC }}>Show all</button>
</>
)}
</span>
<div role="group" aria-label="Sort schools" style={{ display: 'flex', gap: 4, alignItems: 'baseline', fontFamily: font, fontSize: 12, color: C.textMuted }}>
Expand Down Expand Up @@ -478,6 +501,20 @@ export default function ApplicationStatusTab({
</div>
))}
</section>
)}

{!showList && (
<button
onClick={() => onOpen(ALL_SCHOOLS)}
className="ast-card"
style={{ marginTop: 28, width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12, padding: '14px 16px', background: C.surface, border: `1px solid ${C.border}`, borderRadius: 12, cursor: 'pointer', textAlign: 'left' }}
>
<span style={{ fontFamily: font, fontSize: 14, fontWeight: 600, color: C.text }}>
See all {apps.length} {apps.length === 1 ? 'school' : 'schools'}
</span>
<span aria-hidden style={{ color: C.textFaint, fontSize: 18, lineHeight: 1 }}>›</span>
</button>
)}

{confetti}
</motion.div>
Expand Down
Loading
Loading