-
Notifications
You must be signed in to change notification settings - Fork 694
Expand file tree
/
Copy pathreplace-code-modal.spec.tsx
More file actions
67 lines (50 loc) · 1.96 KB
/
replace-code-modal.spec.tsx
File metadata and controls
67 lines (50 loc) · 1.96 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
import { render, fireEvent, screen } from '@testing-library/react';
import { ReplaceCodeModal } from '../replace-code-modal';
jest.mock('react-i18next', () => ({
useTranslation: () => ({
t: (key: string) => key,
}),
}));
describe('ReplaceCodeModal', () => {
const handleCodeReplaceMock = jest.fn();
beforeEach(() => {
handleCodeReplaceMock.mockClear();
});
const renderComponent = () =>
render(<ReplaceCodeModal handleCodeReplace={handleCodeReplaceMock} />);
it('should render the modal with correct title and message', () => {
renderComponent();
expect(screen.getByText('Replace current content?')).toBeInTheDocument();
expect(
screen.getByText('Existing content will be replaced. Do you want to continue?'),
).toBeInTheDocument();
});
it('should render buttons with correct text', () => {
renderComponent();
expect(screen.getByText('Yes')).toBeInTheDocument();
expect(screen.getByText('No')).toBeInTheDocument();
expect(screen.getByText('Keep both')).toBeInTheDocument();
});
it('should call handleCodeReplace when "Yes" button is clicked', () => {
renderComponent();
fireEvent.click(screen.getByText('Yes'));
expect(handleCodeReplaceMock).toHaveBeenCalledTimes(1);
});
it('should call handleCodeReplace when "No" button is clicked', () => {
renderComponent();
fireEvent.click(screen.getByText('No'));
expect(handleCodeReplaceMock).toHaveBeenCalledTimes(1);
});
it('should call handleCodeReplace when "Keep both" button is clicked', () => {
renderComponent();
fireEvent.click(screen.getByText('Keep both'));
expect(handleCodeReplaceMock).toHaveBeenCalledTimes(1);
});
it('should call handleCodeReplace when close button (X) is clicked', () => {
renderComponent();
const closeButton = screen.getByLabelText('Close');
expect(closeButton).toBeInTheDocument();
fireEvent.click(closeButton);
expect(handleCodeReplaceMock).toHaveBeenCalledTimes(1);
});
});