The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/core/components/sidemenu/DropDownChild.test.tsx

48 lines
1.6 KiB

import React from 'react';
import { render, screen } from '@testing-library/react';
import { BrowserRouter } from 'react-router-dom';
import DropDownChild from './DropDownChild';
describe('DropDownChild', () => {
const mockText = 'MyChildItem';
const mockUrl = '/route';
const mockIcon = 'home-alt';
it('displays the text', () => {
render(<DropDownChild text={mockText} />);
const text = screen.getByText(mockText);
expect(text).toBeInTheDocument();
});
it('attaches the link to the text if provided', () => {
render(
<BrowserRouter>
<DropDownChild text={mockText} url={mockUrl} />
</BrowserRouter>
);
const link = screen.getByRole('link', { name: mockText });
expect(link).toBeInTheDocument();
});
it('displays an icon if a valid icon is provided', () => {
render(<DropDownChild text={mockText} icon={mockIcon} />);
const icon = screen.getByTestId('dropdown-child-icon');
expect(icon).toBeInTheDocument();
});
it('displays a divider instead when isDivider is true', () => {
render(<DropDownChild text={mockText} icon={mockIcon} url={mockUrl} isDivider />);
// Check the divider is shown
const divider = screen.getByTestId('dropdown-child-divider');
expect(divider).toBeInTheDocument();
// Check nothing else is rendered
const text = screen.queryByText(mockText);
const icon = screen.queryByTestId('dropdown-child-icon');
const link = screen.queryByRole('link', { name: mockText });
expect(text).not.toBeInTheDocument();
expect(icon).not.toBeInTheDocument();
expect(link).not.toBeInTheDocument();
});
});