Skip to content

Commit

Permalink
Add test coveragee
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmmcken committed Oct 16, 2024
1 parent bc586ae commit 8d3c4df
Showing 1 changed file with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react';
import { render } from '@testing-library/react';
import WidgetPanelTooltip from './WidgetPanelTooltip';

describe('WidgetPanelTooltip', () => {
const descriptor = {
name: 'TestName',
type: 'PartitionedTable',
description: 'This is a test description',
displayName: 'Test Display Name',
};

it('renders the formatted type name', () => {
const { getByText } = render(
<WidgetPanelTooltip descriptor={descriptor} />
);
expect(getByText('Partitioned Table Name')).toBeInTheDocument();
});

it('renders the name and copy button', () => {
const { getByText, getByRole } = render(
<WidgetPanelTooltip descriptor={descriptor} />
);
expect(getByText('TestName')).toBeInTheDocument();
expect(getByRole('button', { name: /copy name/i })).toBeInTheDocument();
});

it('renders the display name if different from name', () => {
const { getByText } = render(
<WidgetPanelTooltip descriptor={descriptor} />
);
expect(getByText('Display Name')).toBeInTheDocument();
expect(getByText('Test Display Name')).toBeInTheDocument();
});

it('does not render the display name if same as name', () => {
const { queryByText } = render(
<WidgetPanelTooltip
descriptor={{ ...descriptor, displayName: 'TestName' }}
/>
);
expect(queryByText('Display Name')).not.toBeInTheDocument();
});

it('renders the description if provided', () => {
const { getByText } = render(
<WidgetPanelTooltip descriptor={descriptor} />
);
expect(getByText('This is a test description')).toBeInTheDocument();
});

it('does not render the description if not provided', () => {
const { queryByText } = render(
<WidgetPanelTooltip descriptor={{ ...descriptor, description: '' }} />
);
expect(queryByText('This is a test description')).not.toBeInTheDocument();
});

it('renders children if provided', () => {
const { getByText } = render(
<WidgetPanelTooltip descriptor={descriptor}>
<div>Child Element</div>
</WidgetPanelTooltip>
);
expect(getByText('Child Element')).toBeInTheDocument();
});
});

0 comments on commit 8d3c4df

Please sign in to comment.