From 1049a58d70f77e6578b09c74e41536803aad932c Mon Sep 17 00:00:00 2001 From: "@s.roertgen" Date: Tue, 16 Apr 2024 14:11:07 +0200 Subject: [PATCH] 284-other-attr-for-cs --- gatsby-node.js | 2 + shapes/skohub.shacl.ttl | 36 ++++++-- src/components/ConceptScheme.jsx | 7 +- src/components/header.jsx | 2 + src/context.js | 4 + src/pages/index.js | 8 +- src/queries.js | 6 ++ src/types.js | 2 + test/conceptScheme.test.jsx | 117 ++++++++++++++++++++++++ test/data/ttl/slashURIConceptScheme.ttl | 2 +- 10 files changed, 174 insertions(+), 12 deletions(-) create mode 100644 test/conceptScheme.test.jsx diff --git a/gatsby-node.js b/gatsby-node.js index 04fa0d7..dd869fc 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -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]), })) diff --git a/shapes/skohub.shacl.ttl b/shapes/skohub.shacl.ttl index eb148af..ecb16f9 100644 --- a/shapes/skohub.shacl.ttl +++ b/shapes/skohub.shacl.ttl @@ -7,6 +7,7 @@ @prefix rdfs: . @prefix skos: . @prefix dct: . +@prefix dc: . @prefix sdo: . @prefix vann: . @@ -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 ; diff --git a/src/components/ConceptScheme.jsx b/src/components/ConceptScheme.jsx index 801f4d3..10bddd8 100644 --- a/src/components/ConceptScheme.jsx +++ b/src/components/ConceptScheme.jsx @@ -36,7 +36,12 @@ const ConceptScheme = ({ id={getDomId(conceptScheme.id)} >
-

{i18n(language)(conceptScheme.title)}

+

+ {(conceptScheme?.title && i18n(language)(conceptScheme.title)) || + (conceptScheme?.prefLabel && + i18n(language)(conceptScheme.prefLabel)) || + (conceptScheme?.dctitle && i18n(language)(conceptScheme.dctitle))} +

{conceptScheme.description && ( diff --git a/src/components/header.jsx b/src/components/header.jsx index 9f84a72..b57aec2 100644 --- a/src/components/header.jsx +++ b/src/components/header.jsx @@ -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}
diff --git a/src/context.js b/src/context.js index 0ae32b3..27ca751 100644 --- a/src/context.js +++ b/src/context.js @@ -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", diff --git a/src/pages/index.js b/src/pages/index.js index f659a6b..14f5ebd 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -58,7 +58,6 @@ const IndexPage = ({ location }) => { }) } }, [data?.languages, data?.selectedLanguage]) - return ( @@ -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} diff --git a/src/queries.js b/src/queries.js index da97cb4..9f6dcce 100644 --- a/src/queries.js +++ b/src/queries.js @@ -139,6 +139,12 @@ module.exports.allConceptScheme = (languages) => ` title { ${[...languages].join(" ")} } + prefLabel { + ${[...languages].join(" ")} + } + dctitle { + ${[...languages].join(" ")} + } description { ${[...languages].join(" ")} } diff --git a/src/types.js b/src/types.js index 911dc60..517e642 100644 --- a/src/types.js +++ b/src/types.js @@ -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] diff --git a/test/conceptScheme.test.jsx b/test/conceptScheme.test.jsx new file mode 100644 index 0000000..30a5be4 --- /dev/null +++ b/test/conceptScheme.test.jsx @@ -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( + + + + + + ) +} +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() + }) +}) diff --git a/test/data/ttl/slashURIConceptScheme.ttl b/test/data/ttl/slashURIConceptScheme.ttl index c04ff56..e2512b7 100644 --- a/test/data/ttl/slashURIConceptScheme.ttl +++ b/test/data/ttl/slashURIConceptScheme.ttl @@ -27,7 +27,7 @@ a skos:Concept ; skos:prefLabel "Konzept 2"@de, "Concept 2"@en ; skos:narrower ; - skos:broader ; + skos:broader ; skos:inScheme <> . a skos:Concept ;