@pie-qti/item-player 0.1.4 → 0.1.5
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/README.md +21 -18
- package/dist/catalog/applyGlossaryTriggers.d.ts +15 -0
- package/dist/catalog/applyGlossaryTriggers.d.ts.map +1 -0
- package/dist/catalog/applyGlossaryTriggers.js +193 -0
- package/dist/catalog/catalogExtractor.d.ts +18 -0
- package/dist/catalog/catalogExtractor.d.ts.map +1 -0
- package/dist/catalog/catalogExtractor.js +114 -0
- package/dist/catalog/catalogLookup.d.ts +18 -0
- package/dist/catalog/catalogLookup.d.ts.map +1 -0
- package/dist/catalog/catalogLookup.js +44 -0
- package/dist/catalog/glossaryAction.d.ts +17 -0
- package/dist/catalog/glossaryAction.d.ts.map +1 -0
- package/dist/catalog/glossaryAction.js +21 -0
- package/dist/catalog/types.d.ts +26 -0
- package/dist/catalog/types.d.ts.map +1 -0
- package/dist/catalog/types.js +6 -0
- package/dist/core/ComponentRegistry.d.ts +9 -0
- package/dist/core/ComponentRegistry.d.ts.map +1 -1
- package/dist/core/ComponentRegistry.js +14 -0
- package/dist/core/ItemRenderer.d.ts.map +1 -1
- package/dist/core/ItemRenderer.js +3 -0
- package/dist/core/Player.d.ts +52 -0
- package/dist/core/Player.d.ts.map +1 -1
- package/dist/core/Player.js +158 -4
- package/dist/core/rolePolicy.d.ts +16 -0
- package/dist/core/rolePolicy.d.ts.map +1 -0
- package/dist/core/rolePolicy.js +15 -0
- package/dist/core/urlPolicy.d.ts.map +1 -1
- package/dist/core/urlPolicy.js +5 -2
- package/dist/element.d.ts +22 -0
- package/dist/element.js +5327 -0
- package/dist/element.js.map +1 -0
- package/dist/extraction/ExtractionRegistry.d.ts.map +1 -1
- package/dist/extraction/ExtractionRegistry.js +3 -1
- package/dist/extraction/extractors/associateExtractor.d.ts +1 -0
- package/dist/extraction/extractors/associateExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/associateExtractor.js +3 -0
- package/dist/extraction/extractors/choiceExtractor.d.ts +2 -0
- package/dist/extraction/extractors/choiceExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/choiceExtractor.js +10 -0
- package/dist/extraction/extractors/extendedTextExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/extendedTextExtractor.js +6 -0
- package/dist/extraction/extractors/gapMatchExtractor.d.ts +1 -0
- package/dist/extraction/extractors/gapMatchExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/gapMatchExtractor.js +33 -20
- package/dist/extraction/extractors/graphicAssociateExtractor.d.ts +1 -0
- package/dist/extraction/extractors/graphicAssociateExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/graphicAssociateExtractor.js +3 -0
- package/dist/extraction/extractors/graphicGapMatchExtractor.d.ts +11 -0
- package/dist/extraction/extractors/graphicGapMatchExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/graphicGapMatchExtractor.js +71 -10
- package/dist/extraction/extractors/hotspotExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/hotspotExtractor.js +27 -8
- package/dist/extraction/extractors/hottextExtractor.d.ts +1 -1
- package/dist/extraction/extractors/hottextExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/hottextExtractor.js +12 -4
- package/dist/extraction/extractors/index.d.ts +1 -0
- package/dist/extraction/extractors/index.d.ts.map +1 -1
- package/dist/extraction/extractors/index.js +4 -0
- package/dist/extraction/extractors/inlineChoiceExtractor.d.ts +3 -0
- package/dist/extraction/extractors/inlineChoiceExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/inlineChoiceExtractor.js +17 -4
- package/dist/extraction/extractors/matchExtractor.d.ts +5 -0
- package/dist/extraction/extractors/matchExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/matchExtractor.js +26 -0
- package/dist/extraction/extractors/orderExtractor.d.ts +2 -0
- package/dist/extraction/extractors/orderExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/orderExtractor.js +4 -0
- package/dist/extraction/extractors/portableCustomExtractor.d.ts +14 -0
- package/dist/extraction/extractors/portableCustomExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/portableCustomExtractor.js +96 -0
- package/dist/extraction/extractors/selectPointExtractor.js +5 -5
- package/dist/extraction/extractors/textEntryExtractor.d.ts +1 -0
- package/dist/extraction/extractors/textEntryExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/textEntryExtractor.js +6 -0
- package/dist/extraction/extractors/uploadExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/uploadExtractor.js +9 -2
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/pci/PciHost.d.ts +53 -0
- package/dist/pci/PciHost.d.ts.map +1 -0
- package/dist/pci/PciHost.js +116 -0
- package/dist/pci/types.d.ts +57 -0
- package/dist/pci/types.d.ts.map +1 -0
- package/dist/pci/types.js +19 -0
- package/dist/pnp/applyPnp.d.ts +9 -0
- package/dist/pnp/applyPnp.d.ts.map +1 -0
- package/dist/pnp/applyPnp.js +19 -0
- package/dist/pnp/parsePnpXml.d.ts +9 -0
- package/dist/pnp/parsePnpXml.d.ts.map +1 -0
- package/dist/pnp/parsePnpXml.js +101 -0
- package/dist/pnp/types.d.ts +40 -0
- package/dist/pnp/types.d.ts.map +1 -0
- package/dist/pnp/types.js +1 -0
- package/dist/types/index.d.ts +22 -8
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/interactions.d.ts +90 -1
- package/dist/types/interactions.d.ts.map +1 -1
- package/package.json +19 -9
- package/src/__tests__/catalog.test.ts +267 -0
- package/src/__tests__/fixtures/pci/echo-pci.js +49 -0
- package/src/__tests__/glossaryTriggers.test.ts +411 -0
- package/src/__tests__/pci.test.ts +353 -0
- package/src/__tests__/pnp.test.ts +250 -0
- package/src/__tests__/qti3-extraction.test.ts +5 -5
- package/src/catalog/applyGlossaryTriggers.ts +232 -0
- package/src/catalog/catalogExtractor.ts +130 -0
- package/src/catalog/catalogLookup.ts +53 -0
- package/src/catalog/glossaryAction.ts +28 -0
- package/src/catalog/types.ts +37 -0
- package/src/components/ItemBody.svelte +134 -26
- package/src/components/ItemPlayer.svelte +6 -2
- package/src/components/index.ts +3 -0
- package/src/core/ComponentRegistry.ts +14 -0
- package/src/core/ItemRenderer.ts +4 -0
- package/src/core/Player.ts +174 -4
- package/src/core/rolePolicy.ts +34 -0
- package/src/core/urlPolicy.ts +5 -2
- package/src/element.ts +128 -0
- package/src/extraction/ExtractionRegistry.ts +5 -1
- package/src/extraction/extractors/associateExtractor.ts +4 -0
- package/src/extraction/extractors/choiceExtractor.ts +12 -1
- package/src/extraction/extractors/conformance-qti3-advanced.test.ts +239 -0
- package/src/extraction/extractors/conformance-qti3-basic.test.ts +82 -0
- package/src/extraction/extractors/conformance.test.ts +208 -0
- package/src/extraction/extractors/extendedTextExtractor.ts +6 -0
- package/src/extraction/extractors/gapMatchExtractor.ts +36 -21
- package/src/extraction/extractors/graphicAssociateExtractor.ts +4 -0
- package/src/extraction/extractors/graphicGapMatchExtractor.ts +82 -10
- package/src/extraction/extractors/hotspotExtractor.ts +26 -8
- package/src/extraction/extractors/hottextExtractor.ts +15 -5
- package/src/extraction/extractors/index.ts +4 -0
- package/src/extraction/extractors/inlineChoiceExtractor.ts +22 -5
- package/src/extraction/extractors/matchExtractor.ts +31 -4
- package/src/extraction/extractors/orderExtractor.ts +6 -0
- package/src/extraction/extractors/portableCustomExtractor.ts +122 -0
- package/src/extraction/extractors/selectPointExtractor.ts +5 -5
- package/src/extraction/extractors/textEntryExtractor.ts +7 -0
- package/src/extraction/extractors/uploadExtractor.ts +10 -2
- package/src/index.ts +17 -1
- package/src/pci/PciHost.ts +138 -0
- package/src/pci/types.ts +70 -0
- package/src/pnp/applyPnp.ts +23 -0
- package/src/pnp/parsePnpXml.ts +118 -0
- package/src/pnp/types.ts +33 -0
- package/src/types/index.ts +22 -8
- package/src/types/interactions.ts +81 -6
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for applyGlossaryTriggers using a minimal DOM mock.
|
|
3
|
+
* We set up a lightweight global DOM before each test so the module
|
|
4
|
+
* can call document.createElement, querySelectorAll, etc.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
|
|
7
|
+
import { applyGlossaryTriggers } from '../catalog/applyGlossaryTriggers.js';
|
|
8
|
+
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Minimal DOM bootstrap (no external deps)
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
type Attrs = Record<string, string>;
|
|
14
|
+
type EventMap = Record<string, ((...args: any[]) => void)[]>;
|
|
15
|
+
|
|
16
|
+
class FakeElement {
|
|
17
|
+
tagName: string;
|
|
18
|
+
className = '';
|
|
19
|
+
textContent = '';
|
|
20
|
+
innerHTML = '';
|
|
21
|
+
style: Record<string, string> = {};
|
|
22
|
+
children: FakeElement[] = [];
|
|
23
|
+
parent: FakeElement | null = null;
|
|
24
|
+
private attrs: Attrs = {};
|
|
25
|
+
private events: EventMap = {};
|
|
26
|
+
|
|
27
|
+
constructor(tag: string) {
|
|
28
|
+
this.tagName = tag.toUpperCase();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
setAttribute(name: string, value: string) { this.attrs[name] = value; }
|
|
32
|
+
getAttribute(name: string) { return this.attrs[name] ?? null; }
|
|
33
|
+
removeAttribute(name: string) { delete this.attrs[name]; }
|
|
34
|
+
hasAttribute(name: string) { return name in this.attrs; }
|
|
35
|
+
|
|
36
|
+
appendChild<T extends FakeElement>(child: T): T {
|
|
37
|
+
// Detach from previous parent (matches real DOM behavior)
|
|
38
|
+
if (child.parent && child.parent !== this) {
|
|
39
|
+
child.parent.children = child.parent.children.filter((c) => c !== child);
|
|
40
|
+
}
|
|
41
|
+
child.parent = this;
|
|
42
|
+
if (!this.children.includes(child)) {
|
|
43
|
+
this.children.push(child);
|
|
44
|
+
}
|
|
45
|
+
return child;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
insertBefore<T extends FakeElement>(newChild: T, ref: FakeElement | null): T {
|
|
49
|
+
if (ref === null || !this.children.includes(ref)) {
|
|
50
|
+
return this.appendChild(newChild);
|
|
51
|
+
}
|
|
52
|
+
const idx = this.children.indexOf(ref);
|
|
53
|
+
newChild.parent = this;
|
|
54
|
+
this.children.splice(idx, 0, newChild);
|
|
55
|
+
return newChild;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
remove() {
|
|
59
|
+
if (this.parent) {
|
|
60
|
+
this.parent.children = this.parent.children.filter((c) => c !== this);
|
|
61
|
+
this.parent = null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
addEventListener(type: string, handler: (...args: any[]) => void) {
|
|
66
|
+
(this.events[type] ??= []).push(handler);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
removeEventListener(type: string, handler: (...args: any[]) => void) {
|
|
70
|
+
this.events[type] = (this.events[type] ?? []).filter((h) => h !== handler);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
dispatchEvent(event: any): boolean {
|
|
74
|
+
for (const h of this.events[event.type] ?? []) h(event);
|
|
75
|
+
if (event.bubbles && this.parent) this.parent.dispatchEvent(event);
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
focus() {}
|
|
80
|
+
|
|
81
|
+
// querySelectorAll for [data-catalog-idref] and focusable selectors
|
|
82
|
+
querySelectorAll(selector: string): FakeElement[] {
|
|
83
|
+
const results: FakeElement[] = [];
|
|
84
|
+
const visit = (el: FakeElement) => {
|
|
85
|
+
if (matchesSelector(el, selector)) results.push(el);
|
|
86
|
+
for (const c of el.children) visit(c);
|
|
87
|
+
};
|
|
88
|
+
for (const c of this.children) visit(c);
|
|
89
|
+
return results;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// offsetParent: fake non-null so focusable elements are considered visible
|
|
93
|
+
get offsetParent(): FakeElement | null { return this.parent ?? new FakeElement('body'); }
|
|
94
|
+
|
|
95
|
+
get parentNode() { return this.parent; }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
class FakeEvent {
|
|
99
|
+
type: string;
|
|
100
|
+
bubbles: boolean;
|
|
101
|
+
composed: boolean;
|
|
102
|
+
detail: any;
|
|
103
|
+
defaultPrevented = false;
|
|
104
|
+
key = '';
|
|
105
|
+
shiftKey = false;
|
|
106
|
+
|
|
107
|
+
constructor(type: string, opts: any = {}) {
|
|
108
|
+
this.type = type;
|
|
109
|
+
this.bubbles = opts.bubbles ?? false;
|
|
110
|
+
this.composed = opts.composed ?? false;
|
|
111
|
+
this.detail = opts.detail ?? {};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
preventDefault() { this.defaultPrevented = true; }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
class FakeDocument {
|
|
118
|
+
createElement(tag: string): FakeElement {
|
|
119
|
+
return new FakeElement(tag);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Simple CSS selector matching for our tests
|
|
124
|
+
function matchesSelector(el: FakeElement, selector: string): boolean {
|
|
125
|
+
// [data-catalog-idref]
|
|
126
|
+
if (selector === '[data-catalog-idref]') {
|
|
127
|
+
return el.getAttribute('data-catalog-idref') !== null;
|
|
128
|
+
}
|
|
129
|
+
// focusable selector used by the focus trap
|
|
130
|
+
if (selector.includes('button:not([disabled])')) {
|
|
131
|
+
return el.tagName === 'BUTTON' && el.getAttribute('disabled') === null;
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let savedDocument: any;
|
|
137
|
+
let savedCustomEvent: any;
|
|
138
|
+
let savedEvent: any;
|
|
139
|
+
|
|
140
|
+
function makeEnv() {
|
|
141
|
+
savedDocument = (globalThis as any).document;
|
|
142
|
+
savedCustomEvent = (globalThis as any).CustomEvent;
|
|
143
|
+
savedEvent = (globalThis as any).Event;
|
|
144
|
+
const doc = new FakeDocument();
|
|
145
|
+
(globalThis as any).document = doc;
|
|
146
|
+
(globalThis as any).CustomEvent = FakeEvent;
|
|
147
|
+
(globalThis as any).Event = FakeEvent;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function clearEnv() {
|
|
151
|
+
if (savedDocument !== undefined) (globalThis as any).document = savedDocument;
|
|
152
|
+
else delete (globalThis as any).document;
|
|
153
|
+
if (savedCustomEvent !== undefined) (globalThis as any).CustomEvent = savedCustomEvent;
|
|
154
|
+
else delete (globalThis as any).CustomEvent;
|
|
155
|
+
if (savedEvent !== undefined) (globalThis as any).Event = savedEvent;
|
|
156
|
+
else delete (globalThis as any).Event;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// ---------------------------------------------------------------------------
|
|
160
|
+
// Test helpers
|
|
161
|
+
// ---------------------------------------------------------------------------
|
|
162
|
+
|
|
163
|
+
const CATALOG_XML = `
|
|
164
|
+
<qti-catalog-info>
|
|
165
|
+
<qti-card identifier="word-osmosis">
|
|
166
|
+
<qti-card-entry usage="glossary-on-screen" xml:lang="en">
|
|
167
|
+
<qti-html-content>Movement of water through a membrane.</qti-html-content>
|
|
168
|
+
</qti-card-entry>
|
|
169
|
+
<qti-card-entry usage="keyword-translation" xml:lang="es">
|
|
170
|
+
<qti-html-content>ósmosis</qti-html-content>
|
|
171
|
+
</qti-card-entry>
|
|
172
|
+
<qti-card-entry usage="tts-pronunciation">
|
|
173
|
+
<qti-html-content>oz-MOH-sis</qti-html-content>
|
|
174
|
+
</qti-card-entry>
|
|
175
|
+
</qti-card>
|
|
176
|
+
</qti-catalog-info>
|
|
177
|
+
`;
|
|
178
|
+
|
|
179
|
+
const ITEM_XML = `<?xml version="1.0" encoding="UTF-8"?>
|
|
180
|
+
<qti-assessment-item
|
|
181
|
+
xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0"
|
|
182
|
+
identifier="glossary-test" title="Glossary Test" adaptive="false" time-dependent="false">
|
|
183
|
+
<qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier"/>
|
|
184
|
+
<qti-outcome-declaration identifier="SCORE" cardinality="single" base-type="float"/>
|
|
185
|
+
${CATALOG_XML}
|
|
186
|
+
<qti-item-body>
|
|
187
|
+
<p>The process of <span data-catalog-idref="word-osmosis">osmosis</span> is important.</p>
|
|
188
|
+
<qti-choice-interaction response-identifier="RESPONSE" max-choices="1">
|
|
189
|
+
<qti-simple-choice identifier="A">True</qti-simple-choice>
|
|
190
|
+
</qti-choice-interaction>
|
|
191
|
+
</qti-item-body>
|
|
192
|
+
</qti-assessment-item>`;
|
|
193
|
+
|
|
194
|
+
function makeMockPlayer(pnp: any, catalog: Record<string, Record<string, string | null>> = {}) {
|
|
195
|
+
return {
|
|
196
|
+
getPnp: () => pnp,
|
|
197
|
+
getCatalogEntry: (idref: string, usage: string, _lang?: string) => {
|
|
198
|
+
return catalog[idref]?.[usage] ?? null;
|
|
199
|
+
},
|
|
200
|
+
getComponentRegistry: () => ({
|
|
201
|
+
getTagNameForType: (_type: string) => null,
|
|
202
|
+
}),
|
|
203
|
+
} as any;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// ---------------------------------------------------------------------------
|
|
207
|
+
// Tests
|
|
208
|
+
// ---------------------------------------------------------------------------
|
|
209
|
+
|
|
210
|
+
describe('applyGlossaryTriggers', () => {
|
|
211
|
+
beforeEach(() => makeEnv());
|
|
212
|
+
afterEach(() => clearEnv());
|
|
213
|
+
|
|
214
|
+
it('does nothing when pnp is undefined', () => {
|
|
215
|
+
const container = new FakeElement('div') as any;
|
|
216
|
+
const term = new FakeElement('span') as any;
|
|
217
|
+
term.setAttribute('data-catalog-idref', 'word-osmosis');
|
|
218
|
+
term.textContent = 'osmosis';
|
|
219
|
+
container.appendChild(term);
|
|
220
|
+
|
|
221
|
+
applyGlossaryTriggers(container, makeMockPlayer(undefined));
|
|
222
|
+
// No wrapper or button children should have been added
|
|
223
|
+
expect(container.children.length).toBe(1);
|
|
224
|
+
expect(container.children[0]).toBe(term);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('does nothing when neither glossaryOnScreen nor keywordTranslation is active', () => {
|
|
228
|
+
const container = new FakeElement('div') as any;
|
|
229
|
+
const term = new FakeElement('span') as any;
|
|
230
|
+
term.setAttribute('data-catalog-idref', 'word-osmosis');
|
|
231
|
+
container.appendChild(term);
|
|
232
|
+
|
|
233
|
+
applyGlossaryTriggers(container, makeMockPlayer({ content: { glossaryOnScreen: false } }));
|
|
234
|
+
expect(container.children.length).toBe(1);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('wraps term in a .qti-catalog-term span and adds a trigger button when glossaryOnScreen', () => {
|
|
238
|
+
const container = new FakeElement('div') as any;
|
|
239
|
+
const term = new FakeElement('span') as any;
|
|
240
|
+
term.setAttribute('data-catalog-idref', 'word-osmosis');
|
|
241
|
+
term.textContent = 'osmosis';
|
|
242
|
+
container.appendChild(term);
|
|
243
|
+
|
|
244
|
+
const player = makeMockPlayer(
|
|
245
|
+
{ content: { glossaryOnScreen: true } },
|
|
246
|
+
{ 'word-osmosis': { 'glossary-on-screen': 'Movement of water.' } }
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
applyGlossaryTriggers(container, player);
|
|
250
|
+
|
|
251
|
+
// The container's first child should now be the wrapper
|
|
252
|
+
const wrapper = container.children[0];
|
|
253
|
+
expect(wrapper.className).toBe('qti-catalog-term');
|
|
254
|
+
// Wrapper should contain the original term + 1 trigger button
|
|
255
|
+
expect(wrapper.children.length).toBe(2);
|
|
256
|
+
const btn = wrapper.children[1];
|
|
257
|
+
expect(btn.tagName).toBe('BUTTON');
|
|
258
|
+
expect(btn.getAttribute('aria-label')).toBe('Show definition: osmosis');
|
|
259
|
+
expect(btn.getAttribute('data-catalog-usage')).toBe('glossary-on-screen');
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('adds a keyword-translation trigger when keywordTranslation is active', () => {
|
|
263
|
+
const container = new FakeElement('div') as any;
|
|
264
|
+
const term = new FakeElement('span') as any;
|
|
265
|
+
term.setAttribute('data-catalog-idref', 'word-osmosis');
|
|
266
|
+
term.textContent = 'osmosis';
|
|
267
|
+
container.appendChild(term);
|
|
268
|
+
|
|
269
|
+
const player = makeMockPlayer(
|
|
270
|
+
{ content: { keywordTranslation: { active: true, languageCode: 'es' } } },
|
|
271
|
+
{ 'word-osmosis': { 'keyword-translation': 'ósmosis' } }
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
applyGlossaryTriggers(container, player);
|
|
275
|
+
|
|
276
|
+
const wrapper = container.children[0];
|
|
277
|
+
// Should have term + 1 kw-translation button
|
|
278
|
+
const btn = wrapper.children.find((c: FakeElement) => c.getAttribute('data-catalog-usage') === 'keyword-translation');
|
|
279
|
+
expect(btn).toBeDefined();
|
|
280
|
+
expect((btn as FakeElement).getAttribute('aria-label')).toBe('Show definition: osmosis');
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('clicking a glossary trigger creates a popup with the entry HTML', () => {
|
|
284
|
+
const container = new FakeElement('div') as any;
|
|
285
|
+
const term = new FakeElement('span') as any;
|
|
286
|
+
term.setAttribute('data-catalog-idref', 'word-osmosis');
|
|
287
|
+
term.textContent = 'osmosis';
|
|
288
|
+
container.appendChild(term);
|
|
289
|
+
|
|
290
|
+
const player = makeMockPlayer(
|
|
291
|
+
{ content: { glossaryOnScreen: true } },
|
|
292
|
+
{ 'word-osmosis': { 'glossary-on-screen': 'Movement of water.' } }
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
applyGlossaryTriggers(container, player);
|
|
296
|
+
|
|
297
|
+
const wrapper = container.children[0];
|
|
298
|
+
const btn = wrapper.children[1];
|
|
299
|
+
|
|
300
|
+
// Click opens popup
|
|
301
|
+
btn.dispatchEvent(new FakeEvent('click', {}));
|
|
302
|
+
|
|
303
|
+
// Wrapper should now have: term + triggerBtn + popup
|
|
304
|
+
const popup = wrapper.children.find((c: FakeElement) => c.getAttribute('role') === 'dialog');
|
|
305
|
+
expect(popup).toBeDefined();
|
|
306
|
+
expect(popup!.getAttribute('aria-label')).toBe('osmosis');
|
|
307
|
+
expect(popup!.getAttribute('aria-modal')).toBe('true');
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it('clicking trigger again closes the open popup', () => {
|
|
311
|
+
const container = new FakeElement('div') as any;
|
|
312
|
+
const term = new FakeElement('span') as any;
|
|
313
|
+
term.setAttribute('data-catalog-idref', 'word-osmosis');
|
|
314
|
+
term.textContent = 'osmosis';
|
|
315
|
+
container.appendChild(term);
|
|
316
|
+
|
|
317
|
+
const player = makeMockPlayer(
|
|
318
|
+
{ content: { glossaryOnScreen: true } },
|
|
319
|
+
{ 'word-osmosis': { 'glossary-on-screen': 'Movement of water.' } }
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
applyGlossaryTriggers(container, player);
|
|
323
|
+
const wrapper = container.children[0];
|
|
324
|
+
const btn = wrapper.children[1];
|
|
325
|
+
|
|
326
|
+
btn.dispatchEvent(new FakeEvent('click', {}));
|
|
327
|
+
expect(wrapper.children.some((c: FakeElement) => c.getAttribute('role') === 'dialog')).toBe(true);
|
|
328
|
+
|
|
329
|
+
btn.dispatchEvent(new FakeEvent('click', {}));
|
|
330
|
+
expect(wrapper.children.some((c: FakeElement) => c.getAttribute('role') === 'dialog')).toBe(false);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('does not open popup when catalog entry is null', () => {
|
|
334
|
+
const container = new FakeElement('div') as any;
|
|
335
|
+
const term = new FakeElement('span') as any;
|
|
336
|
+
term.setAttribute('data-catalog-idref', 'unknown-term');
|
|
337
|
+
term.textContent = 'unknown';
|
|
338
|
+
container.appendChild(term);
|
|
339
|
+
|
|
340
|
+
const player = makeMockPlayer({ content: { glossaryOnScreen: true } }, {});
|
|
341
|
+
|
|
342
|
+
applyGlossaryTriggers(container, player);
|
|
343
|
+
const wrapper = container.children[0];
|
|
344
|
+
const btn = wrapper.children[1];
|
|
345
|
+
btn.dispatchEvent(new FakeEvent('click', {}));
|
|
346
|
+
|
|
347
|
+
expect(wrapper.children.some((c: FakeElement) => c.getAttribute('role') === 'dialog')).toBe(false);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it('fires qti-catalog-lookup CustomEvent for platform usages (tts-pronunciation)', () => {
|
|
351
|
+
const container = new FakeElement('div') as any;
|
|
352
|
+
const term = new FakeElement('span') as any;
|
|
353
|
+
term.setAttribute('data-catalog-idref', 'word-osmosis');
|
|
354
|
+
term.textContent = 'osmosis';
|
|
355
|
+
container.appendChild(term);
|
|
356
|
+
|
|
357
|
+
const firedEvents: any[] = [];
|
|
358
|
+
container.addEventListener('qti-catalog-lookup', (e: any) => firedEvents.push(e));
|
|
359
|
+
// Override addEventListener to track bubbled events from term
|
|
360
|
+
const origDispatch = term.dispatchEvent.bind(term);
|
|
361
|
+
term.dispatchEvent = (e: any) => {
|
|
362
|
+
if (e.type === 'qti-catalog-lookup') firedEvents.push(e);
|
|
363
|
+
return origDispatch(e);
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
const player = makeMockPlayer(
|
|
367
|
+
{ content: { glossaryOnScreen: true } },
|
|
368
|
+
{ 'word-osmosis': { 'glossary-on-screen': 'Movement of water.', 'tts-pronunciation': 'oz-MOH-sis' } }
|
|
369
|
+
);
|
|
370
|
+
|
|
371
|
+
applyGlossaryTriggers(container, player);
|
|
372
|
+
|
|
373
|
+
const ttsFired = firedEvents.find((e) => e.detail?.usage === 'tts-pronunciation');
|
|
374
|
+
expect(ttsFired).toBeDefined();
|
|
375
|
+
expect(ttsFired.detail.idref).toBe('word-osmosis');
|
|
376
|
+
expect(ttsFired.detail.html).toBe('oz-MOH-sis');
|
|
377
|
+
// No popup was created for tts-pronunciation
|
|
378
|
+
const wrapper = container.children[0];
|
|
379
|
+
expect(wrapper.children.some((c: FakeElement) => c.getAttribute('role') === 'dialog')).toBe(false);
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it('handles multiple catalog terms independently', () => {
|
|
383
|
+
const container = new FakeElement('div') as any;
|
|
384
|
+
|
|
385
|
+
const term1 = new FakeElement('span') as any;
|
|
386
|
+
term1.setAttribute('data-catalog-idref', 'word-osmosis');
|
|
387
|
+
term1.textContent = 'osmosis';
|
|
388
|
+
|
|
389
|
+
const term2 = new FakeElement('span') as any;
|
|
390
|
+
term2.setAttribute('data-catalog-idref', 'word-mitosis');
|
|
391
|
+
term2.textContent = 'mitosis';
|
|
392
|
+
|
|
393
|
+
container.appendChild(term1);
|
|
394
|
+
container.appendChild(term2);
|
|
395
|
+
|
|
396
|
+
const player = makeMockPlayer(
|
|
397
|
+
{ content: { glossaryOnScreen: true } },
|
|
398
|
+
{
|
|
399
|
+
'word-osmosis': { 'glossary-on-screen': 'Water movement.' },
|
|
400
|
+
'word-mitosis': { 'glossary-on-screen': 'Cell division.' },
|
|
401
|
+
}
|
|
402
|
+
);
|
|
403
|
+
|
|
404
|
+
applyGlossaryTriggers(container, player);
|
|
405
|
+
|
|
406
|
+
// Two wrappers should exist
|
|
407
|
+
expect(container.children.length).toBe(2);
|
|
408
|
+
expect(container.children[0].className).toBe('qti-catalog-term');
|
|
409
|
+
expect(container.children[1].className).toBe('qti-catalog-term');
|
|
410
|
+
});
|
|
411
|
+
});
|