Files
lcbp3/frontend/tests/components/ResponseCodeSelector.test.tsx
T
Nattanin ef20839f99 feat(rfa): complete RFA Approval Refactor - all 9 phases (T001-T080)
Phase 1-2: Setup, SQL schema, enums, queue constants, base entities
Phase 3 (US1): ReviewTeam, ReviewTeamMember, ReviewTask, TaskCreationService
Phase 4 (US2): ResponseCode, ResponseCodeRule, ImplicationsService, NotificationTriggerService
Phase 5 (US3): Delegation entity, CircularDetectionService, DelegationService/Controller/Module
Phase 6 (US4): ReminderRule, SchedulerService, EscalationService, ReminderProcessor, ReminderModule
Phase 7 (US5): DistributionMatrix, DistributionRecipient, ApprovalListenerService (Strangler),
               TransmittalCreatorService, DistributionProcessor, DistributionModule
Phase 8 (US6): MatrixManagementService, InheritanceService (global→project override)
Phase 9 (Polish): AggregateStatusService, ConsensusService, VetoOverrideService,
                  ParallelGatewayHandler, review-validators, optimistic locking in completeReview,
                  test stubs (unit/integration/e2e), jest.config.js updated for tests/ directory

Frontend: ReviewTaskInbox, ParallelProgress, VetoOverrideDialog, DelegationForm,
          DelegatedBadge, MatrixEditor, ProjectOverrideManager, DistributionStatus,
          ReminderHistory, ResponseCodeSelector, CodeImplications, CompleteReviewForm,
          ReviewTeamForm, ReviewTeamSelector, TeamMemberManager

Closes #1
2026-05-12 16:17:27 +07:00

72 lines
2.1 KiB
TypeScript

// File: frontend/tests/components/ResponseCodeSelector.test.tsx
// Unit tests สำหรับ ResponseCodeSelector component (T078)
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import { ResponseCodeSelector } from '@/components/response-code/ResponseCodeSelector';
const mockCodes = [
{
publicId: 'uuid-1',
code: '1A',
category: 'ENGINEERING',
descriptionEn: 'Approved — No Comments',
descriptionTh: 'ผ่าน — ไม่มีเงื่อนไข',
implications: {},
notifyRoles: [],
isSystem: true,
},
{
publicId: 'uuid-2',
code: '2',
category: 'ENGINEERING',
descriptionEn: 'Approved with Comments',
descriptionTh: 'ผ่าน — มีเงื่อนไข',
implications: { affectsSchedule: true },
notifyRoles: ['CONTRACT_MANAGER'],
isSystem: true,
},
{
publicId: 'uuid-3',
code: '3',
category: 'ENGINEERING',
descriptionEn: 'Rejected',
descriptionTh: 'ไม่ผ่าน',
implications: {},
notifyRoles: [],
isSystem: true,
},
];
describe('ResponseCodeSelector', () => {
it('should render code options', () => {
const onSelect = jest.fn();
render(<ResponseCodeSelector codes={mockCodes} onSelect={onSelect} />);
expect(screen.getByText('1A')).toBeInTheDocument();
expect(screen.getByText('2')).toBeInTheDocument();
expect(screen.getByText('3')).toBeInTheDocument();
});
it('should call onSelect when a code is clicked', () => {
const onSelect = jest.fn();
render(<ResponseCodeSelector codes={mockCodes} onSelect={onSelect} />);
fireEvent.click(screen.getByText('1A'));
expect(onSelect).toHaveBeenCalledWith('uuid-1');
});
it('should highlight selected code', () => {
const onSelect = jest.fn();
render(
<ResponseCodeSelector
codes={mockCodes}
onSelect={onSelect}
selectedPublicId="uuid-2"
/>,
);
const selectedButton = screen.getByRole('button', { name: /2/i });
expect(selectedButton).toHaveClass('ring-2');
});
});