Skip to content

Commit

Permalink
Add tests for deprecation notice #287
Browse files Browse the repository at this point in the history
  • Loading branch information
sroertgen committed Feb 6, 2024
1 parent a5180c1 commit e6ae03b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
9 changes: 8 additions & 1 deletion test/concept.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as Gatsby from "gatsby"

import React from "react"
import Concept from "../src/components/Concept.jsx"
import { ConceptPC } from "./data/pageContext"
import { ConceptPC, ConceptPCDeprecated } from "./data/pageContext"
import mockFetch from "./mocks/mockFetch"
import { mockConfig } from "./mocks/mockConfig"
import { useSkoHubContext } from "../src/context/Context.jsx"
Expand Down Expand Up @@ -226,4 +226,11 @@ describe.concurrent("Concept", () => {
screen.getByRole("link", { name: /just-another-scheme/i })
).toHaveAttribute("href", "http://just-another-scheme.org/")
})

it("renders deprecated notice, if concept is deprecaed", () => {
render(<Concept pageContext={ConceptPCDeprecated} />)
expect(
screen.getByRole("heading", { name: /Deprecated/i })
).toBeInTheDocument()
})
})
35 changes: 35 additions & 0 deletions test/data/pageContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ const concept2 = {
inScheme: [{ id: "http://w3id.org/" }],
}

const topConceptDeprecated = {
id: "http://w3id.org/c1",
type: "Concept",
deprecated: true,
hub: "https://test.skohub.io/hub",
prefLabel: {
de: "Konzept 1",
en: "Concept 1",
},
narrower: [concept2],
topConceptOf: null,
}

export const topConcept = {
id: "http://w3id.org/c1",
type: "Concept",
Expand Down Expand Up @@ -98,6 +111,28 @@ export const ConceptPC = {
],
}

export const ConceptPCDeprecated = {
node: topConceptDeprecated,
language: "de",
collections: [
{
id: "http://w3id.org/collection",
prefLabel: { de: "Meine Collection", en: "My Collection" },
member: [topConcept, concept2],
},
],
}

export const ConceptSchemeDeprecated = {
id: "http://w3id.org/",
type: "ConceptScheme",
title: {
de: "Test Vokabular",
en: "Test Vocabulary",
},
hasTopConcept: [topConceptDeprecated],
}

export const ConceptScheme = {
id: "http://w3id.org/",
type: "ConceptScheme",
Expand Down
18 changes: 17 additions & 1 deletion test/nestedList.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest"
import { render, screen } from "@testing-library/react"
import React from "react"
import NestedList from "../src/components/nestedList"
import { ConceptScheme } from "./data/pageContext"
import { ConceptScheme, ConceptSchemeDeprecated } from "./data/pageContext"
import userEvent from "@testing-library/user-event"
import * as Gatsby from "gatsby"
import { mockConfig } from "./mocks/mockConfig"
Expand Down Expand Up @@ -59,4 +59,20 @@ describe("Nested List", () => {
await user.click(screen.getByRole("button", { expanded: true }))
expect(screen.getByRole("button", { expanded: false }))
})

it("shows deprecation notice for deprecated concepts", () => {
render(
<NestedList
items={ConceptSchemeDeprecated.hasTopConcept}
current={"http://w3id.org/c1"}
filter={null}
highlight={null}
language={"de"}
/>
)
screen.debug()
expect(
screen.getByRole("link", { name: "(DEPRECATED) Konzept 1" })
).toBeInTheDocument()
})
})

0 comments on commit e6ae03b

Please sign in to comment.