import { render, screen } from '@testing-library/react';
import { Button } from './Button';
import styles from './Button.module.scss';
const ArrowIcon = () => ;
describe('button tests', () => {
it('renders button', () => {
render();
const button = screen.getByRole('button');
expect(button).toHaveTextContent('button text');
expect(button).toHaveAttribute('type', 'button');
});
it('render submit button', () => {
render();
const button = screen.getByRole('button');
expect(button).toHaveTextContent('button text');
expect(button).toHaveAttribute('type', 'submit');
});
it('renders icon button', () => {
render();
const button = screen.getByRole('button');
const icon = screen.getByTestId('svg');
expect(button).toContainElement(icon);
expect(button).toHaveClass(styles.noText);
});
it('renders button with icon and text', () => {
render();
const button = screen.getByText('button text');
const icon = screen.getByTestId('svg');
expect(button).toContainElement(icon);
expect(button).toHaveClass(styles.medium);
});
it('renders small/medium/large button with secondary, light, grey and gradient colors', () => {
const { rerender } = render();
const button = screen.getByRole('button');
expect(button).toHaveClass(styles.secondary, styles.small, styles.letterSpacing);
rerender();
expect(button).toHaveClass(styles.light, styles.small);
rerender();
expect(button).toHaveClass(styles.lightGreen, styles.large);
rerender();
expect(button).toHaveClass(styles.grey, styles.medium);
rerender();
expect(button).toHaveClass(styles.gradient, styles.large);
});
it('renders button with transparent background', () => {
render();
const button = screen.getByRole('button');
expect(button).toHaveClass(styles.transparent);
});
it('renders no wrap block button without letter spacing', () => {
render();
const button = screen.getByRole('button');
expect(button).toHaveClass(styles.block, styles.noWrap);
expect(button).not.toHaveClass(styles.letterSpacing);
});
it('passes ref', () => {
const ref = { current: null };
render();
const button = screen.getByRole('button');
expect(ref.current).toBe(button);
});
});