2022-05-02 11:01:29 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2023-08-02 09:15:50 +03:00
|
|
|
import type { SimpleCardProps } from '../../src';
|
|
|
|
import { SimpleCard } from '../../src';
|
|
|
|
|
|
|
|
const setUp = ({ children, ...rest }: SimpleCardProps = {}) => render(<SimpleCard {...rest}>{children}</SimpleCard>);
|
2020-12-08 21:10:29 +03:00
|
|
|
|
|
|
|
describe('<SimpleCard />', () => {
|
2022-05-02 11:01:29 +03:00
|
|
|
it('does not render title if not provided', () => {
|
2023-08-02 09:15:50 +03:00
|
|
|
setUp();
|
2022-05-02 11:01:29 +03:00
|
|
|
expect(screen.queryByRole('heading')).not.toBeInTheDocument();
|
|
|
|
});
|
2020-12-08 21:10:29 +03:00
|
|
|
|
2022-05-02 11:01:29 +03:00
|
|
|
it('renders provided title', () => {
|
2023-08-02 09:15:50 +03:00
|
|
|
setUp({ title: 'Cool title' });
|
2022-05-02 11:01:29 +03:00
|
|
|
expect(screen.getByRole('heading')).toHaveTextContent('Cool title');
|
2020-12-08 21:10:29 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders children inside body', () => {
|
2023-08-02 09:15:50 +03:00
|
|
|
setUp({ children: 'Hello world' });
|
2022-05-02 11:01:29 +03:00
|
|
|
expect(screen.getByText('Hello world')).toBeInTheDocument();
|
2020-12-08 21:10:29 +03:00
|
|
|
});
|
|
|
|
|
2022-05-02 11:01:29 +03:00
|
|
|
it.each(['primary', 'danger', 'warning'])('passes extra props to nested card', (color) => {
|
2023-08-02 09:15:50 +03:00
|
|
|
const { container } = setUp({ className: 'foo', color, children: 'Hello world' });
|
2022-05-02 11:01:29 +03:00
|
|
|
expect(container.firstChild).toHaveAttribute('class', `foo card bg-${color}`);
|
2020-12-08 21:10:29 +03:00
|
|
|
});
|
|
|
|
});
|