|
| 1 | +import { render as reactRender, screen } from "@testing-library/react"; |
| 2 | +import type { Props } from "../ModelEvaluation"; |
| 3 | +import { ModelEvaluation } from "../ModelEvaluation"; |
| 4 | +import { createMockModelEditorViewState } from "../../../../test/factories/model-editor/view-state"; |
| 5 | +import type { ModeledMethod } from "../../../model-editor/modeled-method"; |
| 6 | +import { createMethod } from "../../../../test/factories/model-editor/method-factories"; |
| 7 | +import { createMockVariantAnalysis } from "../../../../test/factories/variant-analysis/shared/variant-analysis"; |
| 8 | +import { VariantAnalysisStatus } from "../../../variant-analysis/shared/variant-analysis"; |
| 9 | +import { createSummaryModeledMethod } from "../../../../test/factories/model-editor/modeled-method-factories"; |
| 10 | + |
| 11 | +describe(ModelEvaluation.name, () => { |
| 12 | + const method = createMethod(); |
| 13 | + const modeledMethodsMap: Record<string, ModeledMethod[]> = {}; |
| 14 | + modeledMethodsMap[method.signature] = [createSummaryModeledMethod(method)]; |
| 15 | + |
| 16 | + const render = (props: Partial<Props> = {}) => |
| 17 | + reactRender( |
| 18 | + <ModelEvaluation |
| 19 | + viewState={createMockModelEditorViewState({ showEvaluationUi: true })} |
| 20 | + modeledMethods={modeledMethodsMap} |
| 21 | + modifiedSignatures={new Set()} |
| 22 | + onStartEvaluation={jest.fn()} |
| 23 | + onStopEvaluation={jest.fn()} |
| 24 | + openModelAlertsView={jest.fn()} |
| 25 | + evaluationRun={undefined} |
| 26 | + {...props} |
| 27 | + />, |
| 28 | + ); |
| 29 | + |
| 30 | + describe("when showEvaluationUi is false", () => { |
| 31 | + it("does not render anything", () => { |
| 32 | + render({ |
| 33 | + viewState: createMockModelEditorViewState({ showEvaluationUi: false }), |
| 34 | + }); |
| 35 | + expect(screen.queryByText("Evaluate")).not.toBeInTheDocument(); |
| 36 | + expect(screen.queryByText("Stop evaluation")).not.toBeInTheDocument(); |
| 37 | + expect(screen.queryByText("Evaluation run")).not.toBeInTheDocument(); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + describe("when showEvaluationUi is true", () => { |
| 42 | + it("renders evaluation UI with 'Evaluate' button enabled", () => { |
| 43 | + render(); |
| 44 | + |
| 45 | + const evaluateButton = screen.queryByText("Evaluate"); |
| 46 | + expect(evaluateButton).toBeInTheDocument(); |
| 47 | + expect(evaluateButton?.getElementsByTagName("input")[0]).toBeEnabled(); |
| 48 | + |
| 49 | + expect(screen.queryByText("Stop evaluation")).not.toBeInTheDocument(); |
| 50 | + |
| 51 | + expect(screen.queryByText("Evaluation run")).not.toBeInTheDocument(); |
| 52 | + }); |
| 53 | + |
| 54 | + it("disables 'Evaluate' button when there are no custom models", () => { |
| 55 | + render({ |
| 56 | + modeledMethods: {}, |
| 57 | + }); |
| 58 | + |
| 59 | + const evaluateButton = screen.queryByText("Evaluate"); |
| 60 | + expect(evaluateButton).toBeInTheDocument(); |
| 61 | + expect(evaluateButton?.getElementsByTagName("input")[0]).toBeDisabled(); |
| 62 | + |
| 63 | + expect(screen.queryByText("Stop evaluation")).not.toBeInTheDocument(); |
| 64 | + |
| 65 | + expect(screen.queryByText("Evaluation run")).not.toBeInTheDocument(); |
| 66 | + }); |
| 67 | + |
| 68 | + it("disables 'Evaluate' button when there are unsaved changes", () => { |
| 69 | + render({ |
| 70 | + modifiedSignatures: new Set([method.signature]), |
| 71 | + }); |
| 72 | + |
| 73 | + const evaluateButton = screen.queryByText("Evaluate"); |
| 74 | + expect(evaluateButton).toBeInTheDocument(); |
| 75 | + expect(evaluateButton?.getElementsByTagName("input")[0]).toBeDisabled(); |
| 76 | + |
| 77 | + expect(screen.queryByText("Stop evaluation")).not.toBeInTheDocument(); |
| 78 | + |
| 79 | + expect(screen.queryByText("Evaluation run")).not.toBeInTheDocument(); |
| 80 | + }); |
| 81 | + |
| 82 | + it("renders 'Evaluate' button and 'Evaluation run' link when there is a completed evaluation", () => { |
| 83 | + render({ |
| 84 | + evaluationRun: { |
| 85 | + isPreparing: false, |
| 86 | + variantAnalysis: createMockVariantAnalysis({ |
| 87 | + status: VariantAnalysisStatus.Succeeded, |
| 88 | + }), |
| 89 | + }, |
| 90 | + }); |
| 91 | + |
| 92 | + const evaluateButton = screen.queryByText("Evaluate"); |
| 93 | + expect(evaluateButton).toBeInTheDocument(); |
| 94 | + expect(evaluateButton?.getElementsByTagName("input")[0]).toBeEnabled(); |
| 95 | + |
| 96 | + expect(screen.queryByText("Evaluation run")).toBeInTheDocument(); |
| 97 | + |
| 98 | + expect(screen.queryByText("Stop evaluation")).not.toBeInTheDocument(); |
| 99 | + }); |
| 100 | + |
| 101 | + it("renders 'Stop evaluation' button and 'Evaluation run' link when there is an in progress evaluation", () => { |
| 102 | + render({ |
| 103 | + evaluationRun: { |
| 104 | + isPreparing: true, |
| 105 | + variantAnalysis: undefined, |
| 106 | + }, |
| 107 | + }); |
| 108 | + |
| 109 | + const stopEvaluationButton = screen.queryByText("Stop evaluation"); |
| 110 | + expect(stopEvaluationButton).toBeInTheDocument(); |
| 111 | + expect( |
| 112 | + stopEvaluationButton?.getElementsByTagName("input")[0], |
| 113 | + ).toBeEnabled(); |
| 114 | + |
| 115 | + expect(screen.queryByText("Evaluation run")).toBeInTheDocument(); |
| 116 | + |
| 117 | + expect(screen.queryByText("Evaluate")).not.toBeInTheDocument(); |
| 118 | + }); |
| 119 | + }); |
| 120 | +}); |
0 commit comments