Skip to content

Commit

Permalink
fix(alert): no wrapper class when no message provided
Browse files Browse the repository at this point in the history
  • Loading branch information
billhimmelsbach committed Nov 19, 2024
1 parent 874fdba commit 4f371dc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/components/Alert/Alert.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ export const Information: Story = {
args: { status: 'info', message: 'A Notification' }
};

export const InformationWithExplanation: Story = {
export const InformationWithMessageAndExplanation: Story = {
...Information,
name: 'Information with explanation',
name: 'Information with a message and an explanation',
args: {
...Information.args,
children: 'You can also add an explanation to the notification.'
message: 'Here is the message of the notification.',
children: 'Here is the explanation of the notification.'
}
};

export const InformationWithOnlyExplanation: Story = {
...Information,
name: 'Information with only an explanation',
args: {
children: 'You can also only have an explanation in the notification.'
}
};

Expand Down
13 changes: 13 additions & 0 deletions src/components/Alert/Alert.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import '@testing-library/jest-dom';
import { render, screen, within } from '@testing-library/react';
import Paragraph from '../Paragraph/Paragraph';
import { Alert, AlertType } from './Alert';
import { AlertFieldLevel } from './AlertFieldLevel';

Expand Down Expand Up @@ -45,6 +46,18 @@ describe('<Alert />', () => {
expect(explanation).toBeInTheDocument();
});

it('does not include an explanation wrapper class when there is no message but children are provided', async () => {
render(
<Alert status='info'>
<Paragraph>Test component</Paragraph>
</Alert>
);
// Icon is displayed: External link
const explanation = screen.queryByTestId('explanation');
expect(explanation).toBeInTheDocument();
expect(explanation).not.toHaveClass('m-notification_explanation');
});

it('displays links when provided', async () => {
render(<Alert status='info' />);
const noLinks = screen.queryAllByRole('listitem');
Expand Down
5 changes: 4 additions & 1 deletion src/components/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ export const Alert = ({
</p>
) : null}
{children ? (
<div className='m-notification_explanation' data-testid='explanation'>
<div
className={`${message ? 'm-notification_explanation' : ''}`}
data-testid='explanation'
>
{children}
</div>
) : null}
Expand Down

0 comments on commit 4f371dc

Please sign in to comment.