|
| 1 | +import React from "react"; |
| 2 | +import { screen, fireEvent } from "@testing-library/react"; |
| 3 | +import { renderWithContext } from "./helpers/renderWithProviders"; |
| 4 | +import { mockVocab } from "./helpers/fixtures"; |
| 5 | +import ConfigForm from "../ConfigForm"; |
| 6 | + |
| 7 | +describe("ConfigForm", () => { |
| 8 | + const defaultConfig = { |
| 9 | + species: [], |
| 10 | + brain_region: [], |
| 11 | + cell_type: [], |
| 12 | + model_scope: [], |
| 13 | + abstraction_level: [], |
| 14 | + test_type: [], |
| 15 | + score_type: [], |
| 16 | + recording_modality: [], |
| 17 | + implementation_status: [], |
| 18 | + project_id: [], |
| 19 | + }; |
| 20 | + |
| 21 | + const defaultProps = { |
| 22 | + open: true, |
| 23 | + onClose: vi.fn(), |
| 24 | + config: defaultConfig, |
| 25 | + display: "Models and Tests", |
| 26 | + }; |
| 27 | + |
| 28 | + const contextOverrides = { |
| 29 | + validFilterValues: [mockVocab, vi.fn()], |
| 30 | + }; |
| 31 | + |
| 32 | + afterEach(() => { |
| 33 | + vi.clearAllMocks(); |
| 34 | + }); |
| 35 | + |
| 36 | + it("renders the dialog with title", () => { |
| 37 | + renderWithContext(<ConfigForm {...defaultProps} />, contextOverrides); |
| 38 | + expect(screen.getByText("Configure App")).toBeInTheDocument(); |
| 39 | + }); |
| 40 | + |
| 41 | + it("renders Cancel and Ok buttons", () => { |
| 42 | + renderWithContext(<ConfigForm {...defaultProps} />, contextOverrides); |
| 43 | + expect(screen.getByRole("button", { name: "Cancel" })).toBeInTheDocument(); |
| 44 | + expect(screen.getByRole("button", { name: "Ok" })).toBeInTheDocument(); |
| 45 | + }); |
| 46 | + |
| 47 | + it("calls onClose with cancel flag when Cancel is clicked", () => { |
| 48 | + renderWithContext(<ConfigForm {...defaultProps} />, contextOverrides); |
| 49 | + fireEvent.click(screen.getByRole("button", { name: "Cancel" })); |
| 50 | + expect(defaultProps.onClose).toHaveBeenCalledWith( |
| 51 | + "Models and Tests", |
| 52 | + defaultConfig, |
| 53 | + true |
| 54 | + ); |
| 55 | + }); |
| 56 | + |
| 57 | + it("calls onClose without cancel flag when Ok is clicked", () => { |
| 58 | + renderWithContext(<ConfigForm {...defaultProps} />, contextOverrides); |
| 59 | + fireEvent.click(screen.getByRole("button", { name: "Ok" })); |
| 60 | + expect(defaultProps.onClose).toHaveBeenCalledWith( |
| 61 | + "Models and Tests", |
| 62 | + defaultConfig |
| 63 | + ); |
| 64 | + }); |
| 65 | + |
| 66 | + it("does not render when open is false", () => { |
| 67 | + renderWithContext(<ConfigForm {...defaultProps} open={false} />, contextOverrides); |
| 68 | + expect(screen.queryByText("Configure App")).not.toBeInTheDocument(); |
| 69 | + }); |
| 70 | + |
| 71 | + it("renders the display switch options", () => { |
| 72 | + renderWithContext(<ConfigForm {...defaultProps} />, contextOverrides); |
| 73 | + expect(screen.getByText("Only Models")).toBeInTheDocument(); |
| 74 | + expect(screen.getByText("Only Tests")).toBeInTheDocument(); |
| 75 | + }); |
| 76 | +}); |
0 commit comments