@semiont/react-ui 0.5.27 → 0.5.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{PdfAnnotationCanvas.client-EVUPTUWZ.js → PdfAnnotationCanvas.client-C2IGG4SW.js} +31 -4
- package/dist/{ar-OU3DQGC6.js → ar-FABPTJVB.js} +39 -23
- package/dist/{bn-PHWCR6AZ.js → bn-LKP6BDMH.js} +39 -23
- package/dist/{chunk-PCRRBU7H.js → chunk-2GOHTTHW.js} +39 -23
- package/dist/{chunk-5VDTWRXJ.js → chunk-2YHEE63S.js} +31 -31
- package/dist/{cs-NEXYZ62I.js → cs-YQYNWHRG.js} +39 -23
- package/dist/{da-FAT43YCU.js → da-QHZOYKRY.js} +39 -23
- package/dist/{de-KRQ3WBCU.js → de-GKA7RD7J.js} +39 -23
- package/dist/{el-Q4IU3EKC.js → el-45T257AL.js} +39 -23
- package/dist/{en-2KADE7N4.js → en-RVW5EQ66.js} +2 -2
- package/dist/{es-2IO3R2MK.js → es-AVER7RU4.js} +39 -23
- package/dist/{fa-Q5GOQFXX.js → fa-K3VPK3O2.js} +39 -23
- package/dist/{fi-R6NMRWBE.js → fi-5NEKF7EB.js} +39 -23
- package/dist/{fr-QY4D5E6J.js → fr-FUMNDLBZ.js} +39 -23
- package/dist/{he-X6Y77XHY.js → he-3JGNA3PR.js} +39 -23
- package/dist/{hi-XL7IOEQM.js → hi-IJY375DF.js} +39 -23
- package/dist/{id-QZ4ZZS67.js → id-LWHKJ7ZD.js} +39 -23
- package/dist/index.css +279 -74
- package/dist/index.d.ts +170 -145
- package/dist/index.js +2743 -2365
- package/dist/{it-ME2Q7OB6.js → it-EBVOV4RW.js} +39 -23
- package/dist/{ja-HX7QASRI.js → ja-KWRIX2NF.js} +39 -23
- package/dist/{ko-EQO5AHAV.js → ko-L5CJMFDS.js} +39 -23
- package/dist/{ms-UILFSF3I.js → ms-LSNMJDR2.js} +39 -23
- package/dist/{nl-NNI45PMK.js → nl-ZB32MB7U.js} +39 -23
- package/dist/{no-MAL5F6P6.js → no-4GTNY7M5.js} +39 -23
- package/dist/{pl-4RMY6JAJ.js → pl-LUHBLTHB.js} +39 -23
- package/dist/{pt-VQH2X3QQ.js → pt-C4H3UNQ6.js} +39 -23
- package/dist/{ro-XXCQO2OG.js → ro-GGITS5V4.js} +39 -23
- package/dist/{sv-7Z6EJ6U4.js → sv-T56RTLBP.js} +39 -23
- package/dist/test-utils.js +2 -2
- package/dist/{th-L3DXXYVQ.js → th-22X2IWCB.js} +39 -23
- package/dist/{tr-P3DFVLFJ.js → tr-77TFG62H.js} +39 -23
- package/dist/{uk-7C5D3PXS.js → uk-MIIL6NXT.js} +39 -23
- package/dist/{vi-ZLTLEO7P.js → vi-7JYOIGNV.js} +39 -23
- package/dist/{zh-5FHVWDIN.js → zh-ID6DRYU4.js} +39 -23
- package/package.json +9 -8
- package/src/components/AssistProgress.tsx +36 -2
- package/src/components/CodeMirrorRenderer.tsx +8 -8
- package/src/components/__tests__/AssistProgress.test.tsx +59 -0
- package/src/components/modals/ComposeStep.tsx +218 -0
- package/src/components/modals/ConfigureGatherStep.tsx +10 -18
- package/src/components/modals/ConfigureGenerationStep.tsx +35 -19
- package/src/components/modals/ConfigureSearchStep.tsx +19 -0
- package/src/components/modals/ContextSummary.tsx +185 -72
- package/src/components/modals/CorpusPane.tsx +75 -0
- package/src/components/modals/DiscardPrompt.tsx +38 -0
- package/src/components/modals/GatherContextStep.tsx +237 -107
- package/src/components/modals/ReferenceWizardModal.tsx +238 -50
- package/src/components/modals/ResourceGenerateModal.tsx +216 -108
- package/src/components/modals/SearchModal.css +337 -101
- package/src/components/modals/SearchResultsStep.tsx +61 -68
- package/src/components/modals/WizardFooter.tsx +7 -1
- package/src/components/modals/__tests__/ComposeStep.test.tsx +152 -0
- package/src/components/modals/__tests__/ConfigureGatherStep.test.tsx +14 -26
- package/src/components/modals/__tests__/ConfigureGenerationStep.test.tsx +35 -0
- package/src/components/modals/__tests__/ConfigureSearchStep.test.tsx +24 -1
- package/src/components/modals/__tests__/GatherContextStep.resource.test.tsx +463 -25
- package/src/components/modals/__tests__/ReferenceWizardModal.test.tsx +417 -38
- package/src/components/modals/__tests__/ResourceGenerateModal.test.tsx +276 -85
- package/src/components/modals/__tests__/SearchResultsStep.test.tsx +61 -0
- package/src/components/modals/__tests__/WizardFooter.test.tsx +113 -4
- package/src/components/pdf-annotation/PdfAnnotationCanvas.tsx +34 -1
- package/src/components/pdf-annotation/__tests__/PdfAnnotationCanvas.test.tsx +38 -1
- package/src/components/resource/AnnotateView.tsx +3 -3
- package/src/components/resource/BrowseView.tsx +5 -5
- package/src/components/resource/ResourceViewer.tsx +4 -4
- package/src/components/resource/__tests__/AnnotateView.embeddable.test.tsx +1 -1
- package/src/components/resource/__tests__/BrowseView.embeddable.test.tsx +1 -1
- package/src/components/resource/__tests__/BrowseView.test.tsx +9 -9
- package/src/components/resource/annotate-renderers.tsx +3 -3
- package/src/components/resource/panels/AssistSection.css +35 -0
- package/src/components/resource/panels/ReferenceEntry.tsx +9 -2
- package/src/components/resource/panels/ReferencesPanel.tsx +4 -0
- package/src/components/resource/panels/ResourceInfoPanel.tsx +89 -20
- package/src/components/resource/panels/UnifiedAnnotationsPanel.tsx +7 -2
- package/src/components/resource/panels/__tests__/ReferenceEntry.test.tsx +41 -0
- package/src/components/resource/panels/__tests__/ReferencesPanel.test.tsx +33 -1
- package/src/components/resource/panels/__tests__/ResourceInfoPanel.test.tsx +148 -6
- package/src/features/resource-compose/__tests__/ResourceComposePage.test.tsx +0 -65
- package/src/features/resource-compose/components/ResourceComposePage.tsx +17 -130
- package/src/features/resource-compose/state/__tests__/compose-page-state-unit.test.ts +1 -100
- package/src/features/resource-compose/state/compose-page-state-unit.ts +5 -57
- package/src/features/resource-viewer/__tests__/ResourceViewerPage.test.tsx +71 -15
- package/src/features/resource-viewer/components/ResourceViewerPage.tsx +133 -59
- package/src/styles/core/forms.css +35 -8
- package/src/styles/features/resource-viewer.css +0 -22
- package/src/styles/features/resource.css +0 -4
- package/translations/ar.json +38 -22
- package/translations/bn.json +38 -22
- package/translations/cs.json +38 -22
- package/translations/da.json +38 -22
- package/translations/de.json +38 -22
- package/translations/el.json +38 -22
- package/translations/en.json +38 -22
- package/translations/es.json +38 -22
- package/translations/fa.json +38 -22
- package/translations/fi.json +38 -22
- package/translations/fr.json +38 -22
- package/translations/he.json +38 -22
- package/translations/hi.json +38 -22
- package/translations/id.json +38 -22
- package/translations/it.json +38 -22
- package/translations/ja.json +38 -22
- package/translations/ko.json +38 -22
- package/translations/ms.json +38 -22
- package/translations/nl.json +38 -22
- package/translations/no.json +38 -22
- package/translations/pl.json +38 -22
- package/translations/pt.json +38 -22
- package/translations/ro.json +38 -22
- package/translations/sv.json +38 -22
- package/translations/th.json +38 -22
- package/translations/tr.json +38 -22
- package/translations/uk.json +38 -22
- package/translations/vi.json +38 -22
- package/translations/zh.json +38 -22
- package/dist/PdfAnnotationCanvas.client-EVUPTUWZ.js.map +0 -1
- package/dist/PdfAnnotationCanvas.client-TGDPPGXJ.css.map +0 -1
- package/dist/ar-OU3DQGC6.js.map +0 -1
- package/dist/bn-PHWCR6AZ.js.map +0 -1
- package/dist/chunk-5VDTWRXJ.js.map +0 -1
- package/dist/chunk-BTUG3VJJ.js.map +0 -1
- package/dist/chunk-O23TLLXW.js.map +0 -1
- package/dist/chunk-PCRRBU7H.js.map +0 -1
- package/dist/chunk-QT7LYM72.js.map +0 -1
- package/dist/chunk-VXASXU4K.js.map +0 -1
- package/dist/cs-NEXYZ62I.js.map +0 -1
- package/dist/da-FAT43YCU.js.map +0 -1
- package/dist/de-KRQ3WBCU.js.map +0 -1
- package/dist/el-Q4IU3EKC.js.map +0 -1
- package/dist/en-2KADE7N4.js.map +0 -1
- package/dist/es-2IO3R2MK.js.map +0 -1
- package/dist/fa-Q5GOQFXX.js.map +0 -1
- package/dist/fi-R6NMRWBE.js.map +0 -1
- package/dist/fr-QY4D5E6J.js.map +0 -1
- package/dist/he-X6Y77XHY.js.map +0 -1
- package/dist/hi-XL7IOEQM.js.map +0 -1
- package/dist/id-QZ4ZZS67.js.map +0 -1
- package/dist/index.css.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/integrations/css-modules-helper.js.map +0 -1
- package/dist/integrations/styled-components-theme.js.map +0 -1
- package/dist/it-ME2Q7OB6.js.map +0 -1
- package/dist/ja-HX7QASRI.js.map +0 -1
- package/dist/ko-EQO5AHAV.js.map +0 -1
- package/dist/ms-UILFSF3I.js.map +0 -1
- package/dist/nl-NNI45PMK.js.map +0 -1
- package/dist/no-MAL5F6P6.js.map +0 -1
- package/dist/pl-4RMY6JAJ.js.map +0 -1
- package/dist/pt-VQH2X3QQ.js.map +0 -1
- package/dist/ro-XXCQO2OG.js.map +0 -1
- package/dist/sv-7Z6EJ6U4.js.map +0 -1
- package/dist/test-utils.css.map +0 -1
- package/dist/test-utils.js.map +0 -1
- package/dist/th-L3DXXYVQ.js.map +0 -1
- package/dist/tr-P3DFVLFJ.js.map +0 -1
- package/dist/uk-7C5D3PXS.js.map +0 -1
- package/dist/vi-ZLTLEO7P.js.map +0 -1
- package/dist/zh-5FHVWDIN.js.map +0 -1
- package/src/components/modals/ResourceSearchModal.tsx +0 -224
- package/src/components/modals/__tests__/ResourceSearchModal.test.tsx +0 -163
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useState, useEffect, useRef } from 'react';
|
|
4
|
-
import { readyValue } from '@semiont/sdk';
|
|
5
|
-
import { Dialog, DialogPanel, DialogTitle, Transition, TransitionChild } from '@headlessui/react';
|
|
6
|
-
import { map } from 'rxjs/operators';
|
|
7
|
-
import { getResourceId, getPrimaryRepresentation } from '@semiont/core';
|
|
8
|
-
import { createSearchPipeline } from '@semiont/sdk';
|
|
9
|
-
import { useSemiont } from '../../session/SemiontProvider';
|
|
10
|
-
import { useObservable } from '../../hooks/useObservable';
|
|
11
|
-
import { useSearchAnnouncements } from '../../hooks/useSearchAnnouncements';
|
|
12
|
-
|
|
13
|
-
import type { ResourceDescriptor } from '@semiont/core';
|
|
14
|
-
|
|
15
|
-
type SearchResult = {
|
|
16
|
-
id: string;
|
|
17
|
-
name: string;
|
|
18
|
-
content?: string;
|
|
19
|
-
mediaType?: string;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const SEARCH_DEBOUNCE_MS = 300;
|
|
23
|
-
const SEARCH_LIMIT = 50;
|
|
24
|
-
|
|
25
|
-
function toSearchResult(resource: ResourceDescriptor & { content?: string }): SearchResult | null {
|
|
26
|
-
const id = getResourceId(resource);
|
|
27
|
-
if (!id) return null;
|
|
28
|
-
const primary = getPrimaryRepresentation(resource);
|
|
29
|
-
return {
|
|
30
|
-
id,
|
|
31
|
-
name: resource.name,
|
|
32
|
-
content: resource.content,
|
|
33
|
-
mediaType: primary?.mediaType,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface ResourceSearchModalProps {
|
|
38
|
-
isOpen: boolean;
|
|
39
|
-
onClose: () => void;
|
|
40
|
-
onSelect: (resourceId: string) => void;
|
|
41
|
-
searchTerm?: string;
|
|
42
|
-
translations?: {
|
|
43
|
-
title?: string;
|
|
44
|
-
placeholder?: string;
|
|
45
|
-
searching?: string;
|
|
46
|
-
noResults?: string;
|
|
47
|
-
close?: string;
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function ResourceSearchModal({
|
|
52
|
-
isOpen,
|
|
53
|
-
onClose,
|
|
54
|
-
onSelect,
|
|
55
|
-
searchTerm = '',
|
|
56
|
-
translations = {}
|
|
57
|
-
}: ResourceSearchModalProps) {
|
|
58
|
-
const { announceSearchResults, announceSearching, announceNavigation } = useSearchAnnouncements();
|
|
59
|
-
const semiont = useObservable(useSemiont().activeSession$)?.client;
|
|
60
|
-
// Pipeline factory captures `semiont` once via useState; if semiont is
|
|
61
|
-
// still loading at first render the captured value would be undefined.
|
|
62
|
-
// Route through a ref so the fetch closure reads the latest client.
|
|
63
|
-
const semiontRef = useRef(semiont);
|
|
64
|
-
semiontRef.current = semiont;
|
|
65
|
-
|
|
66
|
-
const t = {
|
|
67
|
-
title: translations.title || 'Search Resources',
|
|
68
|
-
placeholder: translations.placeholder || 'Search for resources...',
|
|
69
|
-
searching: translations.searching || 'Searching...',
|
|
70
|
-
noResults: translations.noResults || 'No documents found',
|
|
71
|
-
close: translations.close || '✕',
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// ── Search pipeline ─────────────────────────────────────────────────────
|
|
75
|
-
const [pipeline] = useState(() =>
|
|
76
|
-
createSearchPipeline<SearchResult>(
|
|
77
|
-
(q) =>
|
|
78
|
-
semiontRef.current!.browse.resources({ search: q, limit: SEARCH_LIMIT }).pipe(
|
|
79
|
-
map((st) => {
|
|
80
|
-
const resources = readyValue(st)?.resources;
|
|
81
|
-
if (resources === undefined) return undefined;
|
|
82
|
-
return resources
|
|
83
|
-
.map(toSearchResult)
|
|
84
|
-
.filter((r): r is SearchResult => r !== null);
|
|
85
|
-
}),
|
|
86
|
-
),
|
|
87
|
-
{ debounceMs: SEARCH_DEBOUNCE_MS, initialQuery: searchTerm },
|
|
88
|
-
),
|
|
89
|
-
);
|
|
90
|
-
useEffect(() => () => pipeline.dispose(), [pipeline]);
|
|
91
|
-
|
|
92
|
-
const search = useObservable(pipeline.query$) ?? '';
|
|
93
|
-
const searchState = useObservable(pipeline.state$);
|
|
94
|
-
const results = searchState?.results ?? [];
|
|
95
|
-
const loading = searchState?.isSearching ?? false;
|
|
96
|
-
|
|
97
|
-
// Re-seed when modal re-opens with a different searchTerm prop. The
|
|
98
|
-
// initialQuery option only applies to the first construction; subsequent
|
|
99
|
-
// prop changes need an explicit setQuery.
|
|
100
|
-
useEffect(() => {
|
|
101
|
-
if (isOpen && searchTerm) {
|
|
102
|
-
pipeline.setQuery(searchTerm);
|
|
103
|
-
}
|
|
104
|
-
}, [isOpen, searchTerm, pipeline]);
|
|
105
|
-
|
|
106
|
-
// Accessibility announcements for search lifecycle.
|
|
107
|
-
useEffect(() => {
|
|
108
|
-
if (!search.trim()) return;
|
|
109
|
-
if (loading) {
|
|
110
|
-
announceSearching();
|
|
111
|
-
} else {
|
|
112
|
-
announceSearchResults(results.length, search);
|
|
113
|
-
}
|
|
114
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
115
|
-
}, [loading, results.length]);
|
|
116
|
-
|
|
117
|
-
const handleSelect = (resourceId: string, resourceName: string) => {
|
|
118
|
-
announceNavigation(resourceName, 'resource');
|
|
119
|
-
onSelect(resourceId);
|
|
120
|
-
onClose();
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
return (
|
|
124
|
-
<Transition appear show={isOpen}>
|
|
125
|
-
<Dialog as="div" className="semiont-search-modal semiont-search-modal--resource" onClose={onClose}>
|
|
126
|
-
{/* Backdrop */}
|
|
127
|
-
<TransitionChild
|
|
128
|
-
enter="ease-out duration-200"
|
|
129
|
-
enterFrom="opacity-0"
|
|
130
|
-
enterTo="opacity-100"
|
|
131
|
-
leave="ease-in duration-150"
|
|
132
|
-
leaveFrom="opacity-100"
|
|
133
|
-
leaveTo="opacity-0"
|
|
134
|
-
>
|
|
135
|
-
<div className="semiont-search-modal__backdrop" />
|
|
136
|
-
</TransitionChild>
|
|
137
|
-
|
|
138
|
-
{/* Modal panel */}
|
|
139
|
-
<div className="semiont-search-modal__wrapper">
|
|
140
|
-
<div className="semiont-search-modal__centering semiont-search-modal__centering--center">
|
|
141
|
-
<TransitionChild
|
|
142
|
-
enter="ease-out duration-200"
|
|
143
|
-
enterFrom="opacity-0 scale-95"
|
|
144
|
-
enterTo="opacity-100 scale-100"
|
|
145
|
-
leave="ease-in duration-150"
|
|
146
|
-
leaveFrom="opacity-100 scale-100"
|
|
147
|
-
leaveTo="opacity-0 scale-95"
|
|
148
|
-
>
|
|
149
|
-
<DialogPanel className="semiont-search-modal__panel semiont-search-modal__panel--with-border">
|
|
150
|
-
<div className="semiont-search-modal__header">
|
|
151
|
-
<DialogTitle className="semiont-search-modal__title">
|
|
152
|
-
{t.title}
|
|
153
|
-
</DialogTitle>
|
|
154
|
-
<button
|
|
155
|
-
onClick={onClose}
|
|
156
|
-
className="semiont-search-modal__close-button"
|
|
157
|
-
aria-label={t.close}
|
|
158
|
-
>
|
|
159
|
-
{t.close}
|
|
160
|
-
</button>
|
|
161
|
-
</div>
|
|
162
|
-
|
|
163
|
-
<div className="semiont-search-modal__search-form">
|
|
164
|
-
<input
|
|
165
|
-
type="text"
|
|
166
|
-
value={search}
|
|
167
|
-
onChange={(e) => pipeline.setQuery(e.target.value)}
|
|
168
|
-
placeholder={t.placeholder}
|
|
169
|
-
className="semiont-search-modal__search-input"
|
|
170
|
-
autoFocus
|
|
171
|
-
/>
|
|
172
|
-
</div>
|
|
173
|
-
|
|
174
|
-
<div className="semiont-search-modal__results">
|
|
175
|
-
{loading && (
|
|
176
|
-
<div className="semiont-search-modal__empty">
|
|
177
|
-
{t.searching}
|
|
178
|
-
</div>
|
|
179
|
-
)}
|
|
180
|
-
|
|
181
|
-
{!loading && results.length === 0 && search && (
|
|
182
|
-
<div className="semiont-search-modal__empty">
|
|
183
|
-
{t.noResults}
|
|
184
|
-
</div>
|
|
185
|
-
)}
|
|
186
|
-
|
|
187
|
-
{!loading && results.length > 0 && (
|
|
188
|
-
<div className="semiont-search-modal__resource-list">
|
|
189
|
-
{results.map((resource) => {
|
|
190
|
-
const isImage = resource.mediaType?.startsWith('image/');
|
|
191
|
-
|
|
192
|
-
return (
|
|
193
|
-
<div
|
|
194
|
-
key={resource.id}
|
|
195
|
-
className="semiont-search-modal__resource-item"
|
|
196
|
-
onClick={() => handleSelect(resource.id, resource.name)}
|
|
197
|
-
>
|
|
198
|
-
<h4 className="semiont-search-modal__resource-name">
|
|
199
|
-
{resource.name}
|
|
200
|
-
</h4>
|
|
201
|
-
{resource.content && !isImage && (
|
|
202
|
-
<p className="semiont-search-modal__resource-description">
|
|
203
|
-
{resource.content.substring(0, 150)}...
|
|
204
|
-
</p>
|
|
205
|
-
)}
|
|
206
|
-
{isImage && (
|
|
207
|
-
<p className="semiont-search-modal__resource-media-type">
|
|
208
|
-
{resource.mediaType}
|
|
209
|
-
</p>
|
|
210
|
-
)}
|
|
211
|
-
</div>
|
|
212
|
-
);
|
|
213
|
-
})}
|
|
214
|
-
</div>
|
|
215
|
-
)}
|
|
216
|
-
</div>
|
|
217
|
-
</DialogPanel>
|
|
218
|
-
</TransitionChild>
|
|
219
|
-
</div>
|
|
220
|
-
</div>
|
|
221
|
-
</Dialog>
|
|
222
|
-
</Transition>
|
|
223
|
-
);
|
|
224
|
-
}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
|
-
import { asStates } from '../../../__tests__/test-client';
|
|
3
|
-
import { screen, fireEvent, waitFor } from '@testing-library/react';
|
|
4
|
-
import { BehaviorSubject, map } from 'rxjs';
|
|
5
|
-
import { renderWithProviders } from '../../../test-utils';
|
|
6
|
-
import '@testing-library/jest-dom';
|
|
7
|
-
import { ResourceSearchModal } from '../ResourceSearchModal';
|
|
8
|
-
|
|
9
|
-
// Mock HeadlessUI to avoid jsdom OOM issues
|
|
10
|
-
vi.mock('@headlessui/react', () => ({
|
|
11
|
-
Dialog: ({ children, onClose, ...props }: any) => <div role="dialog" {...props}>{typeof children === 'function' ? children({ open: true }) : children}</div>,
|
|
12
|
-
DialogPanel: ({ children, ...props }: any) => <div {...props}>{children}</div>,
|
|
13
|
-
DialogTitle: ({ children, ...props }: any) => <h2 {...props}>{children}</h2>,
|
|
14
|
-
Transition: ({ show, children }: any) => show ? <>{children}</> : null,
|
|
15
|
-
TransitionChild: ({ children }: any) => <>{children}</>,
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
// Mock the http-transport Observable surface.
|
|
19
|
-
// The session-based useSemiont path: useObservable(useSemiont().activeSession$)?.client
|
|
20
|
-
// We mock useSemiont to return a stable browser whose activeSession$ emits a
|
|
21
|
-
// session-shaped object that carries the mock client.
|
|
22
|
-
const browseResourcesSubject = new BehaviorSubject<any[] | undefined>(undefined);
|
|
23
|
-
const browseResourcesMock = vi.fn(() => asStates(browseResourcesSubject.asObservable().pipe(
|
|
24
|
-
// Arrays get the list envelope `resources()` now emits; `undefined`
|
|
25
|
-
// passes through as the pending state.
|
|
26
|
-
map((v) => (Array.isArray(v) ? { resources: v, total: v.length, offset: 0, limit: 20, matchKind: 'lexical' } : v)),
|
|
27
|
-
)));
|
|
28
|
-
const stableMockClient = { browse: { resources: browseResourcesMock } };
|
|
29
|
-
const stableMockSession = { client: stableMockClient };
|
|
30
|
-
const stableActiveSession$ = new BehaviorSubject<any>(stableMockSession);
|
|
31
|
-
const stableMockBrowser = { activeSession$: stableActiveSession$ };
|
|
32
|
-
|
|
33
|
-
vi.mock('../../../session/SemiontProvider', async () => {
|
|
34
|
-
const actual = await vi.importActual<typeof import('../../../session/SemiontProvider')>(
|
|
35
|
-
'../../../session/SemiontProvider'
|
|
36
|
-
);
|
|
37
|
-
return {
|
|
38
|
-
...actual,
|
|
39
|
-
useSemiont: () => stableMockBrowser,
|
|
40
|
-
};
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// Mock search announcements
|
|
44
|
-
vi.mock('../../../hooks/useSearchAnnouncements', () => ({
|
|
45
|
-
useSearchAnnouncements: vi.fn(() => ({
|
|
46
|
-
announceSearchResults: vi.fn(),
|
|
47
|
-
announceSearching: vi.fn(),
|
|
48
|
-
announceNavigation: vi.fn(),
|
|
49
|
-
})),
|
|
50
|
-
}));
|
|
51
|
-
|
|
52
|
-
function setBrowseResults(resources: any[] | undefined) {
|
|
53
|
-
browseResourcesSubject.next(resources);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
describe('ResourceSearchModal', () => {
|
|
57
|
-
const defaultProps = {
|
|
58
|
-
isOpen: true,
|
|
59
|
-
onClose: vi.fn(),
|
|
60
|
-
onSelect: vi.fn(),
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
beforeEach(() => {
|
|
64
|
-
vi.clearAllMocks();
|
|
65
|
-
browseResourcesSubject.next(undefined);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const buildResource = (id: string, name: string, mediaType = 'text/plain', content?: string) => ({
|
|
69
|
-
'@context': 'https://www.w3.org/ns/anno.jsonld',
|
|
70
|
-
'@id': id,
|
|
71
|
-
name,
|
|
72
|
-
content,
|
|
73
|
-
representations: [{ mediaType, isPrimary: true }],
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('renders modal with title when open', () => {
|
|
77
|
-
renderWithProviders(<ResourceSearchModal {...defaultProps} />);
|
|
78
|
-
expect(screen.getByText('Search Resources')).toBeInTheDocument();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('does not render when closed', () => {
|
|
82
|
-
renderWithProviders(
|
|
83
|
-
<ResourceSearchModal {...defaultProps} isOpen={false} />
|
|
84
|
-
);
|
|
85
|
-
expect(screen.queryByText('Search Resources')).not.toBeInTheDocument();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('renders search input with placeholder', () => {
|
|
89
|
-
renderWithProviders(<ResourceSearchModal {...defaultProps} />);
|
|
90
|
-
expect(screen.getByPlaceholderText('Search for resources...')).toBeInTheDocument();
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('uses custom translations', () => {
|
|
94
|
-
renderWithProviders(
|
|
95
|
-
<ResourceSearchModal
|
|
96
|
-
{...defaultProps}
|
|
97
|
-
translations={{ title: 'Find Docs', placeholder: 'Type here...' }}
|
|
98
|
-
/>
|
|
99
|
-
);
|
|
100
|
-
expect(screen.getByText('Find Docs')).toBeInTheDocument();
|
|
101
|
-
expect(screen.getByPlaceholderText('Type here...')).toBeInTheDocument();
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('shows loading state while the Observable has not emitted', async () => {
|
|
105
|
-
renderWithProviders(<ResourceSearchModal {...defaultProps} searchTerm="something" />);
|
|
106
|
-
await waitFor(() => expect(screen.getByText('Searching...')).toBeInTheDocument(), { timeout: 1000 });
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('shows no results message when search returns an empty array', async () => {
|
|
110
|
-
renderWithProviders(<ResourceSearchModal {...defaultProps} searchTerm="xyz" />);
|
|
111
|
-
setBrowseResults([]);
|
|
112
|
-
await waitFor(() => expect(screen.getByText('No documents found')).toBeInTheDocument(), { timeout: 1000 });
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('renders search results', async () => {
|
|
116
|
-
renderWithProviders(<ResourceSearchModal {...defaultProps} searchTerm="test" />);
|
|
117
|
-
setBrowseResults([buildResource('res-1', 'Test Document', 'text/plain', 'Some content here')]);
|
|
118
|
-
await waitFor(() => expect(screen.getByText('Test Document')).toBeInTheDocument(), { timeout: 1000 });
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('calls onSelect and onClose when a result is clicked', async () => {
|
|
122
|
-
const onSelect = vi.fn();
|
|
123
|
-
const onClose = vi.fn();
|
|
124
|
-
|
|
125
|
-
renderWithProviders(
|
|
126
|
-
<ResourceSearchModal
|
|
127
|
-
{...defaultProps}
|
|
128
|
-
searchTerm="test"
|
|
129
|
-
onSelect={onSelect}
|
|
130
|
-
onClose={onClose}
|
|
131
|
-
/>
|
|
132
|
-
);
|
|
133
|
-
setBrowseResults([buildResource('res-1', 'Test Document', 'text/plain', 'Some content')]);
|
|
134
|
-
await waitFor(() => expect(screen.getByText('Test Document')).toBeInTheDocument(), { timeout: 1000 });
|
|
135
|
-
|
|
136
|
-
fireEvent.click(screen.getByText('Test Document'));
|
|
137
|
-
expect(onSelect).toHaveBeenCalledWith('res-1');
|
|
138
|
-
expect(onClose).toHaveBeenCalled();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('shows media type for image results', async () => {
|
|
142
|
-
renderWithProviders(<ResourceSearchModal {...defaultProps} searchTerm="photo" />);
|
|
143
|
-
setBrowseResults([buildResource('res-img', 'Photo', 'image/png')]);
|
|
144
|
-
await waitFor(() => expect(screen.getByText('image/png')).toBeInTheDocument(), { timeout: 1000 });
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('calls onClose when close button is clicked', () => {
|
|
148
|
-
const onClose = vi.fn();
|
|
149
|
-
renderWithProviders(
|
|
150
|
-
<ResourceSearchModal {...defaultProps} onClose={onClose} />
|
|
151
|
-
);
|
|
152
|
-
fireEvent.click(screen.getByLabelText('✕'));
|
|
153
|
-
expect(onClose).toHaveBeenCalled();
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it('passes the search term through to browse.resources', async () => {
|
|
157
|
-
renderWithProviders(<ResourceSearchModal {...defaultProps} searchTerm="hello" />);
|
|
158
|
-
await waitFor(
|
|
159
|
-
() => expect(browseResourcesMock).toHaveBeenCalledWith({ search: 'hello', limit: 50 }),
|
|
160
|
-
{ timeout: 1000 }
|
|
161
|
-
);
|
|
162
|
-
});
|
|
163
|
-
});
|