Files
grafana/public/app/core/components/NavBar/DropdownChild.test.tsx
Ashley Harrison 4350f4931d NavBar: Styling tweaks to tidy up appearance (#39871)
* NavBar: Styling tweaks to tidy up appearance

* NavBar: Add external link icon to external links

* NavBar: Dim the external link icon

* bump drone

* NavBar: Rename variable to better describe what it's doing
2021-10-01 15:53:56 +01:00

56 lines
1.9 KiB
TypeScript

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 url to the text if provided', () => {
render(
<BrowserRouter>
<DropdownChild text={mockText} url={mockUrl} />
</BrowserRouter>
);
const link = screen.getByRole('link', { name: mockText });
expect(link).toBeInTheDocument();
expect(link).toHaveAttribute('href', mockUrl);
});
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 an external link icon if the target is _blank', () => {
render(<DropdownChild text={mockText} icon={mockIcon} url={mockUrl} target="_blank" />);
const icon = screen.getByTestId('external-link-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();
});
});