Skip to content

Commit

Permalink
Merge pull request #3215 from OpenNeuroOrg/no-validation-pending
Browse files Browse the repository at this point in the history
fix(app): Display pending validation when schema validator is running
  • Loading branch information
nellh authored Nov 13, 2024
2 parents 6c4cb2b + 31ad0bb commit c7a044b
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 c7a044b

Please sign in to comment.