From e6ae03b9ed5864054af5f489e1774bd1bb3f20ae Mon Sep 17 00:00:00 2001 From: "@s.roertgen" Date: Tue, 6 Feb 2024 17:20:22 +0100 Subject: [PATCH] Add tests for deprecation notice #287 --- test/concept.test.jsx | 9 ++++++++- test/data/pageContext.js | 35 +++++++++++++++++++++++++++++++++++ test/nestedList.test.jsx | 18 +++++++++++++++++- 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/test/concept.test.jsx b/test/concept.test.jsx index a90d85e..59d39d9 100644 --- a/test/concept.test.jsx +++ b/test/concept.test.jsx @@ -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" @@ -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() + expect( + screen.getByRole("heading", { name: /Deprecated/i }) + ).toBeInTheDocument() + }) }) diff --git a/test/data/pageContext.js b/test/data/pageContext.js index e033f1d..34e877e 100644 --- a/test/data/pageContext.js +++ b/test/data/pageContext.js @@ -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", @@ -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", diff --git a/test/nestedList.test.jsx b/test/nestedList.test.jsx index 3eb33c7..f402546 100644 --- a/test/nestedList.test.jsx +++ b/test/nestedList.test.jsx @@ -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" @@ -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( + + ) + screen.debug() + expect( + screen.getByRole("link", { name: "(DEPRECATED) Konzept 1" }) + ).toBeInTheDocument() + }) })