Skip to content

Commit

Permalink
284-other-attr-for-cs
Browse files Browse the repository at this point in the history
  • Loading branch information
sroertgen committed Apr 16, 2024
1 parent b7d07de commit 1049a58
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 12 deletions.
2 changes: 2 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ exports.createPages = async ({ graphql, actions: { createPage } }) => {
conceptSchemes.data.allConceptScheme.edges.map(({ node: cs }) => ({
id: cs.id,
title: cs.title,
dctitle: cs.dctitle,
prefLabel: cs.prefLabel,
description: cs.description,
languages: Array.from(languagesByCS[cs.id]),
}))
Expand Down
36 changes: 28 additions & 8 deletions shapes/skohub.shacl.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix sdo: <https://schema.org> .
@prefix vann: <http://purl.org/vocab/vann/> .

Expand All @@ -17,14 +18,33 @@
:ConceptSchemeShape
a sh:NodeShape ;
sh:targetClass skos:ConceptScheme ;
sh:property [
sh:path dct:title ;
sh:minCount 1;
sh:datatype rdf:langString ;
sh:message "Concept Scheme has no dct:title with a language tag!" ;
sh:severity sh:Violation ;
rdfs:comment "Tested with 01_cs_no_title.ttl" ;
] ;
sh:or (
[
sh:path dct:title ;
sh:minCount 1;
sh:datatype rdf:langString ;
sh:message "Concept Scheme has no dct:title with a language tag!" ;
sh:severity sh:Violation ;
rdfs:comment "Tested with 01_cs_no_title.ttl" ;
]
[
sh:path skos:prefLabel ;
sh:minCount 1;
sh:datatype rdf:langString ;
sh:message "Concept Scheme has no skos:prefLabel with a language tag!" ;
sh:severity sh:Violation ;
rdfs:comment "Tested with 01_cs_no_title.ttl" ;
]
[
sh:path dc:title ;
sh:minCount 1;
sh:datatype rdf:langString ;
sh:message "Concept Scheme has no dc:title with a language tag!" ;
sh:severity sh:Violation ;
rdfs:comment "Tested with 01_cs_no_title.ttl" ;
]

);
sh:property [
sh:path skos:hasTopConcept ;
sh:minCount 1 ;
Expand Down
7 changes: 6 additions & 1 deletion src/components/ConceptScheme.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ const ConceptScheme = ({
id={getDomId(conceptScheme.id)}
>
<div>
<h1>{i18n(language)(conceptScheme.title)}</h1>
<h1>
{(conceptScheme?.title && i18n(language)(conceptScheme.title)) ||
(conceptScheme?.prefLabel &&
i18n(language)(conceptScheme.prefLabel)) ||
(conceptScheme?.dctitle && i18n(language)(conceptScheme.dctitle))}
</h1>
<ConceptURI id={conceptScheme.id} />
<JsonLink to={getFilePath(conceptScheme.id, "json", customDomain)} />
{conceptScheme.description && (
Expand Down
2 changes: 2 additions & 0 deletions src/components/header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ const Header = ({ siteTitle }) => {
)}
>
{data.currentScheme?.title?.[data.selectedLanguage] ||
data.currentScheme?.prefLabel?.[data.selectedLanguage] ||
data.currentScheme?.dctitle?.[data.selectedLanguage] ||
data.currentScheme.id}
</Link>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const jsonld = {
"@id": "dct:title",
"@container": "@language",
},
dctitle: {
"@id": "http://purl.org/dc/elements/1.1/title",
"@container": "@language",
},
description: {
"@id": "dct:description",
"@container": "@language",
Expand Down
8 changes: 6 additions & 2 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const IndexPage = ({ location }) => {
})
}
}, [data?.languages, data?.selectedLanguage])

return (
<Layout language={language}>
<SEO title="Concept Schemes" keywords={["conceptSchemes"]} />
Expand All @@ -79,7 +78,12 @@ const IndexPage = ({ location }) => {
}
to={getFilePath(conceptScheme.id, `html`, customDomain)}
>
{(conceptScheme.title && i18n(language)(conceptScheme.title)) ||
{(conceptScheme?.title &&
i18n(language)(conceptScheme.title)) ||
(conceptScheme?.prefLabel &&
i18n(language)(conceptScheme.prefLabel)) ||
(conceptScheme?.dctitle &&
i18n(language)(conceptScheme.dctitle)) ||
conceptScheme.id}
</Link>
</li>
Expand Down
6 changes: 6 additions & 0 deletions src/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ module.exports.allConceptScheme = (languages) => `
title {
${[...languages].join(" ")}
}
prefLabel {
${[...languages].join(" ")}
}
dctitle {
${[...languages].join(" ")}
}
description {
${[...languages].join(" ")}
}
Expand Down
2 changes: 2 additions & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module.exports = (languages) => `
type ConceptScheme implements Node {
type: String,
title: LanguageMap,
dctitle: LanguageMap,
prefLabel: LanguageMap,
description: LanguageMap,
hasTopConcept: [Concept] @link(from: "hasTopConcept___NODE"),
languages: [String]
Expand Down
117 changes: 117 additions & 0 deletions test/conceptScheme.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { describe, expect, it, vi } from "vitest"
import { render, screen, within } from "@testing-library/react"
import * as Gatsby from "gatsby"

import React from "react"
import ConceptScheme from "../src/components/ConceptScheme.jsx"
import { ConceptSchemePC } from "./data/pageContext"
import mockFetch from "./mocks/mockFetch"
import { mockConfig } from "./mocks/mockConfig"
import {
createHistory,
createMemorySource,
LocationProvider,
} from "@gatsbyjs/reach-router"
import { ContextProvider, useSkoHubContext } from "../src/context/Context"

const useStaticQuery = vi.spyOn(Gatsby, `useStaticQuery`)

function renderConceptScheme(history, pageContext, location, children = null) {
return render(
<ContextProvider>
<LocationProvider history={history}>
<ConceptScheme
pageContext={pageContext}
children={children}
location={location}
/>
</LocationProvider>
</ContextProvider>
)
}
describe.concurrent("Concept", () => {
afterEach(() => {
vi.clearAllMocks()
})
vi.spyOn(window, "fetch").mockImplementation(mockFetch)
useStaticQuery.mockImplementation(() => mockConfig)
vi.mock("../src/context/Context.jsx", async () => {
const actual = await vi.importActual("../src/context/Context.jsx")
return {
...actual,
useSkoHubContext: vi.fn(),
}
})

it("renders conceptScheme component", () => {
useSkoHubContext.mockReturnValue({
data: {
currentScheme: {},
selectedLanguage: "de",
},
updateState: vi.fn(),
})

const route = "/w3id.org/index.html"
const history = createHistory(createMemorySource(route))
const location = { search: "?lang=de" }
renderConceptScheme(history, ConceptSchemePC, location)
expect(
screen.getByRole("heading", { name: /Test Vokabular/i })
).toBeInTheDocument()
})

it("renders conceptScheme component with skos:prefLabel", () => {
useSkoHubContext.mockReturnValue({
data: {
currentScheme: {},
selectedLanguage: "de",
},
updateState: vi.fn(),
})
const ConceptSchemePCprefLabel = {
...ConceptSchemePC,
node: {
...ConceptSchemePC.node,
prefLabel: {
de: "PrefLabel DE",
},
},
}
delete ConceptSchemePCprefLabel["node"]["title"]
const route = "/w3id.org/index.html"
const history = createHistory(createMemorySource(route))
const location = { search: "?lang=de" }
renderConceptScheme(history, ConceptSchemePCprefLabel, location)
expect(
screen.getByRole("heading", { name: /PrefLabel DE/i })
).toBeInTheDocument()
})

it("renders conceptScheme component with dctitle", () => {
useSkoHubContext.mockReturnValue({
data: {
currentScheme: {},
selectedLanguage: "de",
},
updateState: vi.fn(),
})
const ConceptSchemePCprefLabel = {
...ConceptSchemePC,
node: {
...ConceptSchemePC.node,
dctitle: {
de: "dctitle DE",
},
},
}
delete ConceptSchemePCprefLabel["node"]["title"]
const route = "/w3id.org/index.html"
const history = createHistory(createMemorySource(route))
const location = { search: "?lang=de" }
renderConceptScheme(history, ConceptSchemePCprefLabel, location)
expect(
screen.getByRole("heading", { name: /dctitle DE/i })
).toBeInTheDocument()
})
})
2 changes: 1 addition & 1 deletion test/data/ttl/slashURIConceptScheme.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<c2> a skos:Concept ;
skos:prefLabel "Konzept 2"@de, "Concept 2"@en ;
skos:narrower <c3> ;
skos:broader <n1> ;
skos:broader <c1> ;
skos:inScheme <> .

<c3> a skos:Concept ;
Expand Down

0 comments on commit 1049a58

Please sign in to comment.