From a64b95192224964ebf1849c12aa58ab4d45306a5 Mon Sep 17 00:00:00 2001 From: weeihan Date: Thu, 1 Oct 2026 09:33:44 +0800 Subject: [PATCH] feat(design): migrate the Incidents list to TableCard with server-side views, sort, filters and paging Co-Authored-By: Claude Haiku 4.5 --- app/(protected)/hse/incidents/page.tsx | 111 +++-------- app/(protected)/supervisor/incidents/page.tsx | 111 +++-------- components/incidents/incident-filters.tsx | 138 ------------- components/incidents/incident-list.tsx | 129 ------------ components/incidents/incident-table.tsx | 186 ++++++++++++++++++ components/incidents/pagination.tsx | 32 --- components/ui/button.tsx | 26 +-- .../2026-10-01-ims-admin-refresh-slice-1.md | 6 +- lib/incidents/list-params.ts | 59 ++++++ lib/incidents/list-query.ts | 97 +++++++++ lib/incidents/types.ts | 15 ++ .../incidents/incident-list.test.tsx | 53 ----- .../incidents/incident-table.test.tsx | 107 ++++++++++ tests/components/ui/primitives.test.tsx | 8 +- tests/lib/incidents/list-params.test.ts | 45 +++++ 15 files changed, 576 insertions(+), 547 deletions(-) delete mode 100644 components/incidents/incident-filters.tsx delete mode 100644 components/incidents/incident-list.tsx create mode 100644 components/incidents/incident-table.tsx delete mode 100644 components/incidents/pagination.tsx create mode 100644 lib/incidents/list-params.ts create mode 100644 lib/incidents/list-query.ts create mode 100644 lib/incidents/types.ts delete mode 100644 tests/components/incidents/incident-list.test.tsx create mode 100644 tests/components/incidents/incident-table.test.tsx create mode 100644 tests/lib/incidents/list-params.test.ts diff --git a/app/(protected)/hse/incidents/page.tsx b/app/(protected)/hse/incidents/page.tsx index 5072912..1ac0de8 100644 --- a/app/(protected)/hse/incidents/page.tsx +++ b/app/(protected)/hse/incidents/page.tsx @@ -1,106 +1,39 @@ export const dynamic = 'force-dynamic' +import Link from 'next/link' import { redirect } from 'next/navigation' -import { asAdmin } from '@/lib/db/with-user' import { getSession } from '@/lib/auth/get-session' -import { incidents, sites, zones, trucks, users } from '@/lib/db/schema' -import { eq, and, or, ilike, desc, asc, sql } from 'drizzle-orm' -import { aliasedTable } from 'drizzle-orm' -import { IncidentList, type Incident } from '@/components/incidents/incident-list' -import { Pagination } from '@/components/incidents/pagination' -import { IncidentFilters, type SiteOption, type TruckOption } from '@/components/incidents/incident-filters' - -const PAGE_SIZE = 25 +import { buttonClass } from '@/components/ui/button' +import { IncidentTable } from '@/components/incidents/incident-table' +import { loadIncidentList } from '@/lib/incidents/list-query' +import { parseListParams } from '@/lib/incidents/list-params' export default async function HseInboxPage({ searchParams, }: { - searchParams: Promise<{ page?: string; q?: string; status?: string; type?: string; site_id?: string; truck_id?: string }> + searchParams: Promise> }) { const session = await getSession() if (!session) redirect('/login') - const params = await searchParams - const page = Math.max(1, Number.parseInt(params.page ?? '1', 10) || 1) - const from = (page - 1) * PAGE_SIZE - - const reporterAlias = aliasedTable(users, 'reporter') - - const conditions = [] - if (params.q) conditions.push(or(ilike(incidents.referenceNo, `%${params.q}%`), ilike(incidents.description, `%${params.q}%`))) - if (params.status) conditions.push(eq(incidents.status, params.status as never)) - if (params.type) conditions.push(eq(incidents.incidentType, params.type as never)) - if (params.site_id) conditions.push(eq(incidents.siteId, params.site_id)) - if (params.truck_id) conditions.push(eq(incidents.truckId, params.truck_id)) - const where = conditions.length ? and(...conditions) : undefined - - const [[countRow], incidentRows, siteRows, truckRows] = await Promise.all([ - asAdmin(db => - db.select({ count: sql`count(*)` }) - .from(incidents) - .where(where) - ), - asAdmin(db => - db.select({ - id: incidents.id, - referenceNo: incidents.referenceNo, - incidentType: incidents.incidentType, - status: incidents.status, - severity: incidents.severity, - reportedAt: incidents.reportedAt, - siteName: sites.name, - zoneName: zones.name, - reporterName: reporterAlias.name, - truckNo: trucks.truckNo, - }) - .from(incidents) - .leftJoin(sites, eq(incidents.siteId, sites.id)) - .leftJoin(zones, eq(incidents.zoneId, zones.id)) - .leftJoin(reporterAlias, eq(incidents.reportedBy, reporterAlias.id)) - .leftJoin(trucks, eq(incidents.truckId, trucks.id)) - .where(where) - .orderBy(desc(incidents.reportedAt)) - .limit(PAGE_SIZE) - .offset(from) - ), - asAdmin(db => - db.select({ id: sites.id, name: sites.name }).from(sites).orderBy(asc(sites.name)) - ), - asAdmin(db => - db.select({ id: trucks.id, truckNo: trucks.truckNo }) - .from(trucks) - .where(eq(trucks.active, true)) - .orderBy(asc(trucks.truckNo)) - ), - ]) - - const total = Number(countRow?.count ?? 0) - - const incidentList: Incident[] = incidentRows.map(r => ({ - id: r.id, - reference_no: r.referenceNo, - incident_type: r.incidentType, - status: r.status, - severity: r.severity, - reported_at: r.reportedAt.toISOString(), - sites: r.siteName ? { name: r.siteName } : null, - zones: r.zoneName ? { name: r.zoneName } : null, - trucks: r.truckNo ? { truck_no: r.truckNo } : null, - reporter: r.reporterName ? { name: r.reporterName } : null, - })) - - const siteOptions: SiteOption[] = siteRows.map(s => ({ id: s.id, name: s.name })) - const truckOptions: TruckOption[] = truckRows.map(t => ({ id: t.id, truck_no: t.truckNo })) + const params = parseListParams(await searchParams) + const data = await loadIncidentList(params) return ( -
-
-

Incident Inbox

- {total} incidents +
+
+

Incidents

+ Report incident
- - - -
+ + ) } diff --git a/app/(protected)/supervisor/incidents/page.tsx b/app/(protected)/supervisor/incidents/page.tsx index 37a161f..00db86c 100644 --- a/app/(protected)/supervisor/incidents/page.tsx +++ b/app/(protected)/supervisor/incidents/page.tsx @@ -1,106 +1,39 @@ export const dynamic = 'force-dynamic' +import Link from 'next/link' import { redirect } from 'next/navigation' -import { asAdmin } from '@/lib/db/with-user' import { getSession } from '@/lib/auth/get-session' -import { incidents, sites, zones, trucks, users } from '@/lib/db/schema' -import { eq, and, or, ilike, desc, asc, sql } from 'drizzle-orm' -import { aliasedTable } from 'drizzle-orm' -import { IncidentList, type Incident } from '@/components/incidents/incident-list' -import { Pagination } from '@/components/incidents/pagination' -import { IncidentFilters, type SiteOption, type TruckOption } from '@/components/incidents/incident-filters' - -const PAGE_SIZE = 25 +import { buttonClass } from '@/components/ui/button' +import { IncidentTable } from '@/components/incidents/incident-table' +import { loadIncidentList } from '@/lib/incidents/list-query' +import { parseListParams } from '@/lib/incidents/list-params' export default async function SupervisorInboxPage({ searchParams, }: { - searchParams: Promise<{ page?: string; q?: string; status?: string; type?: string; site_id?: string; truck_id?: string }> + searchParams: Promise> }) { const session = await getSession() if (!session) redirect('/login') - const params = await searchParams - const page = Math.max(1, Number.parseInt(params.page ?? '1', 10) || 1) - const from = (page - 1) * PAGE_SIZE - - const reporterAlias = aliasedTable(users, 'reporter') - - const conditions = [] - if (params.q) conditions.push(or(ilike(incidents.referenceNo, `%${params.q}%`), ilike(incidents.description, `%${params.q}%`))) - if (params.status) conditions.push(eq(incidents.status, params.status as never)) - if (params.type) conditions.push(eq(incidents.incidentType, params.type as never)) - if (params.site_id) conditions.push(eq(incidents.siteId, params.site_id)) - if (params.truck_id) conditions.push(eq(incidents.truckId, params.truck_id)) - const where = conditions.length ? and(...conditions) : undefined - - const [[countRow], incidentRows, siteRows, truckRows] = await Promise.all([ - asAdmin(db => - db.select({ count: sql`count(*)` }) - .from(incidents) - .where(where) - ), - asAdmin(db => - db.select({ - id: incidents.id, - referenceNo: incidents.referenceNo, - incidentType: incidents.incidentType, - status: incidents.status, - severity: incidents.severity, - reportedAt: incidents.reportedAt, - siteName: sites.name, - zoneName: zones.name, - reporterName: reporterAlias.name, - truckNo: trucks.truckNo, - }) - .from(incidents) - .leftJoin(sites, eq(incidents.siteId, sites.id)) - .leftJoin(zones, eq(incidents.zoneId, zones.id)) - .leftJoin(reporterAlias, eq(incidents.reportedBy, reporterAlias.id)) - .leftJoin(trucks, eq(incidents.truckId, trucks.id)) - .where(where) - .orderBy(desc(incidents.reportedAt)) - .limit(PAGE_SIZE) - .offset(from) - ), - asAdmin(db => - db.select({ id: sites.id, name: sites.name }).from(sites).orderBy(asc(sites.name)) - ), - asAdmin(db => - db.select({ id: trucks.id, truckNo: trucks.truckNo }) - .from(trucks) - .where(eq(trucks.active, true)) - .orderBy(asc(trucks.truckNo)) - ), - ]) - - const total = Number(countRow?.count ?? 0) - - const incidentList: Incident[] = incidentRows.map(r => ({ - id: r.id, - reference_no: r.referenceNo, - incident_type: r.incidentType, - status: r.status, - severity: r.severity, - reported_at: r.reportedAt.toISOString(), - sites: r.siteName ? { name: r.siteName } : null, - zones: r.zoneName ? { name: r.zoneName } : null, - trucks: r.truckNo ? { truck_no: r.truckNo } : null, - reporter: r.reporterName ? { name: r.reporterName } : null, - })) - - const siteOptions: SiteOption[] = siteRows.map(s => ({ id: s.id, name: s.name })) - const truckOptions: TruckOption[] = truckRows.map(t => ({ id: t.id, truck_no: t.truckNo })) + const params = parseListParams(await searchParams) + const data = await loadIncidentList(params) return ( -
-
-

Incident Inbox

- {total} incidents +
+
+

Incidents

+ Report incident
- - - -
+ + ) } diff --git a/components/incidents/incident-filters.tsx b/components/incidents/incident-filters.tsx deleted file mode 100644 index 16e5dd4..0000000 --- a/components/incidents/incident-filters.tsx +++ /dev/null @@ -1,138 +0,0 @@ -'use client' - -import { useRouter, useSearchParams, usePathname } from 'next/navigation' -import { useCallback, useState, useTransition, Suspense } from 'react' - -const STATUS_OPTIONS = [ - { value: '', label: 'All Statuses' }, - { value: 'reported', label: 'Reported' }, - { value: 'triaged', label: 'Triaged' }, - { value: 'investigating', label: 'Investigating' }, - { value: 'capa_pending', label: 'CAPA Pending' }, - { value: 'verification', label: 'Pending Verification' }, - { value: 'closed', label: 'Closed' }, -] - -const TYPE_OPTIONS = [ - { value: '', label: 'All Types' }, - { value: 'injury', label: 'Injury' }, - { value: 'near_miss', label: 'Near Miss' }, - { value: 'hazard', label: 'Hazard' }, - { value: 'asset_damage', label: 'Asset Damage' }, - { value: 'environmental', label: 'Environmental' }, - { value: 'security', label: 'Security' }, - { value: 'fire', label: 'Fire' }, - { value: 'transport', label: 'Transport' }, -] - -export interface SiteOption { id: string; name: string } -export interface TruckOption { id: string; truck_no: string } - -interface FiltersProps { - sites: SiteOption[] - trucks: TruckOption[] -} - -function FiltersInner({ sites, trucks }: FiltersProps) { - const router = useRouter() - const pathname = usePathname() - const searchParams = useSearchParams() - const [, startTransition] = useTransition() - const [search, setSearch] = useState(searchParams.get('q') ?? '') - - const updateParam = useCallback((key: string, value: string) => { - const params = new URLSearchParams(searchParams.toString()) - if (value) { - params.set(key, value) - } else { - params.delete(key) - } - params.delete('page') - startTransition(() => { - router.replace(`${pathname}?${params.toString()}`) - }) - }, [router, pathname, searchParams]) - - const handleSearch = useCallback((value: string) => { - setSearch(value) - const timer = setTimeout(() => updateParam('q', value), 300) - return () => clearTimeout(timer) - }, [updateParam]) - - const hasFilters = searchParams.get('q') || searchParams.get('status') || - searchParams.get('type') || searchParams.get('site_id') || searchParams.get('truck_id') - - return ( -
-
- - - - handleSearch(e.target.value)} - className="w-full pl-8 pr-3 py-1.5 text-sm border border-divider focus:outline-none focus:ring-2 focus:ring-accent" - /> -
- - - {sites.length > 0 && ( - - )} - {trucks.length > 0 && ( - - )} - {hasFilters && ( - - )} -
- ) -} - -export function IncidentFilters({ sites, trucks }: FiltersProps) { - return ( - }> - - - ) -} diff --git a/components/incidents/incident-list.tsx b/components/incidents/incident-list.tsx deleted file mode 100644 index 7e4dd69..0000000 --- a/components/incidents/incident-list.tsx +++ /dev/null @@ -1,129 +0,0 @@ -'use client' - -import { useState } from 'react' -import Link from 'next/link' -import { StatusTag } from '@/components/ui/status-tag' - -const TYPE_LABELS: Record = { - injury: 'Injury / Medical', - near_miss: 'Near Miss', - hazard: 'Hazard', - asset_damage: 'Asset Damage', - environmental: 'Environmental', - security: 'Security', - fire: 'Fire / Emergency', - transport: 'Transport / Vehicle', -} - -const STATUS_ORDER = ['reported', 'triaged', 'investigating', 'capa_pending', 'verification', 'closed'] as const - -export type Incident = { - id: string - reference_no: string | null - incident_type: string - status: string - severity: number | null - reported_at: string - sites: { name: string } | null - zones: { name: string } | null - trucks: { truck_no: string } | null - reporter: { name: string } | null -} - -interface Props { - incidents: Incident[] - basePath: string -} - -export function IncidentList({ incidents, basePath }: Props) { - const [typeFilter, setTypeFilter] = useState('') - const [statusFilter, setStatusFilter] = useState('') - const [search, setSearch] = useState('') - - const filtered = incidents.filter(inc => { - if (typeFilter && inc.incident_type !== typeFilter) return false - if (statusFilter && inc.status !== statusFilter) return false - if (search) { - const q = search.toLowerCase() - return ( - inc.reference_no?.toLowerCase().includes(q) || - inc.incident_type.includes(q) || - (inc.sites?.name ?? '').toLowerCase().includes(q) - ) - } - return true - }) - - return ( -
-
- setSearch(e.target.value)} - /> - - -
- - {filtered.length === 0 ? ( -
No incidents found
- ) : ( -
- {filtered.map(inc => ( - -
-
- - {inc.reference_no ?? '—'} - - {inc.status.replace(/_/g, ' ').toUpperCase()} -
-
- {TYPE_LABELS[inc.incident_type] ?? inc.incident_type} - {inc.zones?.name && ` · ${inc.zones.name}`} - {inc.sites?.name && ` · ${inc.sites.name}`} - {inc.trucks?.truck_no && ( - · {inc.trucks.truck_no} - )} -
-
-
-
- {new Date(inc.reported_at).toLocaleDateString('en-MY')} -
- {inc.severity && ( -
Sev {inc.severity}
- )} -
- - ))} -
- )} -
- ) -} diff --git a/components/incidents/incident-table.tsx b/components/incidents/incident-table.tsx new file mode 100644 index 0000000..3be87c7 --- /dev/null +++ b/components/incidents/incident-table.tsx @@ -0,0 +1,186 @@ +'use client' + +import { useEffect, useState } from 'react' +import Link from 'next/link' +import { usePathname, useRouter, useSearchParams } from 'next/navigation' +import { ChevronRight, Eye, Search } from 'lucide-react' +import { Button } from '@/components/ui/button' +import { FilterChip } from '@/components/ui/filter-chip' +import { StatusTag } from '@/components/ui/status-tag' +import { TableCard, type Column } from '@/components/ui/table-card' +import { PAGE_SIZE, nextSort, withParams, type ListParams, type SortKey } from '@/lib/incidents/list-params' +import type { Incident, SiteOption, TruckOption } from '@/lib/incidents/types' + +const TYPE_LABELS: Record = { + injury: 'Injury / Medical', + near_miss: 'Near Miss', + hazard: 'Hazard', + asset_damage: 'Asset Damage', + environmental: 'Environmental', + security: 'Security', + fire: 'Fire / Emergency', + transport: 'Transport / Vehicle', +} + +const STATUS_OPTIONS = [ + { value: 'reported', label: 'Reported' }, + { value: 'triaged', label: 'Triaged' }, + { value: 'investigating', label: 'Investigating' }, + { value: 'capa_pending', label: 'CAPA pending' }, + { value: 'verification', label: 'Verification' }, + { value: 'closed', label: 'Closed' }, +] + +const TYPE_OPTIONS = Object.entries(TYPE_LABELS).map(([value, label]) => ({ value, label })) + +interface Props { + incidents: Incident[] + basePath: string + total: number + counts: { all: number; open: number; closed: number } + params: ListParams + sites: SiteOption[] + trucks: TruckOption[] +} + +const fmtDate = (iso: string) => new Date(iso).toLocaleDateString('en-MY') + +export function IncidentTable({ incidents, basePath, total, counts, params, sites, trucks }: Props) { + const router = useRouter() + const pathname = usePathname() + const searchParams = useSearchParams() + const search = searchParams.toString() ? `?${searchParams.toString()}` : '' + const [q, setQ] = useState(params.q) + + const update = (updates: Record) => + router.replace(`${pathname}${withParams(search, updates)}`) + + useEffect(() => { + if (q === params.q) return + const timer = setTimeout(() => update({ q: q || null }), 300) + return () => clearTimeout(timer) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [q]) + + const columns: Column[] = [ + { + key: 'reference', + header: 'Reference', + sortKey: 'reference_no', + cell: r => {r.reference_no ?? '—'}, + }, + { key: 'status', header: 'Status', sortKey: 'status', cell: r => }, + { key: 'type', header: 'Type', cell: r => TYPE_LABELS[r.incident_type] ?? r.incident_type }, + { + key: 'location', + header: 'Location', + cell: r => [r.zones?.name, r.sites?.name, r.trucks?.truck_no].filter(Boolean).join(' · ') || '—', + }, + { key: 'severity', header: 'Severity', cell: r => (r.severity ? `Sev ${r.severity}` : '—') }, + { key: 'reported', header: 'Reported', sortKey: 'reported_at', cell: r => fmtDate(r.reported_at) }, + ] + + const clearable = Boolean(params.q || params.status || params.type || params.siteId || params.truckId) + const pageCount = Math.max(1, Math.ceil(total / PAGE_SIZE)) + const from = total === 0 ? 0 : (params.page - 1) * PAGE_SIZE + 1 + const to = Math.min(total, from + incidents.length - 1) + + const toolbar = ( + <> + + update({ status: v || null })} /> + update({ type: v || null })} /> + {sites.length > 0 && ( + ({ value: s.id, label: s.name }))} + onChange={v => update({ site_id: v || null })} + /> + )} + {trucks.length > 0 && ( + ({ value: t.id, label: t.truck_no }))} + onChange={v => update({ truck_id: v || null })} + /> + )} + {clearable && ( + + )} + + ) + + return ( + r.id} + onRowOpen={r => router.push(`${basePath}/incidents/${r.id}`)} + rowActions={r => ( + + + + )} + views={{ + items: [ + { key: 'all', label: 'All', count: counts.all }, + { key: 'open', label: 'Open', count: counts.open }, + { key: 'closed', label: 'Closed', count: counts.closed }, + ], + active: params.view, + onChange: key => update({ view: key === 'all' ? null : key }), + }} + toolbar={toolbar} + sort={{ key: params.sort, dir: params.dir }} + onSortChange={key => { + const next = nextSort({ key: params.sort, dir: params.dir }, key as SortKey) + update({ sort: next.key, dir: next.dir }) + }} + footer={{ from, to, total, page: params.page, pageCount, onPage: p => update({ page: String(p) }) }} + empty={{ + title: 'No incidents found', + action: , + }} + mobileRow={r => ( +
+
+
+ {r.reference_no ?? '—'} + +
+

+ {[TYPE_LABELS[r.incident_type] ?? r.incident_type, r.zones?.name].filter(Boolean).join(' · ')} +

+

{fmtDate(r.reported_at)}

+
+ +
+ )} + /> + ) +} diff --git a/components/incidents/pagination.tsx b/components/incidents/pagination.tsx deleted file mode 100644 index 4928d18..0000000 --- a/components/incidents/pagination.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import Link from 'next/link' - -interface Props { - page: number - pageSize: number - total: number - href: string -} - -export function Pagination({ page, pageSize, total, href }: Props) { - const totalPages = Math.max(1, Math.ceil(total / pageSize)) - if (totalPages <= 1) return null - - const link = (p: number, label: string, disabled: boolean) => - disabled ? ( - {label} - ) : ( - - {label} - - ) - - return ( - - ) -} diff --git a/components/ui/button.tsx b/components/ui/button.tsx index ecaecf7..cb4fe2b 100644 --- a/components/ui/button.tsx +++ b/components/ui/button.tsx @@ -19,18 +19,18 @@ type Props = ButtonHTMLAttributes & { mobile?: boolean } -export function Button({ variant = 'primary', block = false, mobile = false, className, type = 'button', ...rest }: Props) { - return ( - ) const b = screen.getByRole('button', { name: 'Submit' }) diff --git a/tests/lib/incidents/list-params.test.ts b/tests/lib/incidents/list-params.test.ts new file mode 100644 index 0000000..2b427f5 --- /dev/null +++ b/tests/lib/incidents/list-params.test.ts @@ -0,0 +1,45 @@ +import { describe, it, expect } from 'vitest' +import { parseListParams, nextSort, withParams, PAGE_SIZE, OPEN_STATUSES } from '@/lib/incidents/list-params' + +describe('parseListParams', () => { + it('applies defaults', () => { + expect(parseListParams({})).toEqual({ + page: 1, q: '', status: '', type: '', siteId: '', truckId: '', view: 'all', sort: 'reported_at', dir: 'desc', + }) + }) + + it('reads every param and rejects bad values', () => { + const p = parseListParams({ page: '3', q: 'fork', status: 'closed', type: 'injury', site_id: 's1', truck_id: 't1', view: 'open', sort: 'status', dir: 'asc' }) + expect(p).toMatchObject({ page: 3, q: 'fork', status: 'closed', siteId: 's1', truckId: 't1', view: 'open', sort: 'status', dir: 'asc' }) + expect(parseListParams({ page: '-4' }).page).toBe(1) + expect(parseListParams({ page: 'x' }).page).toBe(1) + expect(parseListParams({ view: 'bogus' }).view).toBe('all') + expect(parseListParams({ sort: 'drop table' }).sort).toBe('reported_at') + expect(parseListParams({ dir: 'sideways' }).dir).toBe('desc') + }) + + it('exposes the page size and the open statuses', () => { + expect(PAGE_SIZE).toBe(25) + expect(OPEN_STATUSES).toEqual(['reported', 'triaged', 'investigating', 'capa_pending', 'verification']) + }) +}) + +describe('nextSort', () => { + it('flips the direction on the same column', () => { + expect(nextSort({ key: 'reference_no', dir: 'asc' }, 'reference_no')).toEqual({ key: 'reference_no', dir: 'desc' }) + expect(nextSort({ key: 'reference_no', dir: 'desc' }, 'reference_no')).toEqual({ key: 'reference_no', dir: 'asc' }) + }) + + it('starts a new column ascending, but the date column newest first', () => { + expect(nextSort({ key: 'reported_at', dir: 'desc' }, 'status')).toEqual({ key: 'status', dir: 'asc' }) + expect(nextSort({ key: 'status', dir: 'asc' }, 'reported_at')).toEqual({ key: 'reported_at', dir: 'desc' }) + }) +}) + +describe('withParams', () => { + it('sets and removes params and resets the page', () => { + expect(withParams('?status=closed&page=3', { q: 'fork' })).toBe('?status=closed&q=fork') + expect(withParams('?status=closed', { status: null })).toBe('') + expect(withParams('?page=2', { page: '4' })).toBe('?page=4') + }) +})