a8980a3a41
Hem was one ~33-query render behind a single fallback: the greeting waited for the slowest worklist scan, and the request also paid a sequential bank_file_imports read after the batch, a second scan of the suggested matches (getWorklistCounts counted the same 200 rows the pane listed) and an awaited stale-dismissal delete on the read path. - page.tsx awaits only what the greeting shell and the redirects need (settings, profile, agent profile, the Skatteverket flag); the notice line, the setup checklist and the Att göra + Fortsätt panes are async server components behind their own Suspense (hem-sections.tsx). RSC streaming applies to client navigations too, so the greeting paints first on every visit and each block fills in as its queries land. - DashboardContent becomes the shell with three slots; HemNotices keeps the one client-side action (the wrong-account sign-out); HemSkeletons are the two fallbacks. - getWorklistCounts accepts the suggested matches the caller is already fetching (a promise, so it stays parallel); listSuggestedMatches runs once at the scan cap and the pane shows the first five. - countInboxDocuments runs its id chunks in one wave instead of N sequential round trips. - getCompanyNotices takes deferReap; Hem passes Next's after() so the stale-dismissal delete runs after the response. - bank_file_imports joins the checklist section's batch. Tests: worklist aggregate (precomputed matches skip the rescan), notices aggregate (deferReap receives the reap; the delete does not run inline and runs when the task does). Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
56 lines
2.0 KiB
TypeScript
56 lines
2.0 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import type { SupabaseClient } from '@supabase/supabase-js'
|
|
|
|
vi.mock('../categories', () => ({
|
|
countUnbookedTransactions: vi.fn().mockResolvedValue(4),
|
|
countInboxDocuments: vi.fn().mockResolvedValue(6),
|
|
countSuggestedMatches: vi.fn().mockResolvedValue(2),
|
|
countSupplierInvoicesAwaitingApproval: vi.fn().mockResolvedValue(1),
|
|
countVerifikatMissingDocument: vi.fn().mockResolvedValue(3),
|
|
countOverdueInvoices: vi.fn().mockResolvedValue(5),
|
|
countDeadlinesNeedingAction: vi.fn().mockResolvedValue(1),
|
|
countPendingOperations: vi.fn().mockResolvedValue(2),
|
|
countReconciliationDue: vi.fn().mockResolvedValue(1),
|
|
}))
|
|
|
|
import { getWorklistCounts } from '../aggregate'
|
|
|
|
const supabase = {} as SupabaseClient
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
describe('getWorklistCounts', () => {
|
|
it('aggregates every category', async () => {
|
|
const { counts } = await getWorklistCounts(supabase, 'company-1')
|
|
expect(counts).toEqual({
|
|
book_transaction: 4,
|
|
inbox_document: 6,
|
|
suggested_match: 2,
|
|
supplier_invoice_approval: 1,
|
|
verifikat_missing_document: 3,
|
|
overdue_invoice: 5,
|
|
deadline_action: 1,
|
|
pending_operations: 2,
|
|
reconciliation_due: 1,
|
|
})
|
|
})
|
|
|
|
it('takes the suggested-match count from a caller-supplied list instead of rescanning', async () => {
|
|
const { countSuggestedMatches } = await import('../categories')
|
|
const matches = [{ transactionId: 't1' }, { transactionId: 't2' }, { transactionId: 't3' }] as never[]
|
|
const { counts } = await getWorklistCounts(supabase, 'company-1', {
|
|
suggestedMatches: Promise.resolve(matches),
|
|
})
|
|
expect(counts.suggested_match).toBe(3)
|
|
expect(countSuggestedMatches).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('excludes suggested_match from the total (subset of book_transaction)', async () => {
|
|
const { total } = await getWorklistCounts(supabase, 'company-1')
|
|
// 4 + 6 + 1 + 3 + 5 + 1 + 2 + 1, without the 2 suggested matches.
|
|
expect(total).toBe(23)
|
|
})
|
|
})
|