Skip to content

Commit

Permalink
Add action, icon, and iconMapping tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoAndai committed Jan 18, 2024
1 parent 55b3cf7 commit 222979a
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions packages/mui-material/src/Alert/Alert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ describe('<Alert />', () => {
),
).not.to.throw();
});

it('should render the action provided into the Alert', () => {
render(<Alert action={<button data-testid="action">Action</button>}>Hello World</Alert>);

expect(screen.getByTestId('action')).toBeVisible();
});
});

describe('prop: components', () => {
Expand Down Expand Up @@ -148,4 +154,46 @@ describe('<Alert />', () => {
expect(closeIcon).to.have.class('my-class');
});
});

describe('prop: icon', () => {
it('should render the icon provided into the Alert', () => {
render(<Alert icon={<div data-testid="icon" />}>Hello World</Alert>);

expect(screen.getByTestId('icon')).toBeVisible();
});

it('should not render any icon if false is provided', () => {
render(
<Alert
icon={false}
severity="success"
iconMapping={{ success: <div data-testid="success-icon" /> }}
>
Hello World
</Alert>,
);

expect(screen.queryByTestId('success-icon')).to.eq(null);
});
});

describe('prop: iconMapping', () => {
const severities = ['success', 'info', 'warning', 'error'];
const iconMapping = severities.reduce((acc, severity) => {
acc[severity] = <div data-testid={`${severity}-icon`} />;
return acc;
}, {});

severities.forEach((severity) => {
it(`should render the icon provided into the Alert for severity ${severity}`, () => {
render(
<Alert severity={severity} iconMapping={iconMapping}>
Hello World
</Alert>,
);

expect(screen.getByTestId(`${severity}-icon`)).toBeVisible();
});
});
});
});

0 comments on commit 222979a

Please sign in to comment.