import React from 'react';
import { render, screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Banner } from './';
import { Button } from '../Button';
describe('Banner component', () => {
it('displays a title and a description', () => {
const randomDescription = 'Sunt quia cum aliquid vitae.';
render(
}
actions={
}
>
{randomDescription}
,
);
const banner = screen.getByRole('complementary', {
name: 'Hello world',
});
expect(banner).toBeVisible();
expect(banner).toHaveTextContent(randomDescription);
expect(
within(banner).getByRole('button', { name: 'Say Hello' }),
).toBeVisible();
});
it('calls onClick when user click on actions', async () => {
const handleClick1 = vi.fn();
const handleClick2 = vi.fn();
render(
}
actions={
<>
>
}
>
Sunt quia cum aliquid vitae.
,
);
expect(handleClick1).not.toHaveBeenCalled();
await userEvent.click(screen.getByRole('button', { name: 'Say Hello' }));
expect(handleClick1).toHaveBeenCalled();
expect(handleClick2).not.toHaveBeenCalled();
await userEvent.click(screen.getByRole('button', { name: 'Say Goodbye' }));
expect(handleClick2).toHaveBeenCalled();
});
});