Add tests
This commit is contained in:
@@ -4,7 +4,7 @@ import { VSCodeLink } from "@vscode/webview-ui-toolkit/react";
|
||||
import { formatDate } from "../../pure/date";
|
||||
import { VariantAnalysisStatus } from "../../remote-queries/shared/variant-analysis";
|
||||
|
||||
type Props = {
|
||||
export type VariantAnalysisStatusStatsProps = {
|
||||
variantAnalysisStatus: VariantAnalysisStatus;
|
||||
completedAt?: Date;
|
||||
|
||||
@@ -26,7 +26,7 @@ export const VariantAnalysisStatusStats = ({
|
||||
variantAnalysisStatus,
|
||||
completedAt,
|
||||
onViewLogsClick,
|
||||
}: Props) => {
|
||||
}: VariantAnalysisStatusStatsProps) => {
|
||||
if (variantAnalysisStatus === VariantAnalysisStatus.InProgress) {
|
||||
return <Icon className="codicon codicon-loading codicon-modifier-spin" />;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import * as React from "react";
|
||||
import { render as reactRender, screen } from "@testing-library/react";
|
||||
import { VariantAnalysisStatus } from "../../../remote-queries/shared/variant-analysis";
|
||||
import {
|
||||
VariantAnalysisStatusStats,
|
||||
VariantAnalysisStatusStatsProps,
|
||||
} from "../VariantAnalysisStatusStats";
|
||||
import { formatDate } from "../../../pure/date";
|
||||
|
||||
describe(VariantAnalysisStatusStats.name, () => {
|
||||
const onViewLogsClick = jest.fn();
|
||||
|
||||
afterEach(() => {
|
||||
onViewLogsClick.mockReset();
|
||||
});
|
||||
|
||||
const render = (props: Partial<VariantAnalysisStatusStatsProps> = {}) =>
|
||||
reactRender(
|
||||
<VariantAnalysisStatusStats
|
||||
variantAnalysisStatus={VariantAnalysisStatus.InProgress}
|
||||
{...props}
|
||||
/>,
|
||||
);
|
||||
|
||||
it("renders an in-progress status correctly", () => {
|
||||
const { container } = render({
|
||||
variantAnalysisStatus: VariantAnalysisStatus.InProgress,
|
||||
});
|
||||
|
||||
expect(
|
||||
container.getElementsByClassName(
|
||||
"codicon codicon-loading codicon-modifier-spin",
|
||||
).length,
|
||||
).toEqual(1);
|
||||
});
|
||||
|
||||
it("renders when there is a completedAt date", () => {
|
||||
const completedAt = new Date();
|
||||
render({
|
||||
variantAnalysisStatus: VariantAnalysisStatus.Succeeded,
|
||||
completedAt,
|
||||
});
|
||||
|
||||
expect(screen.getByText(formatDate(completedAt))).toBeInTheDocument();
|
||||
expect(screen.queryByText("-")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders when there isn't a completedAt date", () => {
|
||||
render({
|
||||
variantAnalysisStatus: VariantAnalysisStatus.Succeeded,
|
||||
completedAt: undefined,
|
||||
});
|
||||
|
||||
expect(screen.getByText("-")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders when there is a viewLogs links", () => {
|
||||
render({
|
||||
variantAnalysisStatus: VariantAnalysisStatus.Succeeded,
|
||||
onViewLogsClick: () => undefined,
|
||||
});
|
||||
|
||||
expect(screen.getByText("View logs")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders when there isn't a viewLogs links", () => {
|
||||
render({
|
||||
variantAnalysisStatus: VariantAnalysisStatus.Succeeded,
|
||||
onViewLogsClick: undefined,
|
||||
});
|
||||
|
||||
expect(screen.queryByText("View logs")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user