@@ -2,13 +2,14 @@ import { describe, expect, it } from "vitest";
22import { render } from "vitest-browser-react" ;
33import { DocumentContextProvider } from "../../DocumentContextProvider" ;
44import { I18nProvider } from "../../i18n/I18nProvider" ;
5+ import type { DocumentJson } from "../../parser/document" ;
56import { TagCatalogProvider } from "../../tags/TagCatalogProvider" ;
67import { tagCatalog } from "../../tags/tagCatalog" ;
78import { DocumentSidePanelContextProvider } from "../DocumentSidePanelContext" ;
89import { 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 {
0 commit comments