@xynolog/react-ui 0.8.0 → 0.8.1

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.
Files changed (235) hide show
  1. package/README.md +26 -46
  2. package/package.json +12 -9
  3. package/src/components/Button/Button.tsx +0 -188
  4. package/src/components/Button/__tests__/Button.test.tsx +0 -449
  5. package/src/components/CodeMirrorRenderer.tsx +0 -536
  6. package/src/components/DelegateProgress.tsx +0 -308
  7. package/src/components/ErrorBoundary.tsx +0 -174
  8. package/src/components/ItemFoundLog.tsx +0 -42
  9. package/src/components/LiveRegion.tsx +0 -261
  10. package/src/components/ProtectedErrorBoundary.tsx +0 -114
  11. package/src/components/ResizeHandle.tsx +0 -167
  12. package/src/components/ResourceTagsInline.tsx +0 -120
  13. package/src/components/SessionExpiryBanner.tsx +0 -74
  14. package/src/components/SessionTimer.tsx +0 -17
  15. package/src/components/StatusDisplay.tsx +0 -131
  16. package/src/components/Toast.tsx +0 -217
  17. package/src/components/Toolbar.tsx +0 -194
  18. package/src/components/UserMenuSkeleton.tsx +0 -13
  19. package/src/components/__tests__/DelegateProgress.denominator.test.tsx +0 -102
  20. package/src/components/__tests__/DelegateProgress.test.tsx +0 -649
  21. package/src/components/__tests__/ErrorBoundary.test.tsx +0 -565
  22. package/src/components/__tests__/LiveRegion.a11y.test.tsx +0 -258
  23. package/src/components/__tests__/LiveRegion.hooks.test.tsx +0 -140
  24. package/src/components/__tests__/ProtectedErrorBoundary.test.tsx +0 -225
  25. package/src/components/__tests__/ResizeHandle.test.tsx +0 -159
  26. package/src/components/__tests__/ResourceTagsInline.test.tsx +0 -325
  27. package/src/components/__tests__/SessionExpiryBanner.test.tsx +0 -124
  28. package/src/components/__tests__/SessionTimer.test.tsx +0 -199
  29. package/src/components/__tests__/StatusDisplay.test.tsx +0 -179
  30. package/src/components/__tests__/Toast.test.tsx +0 -96
  31. package/src/components/__tests__/Toolbar.test.tsx +0 -111
  32. package/src/components/__tests__/UserMenuSkeleton.test.tsx +0 -182
  33. package/src/components/annotation/AnchoredTextNotice.tsx +0 -36
  34. package/src/components/annotation/AnnotateToolbar.tsx +0 -531
  35. package/src/components/annotation/__tests__/AnnotateToolbar.display.test.tsx +0 -127
  36. package/src/components/annotation/__tests__/AnnotateToolbar.test.tsx +0 -304
  37. package/src/components/annotation-popups/JsonLdView.tsx +0 -127
  38. package/src/components/annotation-popups/SharedPopupElements.tsx +0 -131
  39. package/src/components/annotation-popups/__tests__/JsonLdView.test.tsx +0 -432
  40. package/src/components/annotation-popups/__tests__/SharedPopupElements.test.tsx +0 -297
  41. package/src/components/branding/XynologBranding.tsx +0 -41
  42. package/src/components/branding/__tests__/XynologBranding.test.tsx +0 -383
  43. package/src/components/error-states/ResourceErrorState.tsx +0 -30
  44. package/src/components/error-states/__tests__/ResourceErrorState.test.tsx +0 -102
  45. package/src/components/image-annotation/AnnotationOverlay.tsx +0 -307
  46. package/src/components/image-annotation/SvgDrawingCanvas.tsx +0 -514
  47. package/src/components/image-annotation/__tests__/AnnotationOverlay.click.test.tsx +0 -169
  48. package/src/components/image-annotation/__tests__/AnnotationOverlay.hover.test.tsx +0 -83
  49. package/src/components/image-annotation/__tests__/SvgDrawingCanvas.annotate-gate.test.tsx +0 -228
  50. package/src/components/image-annotation/__tests__/SvgDrawingCanvas.click.test.tsx +0 -204
  51. package/src/components/layout/LeftSidebar.tsx +0 -150
  52. package/src/components/layout/PageLayout.tsx +0 -49
  53. package/src/components/layout/SkipLinks.tsx +0 -36
  54. package/src/components/layout/UnifiedHeader.tsx +0 -151
  55. package/src/components/layout/__tests__/LeftSidebar.test.tsx +0 -426
  56. package/src/components/layout/__tests__/PageLayout.test.tsx +0 -311
  57. package/src/components/layout/__tests__/SkipLinks.a11y.test.tsx +0 -218
  58. package/src/components/layout/__tests__/UnifiedHeader.test.tsx +0 -555
  59. package/src/components/loading-states/ComposeLoadingState.tsx +0 -19
  60. package/src/components/loading-states/ResourceLoadingState.tsx +0 -13
  61. package/src/components/loading-states/__tests__/ComposeLoadingState.test.tsx +0 -37
  62. package/src/components/loading-states/__tests__/ResourceLoadingState.test.tsx +0 -31
  63. package/src/components/modals/ComposeStep.tsx +0 -245
  64. package/src/components/modals/ConfigureGatherStep.tsx +0 -110
  65. package/src/components/modals/ConfigureGenerationStep.tsx +0 -458
  66. package/src/components/modals/ConfigureSearchStep.tsx +0 -124
  67. package/src/components/modals/ContextSummary.tsx +0 -317
  68. package/src/components/modals/CorpusPane.tsx +0 -96
  69. package/src/components/modals/DiscardPrompt.tsx +0 -44
  70. package/src/components/modals/GatherContextStep.tsx +0 -480
  71. package/src/components/modals/KbIdentityConflictModal.tsx +0 -122
  72. package/src/components/modals/KeyboardShortcutsHelpModal.tsx +0 -238
  73. package/src/components/modals/PermissionDeniedModal.tsx +0 -207
  74. package/src/components/modals/ReferenceWizardModal.tsx +0 -656
  75. package/src/components/modals/ResourceGenerateModal.tsx +0 -457
  76. package/src/components/modals/SearchModal.tsx +0 -334
  77. package/src/components/modals/SearchResultsStep.tsx +0 -117
  78. package/src/components/modals/SessionEndedModal.tsx +0 -148
  79. package/src/components/modals/WizardFooter.tsx +0 -72
  80. package/src/components/modals/__tests__/ComposeStep.test.tsx +0 -187
  81. package/src/components/modals/__tests__/ConfigureGatherStep.test.tsx +0 -92
  82. package/src/components/modals/__tests__/ConfigureGenerationStep.test.tsx +0 -574
  83. package/src/components/modals/__tests__/ConfigureSearchStep.test.tsx +0 -124
  84. package/src/components/modals/__tests__/GatherContextStep.resource.test.tsx +0 -702
  85. package/src/components/modals/__tests__/KbIdentityConflictModal.test.tsx +0 -102
  86. package/src/components/modals/__tests__/KeyboardShortcutsHelpModal.test.tsx +0 -115
  87. package/src/components/modals/__tests__/PermissionDeniedModal.test.tsx +0 -218
  88. package/src/components/modals/__tests__/ReferenceWizardModal.test.tsx +0 -936
  89. package/src/components/modals/__tests__/ResourceGenerateModal.test.tsx +0 -532
  90. package/src/components/modals/__tests__/SearchModal.accessibility.test.tsx +0 -95
  91. package/src/components/modals/__tests__/SearchModal.basic.test.tsx +0 -84
  92. package/src/components/modals/__tests__/SearchModal.keyboard.test.tsx +0 -162
  93. package/src/components/modals/__tests__/SearchModal.search-wiring.test.tsx +0 -237
  94. package/src/components/modals/__tests__/SearchModal.translations.test.tsx +0 -91
  95. package/src/components/modals/__tests__/SearchResultsStep.test.tsx +0 -95
  96. package/src/components/modals/__tests__/SessionEndedModal.test.tsx +0 -171
  97. package/src/components/modals/__tests__/WizardFooter.test.tsx +0 -446
  98. package/src/components/modals/__tests__/search-modal-harness.ts +0 -82
  99. package/src/components/navigation/CollapsibleResourceNavigation.tsx +0 -364
  100. package/src/components/navigation/NavigationMenu.tsx +0 -66
  101. package/src/components/navigation/ObservableLink.tsx +0 -90
  102. package/src/components/navigation/SimpleNavigation.tsx +0 -169
  103. package/src/components/navigation/SortableResourceTab.tsx +0 -122
  104. package/src/components/navigation/__tests__/NavigationMenu.a11y.test.tsx +0 -302
  105. package/src/components/navigation/__tests__/NavigationMenu.test.tsx +0 -399
  106. package/src/components/navigation/__tests__/ObservableLink.test.tsx +0 -85
  107. package/src/components/navigation/__tests__/SimpleNavigation.test.tsx +0 -193
  108. package/src/components/navigation/__tests__/SortableResourceTab.test.tsx +0 -421
  109. package/src/components/pdf-annotation/PdfAnnotationCanvas.client.tsx +0 -10
  110. package/src/components/pdf-annotation/PdfAnnotationCanvas.tsx +0 -632
  111. package/src/components/pdf-annotation/PdfPageView.tsx +0 -527
  112. package/src/components/pdf-annotation/__tests__/PdfAnnotationCanvas.annotate-gate.test.tsx +0 -295
  113. package/src/components/pdf-annotation/__tests__/PdfAnnotationCanvas.pixels-before-anchoring.test.tsx +0 -166
  114. package/src/components/pdf-annotation/__tests__/PdfAnnotationCanvas.test.tsx +0 -1719
  115. package/src/components/pdf-annotation/__tests__/estimate-slot-height.test.ts +0 -61
  116. package/src/components/pdf-annotation/__tests__/rects-for-page.test.ts +0 -110
  117. package/src/components/pdf-annotation/estimate-slot-height.ts +0 -31
  118. package/src/components/pdf-annotation/rects-for-page.ts +0 -50
  119. package/src/components/resource/AnnotateView.tsx +0 -373
  120. package/src/components/resource/AnnotationHistory.tsx +0 -169
  121. package/src/components/resource/BrowseView.tsx +0 -440
  122. package/src/components/resource/DownloadFileLink.tsx +0 -53
  123. package/src/components/resource/HistoryEvent.tsx +0 -186
  124. package/src/components/resource/ResourceViewer.tsx +0 -617
  125. package/src/components/resource/__tests__/AnnotateView.code-point-offsets.test.tsx +0 -482
  126. package/src/components/resource/__tests__/AnnotateView.embeddable.test.tsx +0 -78
  127. package/src/components/resource/__tests__/AnnotateView.focus.test.tsx +0 -147
  128. package/src/components/resource/__tests__/AnnotateView.registry.test.tsx +0 -143
  129. package/src/components/resource/__tests__/AnnotationHistory.test.tsx +0 -257
  130. package/src/components/resource/__tests__/BrowseView.code-point-offsets.test.tsx +0 -123
  131. package/src/components/resource/__tests__/BrowseView.embeddable.test.tsx +0 -76
  132. package/src/components/resource/__tests__/BrowseView.links.test.tsx +0 -84
  133. package/src/components/resource/__tests__/BrowseView.overlay-async.test.tsx +0 -165
  134. package/src/components/resource/__tests__/BrowseView.reference-hover.test.tsx +0 -200
  135. package/src/components/resource/__tests__/BrowseView.registry.test.tsx +0 -57
  136. package/src/components/resource/__tests__/BrowseView.test.tsx +0 -915
  137. package/src/components/resource/__tests__/HistoryEvent.test.tsx +0 -571
  138. package/src/components/resource/__tests__/ResourceViewer.delete-failure.test.tsx +0 -103
  139. package/src/components/resource/__tests__/ResourceViewer.embeddable.test.tsx +0 -250
  140. package/src/components/resource/__tests__/ResourceViewer.mode-switch.test.tsx +0 -262
  141. package/src/components/resource/__tests__/ResourceViewer.multi-mount-invalidation.test.tsx +0 -166
  142. package/src/components/resource/__tests__/ResourceViewer.registry.test.tsx +0 -112
  143. package/src/components/resource/__tests__/ResourceViewer.toolbar-opt-out.test.tsx +0 -207
  144. package/src/components/resource/__tests__/ResourceViewer.toolbar-prefs.test.tsx +0 -274
  145. package/src/components/resource/__tests__/annotation-interactions.test.tsx +0 -116
  146. package/src/components/resource/__tests__/browse-renderers.dispatch.test.tsx +0 -183
  147. package/src/components/resource/__tests__/browse-renderers.test.tsx +0 -47
  148. package/src/components/resource/__tests__/download-link.test.tsx +0 -171
  149. package/src/components/resource/__tests__/event-formatting.test.ts +0 -379
  150. package/src/components/resource/__tests__/inline-embedding.test.tsx +0 -133
  151. package/src/components/resource/__tests__/media-completeness.test.tsx +0 -144
  152. package/src/components/resource/annotate-renderers.tsx +0 -186
  153. package/src/components/resource/browse-renderers.tsx +0 -133
  154. package/src/components/resource/event-formatting.ts +0 -393
  155. package/src/components/resource/panels/AssessmentEntry.tsx +0 -127
  156. package/src/components/resource/panels/AssessmentPanel.tsx +0 -309
  157. package/src/components/resource/panels/CollaborationPanel.tsx +0 -228
  158. package/src/components/resource/panels/CommentEntry.tsx +0 -242
  159. package/src/components/resource/panels/CommentsPanel.tsx +0 -320
  160. package/src/components/resource/panels/DelegateSection.tsx +0 -282
  161. package/src/components/resource/panels/DelegateShell.tsx +0 -134
  162. package/src/components/resource/panels/HighlightEntry.tsx +0 -83
  163. package/src/components/resource/panels/HighlightPanel.tsx +0 -212
  164. package/src/components/resource/panels/JsonLdPanel.tsx +0 -119
  165. package/src/components/resource/panels/PanelHeader.tsx +0 -22
  166. package/src/components/resource/panels/ReferenceEntry.tsx +0 -232
  167. package/src/components/resource/panels/ReferencesPanel.tsx +0 -626
  168. package/src/components/resource/panels/ResourceInfoPanel.tsx +0 -433
  169. package/src/components/resource/panels/StatisticsPanel.tsx +0 -145
  170. package/src/components/resource/panels/TagEntry.tsx +0 -87
  171. package/src/components/resource/panels/TaggingPanel.tsx +0 -554
  172. package/src/components/resource/panels/UnifiedAnnotationsPanel.tsx +0 -384
  173. package/src/components/resource/panels/__tests__/AssessmentEntry.test.tsx +0 -292
  174. package/src/components/resource/panels/__tests__/AssessmentPanel.test.tsx +0 -685
  175. package/src/components/resource/panels/__tests__/CollaborationPanel.test.tsx +0 -685
  176. package/src/components/resource/panels/__tests__/CommentEntry.test.tsx +0 -750
  177. package/src/components/resource/panels/__tests__/CommentsPanel.test.tsx +0 -877
  178. package/src/components/resource/panels/__tests__/DelegateSection.test.tsx +0 -623
  179. package/src/components/resource/panels/__tests__/DelegateShell.test.tsx +0 -212
  180. package/src/components/resource/panels/__tests__/HighlightEntry.test.tsx +0 -236
  181. package/src/components/resource/panels/__tests__/HighlightPanel.annotationProgress.test.tsx +0 -506
  182. package/src/components/resource/panels/__tests__/HighlightPanel.out-of-order.test.tsx +0 -132
  183. package/src/components/resource/panels/__tests__/JsonLdPanel.test.tsx +0 -230
  184. package/src/components/resource/panels/__tests__/PanelHeader.test.tsx +0 -54
  185. package/src/components/resource/panels/__tests__/ReferenceEntry.test.tsx +0 -578
  186. package/src/components/resource/panels/__tests__/ReferencesPanel.headless.test.tsx +0 -193
  187. package/src/components/resource/panels/__tests__/ReferencesPanel.observable-flow.test.tsx +0 -193
  188. package/src/components/resource/panels/__tests__/ReferencesPanel.test.tsx +0 -1080
  189. package/src/components/resource/panels/__tests__/ResourceInfoPanel.test.tsx +0 -812
  190. package/src/components/resource/panels/__tests__/ResourceInfoPanel.text-layer.test.tsx +0 -106
  191. package/src/components/resource/panels/__tests__/StatisticsPanel.test.tsx +0 -329
  192. package/src/components/resource/panels/__tests__/TagEntry.test.tsx +0 -250
  193. package/src/components/resource/panels/__tests__/TaggingPanel.test.tsx +0 -772
  194. package/src/components/resource/panels/__tests__/UnifiedAnnotationsPanel.delegated-job.test.tsx +0 -207
  195. package/src/components/resource/panels/__tests__/UnifiedAnnotationsPanel.failure.test.tsx +0 -89
  196. package/src/components/resource/panels/__tests__/agent-label.test.ts +0 -136
  197. package/src/components/resource/panels/agent-label.ts +0 -35
  198. package/src/components/settings/SettingsPanel.tsx +0 -251
  199. package/src/components/settings/__tests__/SettingsPanel.test.tsx +0 -260
  200. package/src/components/viewers/ImageViewer.tsx +0 -18
  201. package/src/components/viewers/__tests__/ImageViewer.test.tsx +0 -57
  202. package/src/components/viewers/index.ts +0 -1
  203. package/src/features/auth/__tests__/AuthErrorDisplay.test.tsx +0 -181
  204. package/src/features/auth/components/AuthErrorDisplay.tsx +0 -89
  205. package/src/features/moderate-entity-tags/__tests__/EntityTagsPage.test.tsx +0 -387
  206. package/src/features/moderate-entity-tags/components/EntityTagsPage.tsx +0 -161
  207. package/src/features/moderate-entity-tags/state/__tests__/entity-tags-state-unit.test.ts +0 -183
  208. package/src/features/moderate-entity-tags/state/entity-tags-state-unit.ts +0 -73
  209. package/src/features/moderate-recent/__tests__/RecentDocumentsPage.test.tsx +0 -422
  210. package/src/features/moderate-recent/components/RecentDocumentsPage.tsx +0 -117
  211. package/src/features/moderate-tag-schemas/__tests__/TagSchemasPage.test.tsx +0 -481
  212. package/src/features/moderate-tag-schemas/components/TagSchemasPage.tsx +0 -161
  213. package/src/features/resource-compose/__tests__/ResourceComposePage.test.tsx +0 -600
  214. package/src/features/resource-compose/__tests__/UploadProgressBar.test.tsx +0 -256
  215. package/src/features/resource-compose/components/ResourceComposePage.tsx +0 -809
  216. package/src/features/resource-compose/components/UploadProgressBar.tsx +0 -125
  217. package/src/features/resource-compose/state/__tests__/compose-page-state-unit.test.ts +0 -195
  218. package/src/features/resource-compose/state/compose-page-state-unit.ts +0 -187
  219. package/src/features/resource-discovery/__tests__/ResourceCard.test.tsx +0 -338
  220. package/src/features/resource-discovery/__tests__/ResourceDiscoveryPage.test.tsx +0 -449
  221. package/src/features/resource-discovery/components/ResourceCard.tsx +0 -80
  222. package/src/features/resource-discovery/components/ResourceDiscoveryPage.tsx +0 -330
  223. package/src/features/resource-discovery/state/__tests__/discover-state-unit.test.ts +0 -477
  224. package/src/features/resource-discovery/state/discover-state-unit.ts +0 -162
  225. package/src/features/resource-viewer/__tests__/ResourceViewerPage.content-loading.test.tsx +0 -260
  226. package/src/features/resource-viewer/__tests__/ResourceViewerPage.test.tsx +0 -570
  227. package/src/features/resource-viewer/__tests__/generation-params.test.ts +0 -49
  228. package/src/features/resource-viewer/components/ResourceViewerPage.tsx +0 -1058
  229. package/src/features/resource-viewer/generation-params.ts +0 -23
  230. package/src/features/resource-viewer/hooks/__tests__/useResourceViewedReport.test.tsx +0 -77
  231. package/src/features/resource-viewer/hooks/useResourceViewedReport.ts +0 -38
  232. package/src/features/resource-viewer/state/__tests__/resource-loader-state-unit.test.ts +0 -178
  233. package/src/features/resource-viewer/state/__tests__/resource-viewer-page-state-unit.test.ts +0 -505
  234. package/src/features/resource-viewer/state/resource-loader-state-unit.ts +0 -93
  235. package/src/features/resource-viewer/state/resource-viewer-page-state-unit.ts +0 -156
