Skip to content

Commit

Permalink
fix(app): Display pending validation when schema validator ran but ha…
Browse files Browse the repository at this point in the history
…sn't returned anything
  • Loading branch information
nellh committed Nov 12, 2024
1 parent 6c4cb2b commit 31ad0bb
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ export const ValidationBlock: React.FC<ValidationBlockProps> = ({
</div>
)
} 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) => {
Expand All @@ -51,11 +51,17 @@ export const ValidationBlock: React.FC<ValidationBlockProps> = ({
},
new Map<string, string>(),
)
return (
<div className="validation-accordion">
<Validation issues={datasetIssues} />
</div>
)
} else {
return (
<div className="validation-accordion">
<Validation issues={null} />
</div>
)
}
return (
<div className="validation-accordion">
<Validation issues={datasetIssues} />
</div>
)
}
}
Original file line number Diff line number Diff line change
@@ -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(<ValidationBlock datasetId="ds000031" issues={issues} />)
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(
<ValidationBlock
datasetId="ds000031"
validation={validation}
/>,
)
expect(screen.getByText("BIDS Validation")).toBeInTheDocument()
})
it("renders pending validation if neither issues nor validation props are present", () => {
render(<ValidationBlock datasetId="ds000031" />)
expect(screen.getByText("Validation Pending")).toBeInTheDocument()
})
})

0 comments on commit 31ad0bb

Please sign in to comment.