|
1 |
| -import React from 'react'; |
2 |
| -import { render, screen } from '@testing-library/react'; |
3 |
| -import { Button } from '..'; |
| 1 | +import React from "react"; |
| 2 | +import { render, screen } from "@testing-library/react"; |
| 3 | +import { Button } from ".."; |
4 | 4 |
|
5 |
| -describe('Button component', () => { |
6 |
| - it('renders without crashing', () => { |
| 5 | +describe("Button component", () => { |
| 6 | + it("renders without crashing", () => { |
7 | 7 | render(<Button>Test Button</Button>);
|
8 |
| - expect(screen.getByRole('button', { name: /test button/i })).toBeInTheDocument(); |
| 8 | + expect(screen.getByRole("button", { name: /test button/i })).toBeInTheDocument(); |
9 | 9 | });
|
10 | 10 |
|
11 |
| - it('applies the "contained" variant classes when variant is "contained"', () => { |
| 11 | + it("applies the contained variant classes when variant is contained", () => { |
12 | 12 | const { container } = render(<Button variant="contained">Test Button</Button>);
|
13 |
| - expect(container.firstChild).toHaveClass('deriv-button__variant--contained'); |
| 13 | + expect(container.firstChild).toHaveClass("deriv-button__variant--contained"); |
14 | 14 | });
|
15 | 15 |
|
16 |
| - it('applies the "ghost" variant classes when variant is "ghost"', () => { |
| 16 | + it("applies the ghost variant classes when variant is ghost", () => { |
17 | 17 | const { container } = render(<Button variant="ghost">Test Button</Button>);
|
18 |
| - expect(container.firstChild).toHaveClass('deriv-button__variant--ghost'); |
| 18 | + expect(container.firstChild).toHaveClass("deriv-button__variant--ghost"); |
19 | 19 | });
|
20 | 20 |
|
21 |
| - it('applies the "outlined" variant classes when variant is "outlined"', () => { |
| 21 | + it("applies the outlined variant classes when variant is outlined", () => { |
22 | 22 | const { container } = render(<Button variant="outlined">Test Button</Button>);
|
23 |
| - expect(container.firstChild).toHaveClass('deriv-button__variant--outlined'); |
| 23 | + expect(container.firstChild).toHaveClass("deriv-button__variant--outlined"); |
24 | 24 | });
|
25 | 25 |
|
26 |
| - it('applies the correct color class based on the "color" prop', () => { |
| 26 | + it("applies the correct color class based on the color prop", () => { |
27 | 27 | const { container } = render(<Button color="primary">Test Button</Button>);
|
28 |
| - expect(container.firstChild).toHaveClass('deriv-button__color--primary'); |
| 28 | + expect(container.firstChild).toHaveClass("deriv-button__color--primary"); |
29 | 29 | });
|
30 | 30 |
|
31 |
| - it('applies full width class when "isFullWidth" prop is true', () => { |
| 31 | + it("applies full width class when isFullWidth prop is true", () => { |
32 | 32 | const { container } = render(<Button isFullWidth>Test Button</Button>);
|
33 |
| - expect(container.firstChild).toHaveClass('deriv-button__full-width'); |
| 33 | + expect(container.firstChild).toHaveClass("deriv-button__full-width"); |
34 | 34 | });
|
35 | 35 |
|
36 |
| - it('does not apply full width class when "isFullWidth" prop is false', () => { |
| 36 | + it("does not apply full width class when isFullWidth prop is false", () => { |
37 | 37 | const { container } = render(<Button>Test Button</Button>);
|
38 |
| - expect(container.firstChild).not.toHaveClass('deriv-button__full-width'); |
| 38 | + expect(container.firstChild).not.toHaveClass("deriv-button__full-width"); |
39 | 39 | });
|
40 | 40 |
|
41 |
| - it('shows loader when "isLoading" prop is true', () => { |
| 41 | + it("shows loader when isLoading prop is true", () => { |
42 | 42 | render(<Button isLoading>Test Button</Button>);
|
43 |
| - expect(screen.getByTestId('dt_derivs-loader')).toBeInTheDocument(); |
| 43 | + expect(screen.getByTestId("dt_derivs-loader")).toBeInTheDocument(); |
44 | 44 | });
|
45 | 45 |
|
46 |
| - it('does not show loader when "isLoading" prop is false', () => { |
| 46 | + it("does not show loader when isLoading prop is false", () => { |
47 | 47 | render(<Button>Test Button</Button>);
|
48 |
| - expect(screen.queryByTestId('loader')).toBeNull(); |
| 48 | + expect(screen.queryByTestId("loader")).toBeNull(); |
49 | 49 | });
|
50 | 50 |
|
51 |
| - it('disables the button when "disabled" prop is true', () => { |
| 51 | + it("disables the button when disabled prop is true", () => { |
52 | 52 | render(<Button disabled>Test Button</Button>);
|
53 |
| - expect(screen.getByRole('button', { name: /test button/i })).toBeDisabled(); |
| 53 | + expect(screen.getByRole("button", { name: /test button/i })).toBeDisabled(); |
54 | 54 | });
|
55 | 55 |
|
56 |
| - it('disables the button when "isLoading" prop is true', () => { |
| 56 | + it("disables the button when isLoading prop is true", () => { |
57 | 57 | render(<Button isLoading>Test Button</Button>);
|
58 |
| - expect(screen.getByRole('button', { name: /test button/i })).toBeDisabled(); |
| 58 | + expect(screen.getByRole("button", { name: /test button/i })).toBeDisabled(); |
59 | 59 | });
|
60 | 60 |
|
61 |
| - it('applies the correct size class based on the "size" prop', () => { |
| 61 | + it("applies the correct size class based on the size prop", () => { |
62 | 62 | const { container } = render(<Button size="lg">Test Button</Button>);
|
63 |
| - expect(container.firstChild).toHaveClass('deriv-button__size--lg'); |
| 63 | + expect(container.firstChild).toHaveClass("deriv-button__size--lg"); |
64 | 64 | });
|
65 | 65 |
|
66 |
| - it('applies the correct rounded class based on the "rounded" prop', () => { |
| 66 | + it("applies the correct rounded class based on the rounded prop", () => { |
67 | 67 | const { container } = render(<Button rounded="md">Test Button</Button>);
|
68 |
| - expect(container.firstChild).toHaveClass('deriv-button__rounded--md'); |
| 68 | + expect(container.firstChild).toHaveClass("deriv-button__rounded--md"); |
69 | 69 | });
|
70 | 70 |
|
71 |
| - it('shows the icon when provided and not loading', () => { |
| 71 | + it("shows the icon when provided and not loading", () => { |
72 | 72 | const Icon = () => <span>Icon</span>;
|
73 | 73 | render(<Button icon={<Icon />}>Test Button</Button>);
|
74 |
| - expect(screen.getByText('Icon')).toBeInTheDocument(); |
| 74 | + expect(screen.getByText("Icon")).toBeInTheDocument(); |
75 | 75 | });
|
76 | 76 |
|
77 |
| - it('does not show the icon when "isLoading" prop is true', () => { |
| 77 | + it("does not show the icon when isLoading prop is true", () => { |
78 | 78 | const Icon = () => <span>Icon</span>;
|
79 | 79 | render(<Button isLoading icon={<Icon />}>Test Button</Button>);
|
80 |
| - expect(screen.queryByText('Icon')).toBeNull(); |
| 80 | + expect(screen.queryByText("Icon")).toBeNull(); |
81 | 81 | });
|
82 | 82 |
|
83 |
| - it('renders children text when not loading', () => { |
| 83 | + it("renders children text when not loading", () => { |
84 | 84 | render(<Button>Test Button</Button>);
|
85 |
| - expect(screen.getByRole('button', { name: /test button/i })).toHaveTextContent('Test Button'); |
| 85 | + expect(screen.getByRole("button", { name: /test button/i })).toHaveTextContent("Test Button"); |
86 | 86 | });
|
87 | 87 |
|
88 |
| - it('does not render children text when "isLoading" prop is true', () => { |
| 88 | + it("does not render children text when isLoading prop is true", () => { |
89 | 89 | render(<Button isLoading>Test Button</Button>);
|
90 |
| - expect(screen.queryByText('Test Button')).toBeNull(); |
| 90 | + expect(screen.queryByText("Test Button")).toBeNull(); |
91 | 91 | });
|
| 92 | + |
| 93 | + it("hover styles are applied when hideHoverStyles is true", () => { |
| 94 | + render( |
| 95 | + <Button hideHoverStyles>Hover Button</Button> |
| 96 | + ); |
| 97 | + const button = screen.getByRole("button"); |
| 98 | + expect(button).toHaveClass("deriv-button__hover--disabled"); |
| 99 | + }); |
| 100 | + |
| 101 | + it("hover styles are not applied when hideHoverStyles is false", () => { |
| 102 | + render( |
| 103 | + <Button>Hover Button</Button> |
| 104 | + ); |
| 105 | + const button = screen.getByRole("button"); |
| 106 | + expect(button).not.toHaveClass("deriv-button__hover--disabled"); |
| 107 | + }); |
| 108 | + |
92 | 109 | });
|
0 commit comments