@@ -1,1080 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
2
- import React from 'react';
3
- import { render, screen, within } from '@testing-library/react';
4
- import userEvent from '@testing-library/user-event';
5
- import '@testing-library/jest-dom';
6
- import { ReferencesPanel } from '../ReferencesPanel';
7
- import type {
8
- Annotation,
9
- AnnotationId,
10
- EventBus,
11
- EventMap,
12
- } from '@xynolog/core';
13
- import type {
14
- LinkComponentProps,
15
- RouteBuilder,
16
- } from '../../../../contexts/RoutingContext';
17
- import {
18
- createMarkStateUnit,
19
- type MarkStateUnit,
20
- type XynologSession,
21
- } from '@xynolog/sdk';
22
- import { createTestXynologWrapper } from '../../../../test-utils';
23
- import { FrameRefusal, jobId, resourceId } from '@xynolog/core';
24
-
25
- // Composition-based event tracker
26
- interface TrackedEvent {
27
- event: string;
28
- payload: EventMap['mark:submit'];
29
- }
30
-
31
- function createEventTracker() {
32
- const events: TrackedEvent[] = [];
33
- return {
34
- events,
35
- clear: () => {
36
- events.length = 0;
37
- },
38
- _attach(eventBus: EventBus) {
39
- const panelEvents = ['mark:submit'] as const;
40
- panelEvents.forEach((eventName) => {
41
- eventBus.on(eventName).subscribe((payload) => {
42
- // Nothing bridges into this test's bus: a refusal on it is the test's own fault.
43
- if (payload instanceof FrameRefusal)
44
- throw new Error(
45
- `refused: ${payload.channel} ${payload.reason} ${payload.member}`,
46
- );
47
- events.push({ event: eventName, payload });
48
- });
49
- });
50
- },
51
- };
52
- }
53
-
54
- // Per-test session/wrapper: created in beforeEach — test-utils disposes every
55
- // created client in a module-scope afterEach, so a module-scope factory call
56
- // would hand tests after the first a disposed client. The component is
57
- // provider-free: the `session` passed as a prop (same factory call as the
58
- // eventBus the tracker attaches to) is the only session it sees.
59
- let session: XynologSession;
60
- let mark: MarkStateUnit;
61
- let eventBus: EventBus;
62
- let XynologWrapper: React.ComponentType<{ children: React.ReactNode }>;
63
-
64
- beforeEach(() => {
65
- ({ session, eventBus, XynologWrapper } = createTestXynologWrapper());
66
- mark = createMarkStateUnit(session.client, resourceId('res-1'));
67
- });
68
-
69
- const renderWithEventBus = (
70
- component: React.ReactElement,
71
- tracker?: ReturnType<typeof createEventTracker>,
72
- ) => {
73
- if (tracker) tracker._attach(eventBus);
74
- const Wrapper = ({ children }: { children: React.ReactNode }) => (
75
- <XynologWrapper>{children}</XynologWrapper>
76
- );
77
- return render(component, { wrapper: Wrapper });
78
- };
79
-
80
- // Mock TranslationContext
81
- vi.mock('../../../../contexts/TranslationContext', () => ({
82
- useTranslations: vi.fn(
83
- () => (key: string, params?: Record<string, unknown>) => {
84
- const translations: Record<string, string> = {
85
- annotateReferences: 'Annotate References',
86
- selectEntityTypes: 'Select entity types',
87
- noEntityTypes: 'No entity types available',
88
- select: 'Select',
89
- deselect: 'Deselect',
90
- typesSelected: '{count} type(s) selected',
91
- annotate: 'Annotate',
92
- found: 'Found {count}',
93
- includeDescriptiveReferences: 'Include descriptive references',
94
- descriptiveReferencesTooltip:
95
- "Also find phrases like 'the CEO', 'the tech giant', 'the physicist' (in addition to names)",
96
- cancel: 'Cancel',
97
- createReference: 'Create Reference',
98
- annotating: 'Annotating...',
99
- // The widget's own strings come from the
100
- // DelegateProgress namespace, not from this panel's.
101
- inProgress: 'Annotating...',
102
- complete: 'Annotation complete!',
103
- failed: 'Annotation failed',
104
- };
105
- let result = translations[key] || key;
106
- // Replace {count} with actual count value if provided
107
- if (params?.count !== undefined) {
108
- result = result.replace('{count}', String(params.count));
109
- }
110
- return result;
111
- },
112
- ),
113
- TranslationProvider: ({ children }: { children: React.ReactNode }) =>
114
- children,
115
- }));
116
-
117
- describe('ReferencesPanel Component', () => {
118
- // Mock Link component
119
- const MockLink = ({ href, children, ...props }: LinkComponentProps) => (
120
- <a href={href} {...props}>
121
- {children}
122
- </a>
123
- );
124
-
125
- // Mock routes
126
- const mockRoutes: RouteBuilder = {
127
- resourceDetail: (id: string) => `/resources/${id}`,
128
- };
129
-
130
- const defaultProps = {
131
- resourceId: resourceId('res-1'),
132
- allEntityTypes: ['Person', 'Organization', 'Location', 'Date'],
133
- isDelegating: false,
134
- progress: null,
135
- jobId: null,
136
- cancelled: false,
137
- annotateMode: true,
138
- Link: MockLink,
139
- routes: mockRoutes,
140
- pendingAnnotation: null,
141
- };
142
-
143
- // Per-test props: merges the beforeEach-created session at render time.
144
- // (Module/describe-scope defaultProps must stay session-free — disposal
145
- // hazard, see note above renderWithEventBus.)
146
- const panelProps = () => ({ ...defaultProps, session, mark });
147
-
148
- beforeEach(() => {
149
- vi.clearAllMocks();
150
- });
151
-
152
- afterEach(() => {
153
- vi.restoreAllMocks();
154
- mark.dispose();
155
- });
156
-
157
- // The panel threads the host's sparkle set down to
158
- // the entries — exactly the ids in the set glow, nothing else.
159
- describe('Resolution sparkle threading', () => {
160
- const linkingReference = (id: string): Annotation => ({
161
- '@context': 'http://www.w3.org/ns/anno.jsonld',
162
- id: id as AnnotationId,
163
- type: 'Annotation',
164
- motivation: 'linking',
165
- created: '2026-08-21T12:00:00Z',
166
- modified: '2026-08-21T12:00:00Z',
167
- target: {
168
- source: resourceId('res-1'),
169
- selector: { type: 'TextQuoteSelector', exact: `text of ${id}` },
170
- },
171
- body: {
172
- type: 'SpecificResource',
173
- source: resourceId('linked-doc'),
174
- purpose: 'linking',
175
- },
176
- });
177
-
178
- it('sparkles exactly the entries named by sparkleAnnotationIds', () => {
179
- const { container } = renderWithEventBus(
180
- <ReferencesPanel
181
- {...panelProps()}
182
- annotations={[
183
- linkingReference('ann-dark'),
184
- linkingReference('ann-lit'),
185
- ]}
186
- sparkleAnnotationIds={new Set(['ann-lit'])}
187
- />,
188
- );
189
-
190
- const sparkling = container.querySelectorAll(
191
- '.xynolog-reference-icon.annotation-sparkle',
192
- );
193
- expect(sparkling).toHaveLength(1);
194
- expect(
195
- sparkling[0]!.closest('.xynolog-annotation-entry'),
196
- ).toHaveTextContent('text of ann-lit');
197
- });
198
- });
199
-
200
- describe('Rendering', () => {
201
- it('should render panel with title', () => {
202
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
203
-
204
- expect(screen.getByText('Annotate References')).toBeInTheDocument();
205
- });
206
-
207
- it('should render all entity type buttons', () => {
208
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
209
-
210
- expect(screen.getByText('Person')).toBeInTheDocument();
211
- expect(screen.getByText('Organization')).toBeInTheDocument();
212
- expect(screen.getByText('Location')).toBeInTheDocument();
213
- expect(screen.getByText('Date')).toBeInTheDocument();
214
- });
215
-
216
- it('should show message when no entity types available', () => {
217
- renderWithEventBus(
218
- <ReferencesPanel {...panelProps()} allEntityTypes={[]} />,
219
- );
220
-
221
- expect(screen.getByText('No entity types available')).toBeInTheDocument();
222
- });
223
-
224
- it('should render start detection button', () => {
225
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
226
-
227
- expect(screen.getByTitle('Annotate')).toBeInTheDocument();
228
- });
229
- });
230
-
231
- // Entity types are optional on a reference, but `MarkSubmitEvent.body` is
232
- // `minItems: 1` — so "no types selected" must OMIT body, not send `[]`.
233
- // Sending `[]` 400s at /bus/emit, and `mark.submit` is fire-and-forget, so
234
- // the failure is silent: the button looks inert.
235
- describe('Create Reference payload', () => {
236
- const pendingLinking = {
237
- motivation: 'linking' as const,
238
- selector: { type: 'TextQuoteSelector' as const, exact: 'thylakoid' },
239
- };
240
-
241
- const submitPayloads = (tracker: ReturnType<typeof createEventTracker>) =>
242
- tracker.events
243
- .filter((e) => e.event === 'mark:submit')
244
- .map((e) => e.payload);
245
-
246
- // The panel's own entity-type chips, not DelegateSection's identically
247
- // labelled ones.
248
- const renderPrompt = (tracker: ReturnType<typeof createEventTracker>) => {
249
- const { container } = renderWithEventBus(
250
- <ReferencesPanel
251
- {...panelProps()}
252
- pendingAnnotation={pendingLinking}
253
- />,
254
- tracker,
255
- );
256
- return within(
257
- container.querySelector('.xynolog-annotation-prompt') as HTMLElement,
258
- );
259
- };
260
-
261
- it('omits body entirely when no entity type is selected', async () => {
262
- const tracker = createEventTracker();
263
- const prompt = renderPrompt(tracker);
264
-
265
- await userEvent.click(
266
- prompt.getByRole('button', { name: /create reference/i }),
267
- );
268
-
269
- const [payload] = submitPayloads(tracker);
270
- expect(payload).toBeDefined();
271
- expect(payload).not.toHaveProperty('body');
272
- });
273
-
274
- it('sends a one-item body when an entity type is selected', async () => {
275
- const tracker = createEventTracker();
276
- const prompt = renderPrompt(tracker);
277
-
278
- await userEvent.click(prompt.getByRole('button', { name: 'Person' }));
279
- await userEvent.click(
280
- prompt.getByRole('button', { name: /create reference/i }),
281
- );
282
-
283
- const [payload] = submitPayloads(tracker);
284
- expect(payload.body).toEqual([
285
- { type: 'TextualBody', value: 'Person', purpose: 'tagging' },
286
- ]);
287
- });
288
- });
289
-
290
- describe('Entity Type Selection', () => {
291
- it('should toggle entity type selection on click', async () => {
292
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
293
-
294
- const personButton = screen.getByText('Person');
295
-
296
- // Initially not selected
297
- expect(personButton).toHaveAttribute('aria-pressed', 'false');
298
-
299
- // Click to select
300
- await userEvent.click(personButton);
301
-
302
- expect(personButton).toHaveAttribute('aria-pressed', 'true');
303
-
304
- // Click again to deselect
305
- await userEvent.click(personButton);
306
-
307
- expect(personButton).toHaveAttribute('aria-pressed', 'false');
308
- });
309
-
310
- it('should allow multiple selections', async () => {
311
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
312
-
313
- const personButton = screen.getByText('Person');
314
- const orgButton = screen.getByText('Organization');
315
- const locationButton = screen.getByText('Location');
316
-
317
- await userEvent.click(personButton);
318
- await userEvent.click(orgButton);
319
- await userEvent.click(locationButton);
320
-
321
- expect(personButton).toHaveAttribute('aria-pressed', 'true');
322
- expect(orgButton).toHaveAttribute('aria-pressed', 'true');
323
- expect(locationButton).toHaveAttribute('aria-pressed', 'true');
324
- });
325
-
326
- it('should deselect when clicking selected type', async () => {
327
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
328
-
329
- const personButton = screen.getByText('Person');
330
-
331
- await userEvent.click(personButton);
332
- expect(personButton).toHaveAttribute('aria-pressed', 'true');
333
-
334
- await userEvent.click(personButton);
335
- expect(personButton).toHaveAttribute('aria-pressed', 'false');
336
- });
337
-
338
- it('should show selected count', async () => {
339
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
340
-
341
- const personButton = screen.getByText('Person');
342
- const orgButton = screen.getByText('Organization');
343
-
344
- await userEvent.click(personButton);
345
-
346
- // Should show count
347
- expect(screen.getByText(/selected/i)).toBeInTheDocument();
348
-
349
- await userEvent.click(orgButton);
350
-
351
- // Should update count
352
- expect(screen.getByText(/selected/i)).toBeInTheDocument();
353
- });
354
-
355
- it('should not show selected count when none selected', () => {
356
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
357
-
358
- expect(screen.queryByText(/selected/i)).not.toBeInTheDocument();
359
- });
360
- });
361
-
362
- describe('Button Styling', () => {
363
- it('should style selected buttons differently', async () => {
364
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
365
-
366
- const personButton = screen.getByText('Person');
367
-
368
- // Before selection
369
- expect(personButton).toHaveClass(
370
- 'xynolog-chip',
371
- 'xynolog-chip--selectable',
372
- );
373
- expect(personButton).toHaveAttribute('data-selected', 'false');
374
-
375
- await userEvent.click(personButton);
376
-
377
- // After selection
378
- expect(personButton).toHaveAttribute('data-selected', 'true');
379
- });
380
-
381
- it('should have proper ARIA attributes', () => {
382
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
383
-
384
- const personButton = screen.getByText('Person');
385
-
386
- expect(personButton).toHaveAttribute('aria-pressed');
387
- expect(personButton).toHaveAttribute('aria-label');
388
- });
389
-
390
- it('should have focus styles', () => {
391
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
392
-
393
- const personButton = screen.getByText('Person');
394
-
395
- expect(personButton).toHaveClass(
396
- 'xynolog-chip',
397
- 'xynolog-chip--selectable',
398
- );
399
- });
400
- });
401
-
402
- describe('Start Annotate Button', () => {
403
- it('should be disabled when no types selected', () => {
404
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
405
-
406
- const startButton = screen.getByTitle('Annotate');
407
-
408
- expect(startButton).toBeDisabled();
409
- });
410
-
411
- it('should be enabled when types are selected', async () => {
412
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
413
-
414
- const personButton = screen.getByText('Person');
415
- await userEvent.click(personButton);
416
-
417
- const startButton = screen.getByTitle('Annotate');
418
-
419
- expect(startButton).not.toBeDisabled();
420
- });
421
-
422
- it('asks the mark unit to delegate a linking job of the chosen types, descriptive references left out', async () => {
423
- const requestDelegate = vi
424
- .spyOn(mark, 'requestDelegate')
425
- .mockImplementation(() => {});
426
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
427
-
428
- await userEvent.click(screen.getByText('Person'));
429
- await userEvent.click(screen.getByText('Organization'));
430
-
431
- const startButton = screen.getByTitle('Annotate');
432
- await userEvent.click(startButton);
433
-
434
- expect(requestDelegate).toHaveBeenCalledExactlyOnceWith(
435
- expect.objectContaining({
436
- motivation: 'linking',
437
- entityTypes: ['Person', 'Organization'],
438
- includeDescriptiveReferences: false,
439
- }),
440
- );
441
- });
442
-
443
- it('delegates with descriptive references included when the box is checked', async () => {
444
- const requestDelegate = vi
445
- .spyOn(mark, 'requestDelegate')
446
- .mockImplementation(() => {});
447
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
448
-
449
- await userEvent.click(screen.getByText('Person'));
450
-
451
- // Check the "Include descriptive references" checkbox
452
- const checkboxLabel = screen.getByText('Include descriptive references');
453
- const checkbox = checkboxLabel.previousElementSibling as HTMLInputElement;
454
- await userEvent.click(checkbox);
455
-
456
- const startButton = screen.getByTitle('Annotate');
457
- await userEvent.click(startButton);
458
-
459
- expect(requestDelegate).toHaveBeenCalledExactlyOnceWith(
460
- expect.objectContaining({
461
- motivation: 'linking',
462
- entityTypes: ['Person'],
463
- includeDescriptiveReferences: true,
464
- }),
465
- );
466
- });
467
-
468
- it('the control of a running job asks for that job to be cancelled, by its id', async () => {
469
- const cancelSpy = vi
470
- .spyOn(session.client.job, 'cancel')
471
- .mockResolvedValue(true);
472
- renderWithEventBus(
473
- <ReferencesPanel
474
- {...panelProps()}
475
- isDelegating={true}
476
- jobId={jobId('job-1')}
477
- progress={{ percentage: 0, completedItems: [] }}
478
- />,
479
- );
480
-
481
- await userEvent.click(screen.getByTestId('xynolog-delegate-control'));
482
- expect(cancelSpy).toHaveBeenCalledExactlyOnceWith('job-1');
483
- });
484
-
485
- it('a running job the queue has not named yet has no cancel control', () => {
486
- renderWithEventBus(
487
- <ReferencesPanel
488
- {...panelProps()}
489
- isDelegating={true}
490
- jobId={null}
491
- cancelled={false}
492
- progress={{ percentage: 0, completedItems: [] }}
493
- />,
494
- );
495
-
496
- expect(screen.queryByTestId('xynolog-delegate-control')).toBeNull();
497
- });
498
-
499
- it('shows how many of the priced entities a running job has found', () => {
500
- // The wire prices the denominator; the panel's own copy words it. The
501
- // count goes through the same translations the panel builds for its
502
- // display, so it fails here if they drop it on the way.
503
- renderWithEventBus(
504
- <ReferencesPanel
505
- {...panelProps()}
506
- isDelegating={true}
507
- progress={{ percentage: 40, entitiesFound: 3, entitiesExpected: 10 }}
508
- />,
509
- );
510
-
511
- expect(screen.getByTestId('xynolog-delegate-tally')).toBeInTheDocument();
512
- });
513
-
514
- it('should clear selected types after detection starts', async () => {
515
- const { rerender } = renderWithEventBus(
516
- <ReferencesPanel {...panelProps()} />,
517
- );
518
-
519
- await userEvent.click(screen.getByText('Person'));
520
-
521
- const startButton = screen.getByTitle('Annotate');
522
- await userEvent.click(startButton);
523
-
524
- // Simulate detection starting
525
- rerender(
526
- <ReferencesPanel
527
- {...panelProps()}
528
- isDelegating={true}
529
- progress={{ percentage: 0, completedItems: [] }}
530
- />,
531
- );
532
-
533
- // Simulate detection completing
534
- rerender(
535
- <ReferencesPanel
536
- {...panelProps()}
537
- isDelegating={false}
538
- progress={{
539
- percentage: 100,
540
- completedItems: [{ value: 'Person', foundCount: 5 }],
541
- }}
542
- />,
543
- );
544
-
545
- // UI should reset but we can't directly test internal state
546
- // We can test that buttons are back to unselected state after going through full cycle
547
- });
548
-
549
- it('should have proper styling when disabled', () => {
550
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
551
-
552
- const startButton = screen.getByTitle('Annotate');
553
-
554
- expect(startButton).toHaveClass('xynolog-button');
555
- expect(startButton).toHaveAttribute('data-variant', 'delegate');
556
- expect(startButton).toHaveAttribute('data-type', 'reference');
557
- expect(startButton).toBeDisabled();
558
- });
559
-
560
- it('should have proper styling when enabled', async () => {
561
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
562
-
563
- await userEvent.click(screen.getByText('Person'));
564
-
565
- const startButton = screen.getByTitle('Annotate');
566
-
567
- expect(startButton).toHaveClass('xynolog-button');
568
- expect(startButton).toHaveAttribute('data-variant', 'delegate');
569
- expect(startButton).toHaveAttribute('data-type', 'reference');
570
- expect(startButton).not.toBeDisabled();
571
- });
572
- });
573
-
574
- describe('Detection Progress', () => {
575
- it('should show progress widget when detecting', () => {
576
- renderWithEventBus(
577
- <ReferencesPanel
578
- {...panelProps()}
579
- isDelegating={true}
580
- progress={{ percentage: 0, completedItems: [] }}
581
- />,
582
- );
583
-
584
- expect(screen.getByText('Annotating...')).toBeInTheDocument();
585
- });
586
-
587
- it('should pass progress data to widget', () => {
588
- const progress = {
589
- percentage: 100,
590
- completedItems: [
591
- { value: 'Person', foundCount: 5 },
592
- { value: 'Organization', foundCount: 3 },
593
- ],
594
- };
595
-
596
- renderWithEventBus(
597
- <ReferencesPanel
598
- {...panelProps()}
599
- isDelegating={true}
600
- progress={progress}
601
- />,
602
- );
603
-
604
- // Real DelegateProgress renders the completed entity-type log.
605
- expect(screen.getByText('Person:')).toBeInTheDocument();
606
- expect(screen.getByText('Organization:')).toBeInTheDocument();
607
- });
608
-
609
- it('renders the entity log with the SAME markup the progress display uses', () => {
610
- // This form-side log and DelegateProgress's completed-entity log are the
611
- // same concept, so both use the xynolog-annotation-log* classes and
612
- // neither has a xynolog-delegate-widget__log* family of its own — one
613
- // concept, one markup.
614
- const { container, rerender } = renderWithEventBus(
615
- <ReferencesPanel
616
- {...panelProps()}
617
- isDelegating={false}
618
- progress={{
619
- percentage: 100,
620
- completedItems: [{ value: 'Person', foundCount: 5 }],
621
- }}
622
- />,
623
- );
624
- rerender(
625
- <ReferencesPanel
626
- {...panelProps()}
627
- isDelegating={false}
628
- progress={null}
629
- />,
630
- );
631
-
632
- expect(
633
- container.querySelector('.xynolog-annotation-log'),
634
- ).toBeInTheDocument();
635
- expect(
636
- container.querySelector('.xynolog-annotation-log-item'),
637
- ).toBeInTheDocument();
638
- expect(
639
- container.querySelector('.xynolog-delegate-widget__log'),
640
- ).not.toBeInTheDocument();
641
- });
642
-
643
- it('should hide entity type selection during detection', () => {
644
- renderWithEventBus(
645
- <ReferencesPanel
646
- {...panelProps()}
647
- isDelegating={true}
648
- progress={{ percentage: 0, completedItems: [] }}
649
- />,
650
- );
651
-
652
- expect(screen.queryByText('Select entity types')).not.toBeInTheDocument();
653
- expect(screen.queryByText('Person')).not.toBeInTheDocument();
654
- });
655
-
656
- it('should render cancel button when detecting, once the job has its id', async () => {
657
- renderWithEventBus(
658
- <ReferencesPanel
659
- {...panelProps()}
660
- isDelegating={true}
661
- jobId={jobId('job-1')}
662
- progress={{ percentage: 0, completedItems: [] }}
663
- />,
664
- );
665
-
666
- // The control's label comes from the DelegateProgress namespace's `cancel`.
667
- const cancelButton = screen.getByTitle('Cancel');
668
- expect(cancelButton).toBeInTheDocument();
669
- });
670
- });
671
-
672
- describe('Detection Complete Log', () => {
673
- it('should show completed log after detection finishes', () => {
674
- const { rerender } = renderWithEventBus(
675
- <ReferencesPanel
676
- {...panelProps()}
677
- isDelegating={false}
678
- progress={{
679
- percentage: 100,
680
- completedItems: [
681
- { value: 'Person', foundCount: 5 },
682
- { value: 'Organization', foundCount: 3 },
683
- ],
684
- }}
685
- />,
686
- );
687
-
688
- // Parent clears progress after completion
689
- rerender(
690
- <ReferencesPanel
691
- {...panelProps()}
692
- isDelegating={false}
693
- progress={null}
694
- />,
695
- );
696
-
697
- expect(screen.getByText('Person:')).toBeInTheDocument();
698
- expect(screen.getByText('Organization:')).toBeInTheDocument();
699
- });
700
-
701
- it('should show found counts in log', () => {
702
- const { rerender } = renderWithEventBus(
703
- <ReferencesPanel
704
- {...panelProps()}
705
- isDelegating={false}
706
- progress={{
707
- percentage: 100,
708
- completedItems: [{ value: 'Person', foundCount: 5 }],
709
- }}
710
- />,
711
- );
712
-
713
- rerender(
714
- <ReferencesPanel
715
- {...panelProps()}
716
- isDelegating={false}
717
- progress={null}
718
- />,
719
- );
720
- expect(screen.getByText(/Found.*5/i)).toBeInTheDocument();
721
- });
722
-
723
- it('should show checkmarks for completed types', () => {
724
- const { rerender } = renderWithEventBus(
725
- <ReferencesPanel
726
- {...panelProps()}
727
- isDelegating={false}
728
- progress={{
729
- percentage: 100,
730
- completedItems: [{ value: 'Person', foundCount: 5 }],
731
- }}
732
- />,
733
- );
734
-
735
- rerender(
736
- <ReferencesPanel
737
- {...panelProps()}
738
- isDelegating={false}
739
- progress={null}
740
- />,
741
- );
742
- expect(screen.getByText('✓')).toBeInTheDocument();
743
- });
744
-
745
- it('should show detection log and selection UI together after completion', () => {
746
- const { rerender } = renderWithEventBus(
747
- <ReferencesPanel
748
- {...panelProps()}
749
- isDelegating={false}
750
- progress={{
751
- percentage: 100,
752
- completedItems: [{ value: 'Person', foundCount: 5 }],
753
- }}
754
- />,
755
- );
756
-
757
- rerender(
758
- <ReferencesPanel
759
- {...panelProps()}
760
- isDelegating={false}
761
- progress={null}
762
- />,
763
- );
764
-
765
- // Should show both the completed log AND the selection UI
766
- expect(screen.getByText('Person:')).toBeInTheDocument(); // Log entry
767
- expect(screen.getByText('Select entity types')).toBeInTheDocument(); // Selection UI
768
- });
769
-
770
- it('should show selection UI immediately after detection completes', async () => {
771
- const { rerender } = renderWithEventBus(
772
- <ReferencesPanel
773
- {...panelProps()}
774
- isDelegating={false}
775
- progress={{
776
- percentage: 100,
777
- completedItems: [{ value: 'Person', foundCount: 5 }],
778
- }}
779
- />,
780
- );
781
-
782
- rerender(
783
- <ReferencesPanel
784
- {...panelProps()}
785
- isDelegating={false}
786
- progress={null}
787
- />,
788
- );
789
-
790
- // Selection UI should be immediately available (no button click needed)
791
- expect(screen.getByText('Select entity types')).toBeInTheDocument();
792
- expect(screen.getByText('Person')).toBeInTheDocument(); // Entity type chip
793
- });
794
-
795
- it('should not show log when empty', () => {
796
- renderWithEventBus(
797
- <ReferencesPanel
798
- {...panelProps()}
799
- isDelegating={false}
800
- progress={{
801
- percentage: 100,
802
- completedItems: [],
803
- }}
804
- />,
805
- );
806
-
807
- // Should not show any log items. Terminal progress (dismissable) is
808
- // shown instead of the form — the DelegateShell normalization; the
809
- // form returns once progress clears.
810
- expect(screen.queryByText('✓')).not.toBeInTheDocument();
811
- expect(screen.queryByText('Select entity types')).not.toBeInTheDocument();
812
- });
813
- });
814
-
815
- describe('State Transitions', () => {
816
- it('should transition from idle to detecting', () => {
817
- const { rerender } = renderWithEventBus(
818
- <ReferencesPanel {...panelProps()} />,
819
- );
820
-
821
- // Idle state
822
- expect(screen.getByText('Select entity types')).toBeInTheDocument();
823
-
824
- // Start detecting
825
- rerender(
826
- <ReferencesPanel
827
- {...panelProps()}
828
- isDelegating={true}
829
- progress={{ percentage: 0, completedItems: [] }}
830
- />,
831
- );
832
-
833
- // Detecting state
834
- expect(screen.getByText('Annotating...')).toBeInTheDocument();
835
- expect(screen.queryByText('Select entity types')).not.toBeInTheDocument();
836
- });
837
-
838
- it('should transition from detecting to complete', () => {
839
- const { rerender } = renderWithEventBus(
840
- <ReferencesPanel
841
- {...panelProps()}
842
- isDelegating={true}
843
- progress={{ percentage: 0, completedItems: [] }}
844
- />,
845
- );
846
-
847
- // Detecting
848
- expect(screen.getByText('Annotating...')).toBeInTheDocument();
849
-
850
- // Complete - first trigger useEffect to copy to lastDetectionLog
851
- rerender(
852
- <ReferencesPanel
853
- {...panelProps()}
854
- isDelegating={false}
855
- progress={{
856
- percentage: 100,
857
- completedItems: [{ value: 'Person', foundCount: 5 }],
858
- }}
859
- />,
860
- );
861
-
862
- // Then clear progress to show the log
863
- rerender(
864
- <ReferencesPanel
865
- {...panelProps()}
866
- isDelegating={false}
867
- progress={null}
868
- />,
869
- );
870
-
871
- expect(
872
- screen.queryByText('Annotation complete!'),
873
- ).not.toBeInTheDocument();
874
- // Both log and selection UI should be visible
875
- expect(screen.getByText('Person:')).toBeInTheDocument();
876
- expect(screen.getByText('Select entity types')).toBeInTheDocument();
877
- });
878
-
879
- it('should show selection UI after detection completes', async () => {
880
- const { rerender } = renderWithEventBus(
881
- <ReferencesPanel
882
- {...panelProps()}
883
- isDelegating={false}
884
- progress={{
885
- percentage: 100,
886
- completedItems: [{ value: 'Person', foundCount: 5 }],
887
- }}
888
- />,
889
- );
890
-
891
- // Clear progress to show the log
892
- rerender(
893
- <ReferencesPanel
894
- {...panelProps()}
895
- isDelegating={false}
896
- progress={null}
897
- />,
898
- );
899
-
900
- // Selection UI should be immediately available
901
- expect(screen.getByText('Select entity types')).toBeInTheDocument();
902
-
903
- rerender(<ReferencesPanel {...panelProps()} />);
904
-
905
- expect(screen.getByText('Select entity types')).toBeInTheDocument();
906
- });
907
- });
908
-
909
- describe('Edge Cases', () => {
910
- it('should handle empty entity types array', () => {
911
- expect(() => {
912
- renderWithEventBus(
913
- <ReferencesPanel {...panelProps()} allEntityTypes={[]} />,
914
- );
915
- }).not.toThrow();
916
- });
917
-
918
- it('should handle many entity types', () => {
919
- const manyTypes = Array.from({ length: 50 }, (_, i) => `Type${i}`);
920
-
921
- expect(() => {
922
- renderWithEventBus(
923
- <ReferencesPanel {...panelProps()} allEntityTypes={manyTypes} />,
924
- );
925
- }).not.toThrow();
926
-
927
- expect(screen.getByText('Type0')).toBeInTheDocument();
928
- expect(screen.getByText('Type49')).toBeInTheDocument();
929
- });
930
-
931
- it('should handle entity types with special characters', () => {
932
- const specialTypes = ['Type-A', 'Type_B', 'Type.C', 'Type/D'];
933
-
934
- renderWithEventBus(
935
- <ReferencesPanel {...panelProps()} allEntityTypes={specialTypes} />,
936
- );
937
-
938
- specialTypes.forEach((type) => {
939
- expect(screen.getByText(type)).toBeInTheDocument();
940
- });
941
- });
942
-
943
- it('should handle selecting and deselecting all types', async () => {
944
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
945
-
946
- // Select all
947
- for (const type of defaultProps.allEntityTypes) {
948
- await userEvent.click(screen.getByText(type));
949
- }
950
-
951
- defaultProps.allEntityTypes.forEach((type) => {
952
- expect(screen.getByText(type)).toHaveAttribute('aria-pressed', 'true');
953
- });
954
-
955
- // Deselect all
956
- for (const type of defaultProps.allEntityTypes) {
957
- await userEvent.click(screen.getByText(type));
958
- }
959
-
960
- defaultProps.allEntityTypes.forEach((type) => {
961
- expect(screen.getByText(type)).toHaveAttribute('aria-pressed', 'false');
962
- });
963
- });
964
-
965
- it('should handle rapid selection changes', async () => {
966
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
967
-
968
- const personButton = screen.getByText('Person');
969
-
970
- // Rapid clicks
971
- for (let i = 0; i < 10; i++) {
972
- await userEvent.click(personButton);
973
- }
974
-
975
- // Should be in a consistent state (even number of clicks = not selected)
976
- expect(personButton).toHaveAttribute('aria-pressed', 'false');
977
- });
978
-
979
- it('should handle zero found count in results', () => {
980
- renderWithEventBus(
981
- <ReferencesPanel
982
- {...panelProps()}
983
- isDelegating={false}
984
- progress={{
985
- percentage: 100,
986
- completedItems: [{ value: 'Person', foundCount: 0 }],
987
- }}
988
- />,
989
- );
990
-
991
- expect(screen.getByText(/Found.*0/i)).toBeInTheDocument();
992
- });
993
-
994
- it('should handle undefined progress', () => {
995
- expect(() => {
996
- renderWithEventBus(
997
- <ReferencesPanel
998
- {...panelProps()}
999
- isDelegating={false}
1000
- // @ts-expect-error — progress is JobProgress or null; this holds that undefined does not throw
1001
- progress={undefined}
1002
- />,
1003
- );
1004
- }).not.toThrow();
1005
- });
1006
- });
1007
-
1008
- describe('Styling and Appearance', () => {
1009
- it('should have proper panel structure', () => {
1010
- const { container } = renderWithEventBus(
1011
- <ReferencesPanel {...panelProps()} />,
1012
- );
1013
-
1014
- const panel = container.firstChild as HTMLElement;
1015
- expect(panel).toHaveClass('xynolog-panel');
1016
- });
1017
-
1018
- it('should support dark mode', () => {
1019
- const { container } = renderWithEventBus(
1020
- <ReferencesPanel {...panelProps()} />,
1021
- );
1022
-
1023
- const panel = container.firstChild as HTMLElement;
1024
- expect(panel).toHaveClass('xynolog-panel');
1025
- });
1026
-
1027
- it('should have title without emoji', () => {
1028
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
1029
-
1030
- // The emoji is not in the title (it is only in the tab)
1031
- const title = screen.getByRole('heading', { level: 2 });
1032
- expect(title.textContent).not.toContain('🔵');
1033
- expect(title.textContent).toContain('title');
1034
- });
1035
-
1036
- it('should have proper button layout', () => {
1037
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
1038
-
1039
- const buttonContainer = screen.getByText('Person').parentElement;
1040
- expect(buttonContainer).toHaveClass('xynolog-delegate-widget__chips');
1041
- });
1042
- });
1043
-
1044
- describe('Accessibility', () => {
1045
- it('should have proper ARIA labels for selection', async () => {
1046
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
1047
-
1048
- const personButton = screen.getByText('Person');
1049
-
1050
- expect(personButton).toHaveAttribute('aria-label');
1051
-
1052
- await userEvent.click(personButton);
1053
-
1054
- // Label should update to indicate deselection is possible
1055
- const label = personButton.getAttribute('aria-label');
1056
- expect(label).toBeTruthy();
1057
- });
1058
-
1059
- it('should have proper ARIA pressed states', async () => {
1060
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
1061
-
1062
- const personButton = screen.getByText('Person');
1063
-
1064
- expect(personButton).toHaveAttribute('aria-pressed', 'false');
1065
-
1066
- await userEvent.click(personButton);
1067
-
1068
- expect(personButton).toHaveAttribute('aria-pressed', 'true');
1069
- });
1070
-
1071
- it('should be keyboard navigable', () => {
1072
- renderWithEventBus(<ReferencesPanel {...panelProps()} />);
1073
-
1074
- const personButton = screen.getByText('Person');
1075
- personButton.focus();
1076
-
1077
- expect(personButton).toHaveFocus();
1078
- });
1079
- });
1080
- });