diff --git a/src/app/dashboard/financial/delivery-notes/flags/[collection]/[recordId]/flag-decision.test.tsx b/src/app/dashboard/financial/delivery-notes/flags/[collection]/[recordId]/flag-decision.test.tsx new file mode 100644 index 0000000..ded166c --- /dev/null +++ b/src/app/dashboard/financial/delivery-notes/flags/[collection]/[recordId]/flag-decision.test.tsx @@ -0,0 +1,41 @@ +import {expect,it,vi} from 'vitest'; +import {renderToStaticMarkup} from 'react-dom/server'; +import * as React from 'react'; + +vi.mock('next/navigation',()=>({useRouter:()=>({push:vi.fn(),refresh:vi.fn()})})); + +import {FlagDecision} from './flag-decision'; + +const render=(props:Partial>={})=>renderToStaticMarkup(); +const text=(html:string)=>html.replace(/<[^>]*>/g,' ').replace(/\s+/g,' ').trim(); +/** The opening tag of the button reading `label`, so its own `disabled` can be read. */ +const buttonTag=(html:string,label:string):string=>html.split('({open:part.slice(0,part.indexOf('>')),label:text(part.slice(part.indexOf('>'),part.indexOf('')))})) + .find(button=>button.label.includes(label))?.open??''; + +it('offers both decisions when the record can be deleted',()=>{ + const html=render(); + expect(text(html)).toContain('Keep'); + expect(text(html)).toContain('Delete'); + expect(html).toContain('{ + const html=render({deleteBlock:'This is delivery evidence and is never deleted. Keep it, or set it aside or move the receipt from its document page.'}); + expect(text(html)).toContain('This is delivery evidence and is never deleted.'); + // Keep stays open: a blocked Delete still lets a person record why it stands. + expect(text(html)).toContain('Keep'); + expect(buttonTag(html,'Delete')).toContain('disabled=""'); + expect(buttonTag(html,'Keep')).not.toContain('disabled=""'); +}); + +it('shows no buttons to somebody who may not decide this flag',()=>{ + const html=render({canDecide:false}); + expect(html).not.toContain('