Skip to content

Commit 1af4d3e

Browse files
Feat(source): Add imprint content to source
1 parent 2c8d58a commit 1af4d3e

13 files changed

Lines changed: 1222 additions & 455 deletions

packages/react-tei/src/SidePanel/source/SourceSection.spec.tsx

Lines changed: 160 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import { describe, expect, it } from "vitest";
22
import { render } from "vitest-browser-react";
33
import { DocumentContextProvider } from "../../DocumentContextProvider";
44
import { I18nProvider } from "../../i18n/I18nProvider";
5+
import type { DocumentJson } from "../../parser/document";
56
import { TagCatalogProvider } from "../../tags/TagCatalogProvider";
67
import { tagCatalog } from "../../tags/tagCatalog";
78
import { DocumentSidePanelContextProvider } from "../DocumentSidePanelContext";
89
import { SourceSection } from "./SourceSection";
910

10-
describe("SourceSection", () => {
11-
const jsonDocument = [
11+
export function createTeiDocument(monogr: DocumentJson[]): DocumentJson[] {
12+
return [
1213
{
1314
tag: "TEI",
1415
value: [
@@ -26,34 +27,7 @@ describe("SourceSection", () => {
2627
value: [
2728
{
2829
tag: "monogr",
29-
value: [
30-
{
31-
tag: "title",
32-
attributes: {
33-
"@type": "main",
34-
"@level": "m",
35-
},
36-
value: [
37-
{
38-
tag: "#text",
39-
value: "Main Title of the Document",
40-
},
41-
],
42-
},
43-
{
44-
tag: "title",
45-
attributes: {
46-
"@type": "sub",
47-
"@level": "m",
48-
},
49-
value: [
50-
{
51-
tag: "#text",
52-
value: "Subtitle of the Document",
53-
},
54-
],
55-
},
56-
],
30+
value: monogr,
5731
},
5832
],
5933
},
@@ -66,18 +40,62 @@ describe("SourceSection", () => {
6640
],
6741
},
6842
];
43+
}
44+
45+
export function TestWrapper({
46+
children,
47+
monogr,
48+
}: {
49+
children: React.ReactNode;
50+
monogr: DocumentJson[];
51+
}) {
52+
return (
53+
<I18nProvider>
54+
<DocumentSidePanelContextProvider>
55+
<DocumentContextProvider jsonDocument={createTeiDocument(monogr)}>
56+
<TagCatalogProvider tagCatalog={tagCatalog}>
57+
{children}
58+
</TagCatalogProvider>
59+
</DocumentContextProvider>
60+
</DocumentSidePanelContextProvider>
61+
</I18nProvider>
62+
);
63+
}
64+
65+
describe("SourceSection", () => {
66+
const monogr = [
67+
{
68+
tag: "title",
69+
attributes: {
70+
"@type": "main",
71+
"@level": "m",
72+
},
73+
value: [
74+
{
75+
tag: "#text",
76+
value: "Main Title of the Document",
77+
},
78+
],
79+
},
80+
{
81+
tag: "title",
82+
attributes: {
83+
"@type": "sub",
84+
"@level": "m",
85+
},
86+
value: [
87+
{
88+
tag: "#text",
89+
value: "Subtitle of the Document",
90+
},
91+
],
92+
},
93+
];
94+
6995
it("should render source section", async () => {
7096
const { getByRole, getByText } = await render(<SourceSection />, {
7197
wrapper: ({ children }) => (
72-
<I18nProvider>
73-
<DocumentSidePanelContextProvider>
74-
<DocumentContextProvider jsonDocument={jsonDocument}>
75-
<TagCatalogProvider tagCatalog={tagCatalog}>
76-
{children}
77-
</TagCatalogProvider>
78-
</DocumentContextProvider>
79-
</DocumentSidePanelContextProvider>
80-
</I18nProvider>
98+
<TestWrapper monogr={monogr}>{children}</TestWrapper>
8199
),
82100
});
83101

@@ -98,6 +116,109 @@ describe("SourceSection", () => {
98116
expect(getByText("Subtitle of the Document")).not.toBeVisible();
99117
});
100118

119+
it("should render source section with imprint tag", async () => {
120+
const monogr = [
121+
{
122+
tag: "title",
123+
attributes: {
124+
"@type": "main",
125+
"@level": "m",
126+
},
127+
value: [
128+
{
129+
tag: "#text",
130+
value: "Main Title of the Document",
131+
},
132+
],
133+
},
134+
{
135+
tag: "title",
136+
attributes: {
137+
"@type": "sub",
138+
"@level": "m",
139+
},
140+
value: [
141+
{
142+
tag: "#text",
143+
value: "Subtitle of the Document",
144+
},
145+
],
146+
},
147+
{
148+
tag: "imprint",
149+
value: [
150+
{
151+
tag: "publisher",
152+
value: [
153+
{
154+
tag: "#text",
155+
value: "Nature Publishing Group",
156+
},
157+
],
158+
},
159+
{
160+
tag: "biblScope",
161+
attributes: { "@unit": "vol" },
162+
value: [
163+
{
164+
tag: "#text",
165+
value: "10",
166+
},
167+
],
168+
},
169+
{
170+
tag: "biblScope",
171+
attributes: { "@unit": "issue" },
172+
value: [
173+
{
174+
tag: "#text",
175+
value: "2",
176+
},
177+
],
178+
},
179+
{
180+
tag: "biblScope",
181+
attributes: { "@unit": "page", "@from": "100" },
182+
value: [
183+
{
184+
tag: "#text",
185+
value: "100",
186+
},
187+
],
188+
},
189+
{
190+
tag: "biblScope",
191+
attributes: { "@unit": "page", "@to": "110" },
192+
value: [
193+
{
194+
tag: "#text",
195+
value: "110",
196+
},
197+
],
198+
},
199+
{
200+
tag: "date",
201+
attributes: { "@when": "2020" },
202+
value: [],
203+
},
204+
],
205+
},
206+
];
207+
208+
const { getByText } = await render(<SourceSection />, {
209+
wrapper: ({ children }) => (
210+
<TestWrapper monogr={monogr}>{children}</TestWrapper>
211+
),
212+
});
213+
await expect
214+
.element(
215+
getByText(
216+
"Vol. 10, n° 2 (2020), pp. 100-110 – Nature Publishing Group.",
217+
),
218+
)
219+
.toBeInTheDocument();
220+
});
221+
101222
it("should not render source section if no title is present", async () => {
102223
const jsonDocumentWithoutTitle = [
103224
{
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { SourceIdno } from "./SourceIdno";
1+
import { SourceIdno } from "./tags/SourceIdno";
2+
import { SourceImprint } from "./tags/SourceImprint";
23

34
export const sourceTagCatalog = {
45
idno: SourceIdno,
6+
imprint: SourceImprint,
57
};

packages/react-tei/src/SidePanel/source/SourceIdno.spec.tsx renamed to packages/react-tei/src/SidePanel/source/tags/SourceIdno.spec.tsx

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { afterAll, describe, expect, it, vi } from "vitest";
22
import { render } from "vitest-browser-react";
3-
import { I18nProvider } from "../../i18n/I18nProvider";
4-
import { TagCatalogProvider } from "../../tags/TagCatalogProvider";
5-
import { tagCatalog } from "../../tags/tagCatalog";
3+
import { I18nProvider } from "../../../i18n/I18nProvider";
4+
import { TagCatalogProvider } from "../../../tags/TagCatalogProvider";
5+
import { tagCatalog } from "../../../tags/tagCatalog";
66
import { SourceIdno } from "./SourceIdno";
77

88
vi.mock("../../debug/debug.const", () => ({
@@ -36,18 +36,4 @@ describe("SourceIdno", () => {
3636
});
3737
expect(screen.getByText(expectedText)).toBeVisible();
3838
});
39-
40-
it("renders DebugTag for unsupported type", async () => {
41-
const data = {
42-
tag: "idno",
43-
attributes: { "@type": "other" },
44-
value: "something else",
45-
};
46-
const screen = await render(<SourceIdno data={data} />, {
47-
wrapper: Wrapper,
48-
});
49-
await expect
50-
.element(screen.container.querySelector(".debug") as HTMLElement)
51-
.toBeInTheDocument();
52-
});
5339
});

packages/react-tei/src/SidePanel/source/SourceIdno.tsx renamed to packages/react-tei/src/SidePanel/source/tags/SourceIdno.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Typography from "@mui/material/Typography";
22
import { useTranslation } from "react-i18next";
3-
import { DebugTag } from "../../debug/DebugTag";
4-
import type { ComponentProps } from "../../tags/type";
5-
import { Value } from "../../tags/Value";
3+
import { DebugTag } from "../../../debug/DebugTag";
4+
import type { ComponentProps } from "../../../tags/type";
5+
import { Value } from "../../../tags/Value";
66

77
export function SourceIdno({ data }: ComponentProps) {
88
const { t } = useTranslation();

0 commit comments

Comments
 (0)