Move variant analysis header tests to individual components

This commit is contained in:
Koen Vlaswinkel
2022-09-16 14:40:41 +02:00
parent 3079d7f285
commit c914312e85
3 changed files with 53 additions and 85 deletions

View File

@@ -3,7 +3,7 @@ import styled from 'styled-components';
import ViewTitle from '../remote-queries/ViewTitle';
import { LinkIconButton } from './LinkIconButton';
type Props = {
export type QueryDetailsProps = {
queryName: string;
queryFileName: string;
@@ -25,7 +25,7 @@ export const QueryDetails = ({
queryFileName,
onOpenQueryFileClick,
onViewQueryTextClick,
}: Props) => {
}: QueryDetailsProps) => {
return (
<Container>
<ViewTitle>{queryName}</ViewTitle>

View File

@@ -0,0 +1,51 @@
import * as React from 'react';
import { render as reactRender, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { QueryDetails, QueryDetailsProps } from '../QueryDetails';
describe(QueryDetails.name, () => {
const onOpenQueryFileClick = jest.fn();
const onViewQueryTextClick = jest.fn();
const onStopQueryClick = jest.fn();
const onCopyRepositoryListClick = jest.fn();
const onExportResultsClick = jest.fn();
afterEach(() => {
onOpenQueryFileClick.mockReset();
onViewQueryTextClick.mockReset();
onStopQueryClick.mockReset();
onCopyRepositoryListClick.mockReset();
onExportResultsClick.mockReset();
});
const render = (props: Partial<QueryDetailsProps> = {}) =>
reactRender(
<QueryDetails
queryName="Query name"
queryFileName="example.ql"
onOpenQueryFileClick={onOpenQueryFileClick}
onViewQueryTextClick={onViewQueryTextClick}
{...props}
/>
);
it('renders correctly', () => {
render();
expect(screen.getByText('Query name')).toBeInTheDocument();
});
it('renders the query file name as a button', async () => {
render();
await userEvent.click(screen.getByText('example.ql'));
expect(onOpenQueryFileClick).toHaveBeenCalledTimes(1);
});
it('renders a view query button', async () => {
render();
await userEvent.click(screen.getByText('View query'));
expect(onViewQueryTextClick).toHaveBeenCalledTimes(1);
});
});

View File

@@ -1,83 +0,0 @@
import * as React from 'react';
import { VariantAnalysisHeader, VariantAnalysisHeaderProps } from '../VariantAnalysisHeader';
import { render as reactRender, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { VariantAnalysisStatus } from '../../../remote-queries/shared/variant-analysis';
describe(VariantAnalysisHeader.name, () => {
const onOpenQueryFileClick = jest.fn();
const onViewQueryTextClick = jest.fn();
const onStopQueryClick = jest.fn();
const onCopyRepositoryListClick = jest.fn();
const onExportResultsClick = jest.fn();
afterEach(() => {
onOpenQueryFileClick.mockReset();
onViewQueryTextClick.mockReset();
onStopQueryClick.mockReset();
onCopyRepositoryListClick.mockReset();
onExportResultsClick.mockReset();
});
const render = (props: Partial<VariantAnalysisHeaderProps> = {}) =>
reactRender(
<VariantAnalysisHeader
queryName="Query name"
queryFileName="example.ql"
variantAnalysisStatus={VariantAnalysisStatus.InProgress}
onOpenQueryFileClick={onOpenQueryFileClick}
onViewQueryTextClick={onViewQueryTextClick}
onStopQueryClick={onStopQueryClick}
onCopyRepositoryListClick={onCopyRepositoryListClick}
onExportResultsClick={onExportResultsClick}
{...props}
/>
);
it('renders correctly', () => {
render();
expect(screen.getByText('Query name')).toBeInTheDocument();
});
it('renders the query file name as a button', async () => {
render();
await userEvent.click(screen.getByText('example.ql'));
expect(onOpenQueryFileClick).toHaveBeenCalledTimes(1);
});
it('renders a view query button', async () => {
render();
await userEvent.click(screen.getByText('View query'));
expect(onViewQueryTextClick).toHaveBeenCalledTimes(1);
});
it('renders the stop query button when in progress', async () => {
render({ variantAnalysisStatus: VariantAnalysisStatus.InProgress });
await userEvent.click(screen.getByText('Stop query'));
expect(onStopQueryClick).toHaveBeenCalledTimes(1);
});
it('renders the copy repository list button when succeeded', async () => {
render({ variantAnalysisStatus: VariantAnalysisStatus.Succeeded });
await userEvent.click(screen.getByText('Copy repository list'));
expect(onCopyRepositoryListClick).toHaveBeenCalledTimes(1);
});
it('renders the export results button when succeeded', async () => {
render({ variantAnalysisStatus: VariantAnalysisStatus.Succeeded });
await userEvent.click(screen.getByText('Export results'));
expect(onExportResultsClick).toHaveBeenCalledTimes(1);
});
it('does not render any buttons when failed', async () => {
const { container } = render({ variantAnalysisStatus: VariantAnalysisStatus.Failed });
expect(container.querySelectorAll('vscode-button').length).toEqual(0);
});
});