Update handoff test

This commit is contained in:
voltsrage
2026-06-25 15:25:24 +08:00
parent d48e1737b5
commit 26bef39aae
@@ -1,93 +1,67 @@
import { describe, it, expect } from 'vitest' import { describe, it, expect, vi } from 'vitest'
import { import { mount } from '@vue/test-utils'
buildPatientReport, import HandoffReport from '@/components/ward/HandoffReport.vue'
buildSbar,
buildWardSummary,
extractLatestVitals,
formatAlertsSummary,
formatVitalsSummary,
} from '@/composables/handoffReport'
const wardPatient = { const mockReport = {
encounterId: 'enc-1', generatedAt: '2026-06-23T08:00:00Z',
firstName: 'Jane', generatedBy: 'Test Nurse',
lastName: 'Doe', summary: {
mrn: 'MRN001', department: 'ICU',
roomBed: 'ICU-3', patientCount: 1,
department: 'ICU', criticalCount: 1,
attendingPhysician: 'Dr Smith', alertCount: 2,
news2Score: 8, activeBundles: 1,
sofaScore: 6,
sofaDelta: 2,
gcsScore: 14,
qsofaScore: 2,
openAlertCount: 1,
}
const enrichment = {
encounter: {
admissionReason: 'Sepsis workup',
patient: { allergies: 'Penicillin' },
}, },
openAlerts: [{ alertType: 'NEWS2_EMERGENCY' }], patients: [
pendingOrders: [{ description: 'Blood cultures', status: 'Pending' }], {
vitals: extractLatestVitals([ encounterId: 'enc-1',
{ observationCode: 'HEART_RATE', value: 110, unit: 'bpm', recordedAt: '2026-06-23T10:00:00Z' }, name: 'Jane Doe',
{ observationCode: 'SPO2', value: 94, unit: '%', recordedAt: '2026-06-23T10:00:00Z' }, mrn: 'MRN001',
]), room: 'ICU-3',
bundle: null, department: 'ICU',
attending: 'Dr Smith',
news2: 8,
sofa: 6,
sofaDelta: 2,
gcs: 14,
qsofa: 2,
vitalsSummary: 'HR 110 bpm',
alertsSummary: 'NEWS2 Emergency',
pendingOrders: 'Blood cultures',
sbar: {
situation: 'Sepsis workup',
background: 'Allergies: Penicillin',
assessment: 'NEWS2 8',
recommendation: 'Blood cultures',
},
},
],
} }
describe('handoffReport', () => { vi.mock('@/composables/handoffReport', async importOriginal => {
it('buildsWardSummary', () => { const actual = await importOriginal()
const summary = buildWardSummary( return {
[ ...actual,
wardPatient, buildHandoffReport: vi.fn(() => Promise.resolve(mockReport)),
{ news2Score: 3, openAlertCount: 0, sepsisActive: true }, }
], })
'ICU',
)
expect(summary).toMatchObject({
department: 'ICU',
patientCount: 2,
criticalCount: 1,
alertCount: 1,
activeBundles: 1,
})
})
it('formatsLatestVitals', () => { describe('HandoffReport', () => {
expect(formatVitalsSummary(enrichment.vitals)).toContain('HR 110 bpm') it('rendersWardSummaryAndPatientRows', async () => {
expect(formatVitalsSummary(enrichment.vitals)).toContain('SpO₂ 94%') const wrapper = mount(HandoffReport, {
}) props: {
encounters: [{ encounterId: 'enc-1' }],
it('formatsAlertSummary', () => { department: 'ICU',
expect(formatAlertsSummary(enrichment.openAlerts)).toContain('NEWS2 Emergency') generatedBy: 'Test Nurse',
})
it('buildsPatientReportWithSbar', () => {
const report = buildPatientReport(wardPatient, enrichment)
expect(report.name).toBe('Jane Doe')
expect(report.pendingOrders).toContain('Blood cultures')
expect(report.sbar.situation).toBe('Sepsis workup')
expect(report.sbar.background).toContain('Penicillin')
expect(report.sbar.assessment).toContain('NEWS2 8')
expect(report.sbar.recommendation).toContain('Blood cultures')
})
it('includesBundleInRecommendation', () => {
const sbar = buildSbar(wardPatient, enrichment.encounter, {
...enrichment,
pendingOrders: [],
bundle: {
complianceStatus: 'IN_PROGRESS',
elements: [
{ elementType: 'BloodCultures', status: 'Pending' },
{ elementType: 'SerumLactate', status: 'Completed' },
],
}, },
attachTo: document.body,
}) })
expect(sbar.recommendation).toContain('Sepsis bundle')
expect(sbar.recommendation).toContain('Blood cultures') await vi.waitFor(() => expect(document.body.textContent).toContain('Ward Summary'))
expect(document.body.textContent).toContain('Jane Doe')
expect(document.body.textContent).toContain('SBAR')
expect(document.body.textContent).toContain('Sepsis workup')
wrapper.unmount()
document.body.innerHTML = ''
}) })
}) })