- Auto-fixed 712 import ordering errors via `pnpm lint --fix` - Manually fixed 13 remaining ESLint errors: - Prefixed unused vars with _ (mockAdminUser, params) - Removed unused imports (UnauthorizedException, vi, screen) - Moved imports above vi.mock() calls to fix import group ordering - Removed eslint-disable for non-existent rules - Fixed empty object pattern in Playwright fixture - Fixed ~40 TypeScript TS4111 index signature errors in test files: - Used bracket notation for Record<string, unknown> property access - Added missing PropertyMedia fields (id, order, caption) to test data - Fixed pre-existing test failures in rate-limit guard specs: - Added NODE_ENV override to bypass test-mode skip in guard Both `pnpm lint` and `pnpm typecheck` now exit 0 cleanly. Co-Authored-By: Paperclip <noreply@paperclip.ing>
113 lines
3.0 KiB
TypeScript
113 lines
3.0 KiB
TypeScript
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
import type { InquiryReadDto } from '@/lib/inquiries-api';
|
|
import { InquiryStatusBadge, InquiryRow } from '../inquiry-row';
|
|
|
|
describe('InquiryStatusBadge', () => {
|
|
it('renders "Đã đọc" when isRead is true', () => {
|
|
render(<InquiryStatusBadge isRead={true} />);
|
|
expect(screen.getByText('Đã đọc')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders "Chưa đọc" when isRead is false', () => {
|
|
render(<InquiryStatusBadge isRead={false} />);
|
|
expect(screen.getByText('Chưa đọc')).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
const mockInquiry: InquiryReadDto = {
|
|
id: 'inq-1',
|
|
listingId: 'listing-1',
|
|
listingTitle: 'Căn hộ 2PN Quận 7',
|
|
userId: 'user-1',
|
|
userName: 'Nguyễn Văn A',
|
|
userPhone: '0912345678',
|
|
message: 'Tôi muốn xem nhà vào cuối tuần',
|
|
phone: null,
|
|
isRead: false,
|
|
createdAt: '2026-01-15T10:30:00Z',
|
|
};
|
|
|
|
describe('InquiryRow', () => {
|
|
it('renders inquiry user name', () => {
|
|
render(
|
|
<table>
|
|
<tbody>
|
|
<InquiryRow inquiry={mockInquiry} onSelect={vi.fn()} />
|
|
</tbody>
|
|
</table>,
|
|
);
|
|
expect(screen.getByText('Nguyễn Văn A')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders inquiry user phone', () => {
|
|
render(
|
|
<table>
|
|
<tbody>
|
|
<InquiryRow inquiry={mockInquiry} onSelect={vi.fn()} />
|
|
</tbody>
|
|
</table>,
|
|
);
|
|
expect(screen.getByText('0912345678')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders listing title', () => {
|
|
render(
|
|
<table>
|
|
<tbody>
|
|
<InquiryRow inquiry={mockInquiry} onSelect={vi.fn()} />
|
|
</tbody>
|
|
</table>,
|
|
);
|
|
expect(screen.getByText('Căn hộ 2PN Quận 7')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders inquiry message', () => {
|
|
render(
|
|
<table>
|
|
<tbody>
|
|
<InquiryRow inquiry={mockInquiry} onSelect={vi.fn()} />
|
|
</tbody>
|
|
</table>,
|
|
);
|
|
expect(screen.getByText('Tôi muốn xem nhà vào cuối tuần')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders unread status badge', () => {
|
|
render(
|
|
<table>
|
|
<tbody>
|
|
<InquiryRow inquiry={mockInquiry} onSelect={vi.fn()} />
|
|
</tbody>
|
|
</table>,
|
|
);
|
|
expect(screen.getByText('Chưa đọc')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders read status badge when isRead is true', () => {
|
|
const readInquiry = { ...mockInquiry, isRead: true };
|
|
render(
|
|
<table>
|
|
<tbody>
|
|
<InquiryRow inquiry={readInquiry} onSelect={vi.fn()} />
|
|
</tbody>
|
|
</table>,
|
|
);
|
|
expect(screen.getByText('Đã đọc')).toBeInTheDocument();
|
|
});
|
|
|
|
it('calls onSelect when row is clicked', async () => {
|
|
const onSelect = vi.fn();
|
|
render(
|
|
<table>
|
|
<tbody>
|
|
<InquiryRow inquiry={mockInquiry} onSelect={onSelect} />
|
|
</tbody>
|
|
</table>,
|
|
);
|
|
await userEvent.click(screen.getByText('Nguyễn Văn A'));
|
|
expect(onSelect).toHaveBeenCalledWith(mockInquiry);
|
|
});
|
|
});
|