Skip to content

Commit

Permalink
test close button
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahgm committed Oct 10, 2024
1 parent b516c33 commit 002a645
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/components/src/SectionMessage/SectionMessage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Theme, ThemeProvider, cva } from '@marigold/system';
import { setup } from '../test.utils';
import { SectionMessage } from './SectionMessage';
Expand Down Expand Up @@ -45,6 +46,7 @@ const theme: Theme = {
};

const { render } = setup({ theme });
const user = userEvent.setup();

test('message container supports base styling and themeSection', () => {
render(
Expand Down Expand Up @@ -136,3 +138,24 @@ test('set alert role if variant is "error"', () => {

expect(message).toHaveAttribute('role', 'alert');
});

test('allow to close button in message', async () => {
render(
<ThemeProvider theme={theme}>
<SectionMessage data-testid="messages" variant="error" closeButton>
<SectionMessage.Title>messages</SectionMessage.Title>
<SectionMessage.Content>default</SectionMessage.Content>
</SectionMessage>
</ThemeProvider>
);
const message = screen.getByTestId(/messages/);
const button = screen.getByRole('button');

expect(message).toBeInTheDocument();
expect(button).toBeInTheDocument();
expect(button).toHaveAttribute('aria-label');

await user.click(button);

expect(message).not.toBeInTheDocument();
});

0 comments on commit 002a645

Please sign in to comment.