Skip to content

Commit 288a273

Browse files
Add tests for InfoMessage component to verify rendering with and without links
1 parent bb51fee commit 288a273

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

src/lib/components/infomessage/InfoMessageUtils.test.tsx

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,66 @@
1+
import React from 'react';
12
import '@testing-library/jest-dom';
2-
import { render } from '@testing-library/react';
3+
import { render, screen } from '@testing-library/react';
34
import { coreUIAvailableThemes } from '../../style/theme';
45
import { CoreUiThemeProvider } from '../coreuithemeprovider/CoreUiThemeProvider';
56
import { useComputeBackgroundColor } from './InfoMessageUtils';
7+
import { InfoMessage } from './InfoMessage.component';
8+
import { getWrapper } from '../../testUtils';
9+
10+
describe('InfoMessage', () => {
11+
const selectors = {
12+
title: () => screen.getByText('Title'),
13+
content: () => screen.getByText('Content'),
14+
defaultLinkText: () => screen.getByText('More info'),
15+
link: () => screen.getByRole('link'),
16+
linkText: () => screen.getByText('Link text'),
17+
};
18+
it('should render', () => {
19+
const { Wrapper } = getWrapper();
20+
render(<InfoMessage title="Title" content="Content" />, {
21+
wrapper: Wrapper,
22+
});
23+
expect(selectors.title()).toBeInTheDocument();
24+
expect(selectors.content()).toBeInTheDocument();
25+
});
26+
it('should render with link and default link text', () => {
27+
const { Wrapper } = getWrapper();
28+
render(
29+
<InfoMessage
30+
title="Title"
31+
content="Content"
32+
link="https://www.google.com"
33+
/>,
34+
{
35+
wrapper: Wrapper,
36+
},
37+
);
38+
expect(selectors.title()).toBeInTheDocument();
39+
expect(selectors.content()).toBeInTheDocument();
40+
expect(selectors.link()).toBeInTheDocument();
41+
expect(selectors.defaultLinkText()).toBeInTheDocument();
42+
expect(selectors.link()).toHaveAttribute('href', 'https://www.google.com');
43+
});
44+
it('should render with correct link text', () => {
45+
const { Wrapper } = getWrapper();
46+
render(
47+
<InfoMessage
48+
title="Title"
49+
content="Content"
50+
link="https://www.google.com"
51+
linkText="Link text"
52+
/>,
53+
{
54+
wrapper: Wrapper,
55+
},
56+
);
57+
expect(selectors.title()).toBeInTheDocument();
58+
expect(selectors.content()).toBeInTheDocument();
59+
expect(selectors.link()).toBeInTheDocument();
60+
expect(selectors.linkText()).toBeInTheDocument();
61+
expect(selectors.link()).toHaveAttribute('href', 'https://www.google.com');
62+
});
63+
});
664

765
describe('useComputeBackgroundColor', () => {
866
const SUT = jest.fn();

0 commit comments

Comments
 (0)