Skip to content

Commit 6e70ae3

Browse files
committed
test: Add test for the MenuEntry component
1 parent 90a99bb commit 6e70ae3

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* SPDX-FileCopyrightText: 2025 Greenbone AG
2+
*
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import {describe, test, expect, testing} from '@gsa/testing';
7+
import MenuEntry from 'web/components/menu/MenuEntry';
8+
import {render, rendererWith, screen, fireEvent} from 'web/utils/Testing';
9+
10+
describe('MenuEntry', () => {
11+
test('should render title', () => {
12+
render(<MenuEntry title="Test Title" />);
13+
expect(screen.getByText('Test Title')).toBeInTheDocument();
14+
});
15+
16+
test('should render a link when "to" is defined', () => {
17+
const {render} = rendererWith();
18+
render(<MenuEntry title="Test Title" to="/test-path" />);
19+
const link = screen.getByRole('link', {name: 'Test Title'});
20+
expect(link).toBeInTheDocument();
21+
expect(link).toHaveAttribute('href', '/test-path');
22+
});
23+
24+
test('should call onClick with value and name when clicked', () => {
25+
const handleClick = testing.fn();
26+
render(
27+
<MenuEntry
28+
name="testName"
29+
title="Test Title"
30+
value="testValue"
31+
onClick={handleClick}
32+
/>,
33+
);
34+
35+
const element = screen.getByText('Test Title');
36+
fireEvent.click(element);
37+
38+
expect(handleClick).toHaveBeenCalledWith('testValue', 'testName');
39+
});
40+
41+
test('should render children when provided', () => {
42+
render(
43+
<MenuEntry>
44+
<span>Child Content</span>
45+
</MenuEntry>,
46+
);
47+
48+
expect(screen.getByText('Child Content')).toBeInTheDocument();
49+
});
50+
});

0 commit comments

Comments
 (0)