@pie-qti/item-player 0.1.9 → 0.1.10

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 (199) hide show
  1. package/README.md +17 -0
  2. package/dist/catalog/applyGlossaryTriggers.d.ts +13 -2
  3. package/dist/catalog/applyGlossaryTriggers.d.ts.map +1 -1
  4. package/dist/catalog/glossaryAction.d.ts +4 -2
  5. package/dist/catalog/glossaryAction.d.ts.map +1 -1
  6. package/dist/components/utils/index.d.ts +1 -2
  7. package/dist/components/utils/index.d.ts.map +1 -1
  8. package/dist/components/utils/index.js +1 -2
  9. package/dist/core/ComponentRegistry.d.ts +10 -1
  10. package/dist/core/ComponentRegistry.d.ts.map +1 -1
  11. package/dist/core/ComponentRegistry.js +42 -1
  12. package/dist/core/Player.d.ts +10 -2
  13. package/dist/core/Player.d.ts.map +1 -1
  14. package/dist/core/Player.js +54 -46
  15. package/dist/document/AssessmentItemDocument.d.ts +1 -1
  16. package/dist/element.d.ts +15 -0
  17. package/dist/element.js +1817 -1625
  18. package/dist/element.js.map +1 -1
  19. package/dist/extraction/ExtractionRegistry.d.ts +1 -1
  20. package/dist/extraction/createContext.d.ts +1 -1
  21. package/dist/extraction/index.d.ts +2 -2
  22. package/dist/extraction/index.d.ts.map +1 -1
  23. package/dist/extraction/index.js +1 -1
  24. package/dist/extraction/interactionExtractionPipeline.d.ts +1 -1
  25. package/dist/extraction/interactionSecurity.d.ts +1 -1
  26. package/dist/extraction/types.d.ts +1 -1
  27. package/dist/presentation/itemPresentationPlan.d.ts +54 -0
  28. package/dist/presentation/itemPresentationPlan.d.ts.map +1 -0
  29. package/dist/presentation/itemPresentationPlan.js +98 -0
  30. package/dist/types/index.d.ts +17 -2
  31. package/dist/types/index.d.ts.map +1 -1
  32. package/dist/types/index.js +0 -3
  33. package/dist/web-components/QTIInteractionBase.d.ts +1 -1
  34. package/dist/web-components/QTIInteractionElement.d.ts +1 -1
  35. package/package.json +7 -14
  36. package/src/__tests__/catalog.test.ts +0 -267
  37. package/src/__tests__/fixtures/pci/echo-pci.js +0 -49
  38. package/src/__tests__/pci.test.ts +0 -353
  39. package/src/__tests__/qti3-attribute-extraction.test.ts +0 -174
  40. package/src/__tests__/qti3-debug.test.ts +0 -140
  41. package/src/__tests__/qti3-extraction.test.ts +0 -309
  42. package/src/catalog/applyGlossaryTriggers.ts +0 -372
  43. package/src/catalog/catalogExtractor.ts +0 -130
  44. package/src/catalog/catalogLookup.ts +0 -53
  45. package/src/catalog/glossaryAction.ts +0 -38
  46. package/src/catalog/types.ts +0 -37
  47. package/src/components/ItemBody.svelte +0 -363
  48. package/src/components/ItemPlayer.svelte +0 -163
  49. package/src/components/ModalFeedbackDisplay.svelte +0 -97
  50. package/src/components/actions/typesetAction.ts +0 -74
  51. package/src/components/index.ts +0 -22
  52. package/src/components/utils/assignProps.ts +0 -2
  53. package/src/components/utils/feedbackUtils.ts +0 -140
  54. package/src/components/utils/index.ts +0 -13
  55. package/src/components/utils/stimulusRender.ts +0 -93
  56. package/src/components/utils/stylesheetRender.ts +0 -58
  57. package/src/core/ComponentRegistry.ts +0 -248
  58. package/src/core/Player.ts +0 -1618
  59. package/src/core/Plugin.ts +0 -123
  60. package/src/core/PluginManager.ts +0 -182
  61. package/src/core/constants.ts +0 -117
  62. package/src/core/declarations.ts +0 -171
  63. package/src/core/parsingLimits.ts +0 -62
  64. package/src/core/random.ts +0 -24
  65. package/src/core/rolePolicy.ts +0 -34
  66. package/src/core/sanitizer.ts +0 -305
  67. package/src/core/trustedTypes.ts +0 -63
  68. package/src/core/urlPolicy.ts +0 -98
  69. package/src/document/AssessmentItemDocument.ts +0 -247
  70. package/src/element.ts +0 -128
  71. package/src/extensions/MathLiveEditor.ts +0 -313
  72. package/src/extraction/ExtractionRegistry.ts +0 -335
  73. package/src/extraction/createContext.ts +0 -52
  74. package/src/extraction/extractors/associateExtractor.ts +0 -1
  75. package/src/extraction/extractors/choiceExtractor.ts +0 -1
  76. package/src/extraction/extractors/conformance-qti3-advanced.test.ts +0 -239
  77. package/src/extraction/extractors/conformance-qti3-basic.test.ts +0 -82
  78. package/src/extraction/extractors/conformance.test.ts +0 -208
  79. package/src/extraction/extractors/customExtractor.ts +0 -1
  80. package/src/extraction/extractors/drawingExtractor.ts +0 -1
  81. package/src/extraction/extractors/endAttemptExtractor.ts +0 -1
  82. package/src/extraction/extractors/extendedTextExtractor.ts +0 -1
  83. package/src/extraction/extractors/gapMatchExtractor.ts +0 -1
  84. package/src/extraction/extractors/graphicAssociateExtractor.ts +0 -1
  85. package/src/extraction/extractors/graphicGapMatchExtractor.ts +0 -1
  86. package/src/extraction/extractors/graphicOrderExtractor.ts +0 -1
  87. package/src/extraction/extractors/hotspotExtractor.ts +0 -1
  88. package/src/extraction/extractors/hottextExtractor.ts +0 -1
  89. package/src/extraction/extractors/index.ts +0 -9
  90. package/src/extraction/extractors/inlineChoiceExtractor.ts +0 -1
  91. package/src/extraction/extractors/matchExtractor.ts +0 -1
  92. package/src/extraction/extractors/mediaExtractor.ts +0 -1
  93. package/src/extraction/extractors/orderExtractor.ts +0 -1
  94. package/src/extraction/extractors/portableCustomExtractor.ts +0 -1
  95. package/src/extraction/extractors/positionObjectExtractor.ts +0 -1
  96. package/src/extraction/extractors/selectPointExtractor.ts +0 -1
  97. package/src/extraction/extractors/sliderExtractor.ts +0 -1
  98. package/src/extraction/extractors/textEntryExtractor.ts +0 -1
  99. package/src/extraction/extractors/uploadExtractor.ts +0 -1
  100. package/src/extraction/index.ts +0 -108
  101. package/src/extraction/interactionExtractionPipeline.ts +0 -70
  102. package/src/extraction/interactionSecurity.ts +0 -60
  103. package/src/extraction/types.ts +0 -246
  104. package/src/extraction/utils.ts +0 -243
  105. package/src/iframe/IFramePlayerHost.ts +0 -265
  106. package/src/iframe/index.ts +0 -11
  107. package/src/iframe/protocol.ts +0 -137
  108. package/src/index.ts +0 -101
  109. package/src/interactions/associate/extractor.ts +0 -133
  110. package/src/interactions/associate/index.ts +0 -2
  111. package/src/interactions/associate/types.ts +0 -1
  112. package/src/interactions/choice/extractor.ts +0 -121
  113. package/src/interactions/choice/index.ts +0 -2
  114. package/src/interactions/choice/types.ts +0 -1
  115. package/src/interactions/custom/extractor.ts +0 -72
  116. package/src/interactions/custom/index.ts +0 -2
  117. package/src/interactions/custom/types.ts +0 -1
  118. package/src/interactions/drawing/extractor.ts +0 -113
  119. package/src/interactions/drawing/index.ts +0 -2
  120. package/src/interactions/drawing/types.ts +0 -1
  121. package/src/interactions/end-attempt/extractor.ts +0 -74
  122. package/src/interactions/end-attempt/index.ts +0 -2
  123. package/src/interactions/end-attempt/types.ts +0 -1
  124. package/src/interactions/extended-text/extractor.ts +0 -92
  125. package/src/interactions/extended-text/index.ts +0 -2
  126. package/src/interactions/extended-text/types.ts +0 -1
  127. package/src/interactions/gap-match/extractor.ts +0 -193
  128. package/src/interactions/gap-match/index.ts +0 -2
  129. package/src/interactions/gap-match/types.ts +0 -1
  130. package/src/interactions/graphic-associate/extractor.ts +0 -192
  131. package/src/interactions/graphic-associate/index.ts +0 -2
  132. package/src/interactions/graphic-associate/types.ts +0 -1
  133. package/src/interactions/graphic-gap-match/extractor.ts +0 -257
  134. package/src/interactions/graphic-gap-match/index.ts +0 -2
  135. package/src/interactions/graphic-gap-match/types.ts +0 -1
  136. package/src/interactions/graphic-order/extractor.ts +0 -162
  137. package/src/interactions/graphic-order/index.ts +0 -2
  138. package/src/interactions/graphic-order/types.ts +0 -1
  139. package/src/interactions/hotspot/extractor.ts +0 -208
  140. package/src/interactions/hotspot/index.ts +0 -2
  141. package/src/interactions/hotspot/types.ts +0 -1
  142. package/src/interactions/hottext/extractor.ts +0 -163
  143. package/src/interactions/hottext/index.ts +0 -2
  144. package/src/interactions/hottext/types.ts +0 -1
  145. package/src/interactions/index.ts +0 -52
  146. package/src/interactions/inline/index.ts +0 -1
  147. package/src/interactions/inline/render-plan.ts +0 -105
  148. package/src/interactions/inline-choice/InlineChoice.svelte +0 -57
  149. package/src/interactions/inline-choice/extractor.ts +0 -105
  150. package/src/interactions/inline-choice/index.ts +0 -2
  151. package/src/interactions/inline-choice/types.ts +0 -1
  152. package/src/interactions/match/extractor.ts +0 -187
  153. package/src/interactions/match/index.ts +0 -2
  154. package/src/interactions/match/types.ts +0 -1
  155. package/src/interactions/media/extractor.ts +0 -168
  156. package/src/interactions/media/index.ts +0 -2
  157. package/src/interactions/media/types.ts +0 -1
  158. package/src/interactions/modules.ts +0 -111
  159. package/src/interactions/order/extractor.ts +0 -120
  160. package/src/interactions/order/index.ts +0 -2
  161. package/src/interactions/order/types.ts +0 -1
  162. package/src/interactions/portable-custom/extractor.ts +0 -122
  163. package/src/interactions/portable-custom/index.ts +0 -2
  164. package/src/interactions/portable-custom/types.ts +0 -1
  165. package/src/interactions/position-object/extractor.ts +0 -243
  166. package/src/interactions/position-object/index.ts +0 -2
  167. package/src/interactions/position-object/types.ts +0 -1
  168. package/src/interactions/select-point/extractor.ts +0 -143
  169. package/src/interactions/select-point/index.ts +0 -2
  170. package/src/interactions/select-point/types.ts +0 -1
  171. package/src/interactions/shared/index.ts +0 -1
  172. package/src/interactions/shared/types.ts +0 -430
  173. package/src/interactions/slider/extractor.ts +0 -102
  174. package/src/interactions/slider/index.ts +0 -2
  175. package/src/interactions/slider/types.ts +0 -1
  176. package/src/interactions/text-entry/InlineTextEntry.svelte +0 -75
  177. package/src/interactions/text-entry/extractor.ts +0 -79
  178. package/src/interactions/text-entry/index.ts +0 -2
  179. package/src/interactions/text-entry/types.ts +0 -1
  180. package/src/interactions/upload/extractor.ts +0 -81
  181. package/src/interactions/upload/index.ts +0 -2
  182. package/src/interactions/upload/types.ts +0 -1
  183. package/src/pci/PciHost.ts +0 -138
  184. package/src/pci/types.ts +0 -70
  185. package/src/pnp/applyPnp.ts +0 -29
  186. package/src/pnp/parsePnpXml.ts +0 -215
  187. package/src/pnp/types.ts +0 -75
  188. package/src/server.ts +0 -14
  189. package/src/types/index.ts +0 -388
  190. package/src/types/interactions.ts +0 -8
  191. package/src/types/responseValidation.ts +0 -29
  192. package/src/types/xmldom.d.ts +0 -12
  193. package/src/utils/PerformanceMonitor.ts +0 -335
  194. package/src/utils/drawingUtils.ts +0 -73
  195. package/src/utils/responseUtils.ts +0 -51
  196. package/src/utils/touchDragHelper.ts +0 -1
  197. package/src/web-components/QTIInteractionBase.ts +0 -303
  198. package/src/web-components/QTIInteractionElement.ts +0 -125
  199. package/src/web-components/index.ts +0 -22
