-
Notifications
You must be signed in to change notification settings - Fork 272
Expand file tree
/
Copy pathindex.test.tsx
More file actions
65 lines (52 loc) · 1.71 KB
/
index.test.tsx
File metadata and controls
65 lines (52 loc) · 1.71 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
import useUASButton from '#app/hooks/useUASButton';
import { render, screen } from '../react-testing-library-with-providers';
import SaveArticleButton from './index';
jest.mock('#app/hooks/useUASButton');
const mockedUseUASButton = useUASButton as jest.Mock;
describe('SaveArticleButton', () => {
const defaultProps = {
articleId: '123',
service: 'hindi',
};
afterEach(() => {
jest.clearAllMocks();
});
test('does not render button when showButton is false', () => {
mockedUseUASButton.mockReturnValue({
showButton: false,
isSaved: false,
isLoading: false,
});
const { container } = render(<SaveArticleButton {...defaultProps} />);
expect(container.firstChild).toBeNull();
});
test('renders "Save for later" when not saved', () => {
mockedUseUASButton.mockReturnValue({
showButton: true,
isSaved: false,
isLoading: false,
});
render(<SaveArticleButton {...defaultProps} />);
expect(screen.getByRole('button')).toHaveTextContent('Save for later');
});
test('renders "Remove from saved" when saved', () => {
mockedUseUASButton.mockReturnValue({
showButton: true,
isSaved: true,
isLoading: false,
});
render(<SaveArticleButton {...defaultProps} />);
expect(screen.getByRole('button')).toHaveTextContent('Remove from saved');
});
test('renders loading state and disables button', () => {
mockedUseUASButton.mockReturnValue({
showButton: true,
isSaved: false,
isLoading: true,
});
render(<SaveArticleButton {...defaultProps} />);
const button = screen.getByRole('button');
expect(button).toHaveTextContent('Loading...');
expect(button).toBeDisabled();
});
});