|
| 1 | +import * as React from "react"; |
| 2 | +import { render as reactRender, screen } from "@testing-library/react"; |
| 3 | +import { VariantAnalysisStatus } from "../../../remote-queries/shared/variant-analysis"; |
| 4 | +import { |
| 5 | + VariantAnalysisStatusStats, |
| 6 | + VariantAnalysisStatusStatsProps, |
| 7 | +} from "../VariantAnalysisStatusStats"; |
| 8 | +import { formatDate } from "../../../pure/date"; |
| 9 | + |
| 10 | +describe(VariantAnalysisStatusStats.name, () => { |
| 11 | + const onViewLogsClick = jest.fn(); |
| 12 | + |
| 13 | + afterEach(() => { |
| 14 | + onViewLogsClick.mockReset(); |
| 15 | + }); |
| 16 | + |
| 17 | + const render = (props: Partial<VariantAnalysisStatusStatsProps> = {}) => |
| 18 | + reactRender( |
| 19 | + <VariantAnalysisStatusStats |
| 20 | + variantAnalysisStatus={VariantAnalysisStatus.InProgress} |
| 21 | + {...props} |
| 22 | + />, |
| 23 | + ); |
| 24 | + |
| 25 | + it("renders an in-progress status correctly", () => { |
| 26 | + const { container } = render({ |
| 27 | + variantAnalysisStatus: VariantAnalysisStatus.InProgress, |
| 28 | + }); |
| 29 | + |
| 30 | + expect( |
| 31 | + container.getElementsByClassName( |
| 32 | + "codicon codicon-loading codicon-modifier-spin", |
| 33 | + ).length, |
| 34 | + ).toEqual(1); |
| 35 | + }); |
| 36 | + |
| 37 | + it("renders when there is a completedAt date", () => { |
| 38 | + const completedAt = new Date(); |
| 39 | + render({ |
| 40 | + variantAnalysisStatus: VariantAnalysisStatus.Succeeded, |
| 41 | + completedAt, |
| 42 | + }); |
| 43 | + |
| 44 | + expect(screen.getByText(formatDate(completedAt))).toBeInTheDocument(); |
| 45 | + expect(screen.queryByText("-")).not.toBeInTheDocument(); |
| 46 | + }); |
| 47 | + |
| 48 | + it("renders when there isn't a completedAt date", () => { |
| 49 | + render({ |
| 50 | + variantAnalysisStatus: VariantAnalysisStatus.Succeeded, |
| 51 | + completedAt: undefined, |
| 52 | + }); |
| 53 | + |
| 54 | + expect(screen.getByText("-")).toBeInTheDocument(); |
| 55 | + }); |
| 56 | + |
| 57 | + it("renders when there is a viewLogs links", () => { |
| 58 | + render({ |
| 59 | + variantAnalysisStatus: VariantAnalysisStatus.Succeeded, |
| 60 | + onViewLogsClick: () => undefined, |
| 61 | + }); |
| 62 | + |
| 63 | + expect(screen.getByText("View logs")).toBeInTheDocument(); |
| 64 | + }); |
| 65 | + |
| 66 | + it("renders when there isn't a viewLogs links", () => { |
| 67 | + render({ |
| 68 | + variantAnalysisStatus: VariantAnalysisStatus.Succeeded, |
| 69 | + onViewLogsClick: undefined, |
| 70 | + }); |
| 71 | + |
| 72 | + expect(screen.queryByText("View logs")).not.toBeInTheDocument(); |
| 73 | + }); |
| 74 | +}); |
0 commit comments