-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathIconButton.spec.tsx
59 lines (52 loc) · 2.68 KB
/
IconButton.spec.tsx
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
import * as React from 'react';
import { render, screen } from '@testing-library/react';
import { IconButton } from './IconButton';
import { TrashIcon } from '../../../icons';
describe('Experimental: IconButton', () => {
it('renders an icon button with the provided icon', () => {
const onPress = jest.fn();
render(<IconButton onPress={onPress} Icon={TrashIcon} label="Icon label" />);
expect(screen.getByRole("button", { name: "Icon label"})).toBeInTheDocument();
});
it('calls onPress when clicked', () => {
const onPress = jest.fn();
render(<IconButton Icon={TrashIcon} onPress={onPress} label="Icon label"/>);
screen.getByRole("button", { name: "Icon label"}).click();
expect(onPress).toHaveBeenCalledTimes(1);
});
it('does not call onPress when disabled', () => {
const onPress = jest.fn();
render(<IconButton Icon={TrashIcon} onPress={onPress} isDisabled label="Icon label"/>);
screen.getByRole("button", { name: "Icon label"}).click();
expect(onPress).toHaveBeenCalledTimes(0);
});
it('does not call onPress when is loading', () => {
const onPress = jest.fn();
render(<IconButton Icon={TrashIcon} onPress={onPress} isLoading label="Icon label"/>);
screen.getByRole("button", { name: "Icon label"}).click();
expect(onPress).toHaveBeenCalledTimes(0);
});
it('sets the right sizes for standard variant', () => {
const onPress = jest.fn();
render(<IconButton Icon={TrashIcon} onPress={onPress} label="Icon label"/>);
const iconContainerInstance = screen.getByRole("button", { name: "Icon label"});
const containerStyle = window.getComputedStyle(iconContainerInstance);
expect(containerStyle.width).toBe('2.5rem');
expect(containerStyle.height).toBe('2.5rem');
expect(containerStyle.borderRadius).toBe('100%');
});
it('sets the right sizes for tonal variant', () => {
const onPress = jest.fn();
render(<IconButton Icon={TrashIcon} onPress={onPress} variant="tonal" label="Icon label"/>);
const iconContainerInstance = screen.getByRole("button", { name: "Icon label"});
const containerStyle = window.getComputedStyle(iconContainerInstance);
expect(containerStyle.width).toBe('3.5rem');
expect(containerStyle.height).toBe('3.5rem');
expect(containerStyle.borderRadius).toBe('100%');
});
it('spinner is rendered when loading', () => {
const onPress = jest.fn();
render(<IconButton Icon={TrashIcon} onPress={onPress} isLoading label="Icon label"/>);
expect(screen.getByTestId('iconbutton-spinner')).toBeInTheDocument();
});
});