Some checks failed
CI / Lint → Typecheck → Test → Build (22) (push) Failing after 18s
CI / E2E Tests (push) Has been skipped
CodeQL Analysis / CodeQL (javascript-typescript) (push) Failing after 1m15s
Deploy / Build API Image (push) Failing after 33s
Deploy / Build Web Image (push) Failing after 14s
Deploy / Build AI Services Image (push) Failing after 13s
E2E Tests / Playwright E2E (push) Failing after 11s
Security Scanning / Dependency Audit (pnpm) (push) Failing after 3s
Security Scanning / Trivy Scan — API Image (push) Failing after 2m1s
Security Scanning / Trivy Scan — Web Image (push) Failing after 51s
Security Scanning / Trivy Scan — AI Services Image (push) Failing after 47s
Security Scanning / Trivy Filesystem Scan (push) Failing after 35s
Deploy / Deploy to Staging (push) Has been skipped
Deploy / Smoke Test Staging (push) Has been skipped
Deploy / Deploy to Production (push) Has been skipped
Deploy / Smoke Test Production (push) Has been skipped
Security Scanning / Security Gate (push) Failing after 1s
Deploy / Rollback Staging (push) Has been skipped
Deploy / Rollback Production (push) Has been skipped
- AI advice handler now sends both `x-api-key` and `Authorization: Bearer` so proxy gateways (e.g. chat.trollllm.xyz) accept the request. Native Anthropic ignores the extra header. - Remove `lg:sticky lg:top-20` from listing detail contact card — sidebar now scrolls with the page. - Fix missing Vietnamese diacritics on AI estimate button: "Dinh gia AI" -> "Định giá AI", "Dang dinh gia..." -> "Đang định giá...". Tests updated accordingly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
import { AiEstimateButton } from '../ai-estimate-button';
|
|
|
|
// Mock the hook
|
|
const mockMutate = vi.fn();
|
|
vi.mock('@/lib/hooks/use-valuation', () => ({
|
|
useValuationPredictForListing: () => ({
|
|
mutate: mockMutate,
|
|
isPending: false,
|
|
data: null,
|
|
}),
|
|
}));
|
|
|
|
describe('AiEstimateButton', () => {
|
|
beforeEach(() => {
|
|
mockMutate.mockClear();
|
|
});
|
|
|
|
it('renders the button', () => {
|
|
render(<AiEstimateButton listingId="listing-1" />);
|
|
expect(screen.getByText('Định giá AI')).toBeInTheDocument();
|
|
});
|
|
|
|
it('calls mutate when clicked', async () => {
|
|
const user = userEvent.setup();
|
|
render(<AiEstimateButton listingId="listing-1" />);
|
|
|
|
await user.click(screen.getByText('Định giá AI'));
|
|
expect(mockMutate).toHaveBeenCalledWith('listing-1', expect.any(Object));
|
|
});
|
|
|
|
it('renders as a button element', () => {
|
|
render(<AiEstimateButton listingId="listing-1" />);
|
|
expect(screen.getByRole('button', { name: /Định giá AI/ })).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe('AiEstimateButton - loading state', () => {
|
|
it('shows loading text when pending', () => {
|
|
vi.mocked(vi.fn()).mockReturnValue(undefined);
|
|
// Re-mock with isPending
|
|
vi.doMock('@/lib/hooks/use-valuation', () => ({
|
|
useValuationPredictForListing: () => ({
|
|
mutate: vi.fn(),
|
|
isPending: true,
|
|
data: null,
|
|
}),
|
|
}));
|
|
|
|
// This test validates the loading button text exists in the component
|
|
render(<AiEstimateButton listingId="listing-1" />);
|
|
// Component shows 'Định giá AI' or 'Đang định giá...' based on isPending
|
|
expect(screen.getByRole('button')).toBeInTheDocument();
|
|
});
|
|
});
|