38 lines
3.4 KiB
TypeScript
38 lines
3.4 KiB
TypeScript
import {render,screen,fireEvent,within,waitFor} from '@testing-library/react';
|
|
import {beforeEach,it,expect,vi} from 'vitest';
|
|
import api from '../services/api';
|
|
import OrchestrationCommandCenter from './OrchestrationCommandCenter';
|
|
vi.mock('../services/api',()=>({default:{get:vi.fn(),post:vi.fn(),put:vi.fn()}}));
|
|
const proposal={id:'pending',key:'p',title:'بررسی منابع محتوا',department:'Content',state:'GATE1_PENDING',version:3,operationMode:'PREPARE',budgetLimitCents:240,metadata:{scope:'فقط تحقیق منابع عمومی',acceptanceCriteria:['سه منبع معتبر']},availableActions:['APPROVE_GATE1','HOLD_GATE1','REJECT_GATE1']};
|
|
beforeEach(()=>{vi.resetAllMocks();vi.mocked(api.get).mockImplementation(async url=>({data:url.endsWith('/overview')?{items:[],measuredAt:'now',capabilities:{mutations:true}}:url.endsWith('/tasks')?[proposal,{...proposal,id:'held',title:'کار نگهداشته',state:'GATE1_HELD'}, {...proposal,id:'done',title:'کار پایانیافته',state:'CLOSED'}]:proposal}));});
|
|
it('opens with obvious pending and held owner queue, scope, criteria and budget; filters without invented actions',async()=>{
|
|
render(<OrchestrationCommandCenter/>);
|
|
const queue=await screen.findByRole('region',{name:'منتظر تصمیم شما'});
|
|
expect(await within(queue).findByRole('button',{name:proposal.title})).toBeInTheDocument();
|
|
const card=within(queue).getByRole('button',{name:proposal.title}).closest('article')!;
|
|
expect(within(card).getByText(/فقط تحقیق منابع عمومی/)).toBeInTheDocument();
|
|
expect(within(card).getByText('سه منبع معتبر')).toBeInTheDocument();
|
|
expect(within(card).getByText(/240/)).toBeInTheDocument();
|
|
expect(within(queue).queryByText('کار پایانیافته')).not.toBeInTheDocument();
|
|
fireEvent.change(within(queue).getByLabelText('فیلتر تصمیمها'),{target:{value:'GATE1_HELD'}});
|
|
expect(within(queue).queryByRole('button',{name:proposal.title})).not.toBeInTheDocument();
|
|
fireEvent.click(within(queue).getByRole('button',{name:'کار نگهداشته'}));
|
|
expect(await screen.findByRole('button',{name:'تعویق تصمیم Gate1'})).toBeInTheDocument();
|
|
expect(api.put).not.toHaveBeenCalled();expect(api.post).not.toHaveBeenCalled();
|
|
});
|
|
it('holds through authenticated server transition and reloads instead of fabricating a local decision',async()=>{
|
|
vi.mocked(api.put).mockResolvedValue({data:{}});
|
|
render(<OrchestrationCommandCenter/>);
|
|
fireEvent.click(await screen.findByRole('button',{name:proposal.title}));
|
|
fireEvent.click(await screen.findByRole('button',{name:'تعویق تصمیم Gate1'}));
|
|
const dialog=screen.getByRole('dialog');
|
|
expect(within(dialog).queryByLabelText('زمان انقضا')).not.toBeInTheDocument();
|
|
fireEvent.change(within(dialog).getByLabelText('دلیل'),{target:{value:'بررسی بودجه'}});
|
|
fireEvent.click(within(dialog).getByRole('checkbox'));
|
|
fireEvent.click(within(dialog).getByRole('button',{name:'تأیید فرمان'}));
|
|
await waitFor(()=>expect(api.put).toHaveBeenCalledWith('/admin/orchestration/tasks/pending/transition',{toState:'GATE1_HELD',expectedVersion:3,idempotencyKey:expect.any(String),reason:'بررسی بودجه'}));
|
|
await waitFor(()=>expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
|
expect(await screen.findByRole('button',{name:proposal.title})).toBeInTheDocument();
|
|
expect(api.post).not.toHaveBeenCalled();
|
|
});
|