From 31ad0bb9d0cf124f935630c9f74a4fab851f3fae Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Tue, 12 Nov 2024 15:31:01 -0800 Subject: [PATCH] fix(app): Display pending validation when schema validator ran but hasn't returned anything --- .../dataset/components/ValidationBlock.tsx | 20 +++++---- .../__tests__/ValidationBlock.spec.tsx | 42 +++++++++++++++++++ 2 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 packages/openneuro-app/src/scripts/dataset/components/__tests__/ValidationBlock.spec.tsx diff --git a/packages/openneuro-app/src/scripts/dataset/components/ValidationBlock.tsx b/packages/openneuro-app/src/scripts/dataset/components/ValidationBlock.tsx index d2b8aab7a..24e44601c 100644 --- a/packages/openneuro-app/src/scripts/dataset/components/ValidationBlock.tsx +++ b/packages/openneuro-app/src/scripts/dataset/components/ValidationBlock.tsx @@ -39,10 +39,10 @@ export const ValidationBlock: React.FC = ({ ) } else { - // Reconstruct DatasetIssues from JSON - const datasetIssues = new DatasetIssues() // If data exists, populate this. Otherwise we show pending. if (validation?.issues) { + // Reconstruct DatasetIssues from JSON + const datasetIssues = new DatasetIssues() datasetIssues.issues = validation.issues datasetIssues.codeMessages = validation.codeMessages.reduce( (acc, curr) => { @@ -51,11 +51,17 @@ export const ValidationBlock: React.FC = ({ }, new Map(), ) + return ( +
+ +
+ ) + } else { + return ( +
+ +
+ ) } - return ( -
- -
- ) } } diff --git a/packages/openneuro-app/src/scripts/dataset/components/__tests__/ValidationBlock.spec.tsx b/packages/openneuro-app/src/scripts/dataset/components/__tests__/ValidationBlock.spec.tsx new file mode 100644 index 000000000..5a27bb370 --- /dev/null +++ b/packages/openneuro-app/src/scripts/dataset/components/__tests__/ValidationBlock.spec.tsx @@ -0,0 +1,42 @@ +import React from "react" +import { render, screen } from "@testing-library/react" +import { ValidationBlock } from "../ValidationBlock" +import { vi } from "vitest" + +vi.mock("../../../config.ts") + +describe("ValidationBlock component", () => { + it("renders legacy validation if issues prop is present", () => { + const issues = [ + {}, + ] + render() + expect(screen.getByText("BIDS Validation")).toBeInTheDocument() + }) + it("renders schema validation if validation prop is present", () => { + const validation = { + issues: [ + { + code: "JSON_KEY_RECOMMENDED", + location: "/dataset_description.json", + rule: "rules.dataset_metadata.dataset_description", + subCode: "DatasetType", + }, + ], + codeMessages: [ + { code: "JSON_KEY_RECOMMENDED", message: "message" }, + ], + } + render( + , + ) + expect(screen.getByText("BIDS Validation")).toBeInTheDocument() + }) + it("renders pending validation if neither issues nor validation props are present", () => { + render() + expect(screen.getByText("Validation Pending")).toBeInTheDocument() + }) +})