-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.test.tsx
More file actions
70 lines (59 loc) · 1.82 KB
/
App.test.tsx
File metadata and controls
70 lines (59 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { fireEvent, render, screen } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import App from './App';
// 1. Mock Monaco Editor (it's too heavy for JSDOM)
vi.mock('@monaco-editor/react', () => ({
default: ({ value, onChange }: any) => (
<textarea
data-testid="monaco-editor"
value={value}
onChange={(e) => onChange(e.target.value)}
/>
),
DiffEditor: ({ modified }: any) => (
<div data-testid="diff-editor">{modified}</div>
),
}));
// 2. Mock API Client
vi.mock('./api/client', () => ({
translateCode: vi.fn(),
reviewCode: vi.fn(),
fixBugs: vi.fn(),
}));
// 3. Mock Child Components that were already tested
vi.mock('./components/LanguageSelector', () => ({
LanguageSelector: ({ label, onChange }: any) => (
<div>
<label>{label}</label>
<select
onChange={(e) => onChange(e.target.value)}
data-testid={`select-${label}`}
>
<option value="javascript">JavaScript</option>
<option value="python">Python</option>
</select>
</div>
),
}));
describe('App Integration', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('renders the initial state correctly', () => {
render(<App />);
expect(screen.getByText(/CodePapi/i)).toBeDefined();
});
it('switches to Review mode and updates UI context', () => {
render(<App />);
const reviewTab = screen.getByText('Review');
fireEvent.click(reviewTab);
expect(screen.getByText('Analysis Mode')).toBeDefined();
});
it('switches to Fix mode and displays DiffEditor', () => {
render(<App />);
const fixTab = screen.getByText('Check Bugs');
fireEvent.click(fixTab);
expect(screen.getByText('Refactor Mode (Diff)')).toBeDefined();
expect(screen.getByTestId('diff-editor')).toBeDefined();
});
});