@@ -1,174 +0,0 @@
1
- /**
2
- * QTI 3.0 Attribute Extraction Tests
3
- *
4
- * Verifies that the attribute mapper integration works correctly for QTI 3.0
5
- * kebab-case attributes at the extraction utilities layer.
6
- */
7
-
8
- import { describe, it, expect } from 'bun:test';
9
- import { parse } from 'node-html-parser';
10
- import { createQtiParser } from '@pie-qti/qti-common';
11
- import { createExtractionUtils } from '../extraction/utils.js';
12
- import type { QTIElement } from '../types/interactions.js';
13
-
14
- describe('QTI 3.0 Attribute Extraction', () => {
15
- it('should extract max-choices attribute (kebab-case) from QTI 3.0 element', () => {
16
- const xml = `
17
- <qti-choice-interaction response-identifier="RESPONSE" shuffle="false" max-choices="1">
18
- <qti-prompt>Select one</qti-prompt>
19
- <qti-simple-choice identifier="A">Choice A</qti-simple-choice>
20
- </qti-choice-interaction>`;
21
-
22
- const { attributeMapper } = createQtiParser(xml);
23
- const dom = parse(xml);
24
- const element = dom.querySelector('qti-choice-interaction') as unknown as QTIElement;
25
-
26
- const utils = createExtractionUtils(undefined, undefined, attributeMapper);
27
-
28
- // Extract QTI 3.0 kebab-case attributes using camelCase names
29
- const maxChoices = utils.getNumberAttribute(element, 'maxChoices', 0);
30
- const shuffle = utils.getBooleanAttribute(element, 'shuffle', true);
31
- const responseId = utils.getAttribute(element, 'responseIdentifier', '');
32
-
33
- expect(maxChoices).toBe(1);
34
- expect(shuffle).toBe(false);
35
- expect(responseId).toBe('RESPONSE');
36
- });
37
-
38
- it('should extract expected-length attribute from QTI 3.0 text entry', () => {
39
- const xml = `
40
- <qti-text-entry-interaction response-identifier="RESPONSE" expected-length="15" />`;
41
-
42
- const { attributeMapper } = createQtiParser(xml);
43
- const dom = parse(xml);
44
- const element = dom.querySelector('qti-text-entry-interaction') as unknown as QTIElement;
45
-
46
- const utils = createExtractionUtils(undefined, undefined, attributeMapper);
47
-
48
- const expectedLength = utils.getNumberAttribute(element, 'expectedLength', 0);
49
- const responseId = utils.getAttribute(element, 'responseIdentifier', '');
50
-
51
- expect(expectedLength).toBe(15);
52
- expect(responseId).toBe('RESPONSE');
53
- });
54
-
55
- it('should extract expected-lines and placeholder-text from QTI 3.0 extended text', () => {
56
- const xml = `
57
- <qti-extended-text-interaction
58
- response-identifier="RESPONSE"
59
- expected-lines="5"
60
- expected-length="500"
61
- placeholder-text="Type here..." />`;
62
-
63
- const { attributeMapper } = createQtiParser(xml);
64
- const dom = parse(xml);
65
- const element = dom.querySelector('qti-extended-text-interaction') as unknown as QTIElement;
66
-
67
- const utils = createExtractionUtils(undefined, undefined, attributeMapper);
68
-
69
- const expectedLines = utils.getNumberAttribute(element, 'expectedLines', 0);
70
- const expectedLength = utils.getNumberAttribute(element, 'expectedLength', 0);
71
- const placeholderText = utils.getAttribute(element, 'placeholderText', '');
72
-
73
- expect(expectedLines).toBe(5);
74
- expect(expectedLength).toBe(500);
75
- expect(placeholderText).toBe('Type here...');
76
- });
77
-
78
- it('should extract max-associations from QTI 3.0 match interaction', () => {
79
- const xml = `
80
- <qti-match-interaction response-identifier="RESPONSE" shuffle="false" max-associations="3">
81
- <qti-simple-match-set>
82
- <qti-simple-associable-choice identifier="A" match-max="1">Item A</qti-simple-associable-choice>
83
- </qti-simple-match-set>
84
- </qti-match-interaction>`;
85
-
86
- const { attributeMapper } = createQtiParser(xml);
87
- const dom = parse(xml);
88
- const interaction = dom.querySelector('qti-match-interaction') as unknown as QTIElement;
89
- const choice = dom.querySelector('qti-simple-associable-choice') as unknown as QTIElement;
90
-
91
- const utils = createExtractionUtils(undefined, undefined, attributeMapper);
92
-
93
- const maxAssociations = utils.getNumberAttribute(interaction, 'maxAssociations', 0);
94
- const matchMax = utils.getNumberAttribute(choice, 'matchMax', 0);
95
-
96
- expect(maxAssociations).toBe(3);
97
- expect(matchMax).toBe(1);
98
- });
99
-
100
- it('should handle QTI 2.x camelCase attributes with default mapper', () => {
101
- const xml = `
102
- <choiceInteraction responseIdentifier="RESPONSE" shuffle="true" maxChoices="2">
103
- <simpleChoice identifier="A">Choice A</simpleChoice>
104
- </choiceInteraction>`;
105
-
106
- // No mapper specified - defaults to QTI 2.x
107
- const dom = parse(xml);
108
- const element = dom.querySelector('choiceinteraction') as unknown as QTIElement;
109
-
110
- const utils = createExtractionUtils(); // Defaults to Qti2xAttributeNameMapper
111
-
112
- const maxChoices = utils.getNumberAttribute(element, 'maxChoices', 0);
113
- const shuffle = utils.getBooleanAttribute(element, 'shuffle', false);
114
- const responseId = utils.getAttribute(element, 'responseIdentifier', '');
115
-
116
- expect(maxChoices).toBe(2);
117
- expect(shuffle).toBe(true);
118
- expect(responseId).toBe('RESPONSE');
119
- });
120
-
121
- it('should handle boolean attributes correctly for both versions', () => {
122
- // QTI 3.0
123
- const qti3xml = `<qti-choice-interaction shuffle="true" />`;
124
- const { attributeMapper: qti3Mapper } = createQtiParser(qti3xml);
125
- const qti3Dom = parse(qti3xml);
126
- const qti3Element = qti3Dom.querySelector('qti-choice-interaction') as unknown as QTIElement;
127
- const qti3Utils = createExtractionUtils(undefined, undefined, qti3Mapper);
128
-
129
- expect(qti3Utils.getBooleanAttribute(qti3Element, 'shuffle', false)).toBe(true);
130
-
131
- // QTI 2.x
132
- const qti2xml = `<choiceInteraction shuffle="true" />`;
133
- const qti2Dom = parse(qti2xml);
134
- const qti2Element = qti2Dom.querySelector('choiceinteraction') as unknown as QTIElement;
135
- const qti2Utils = createExtractionUtils(); // defaults
136
-
137
- expect(qti2Utils.getBooleanAttribute(qti2Element, 'shuffle', false)).toBe(true);
138
- });
139
-
140
- it('should return default values when attributes are missing', () => {
141
- const xml = `<qti-choice-interaction response-identifier="RESPONSE" />`;
142
- const { attributeMapper } = createQtiParser(xml);
143
- const dom = parse(xml);
144
- const element = dom.querySelector('qti-choice-interaction') as unknown as QTIElement;
145
-
146
- const utils = createExtractionUtils(undefined, undefined, attributeMapper);
147
-
148
- // These attributes don't exist, should return defaults
149
- const maxChoices = utils.getNumberAttribute(element, 'maxChoices', 99);
150
- const shuffle = utils.getBooleanAttribute(element, 'shuffle', true);
151
-
152
- expect(maxChoices).toBe(99);
153
- expect(shuffle).toBe(true);
154
- });
155
-
156
- it('should handle lower-bound and upper-bound for slider', () => {
157
- const xml = `
158
- <qti-slider-interaction response-identifier="RESPONSE" lower-bound="0" upper-bound="100" step="5" />`;
159
-
160
- const { attributeMapper } = createQtiParser(xml);
161
- const dom = parse(xml);
162
- const element = dom.querySelector('qti-slider-interaction') as unknown as QTIElement;
163
-
164
- const utils = createExtractionUtils(undefined, undefined, attributeMapper);
165
-
166
- const lowerBound = utils.getNumberAttribute(element, 'lowerBound', 0);
167
- const upperBound = utils.getNumberAttribute(element, 'upperBound', 0);
168
- const step = utils.getNumberAttribute(element, 'step', 0);
169
-
170
- expect(lowerBound).toBe(0);
171
- expect(upperBound).toBe(100);
172
- expect(step).toBe(5);
173
- });
174
- });
@@ -1,140 +0,0 @@
1
- import { describe, it, expect } from 'bun:test';
2
- import { detectQtiVersion } from '@pie-qti/qti-common';
3
- import { Player } from '../core/Player.js';
4
- import { parse } from 'node-html-parser';
5
-
6
- const QTI3_SIMPLE = `<?xml version="1.0" encoding="UTF-8"?>
7
- <qti-assessment-item
8
- xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0"
9
- identifier="test"
10
- title="Test">
11
- <qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier"/>
12
- <qti-item-body>
13
- <qti-choice-interaction response-identifier="RESPONSE" max-choices="1">
14
- <qti-simple-choice identifier="A">A</qti-simple-choice>
15
- </qti-choice-interaction>
16
- </qti-item-body>
17
- </qti-assessment-item>`;
18
-
19
- const QTI3_TEXT_ENTRY = `<?xml version="1.0" encoding="UTF-8"?>
20
- <qti-assessment-item
21
- xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0"
22
- identifier="qti3-text-entry"
23
- title="Text Entry">
24
- <qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="string"/>
25
- <qti-item-body>
26
- <p>What is the capital? <qti-text-entry-interaction response-identifier="RESPONSE" expected-length="15"/></p>
27
- </qti-item-body>
28
- </qti-assessment-item>`;
29
-
30
- describe('QTI 3.0 Debug', () => {
31
- it('should detect QTI 3.0 version', () => {
32
- const version = detectQtiVersion(QTI3_SIMPLE);
33
- console.log('Detected version:', version);
34
- expect(version).toBe('3.0');
35
- });
36
-
37
- it('should create player with QTI 3.0', () => {
38
- const player = new Player({ itemXml: QTI3_SIMPLE });
39
- console.log('Player created successfully');
40
- expect(player).toBeDefined();
41
- });
42
-
43
- it('should parse HTML and find elements', () => {
44
- const docRoot = parse(QTI3_SIMPLE, { lowerCaseTagName: false, comment: false });
45
- console.log('Parsed HTML structure:');
46
- console.log('Root tag:', docRoot.rawTagName);
47
-
48
- const itemBody = docRoot.querySelector('qti-item-body');
49
- console.log('Found qti-item-body:', !!itemBody);
50
- if (itemBody) {
51
- console.log('itemBody children:', itemBody.childNodes.length);
52
- }
53
-
54
- const choiceInteraction = docRoot.querySelector('qti-choice-interaction');
55
- console.log('Found qti-choice-interaction:', !!choiceInteraction);
56
- if (choiceInteraction) {
57
- console.log('choiceInteraction tag:', (choiceInteraction as any).rawTagName);
58
- console.log('response-identifier attr:', choiceInteraction.getAttribute('response-identifier'));
59
- }
60
-
61
- expect(choiceInteraction).toBeDefined();
62
- });
63
-
64
- it('should extract choice interaction', () => {
65
- const player = new Player({ itemXml: QTI3_SIMPLE });
66
- const interactions = player.getInteractionData();
67
- console.log('Choice interactions found:', interactions.length);
68
- expect(interactions.length).toBeGreaterThan(0);
69
- });
70
-
71
- it('should parse text entry in HTML', () => {
72
- const docRoot = parse(QTI3_TEXT_ENTRY, { lowerCaseTagName: false, comment: false });
73
- const textEntry = docRoot.querySelector('qti-text-entry-interaction');
74
- console.log('Found qti-text-entry-interaction:', !!textEntry);
75
- if (textEntry) {
76
- console.log('textEntry tag:', (textEntry as any).rawTagName);
77
- console.log('response-identifier attr:', textEntry.getAttribute('response-identifier'));
78
- } else {
79
- // Try finding all elements
80
- const allElements = docRoot.querySelectorAll('*');
81
- console.log('Total elements found:', allElements.length);
82
- console.log('Element tags:', allElements.map((el: any) => el.rawTagName).slice(0, 10));
83
- }
84
- expect(textEntry).toBeDefined();
85
- });
86
-
87
- it('should extract text entry interaction', () => {
88
- const player = new Player({ itemXml: QTI3_TEXT_ENTRY });
89
- const interactions = player.getInteractionData();
90
- console.log('Text entry interactions found:', interactions.length);
91
- console.log('Interactions:', JSON.stringify(interactions, null, 2));
92
- expect(interactions.length).toBeGreaterThan(0);
93
- });
94
-
95
- it('should process responses for QTI 3.0', () => {
96
- const qti3WithProcessing = `<?xml version="1.0" encoding="UTF-8"?>
97
- <qti-assessment-item
98
- xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0"
99
- identifier="test"
100
- title="Test">
101
- <qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier">
102
- <qti-correct-response>
103
- <qti-value>A</qti-value>
104
- </qti-correct-response>
105
- </qti-response-declaration>
106
- <qti-outcome-declaration identifier="SCORE" cardinality="single" base-type="float">
107
- <qti-default-value>
108
- <qti-value>0</qti-value>
109
- </qti-default-value>
110
- </qti-outcome-declaration>
111
- <qti-item-body>
112
- <qti-choice-interaction response-identifier="RESPONSE" max-choices="1">
113
- <qti-simple-choice identifier="A">Correct</qti-simple-choice>
114
- <qti-simple-choice identifier="B">Wrong</qti-simple-choice>
115
- </qti-choice-interaction>
116
- </qti-item-body>
117
- <qti-response-processing>
118
- <qti-response-condition>
119
- <qti-response-if>
120
- <qti-match>
121
- <qti-variable identifier="RESPONSE"/>
122
- <qti-correct identifier="RESPONSE"/>
123
- </qti-match>
124
- <qti-set-outcome-value identifier="SCORE">
125
- <qti-base-value base-type="float">1.0</qti-base-value>
126
- </qti-set-outcome-value>
127
- </qti-response-if>
128
- </qti-response-condition>
129
- </qti-response-processing>
130
- </qti-assessment-item>`;
131
-
132
- const player = new Player({ itemXml: qti3WithProcessing });
133
- player.setResponses({ RESPONSE: 'A' });
134
- const result = player.processResponses();
135
- console.log('Response processing result:', result);
136
- console.log('Score:', result.score);
137
- console.log('Outcome values:', result.outcomeValues);
138
- expect(result.score).toBe(1.0);
139
- });
140
- });
@@ -1,309 +0,0 @@
1
- /**
2
- * QTI 3.0 Extraction Tests
3
- *
4
- * Verifies that QTI 3.0 content (kebab-case attributes/elements) extracts correctly
5
- * and produces identical data structures to QTI 2.x equivalents.
6
- */
7
-
8
- import { describe, it, expect } from 'bun:test';
9
- import { Player } from '../core/Player.js';
10
-
11
- // QTI 3.0 sample items
12
- const QTI3_SIMPLE_CHOICE = `<?xml version="1.0" encoding="UTF-8"?>
13
- <qti-assessment-item
14
- xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0"
15
- identifier="qti3-simple-choice"
16
- title="Simple Multiple Choice (QTI 3.0)"
17
- adaptive="false"
18
- time-dependent="false">
19
-
20
- <qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier">
21
- <qti-correct-response>
22
- <qti-value>ChoiceA</qti-value>
23
- </qti-correct-response>
24
- </qti-response-declaration>
25
-
26
- <qti-outcome-declaration identifier="SCORE" cardinality="single" base-type="float">
27
- <qti-default-value>
28
- <qti-value>0.0</qti-value>
29
- </qti-default-value>
30
- </qti-outcome-declaration>
31
-
32
- <qti-item-body>
33
- <p>If Maya has 12 cookies and gives 5 to her friend, how many cookies does she have left?</p>
34
- <qti-choice-interaction response-identifier="RESPONSE" shuffle="false" max-choices="1">
35
- <qti-prompt>Select the correct answer:</qti-prompt>
36
- <qti-simple-choice identifier="ChoiceA">7</qti-simple-choice>
37
- <qti-simple-choice identifier="ChoiceB">17</qti-simple-choice>
38
- <qti-simple-choice identifier="ChoiceC">5</qti-simple-choice>
39
- <qti-simple-choice identifier="ChoiceD">8</qti-simple-choice>
40
- </qti-choice-interaction>
41
- </qti-item-body>
42
-
43
- <qti-response-processing>
44
- <qti-response-condition>
45
- <qti-response-if>
46
- <qti-match>
47
- <qti-variable identifier="RESPONSE"/>
48
- <qti-correct identifier="RESPONSE"/>
49
- </qti-match>
50
- <qti-set-outcome-value identifier="SCORE">
51
- <qti-base-value base-type="float">1.0</qti-base-value>
52
- </qti-set-outcome-value>
53
- </qti-response-if>
54
- </qti-response-condition>
55
- </qti-response-processing>
56
- </qti-assessment-item>`;
57
-
58
- const QTI3_TEXT_ENTRY = `<?xml version="1.0" encoding="UTF-8"?>
59
- <qti-assessment-item
60
- xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0"
61
- identifier="qti3-text-entry"
62
- title="Text Entry (QTI 3.0)"
63
- adaptive="false"
64
- time-dependent="false">
65
-
66
- <qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="string">
67
- <qti-correct-response>
68
- <qti-value>Paris</qti-value>
69
- </qti-correct-response>
70
- </qti-response-declaration>
71
-
72
- <qti-item-body>
73
- <p>What is the capital of France? <qti-text-entry-interaction response-identifier="RESPONSE" expected-length="15"/></p>
74
- </qti-item-body>
75
-
76
- <qti-response-processing>
77
- <qti-response-condition>
78
- <qti-response-if>
79
- <qti-match>
80
- <qti-variable identifier="RESPONSE"/>
81
- <qti-correct identifier="RESPONSE"/>
82
- </qti-match>
83
- <qti-set-outcome-value identifier="SCORE">
84
- <qti-base-value base-type="float">1.0</qti-base-value>
85
- </qti-set-outcome-value>
86
- </qti-response-if>
87
- </qti-response-condition>
88
- </qti-response-processing>
89
- </qti-assessment-item>`;
90
-
91
- const QTI3_EXTENDED_TEXT = `<?xml version="1.0" encoding="UTF-8"?>
92
- <qti-assessment-item
93
- xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0"
94
- identifier="qti3-extended-text"
95
- title="Extended Text (QTI 3.0)"
96
- adaptive="false"
97
- time-dependent="false">
98
-
99
- <qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="string"/>
100
-
101
- <qti-item-body>
102
- <p>Describe the water cycle in your own words.</p>
103
- <qti-extended-text-interaction
104
- response-identifier="RESPONSE"
105
- expected-lines="5"
106
- expected-length="500"
107
- placeholder-text="Type your answer here..."/>
108
- </qti-item-body>
109
- </qti-assessment-item>`;
110
-
111
- const QTI3_MATCH = `<?xml version="1.0" encoding="UTF-8"?>
112
- <qti-assessment-item
113
- xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0"
114
- identifier="qti3-match"
115
- title="Match Interaction (QTI 3.0)"
116
- adaptive="false"
117
- time-dependent="false">
118
-
119
- <qti-response-declaration identifier="RESPONSE" cardinality="multiple" base-type="directedPair">
120
- <qti-correct-response>
121
- <qti-value>france paris</qti-value>
122
- <qti-value>germany berlin</qti-value>
123
- </qti-correct-response>
124
- <qti-mapping default-value="0">
125
- <qti-map-entry map-key="france paris" mapped-value="1.5"/>
126
- <qti-map-entry map-key="germany berlin" mapped-value="1.5"/>
127
- </qti-mapping>
128
- </qti-response-declaration>
129
-
130
- <qti-outcome-declaration identifier="SCORE" cardinality="single" base-type="float">
131
- <qti-default-value>
132
- <qti-value>0</qti-value>
133
- </qti-default-value>
134
- </qti-outcome-declaration>
135
-
136
- <qti-item-body>
137
- <p>Match each country with its capital city:</p>
138
- <qti-match-interaction response-identifier="RESPONSE" shuffle="false" max-associations="3">
139
- <qti-prompt>Drag each capital to its country:</qti-prompt>
140
- <qti-simple-match-set>
141
- <qti-simple-associable-choice identifier="france" match-max="1">France</qti-simple-associable-choice>
142
- <qti-simple-associable-choice identifier="germany" match-max="1">Germany</qti-simple-associable-choice>
143
- </qti-simple-match-set>
144
- <qti-simple-match-set>
145
- <qti-simple-associable-choice identifier="paris" match-max="1">Paris</qti-simple-associable-choice>
146
- <qti-simple-associable-choice identifier="berlin" match-max="1">Berlin</qti-simple-associable-choice>
147
- </qti-simple-match-set>
148
- </qti-match-interaction>
149
- </qti-item-body>
150
-
151
- <qti-response-processing>
152
- <qti-response-condition>
153
- <qti-response-if>
154
- <qti-is-null>
155
- <qti-variable identifier="RESPONSE"/>
156
- </qti-is-null>
157
- <qti-set-outcome-value identifier="SCORE">
158
- <qti-base-value base-type="float">0</qti-base-value>
159
- </qti-set-outcome-value>
160
- </qti-response-if>
161
- <qti-response-else>
162
- <qti-set-outcome-value identifier="SCORE">
163
- <qti-map-response identifier="RESPONSE"/>
164
- </qti-set-outcome-value>
165
- </qti-response-else>
166
- </qti-response-condition>
167
- </qti-response-processing>
168
- </qti-assessment-item>`;
169
-
170
- describe('QTI 3.0 Extraction', () => {
171
- describe('Choice Interaction', () => {
172
- it('should extract and render QTI 3.0 choice interaction', () => {
173
- const player = new Player({ itemXml: QTI3_SIMPLE_CHOICE });
174
- const interactions = player.getInteractionData();
175
-
176
- // Verify interaction was extracted
177
- expect(interactions).toHaveLength(1);
178
- const interaction = interactions[0];
179
-
180
- expect(interaction.type).toBe('choiceInteraction'); // normalized to QTI 2.x camelCase
181
- expect(interaction.responseId).toBe('RESPONSE');
182
- expect(interaction.maxChoices).toBe(1);
183
- expect(interaction.shuffle).toBe(false);
184
- expect(interaction.choices).toHaveLength(4);
185
- expect(interaction.choices[0].identifier).toBe('ChoiceA');
186
- expect(interaction.choices[0].text).toContain('7');
187
- });
188
-
189
- it('should process responses correctly for QTI 3.0 items', () => {
190
- const player = new Player({ itemXml: QTI3_SIMPLE_CHOICE });
191
-
192
- // Set correct response
193
- player.setResponses({ RESPONSE: 'ChoiceA' });
194
- const result = player.processResponses();
195
-
196
- expect(result.score).toBe(1.0);
197
- expect(result.outcomeValues.SCORE).toBe(1.0);
198
- });
199
- });
200
-
201
- describe('Text Entry Interaction', () => {
202
- it('should extract QTI 3.0 text entry with expected-length attribute', () => {
203
- const player = new Player({ itemXml: QTI3_TEXT_ENTRY });
204
- const interactions = player.getInteractionData();
205
-
206
- expect(interactions).toHaveLength(1);
207
- const interaction = interactions[0];
208
-
209
- expect(interaction.type).toBe('textEntryInteraction'); // normalized to QTI 2.x camelCase
210
- expect(interaction.responseId).toBe('RESPONSE');
211
- expect(interaction.expectedLength).toBe(15);
212
- });
213
-
214
- it('should process text entry responses correctly', () => {
215
- const player = new Player({ itemXml: QTI3_TEXT_ENTRY });
216
-
217
- player.setResponses({ RESPONSE: 'Paris' });
218
- const result = player.processResponses();
219
-
220
- expect(result.score).toBe(1.0);
221
- });
222
- });
223
-
224
- describe('Extended Text Interaction', () => {
225
- it('should extract QTI 3.0 extended text with kebab-case attributes', () => {
226
- const player = new Player({ itemXml: QTI3_EXTENDED_TEXT });
227
- const interactions = player.getInteractionData();
228
-
229
- expect(interactions).toHaveLength(1);
230
- const interaction = interactions[0];
231
-
232
- expect(interaction.type).toBe('extendedTextInteraction'); // normalized to QTI 2.x camelCase
233
- expect(interaction.responseId).toBe('RESPONSE');
234
- expect(interaction.expectedLines).toBe(5);
235
- expect(interaction.expectedLength).toBe(500);
236
- expect(interaction.placeholderText).toBe('Type your answer here...');
237
- });
238
- });
239
-
240
- describe('Match Interaction', () => {
241
- it('should extract QTI 3.0 match interaction with kebab-case attributes', () => {
242
- const player = new Player({ itemXml: QTI3_MATCH });
243
- const interactions = player.getInteractionData();
244
-
245
- expect(interactions).toHaveLength(1);
246
- const interaction = interactions[0];
247
-
248
- expect(interaction.type).toBe('matchInteraction'); // normalized to QTI 2.x camelCase
249
- expect(interaction.responseId).toBe('RESPONSE');
250
- expect(interaction.maxAssociations).toBe(3);
251
- expect(interaction.shuffle).toBe(false);
252
- expect(interaction.sourceSet).toHaveLength(2);
253
- expect(interaction.targetSet).toHaveLength(2);
254
- expect(interaction.sourceSet[0].identifier).toBe('france');
255
- expect(interaction.targetSet[0].identifier).toBe('paris');
256
- });
257
-
258
- it('should process match interaction responses correctly', () => {
259
- const player = new Player({ itemXml: QTI3_MATCH });
260
-
261
- // Set correct response
262
- player.setResponses({ RESPONSE: ['france paris', 'germany berlin'] });
263
- const result = player.processResponses();
264
-
265
- expect(result.score).toBe(3.0);
266
- });
267
- });
268
-
269
- describe('Backward Compatibility', () => {
270
- it('should handle QTI 2.x without mappers (default behavior)', () => {
271
- const qti2xml = `<?xml version="1.0" encoding="UTF-8"?>
272
- <assessmentItem xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2"
273
- identifier="qti2-choice"
274
- title="QTI 2.x Choice"
275
- adaptive="false"
276
- timeDependent="false">
277
- <responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier">
278
- <correctResponse>
279
- <value>A</value>
280
- </correctResponse>
281
- </responseDeclaration>
282
- <outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float">
283
- <defaultValue><value>0</value></defaultValue>
284
- </outcomeDeclaration>
285
- <itemBody>
286
- <choiceInteraction responseIdentifier="RESPONSE" shuffle="true" maxChoices="1">
287
- <simpleChoice identifier="A">Choice A</simpleChoice>
288
- <simpleChoice identifier="B">Choice B</simpleChoice>
289
- </choiceInteraction>
290
- </itemBody>
291
- <responseProcessing template="http://www.imsglobal.org/question/qti_v2p2/rptemplates/match_correct"/>
292
- </assessmentItem>`;
293
-
294
- // No explicit mappers - should automatically use QTI 2.x defaults
295
- const player = new Player({ itemXml: qti2xml });
296
- const interactions = player.getInteractionData();
297
-
298
- expect(interactions).toHaveLength(1);
299
- expect(interactions[0].type).toBe('choiceInteraction');
300
- expect(interactions[0].maxChoices).toBe(1);
301
- expect(interactions[0].shuffle).toBe(true);
302
-
303
- // Verify responses work
304
- player.setResponses({ RESPONSE: 'A' });
305
- const result = player.processResponses();
306
- expect(result.score).toBe(1);
307
- });
308
- });
309
- });