@harvard-lts/mirador-eda-plugin 0.1.2 → 0.1.4
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/es/index.js +23 -34
- package/package.json +5 -4
- package/.github/pull_request_template.md +0 -31
- package/.github/workflows/publish-package.yml +0 -34
- package/.nvmrc +0 -1
- package/.parcelrc +0 -9
- package/.travis.yml +0 -16
- package/CONTRIBUTING.md +0 -20
- package/__mocks__/fileMock.js +0 -1
- package/babel.config.json +0 -11
- package/demo/data/manifest-3037.json +0 -524
- package/demo/data/manifest-5f3b.json +0 -315
- package/demo/data/manifest-609.json +0 -500
- package/demo/data/ms_am_1118_3_142_0001.jpg +0 -0
- package/demo/data/ms_am_1118_3_142_0002.jpg +0 -0
- package/demo/data/ms_am_1118_3_142_0003.jpg +0 -0
- package/demo/demoEntry.js +0 -21
- package/demo/index.html +0 -23
- package/jest.config.js +0 -23
- package/nwb.config.js +0 -20
- package/rollup.config.mjs +0 -12
- package/setupTests.js +0 -1
- package/src/index.js +0 -15
- package/src/plugins/EdaSideBarButtonsWrapper.js +0 -51
- package/src/plugins/EdaTranscriptionButton.js +0 -19
- package/src/plugins/EdaTranscriptionPanel.js +0 -245
- package/src/plugins/__tests__/EdaSideBarButtonsWrapper.spec.js +0 -183
- package/src/plugins/__tests__/EdaTranscriptionButton.spec.js +0 -17
- package/src/plugins/__tests__/EdaTranscriptionPanel.spec.js +0 -188
- package/src/plugins/__tests__/edaManifest.spec.js +0 -110
- package/src/plugins/__tests__/nonEdaManifest.spec.js +0 -64
- package/src/plugins/__tests__/transcriptionUtils.spec.js +0 -430
- package/src/plugins/testFixtures/combinedEditionsTranscriptions.js +0 -62
- package/src/plugins/testFixtures/franklinVariorum1998Transcription.js +0 -85
- package/src/plugins/testFixtures/johnsonPoems1955Transcription.js +0 -88
- package/src/plugins/transcriptionUtils.js +0 -114
- package/src/plugins/utils/suppressWarnings.js +0 -41
- package/webpack.config.cjs +0 -56
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import { render, screen, fireEvent } from "@testing-library/react"
|
|
2
|
-
import { Provider } from "react-redux"
|
|
3
|
-
import { configureStore } from "@reduxjs/toolkit"
|
|
4
|
-
import '@testing-library/jest-dom'
|
|
5
|
-
import { withStyles } from "@material-ui/core/styles"
|
|
6
|
-
import EdaTranscriptionPanel from "../EdaTranscriptionPanel"
|
|
7
|
-
|
|
8
|
-
const styles = () => ({ section: "section", controls: "controls", formControl: "formControl", editionLabel: "editionLabel" })
|
|
9
|
-
const StyledPanel = withStyles(styles)(EdaTranscriptionPanel.component)
|
|
10
|
-
|
|
11
|
-
// Mock the CompanionWindow component from Mirador to avoid theme dependency issues
|
|
12
|
-
jest.mock("mirador/dist/es/src/containers/CompanionWindow", () => ({
|
|
13
|
-
__esModule: true,
|
|
14
|
-
default: ({ children, title }) => (
|
|
15
|
-
<div
|
|
16
|
-
data-testid="mock-companion-window"
|
|
17
|
-
className="mirador-companion-window mirador-companion-window-right react-draggable"
|
|
18
|
-
>
|
|
19
|
-
<div className="mirador-window-title-bar">
|
|
20
|
-
<h2>{title}</h2>
|
|
21
|
-
</div>
|
|
22
|
-
<div className="mirador-companion-window-body">
|
|
23
|
-
{children}
|
|
24
|
-
</div>
|
|
25
|
-
<div style={{ cursor: 'col-resize' }} className="react-draggable-handle"></div>
|
|
26
|
-
</div>
|
|
27
|
-
)
|
|
28
|
-
}))
|
|
29
|
-
import johnsonPoems1955 from "../testFixtures/johnsonPoems1955Transcription"
|
|
30
|
-
import franklinVariorum1998 from "../testFixtures/franklinVariorum1998Transcription"
|
|
31
|
-
|
|
32
|
-
function renderPanel({ transcriptions = [johnsonPoems1955, franklinVariorum1998], windowId = "window-1" } = {}) {
|
|
33
|
-
// Minimal reducer for testing, returns state as-is
|
|
34
|
-
const reducer = (state = {}) => state
|
|
35
|
-
// Provide transcriptions in the state as expected by getEdaTranscription
|
|
36
|
-
const preloadedState = {
|
|
37
|
-
manifests: {
|
|
38
|
-
"mock-manifest": {
|
|
39
|
-
json: {
|
|
40
|
-
items: [
|
|
41
|
-
{
|
|
42
|
-
id: "mock-canvas",
|
|
43
|
-
annotations: [
|
|
44
|
-
{ items: transcriptions.map(t => ({ body: { format: "text/html", value: t } })) }
|
|
45
|
-
]
|
|
46
|
-
}
|
|
47
|
-
]
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
windows: {
|
|
52
|
-
[windowId]: {
|
|
53
|
-
manifestId: "mock-manifest",
|
|
54
|
-
canvasId: "mock-canvas"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const store = configureStore({ reducer, preloadedState })
|
|
59
|
-
return render(
|
|
60
|
-
<Provider store={store}>
|
|
61
|
-
<StyledPanel windowId={windowId} classes={styles()} />
|
|
62
|
-
</Provider>
|
|
63
|
-
)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
describe("the EdaTranscriptionPanel should", () => {
|
|
67
|
-
it("render the sidebar panel", () => {
|
|
68
|
-
renderPanel()
|
|
69
|
-
// Check for the companion window with the right title
|
|
70
|
-
expect(screen.getAllByText("EDA Transcription")[0]).toBeInTheDocument()
|
|
71
|
-
expect(screen.getByText("Edition")).toBeInTheDocument()
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it("use the paperClassName prop for width styling", () => {
|
|
75
|
-
const { container } = renderPanel()
|
|
76
|
-
// CompanionWindow component receives paperClassName={classes.paper}
|
|
77
|
-
const companionWindow = container.querySelector('.mirador-companion-window')
|
|
78
|
-
expect(companionWindow).toBeInTheDocument()
|
|
79
|
-
// We're verifying the structure exists - the actual styling is handled by Material-UI
|
|
80
|
-
// and the global styles in the component
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
it("use the @global.mirador-companion-window-left react-draggable for resizing", () => {
|
|
84
|
-
const { container } = renderPanel()
|
|
85
|
-
const companionWindow = container.querySelector('.mirador-companion-window-right')
|
|
86
|
-
expect(companionWindow).toBeInTheDocument()
|
|
87
|
-
const draggableElement = container.querySelector('.react-draggable')
|
|
88
|
-
expect(draggableElement).toBeInTheDocument()
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it("should be resizable like other Mirador panels", () => {
|
|
92
|
-
const { container } = renderPanel()
|
|
93
|
-
expect(container.querySelector('.mirador-companion-window-right')).toBeInTheDocument()
|
|
94
|
-
const draggableElement = container.querySelector('.react-draggable')
|
|
95
|
-
expect(draggableElement).toBeInTheDocument()
|
|
96
|
-
const resizeHandle = container.querySelector('[style*="cursor: col-resize;"]') ||
|
|
97
|
-
container.querySelector('[style*="cursor: row-resize;"]')
|
|
98
|
-
expect(resizeHandle).toBeInTheDocument()
|
|
99
|
-
})
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
describe("the EdaTranscriptionPanel editions select menu should", () => {
|
|
103
|
-
it("render if there is at least one transcription", () => {
|
|
104
|
-
renderPanel({ transcriptions: [johnsonPoems1955] })
|
|
105
|
-
// The select should be present
|
|
106
|
-
expect(screen.getByRole("button")).toBeInTheDocument()
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it("be disabled if there is only one transcription", () => {
|
|
110
|
-
renderPanel({ transcriptions: [johnsonPoems1955] })
|
|
111
|
-
const select = screen.getByRole("button")
|
|
112
|
-
// Material-UI handles disabled state differently in tests
|
|
113
|
-
expect(select.getAttribute("aria-disabled")).toBe("true")
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
it("be enabled if there are multiple transcriptions", () => {
|
|
117
|
-
renderPanel({ transcriptions: [johnsonPoems1955, franklinVariorum1998] })
|
|
118
|
-
const select = screen.getByRole("button")
|
|
119
|
-
// For enabled state, Material-UI might not set aria-disabled at all
|
|
120
|
-
expect(select.getAttribute("aria-disabled")).not.toBe("true")
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
it("default to the first edition", () => {
|
|
124
|
-
renderPanel()
|
|
125
|
-
expect(screen.getByText("Johnson Poems 1955")).toBeInTheDocument()
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
it("change when a new edition is selected", () => {
|
|
129
|
-
renderPanel()
|
|
130
|
-
const select = screen.getByRole("button")
|
|
131
|
-
fireEvent.mouseDown(select)
|
|
132
|
-
const edition2 = screen.getAllByText("Franklin Variorum 1998")[0]
|
|
133
|
-
fireEvent.click(edition2)
|
|
134
|
-
expect(screen.getAllByText("Franklin Variorum 1998").length).toBeGreaterThan(0)
|
|
135
|
-
})
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
describe("the EdaTranscriptionPanel physical line breaks checkbox should", () => {
|
|
139
|
-
it("be true (checked) by default", () => {
|
|
140
|
-
renderPanel()
|
|
141
|
-
const linebreakCheckbox = screen.getByLabelText("Physical Line Breaks")
|
|
142
|
-
expect(linebreakCheckbox).toBeChecked()
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
it("change values when unchecked", () => {
|
|
146
|
-
renderPanel()
|
|
147
|
-
const linebreakCheckbox = screen.getByLabelText("Physical Line Breaks")
|
|
148
|
-
fireEvent.click(linebreakCheckbox)
|
|
149
|
-
expect(linebreakCheckbox).not.toBeChecked()
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
it("toggle physical line breaks in rendered code", () => {
|
|
153
|
-
renderPanel()
|
|
154
|
-
// By default, linebreaks are shown
|
|
155
|
-
const htmlWithBreaks = screen.getByText("If I may have it, when it's dead,").parentElement.innerHTML
|
|
156
|
-
expect(htmlWithBreaks).toContain("<br")
|
|
157
|
-
|
|
158
|
-
// Toggle the checkbox to hide linebreaks
|
|
159
|
-
const linebreakCheckbox = screen.getByLabelText("Physical Line Breaks")
|
|
160
|
-
fireEvent.click(linebreakCheckbox)
|
|
161
|
-
// After toggling, <br> should still exist in the HTML, but the CSS class disables its display
|
|
162
|
-
// So we check the parent class
|
|
163
|
-
const sectionDiv = screen.getByText("If I may have it, when it's dead,").closest(".section")
|
|
164
|
-
expect(sectionDiv.className).not.toContain("show-linebreaks")
|
|
165
|
-
})
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
describe("the EdaTranscriptionPanel hide edits checkbox should", () => {
|
|
169
|
-
it("be false (unchecked)by default", () => {
|
|
170
|
-
renderPanel()
|
|
171
|
-
const editsCheckbox = screen.getByLabelText("Hide Edits")
|
|
172
|
-
expect(editsCheckbox).not.toBeChecked()
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
it("change values when checked", () => {
|
|
176
|
-
renderPanel()
|
|
177
|
-
const editsCheckbox = screen.getByLabelText("Hide Edits")
|
|
178
|
-
fireEvent.click(editsCheckbox)
|
|
179
|
-
expect(editsCheckbox).toBeChecked()
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
it("toggle hide edits in rendered code", () => {
|
|
183
|
-
renderPanel()
|
|
184
|
-
const htmlWithEdits = screen.getByText("If I may have it, when it's dead,").parentElement.innerHTML
|
|
185
|
-
// Check for <ins> or <rt> as editorial marks
|
|
186
|
-
expect(htmlWithEdits).toMatch(/<(ins|rt)[^>]*>/)
|
|
187
|
-
})
|
|
188
|
-
})
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/** @jest-environment jsdom */
|
|
2
|
-
import React from "react"
|
|
3
|
-
import { getEdaTranscription } from "../transcriptionUtils"
|
|
4
|
-
|
|
5
|
-
// Mock the transcriptionUtils
|
|
6
|
-
jest.mock("../transcriptionUtils")
|
|
7
|
-
|
|
8
|
-
describe("Emily Dickinson Manifest Support", () => {
|
|
9
|
-
// Sample Emily Dickinson manifest based on the demo files
|
|
10
|
-
const emilyDickinsonManifest = {
|
|
11
|
-
"@context": "http://iiif.io/api/presentation/3/context.json",
|
|
12
|
-
"id": "https://www.edickinson.org/manifestation/3037",
|
|
13
|
-
"type": "Manifest",
|
|
14
|
-
"label": { "en": ["Emily Dickinson Archive - J577 - If I may have it when it\"s dead"] },
|
|
15
|
-
"items": [
|
|
16
|
-
{
|
|
17
|
-
"id": "canvas/3945",
|
|
18
|
-
"type": "Canvas",
|
|
19
|
-
"annotations": [
|
|
20
|
-
{
|
|
21
|
-
"items": [
|
|
22
|
-
{
|
|
23
|
-
"body": {
|
|
24
|
-
"format": "text/html",
|
|
25
|
-
"value": '<div class="work-body" data-exhibit="emily-dickinson-archive" data-edition="Johnson Poems 1955">Sample transcription</div>'
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
]
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
}
|
|
32
|
-
]
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
describe("transcription extraction", () => {
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
// Reset all mocks before each test
|
|
38
|
-
jest.clearAllMocks()
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it("should identify EDA transcriptions from manifest", () => {
|
|
42
|
-
// Mock the state that would be passed to getEdaTranscription
|
|
43
|
-
const state = {
|
|
44
|
-
manifests: {
|
|
45
|
-
"manifest-1": {
|
|
46
|
-
json: emilyDickinsonManifest
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
windows: {
|
|
50
|
-
"window-1": {
|
|
51
|
-
manifestId: "manifest-1",
|
|
52
|
-
canvasId: "canvas/3945"
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Call getEdaTranscription with our mock state
|
|
58
|
-
getEdaTranscription(state, { windowId: "window-1" })
|
|
59
|
-
|
|
60
|
-
// Verify the function was called with correct state and windowId
|
|
61
|
-
expect(getEdaTranscription).toHaveBeenCalledWith(
|
|
62
|
-
state,
|
|
63
|
-
expect.objectContaining({ windowId: "window-1" })
|
|
64
|
-
)
|
|
65
|
-
})
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
describe("manifest structure", () => {
|
|
69
|
-
it("should match expected manifest ID format", () => {
|
|
70
|
-
const demoManifestId = "https://www.edickinson.org/manifestation/3037"
|
|
71
|
-
expect(emilyDickinsonManifest.id).toBe(demoManifestId)
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it("should include required EDA transcription metadata", () => {
|
|
75
|
-
const transcription = emilyDickinsonManifest.items[0].annotations[0].items[0].body.value
|
|
76
|
-
expect(transcription).toContain('data-exhibit="emily-dickinson-archive"')
|
|
77
|
-
expect(transcription).toContain('data-edition="Johnson Poems 1955"')
|
|
78
|
-
})
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
describe("annotation handling", () => {
|
|
82
|
-
beforeEach(() => {
|
|
83
|
-
getEdaTranscription.mockReset()
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
it("should properly identify annotation content", () => {
|
|
87
|
-
const edaTranscription = '<div class="work-body" data-exhibit="emily-dickinson-archive">Sample</div>'
|
|
88
|
-
getEdaTranscription.mockReturnValue([edaTranscription])
|
|
89
|
-
|
|
90
|
-
const state = {
|
|
91
|
-
manifests: {
|
|
92
|
-
"manifest-1": {
|
|
93
|
-
json: emilyDickinsonManifest
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
windows: {
|
|
97
|
-
"window-1": {
|
|
98
|
-
manifestId: "manifest-1",
|
|
99
|
-
canvasId: "canvas/3945"
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const transcriptions = getEdaTranscription(state, { windowId: "window-1" })
|
|
105
|
-
|
|
106
|
-
expect(transcriptions).toHaveLength(1)
|
|
107
|
-
expect(transcriptions[0]).toContain("emily-dickinson-archive")
|
|
108
|
-
})
|
|
109
|
-
})
|
|
110
|
-
})
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { getEdaTranscription } from "../transcriptionUtils"
|
|
2
|
-
|
|
3
|
-
// Sample Harvard (non-EDA) manifest
|
|
4
|
-
const harvardManifest = {
|
|
5
|
-
"@context": "http://iiif.io/api/presentation/2/context.json",
|
|
6
|
-
"@id": "https://iiif.lib.harvard.edu/manifests/ids:488815",
|
|
7
|
-
"@type": "sc:Manifest",
|
|
8
|
-
"label": "Harvard University Test Manifest",
|
|
9
|
-
"sequences": [
|
|
10
|
-
{
|
|
11
|
-
"canvases": [
|
|
12
|
-
{
|
|
13
|
-
"@id": "https://iiif.lib.harvard.edu/manifests/ids:488815/canvas/canvas-488815.json",
|
|
14
|
-
"images": [{ "@type": "oa:Annotation" }]
|
|
15
|
-
}
|
|
16
|
-
]
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
jest.mock("../transcriptionUtils")
|
|
22
|
-
|
|
23
|
-
describe("Non-Emily Dickinson manifest", () => {
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
jest.clearAllMocks()
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it("should return empty transcriptions array", () => {
|
|
29
|
-
const state = {
|
|
30
|
-
manifests: {
|
|
31
|
-
"manifest-1": { json: harvardManifest }
|
|
32
|
-
},
|
|
33
|
-
windows: {
|
|
34
|
-
"window-1": {
|
|
35
|
-
manifestId: "manifest-1",
|
|
36
|
-
canvasId: "canvas-1"
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
getEdaTranscription.mockReturnValue([])
|
|
42
|
-
|
|
43
|
-
const transcriptions = getEdaTranscription(state, { windowId: "window-1" })
|
|
44
|
-
expect(transcriptions).toEqual([])
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
it("should not contain EDA metadata", () => {
|
|
48
|
-
const canvas = harvardManifest.sequences[0].canvases[0]
|
|
49
|
-
expect(canvas.annotations).toBeUndefined()
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it("should handle transcription request for non-EDA manifests", () => {
|
|
53
|
-
const handleClickMock = jest.fn().mockReturnValue("panel-opened")
|
|
54
|
-
|
|
55
|
-
const props = {
|
|
56
|
-
transcriptions: [], // Empty for non-EDA manifests
|
|
57
|
-
handleClick: () => handleClickMock("edaTranscription")
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const result = props.handleClick()
|
|
61
|
-
expect(handleClickMock).toHaveBeenCalledWith("edaTranscription")
|
|
62
|
-
expect(result).toBe("panel-opened")
|
|
63
|
-
})
|
|
64
|
-
})
|