|
| 1 | +import { screen } from '@testing-library/react'; |
| 2 | +import userEvent from '@testing-library/user-event'; |
| 3 | +import { h } from 'react-hyperscript-helpers'; |
| 4 | + |
| 5 | +import { InfoBox } from './InfoBox'; |
| 6 | +import { renderWithTheme } from './internal/test-utils'; |
| 7 | + |
| 8 | +describe('InfoBox', () => { |
| 9 | + it('renders an icon button', async () => { |
| 10 | + // Act |
| 11 | + renderWithTheme(h(InfoBox, ['More information about the thing.'])); |
| 12 | + const trigger = screen.getByRole('button'); |
| 13 | + |
| 14 | + // Assert |
| 15 | + expect(trigger).toHaveAccessibleName('More info'); |
| 16 | + |
| 17 | + const icon = trigger.querySelector('svg')!; |
| 18 | + expect(icon).toHaveAttribute('data-icon', 'info-circle'); |
| 19 | + }); |
| 20 | + |
| 21 | + it('allows overriding the default icon', async () => { |
| 22 | + // Act |
| 23 | + renderWithTheme(h(InfoBox, { icon: 'error-standard' }, ['More information about the thing.'])); |
| 24 | + const trigger = screen.getByRole('button'); |
| 25 | + |
| 26 | + // Assert |
| 27 | + const icon = trigger.querySelector('svg')!; |
| 28 | + expect(icon).toHaveAttribute('data-icon', 'error-standard'); |
| 29 | + }); |
| 30 | + |
| 31 | + it('renders children in a dialog', async () => { |
| 32 | + // Arrange |
| 33 | + const user = userEvent.setup(); |
| 34 | + |
| 35 | + renderWithTheme(h(InfoBox, ['More information about the thing.'])); |
| 36 | + |
| 37 | + // Act |
| 38 | + const trigger = screen.getByRole('button'); |
| 39 | + await user.click(trigger); |
| 40 | + |
| 41 | + // Assert |
| 42 | + const dialog = screen.getByRole('dialog'); |
| 43 | + expect(dialog).toHaveTextContent('More information about the thing.'); |
| 44 | + }); |
| 45 | +}); |
0 commit comments