@pie-qti/item-player 0.1.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.
- package/.turbo/turbo-build.log +1 -0
- package/CHANGELOG.md +9 -0
- package/README.md +466 -0
- package/docs/QTI-COMPLIANCE.md +197 -0
- package/docs/WCAG-2.2-COMPLIANCE.md +466 -0
- package/docs/custom-extractors.md +679 -0
- package/docs/iframe-mode.md +78 -0
- package/docs/security-audit.md +236 -0
- package/docs/server-api.md +691 -0
- package/package.json +78 -0
- package/src/components/ItemBody.svelte +382 -0
- package/src/components/ItemPlayer.svelte +155 -0
- package/src/components/ModalFeedbackDisplay.svelte +87 -0
- package/src/components/actions/typesetAction.ts +74 -0
- package/src/components/index.ts +19 -0
- package/src/components/utils/assignProps.ts +24 -0
- package/src/components/utils/feedbackUtils.ts +140 -0
- package/src/components/utils/index.ts +13 -0
- package/src/core/ComponentRegistry.ts +219 -0
- package/src/core/ItemRenderer.ts +367 -0
- package/src/core/Player.ts +1152 -0
- package/src/core/Plugin.ts +123 -0
- package/src/core/PluginManager.ts +182 -0
- package/src/core/constants.ts +117 -0
- package/src/core/declarations.ts +171 -0
- package/src/core/parsingLimits.ts +62 -0
- package/src/core/random.ts +24 -0
- package/src/core/sanitizer.ts +235 -0
- package/src/core/trustedTypes.ts +63 -0
- package/src/core/urlPolicy.ts +95 -0
- package/src/extensions/MathLiveEditor.ts +310 -0
- package/src/extraction/ExtractionRegistry.ts +295 -0
- package/src/extraction/createContext.ts +47 -0
- package/src/extraction/extractors/associateExtractor.ts +129 -0
- package/src/extraction/extractors/choiceExtractor.ts +110 -0
- package/src/extraction/extractors/customExtractor.ts +72 -0
- package/src/extraction/extractors/drawingExtractor.ts +113 -0
- package/src/extraction/extractors/endAttemptExtractor.ts +74 -0
- package/src/extraction/extractors/extendedTextExtractor.ts +80 -0
- package/src/extraction/extractors/gapMatchExtractor.ts +178 -0
- package/src/extraction/extractors/graphicAssociateExtractor.ts +188 -0
- package/src/extraction/extractors/graphicGapMatchExtractor.ts +185 -0
- package/src/extraction/extractors/graphicOrderExtractor.ts +162 -0
- package/src/extraction/extractors/hotspotExtractor.ts +190 -0
- package/src/extraction/extractors/hottextExtractor.ts +153 -0
- package/src/extraction/extractors/index.ts +111 -0
- package/src/extraction/extractors/inlineChoiceExtractor.ts +88 -0
- package/src/extraction/extractors/matchExtractor.ts +160 -0
- package/src/extraction/extractors/mediaExtractor.ts +168 -0
- package/src/extraction/extractors/orderExtractor.ts +114 -0
- package/src/extraction/extractors/positionObjectExtractor.ts +243 -0
- package/src/extraction/extractors/selectPointExtractor.ts +143 -0
- package/src/extraction/extractors/sliderExtractor.ts +102 -0
- package/src/extraction/extractors/textEntryExtractor.ts +70 -0
- package/src/extraction/extractors/uploadExtractor.ts +73 -0
- package/src/extraction/index.ts +109 -0
- package/src/extraction/types.ts +246 -0
- package/src/extraction/utils.ts +160 -0
- package/src/iframe/IFramePlayerHost.ts +265 -0
- package/src/iframe/index.ts +11 -0
- package/src/iframe/protocol.ts +137 -0
- package/src/index.ts +87 -0
- package/src/server.ts +14 -0
- package/src/types/index.ts +301 -0
- package/src/types/interactions.ts +354 -0
- package/src/types/responseValidation.ts +29 -0
- package/src/utils/PerformanceMonitor.ts +335 -0
- package/src/utils/responseUtils.ts +51 -0
- package/src/utils/touchDragHelper.ts +211 -0
- package/src/web-components/QTIInteractionBase.ts +302 -0
- package/src/web-components/QTIInteractionElement.ts +118 -0
- package/src/web-components/index.ts +21 -0
- package/tests/conformance/FIXTURE_POLICY.md +29 -0
- package/tests/conformance/README.md +70 -0
- package/tests/conformance/fixtures/baseTypes_all/cases.json +61 -0
- package/tests/conformance/fixtures/baseTypes_all/item.xml +131 -0
- package/tests/conformance/fixtures/baseTypes_all/manifest.json +7 -0
- package/tests/conformance/fixtures/choice_match_correct/cases.json +17 -0
- package/tests/conformance/fixtures/choice_match_correct/item.xml +55 -0
- package/tests/conformance/fixtures/choice_match_correct/manifest.json +14 -0
- package/tests/conformance/fixtures/contains_multiple/cases.json +12 -0
- package/tests/conformance/fixtures/contains_multiple/item.xml +37 -0
- package/tests/conformance/fixtures/contains_multiple/manifest.json +13 -0
- package/tests/conformance/fixtures/isNull_isNotNull/cases.json +9 -0
- package/tests/conformance/fixtures/isNull_isNotNull/item.xml +41 -0
- package/tests/conformance/fixtures/isNull_isNotNull/manifest.json +23 -0
- package/tests/conformance/fixtures/mapResponse_bounds_default_duplicates/cases.json +27 -0
- package/tests/conformance/fixtures/mapResponse_bounds_default_duplicates/item.xml +30 -0
- package/tests/conformance/fixtures/mapResponse_bounds_default_duplicates/manifest.json +15 -0
- package/tests/conformance/fixtures/mapResponse_integer_mapKey/cases.json +11 -0
- package/tests/conformance/fixtures/mapResponse_integer_mapKey/item.xml +26 -0
- package/tests/conformance/fixtures/mapResponse_integer_mapKey/manifest.json +13 -0
- package/tests/conformance/fixtures/mapResponse_mapEntry_caseSensitive_override/cases.json +27 -0
- package/tests/conformance/fixtures/mapResponse_mapEntry_caseSensitive_override/item.xml +32 -0
- package/tests/conformance/fixtures/mapResponse_mapEntry_caseSensitive_override/manifest.json +7 -0
- package/tests/conformance/fixtures/mapResponse_mapping_caseSensitive_defaultValue/cases.json +9 -0
- package/tests/conformance/fixtures/mapResponse_mapping_caseSensitive_defaultValue/item.xml +25 -0
- package/tests/conformance/fixtures/mapResponse_mapping_caseSensitive_defaultValue/manifest.json +12 -0
- package/tests/conformance/fixtures/mapResponse_multiple_cardinality/cases.json +12 -0
- package/tests/conformance/fixtures/mapResponse_multiple_cardinality/item.xml +35 -0
- package/tests/conformance/fixtures/mapResponse_multiple_cardinality/manifest.json +11 -0
- package/tests/conformance/fixtures/mapping_bounds_upperLower/cases.json +12 -0
- package/tests/conformance/fixtures/mapping_bounds_upperLower/item.xml +37 -0
- package/tests/conformance/fixtures/mapping_bounds_upperLower/manifest.json +11 -0
- package/tests/conformance/fixtures/mapping_mapResponse/cases.json +22 -0
- package/tests/conformance/fixtures/mapping_mapResponse/item.xml +53 -0
- package/tests/conformance/fixtures/mapping_mapResponse/manifest.json +16 -0
- package/tests/conformance/fixtures/member_multiple/cases.json +12 -0
- package/tests/conformance/fixtures/member_multiple/item.xml +37 -0
- package/tests/conformance/fixtures/member_multiple/manifest.json +13 -0
- package/tests/conformance/fixtures/modalFeedback_basic/cases.json +17 -0
- package/tests/conformance/fixtures/modalFeedback_basic/item.xml +52 -0
- package/tests/conformance/fixtures/modalFeedback_basic/manifest.json +13 -0
- package/tests/conformance/fixtures/multiple_unordered_match/cases.json +17 -0
- package/tests/conformance/fixtures/multiple_unordered_match/item.xml +44 -0
- package/tests/conformance/fixtures/multiple_unordered_match/manifest.json +11 -0
- package/tests/conformance/fixtures/ordered_match/cases.json +17 -0
- package/tests/conformance/fixtures/ordered_match/item.xml +48 -0
- package/tests/conformance/fixtures/ordered_match/manifest.json +13 -0
- package/tests/conformance/fixtures/outcomeProcessing_derive_percent_passfail/cases.json +27 -0
- package/tests/conformance/fixtures/outcomeProcessing_derive_percent_passfail/item.xml +103 -0
- package/tests/conformance/fixtures/outcomeProcessing_derive_percent_passfail/manifest.json +7 -0
- package/tests/conformance/fixtures/outcomeProcessing_exitTest/cases.json +15 -0
- package/tests/conformance/fixtures/outcomeProcessing_exitTest/item.xml +33 -0
- package/tests/conformance/fixtures/outcomeProcessing_exitTest/manifest.json +10 -0
- package/tests/conformance/fixtures/outcomeProcessing_numberExpressions/cases.json +14 -0
- package/tests/conformance/fixtures/outcomeProcessing_numberExpressions/item.xml +26 -0
- package/tests/conformance/fixtures/outcomeProcessing_numberExpressions/manifest.json +8 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_equal/cases.json +17 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_equal/item.xml +43 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_equal/manifest.json +16 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_toBoolean/cases.json +27 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_toBoolean/item.xml +37 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_toBoolean/manifest.json +16 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeMaximum/cases.json +14 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeMaximum/item.xml +35 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeMaximum/manifest.json +8 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeMinimum/cases.json +14 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeMinimum/item.xml +35 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeMinimum/manifest.json +8 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeProcessingFragment/cases.json +15 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeProcessingFragment/item.xml +39 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeProcessingFragment/manifest.json +11 -0
- package/tests/conformance/fixtures/outcomeProcessing_testVariables/cases.json +14 -0
- package/tests/conformance/fixtures/outcomeProcessing_testVariables/item.xml +35 -0
- package/tests/conformance/fixtures/outcomeProcessing_testVariables/manifest.json +8 -0
- package/tests/conformance/fixtures/pair_unordered_match/cases.json +22 -0
- package/tests/conformance/fixtures/pair_unordered_match/item.xml +44 -0
- package/tests/conformance/fixtures/pair_unordered_match/manifest.json +13 -0
- package/tests/conformance/fixtures/positionObject_coordinateSystem_aspectRatio/cases.json +95 -0
- package/tests/conformance/fixtures/positionObject_coordinateSystem_aspectRatio/item.xml +53 -0
- package/tests/conformance/fixtures/positionObject_mapResponsePoint_scoring/cases.json +115 -0
- package/tests/conformance/fixtures/positionObject_mapResponsePoint_scoring/item.xml +45 -0
- package/tests/conformance/fixtures/positionObject_mapResponse_wrong/cases.json +29 -0
- package/tests/conformance/fixtures/positionObject_mapResponse_wrong/item.xml +40 -0
- package/tests/conformance/fixtures/responseCondition_elseIf_chain/cases.json +10 -0
- package/tests/conformance/fixtures/responseCondition_elseIf_chain/item.xml +49 -0
- package/tests/conformance/fixtures/responseCondition_elseIf_chain/manifest.json +15 -0
- package/tests/conformance/fixtures/responseProcessing_anyN/cases.json +27 -0
- package/tests/conformance/fixtures/responseProcessing_anyN/item.xml +47 -0
- package/tests/conformance/fixtures/responseProcessing_anyN/manifest.json +16 -0
- package/tests/conformance/fixtures/responseProcessing_anyN_allN/cases.json +27 -0
- package/tests/conformance/fixtures/responseProcessing_anyN_allN/item.xml +69 -0
- package/tests/conformance/fixtures/responseProcessing_anyN_allN/manifest.json +23 -0
- package/tests/conformance/fixtures/responseProcessing_arithmetic_nulls/cases.json +15 -0
- package/tests/conformance/fixtures/responseProcessing_arithmetic_nulls/item.xml +58 -0
- package/tests/conformance/fixtures/responseProcessing_arithmetic_nulls/manifest.json +15 -0
- package/tests/conformance/fixtures/responseProcessing_boolean_compare_ops/cases.json +37 -0
- package/tests/conformance/fixtures/responseProcessing_boolean_compare_ops/item.xml +94 -0
- package/tests/conformance/fixtures/responseProcessing_boolean_compare_ops/manifest.json +27 -0
- package/tests/conformance/fixtures/responseProcessing_containerSize_index/cases.json +33 -0
- package/tests/conformance/fixtures/responseProcessing_containerSize_index/item.xml +79 -0
- package/tests/conformance/fixtures/responseProcessing_containerSize_index/manifest.json +16 -0
- package/tests/conformance/fixtures/responseProcessing_customOperator/cases.json +15 -0
- package/tests/conformance/fixtures/responseProcessing_customOperator/item.xml +30 -0
- package/tests/conformance/fixtures/responseProcessing_customOperator/manifest.json +12 -0
- package/tests/conformance/fixtures/responseProcessing_default_expression/cases.json +12 -0
- package/tests/conformance/fixtures/responseProcessing_default_expression/item.xml +48 -0
- package/tests/conformance/fixtures/responseProcessing_default_expression/manifest.json +13 -0
- package/tests/conformance/fixtures/responseProcessing_deleteValue_repeat/cases.json +29 -0
- package/tests/conformance/fixtures/responseProcessing_deleteValue_repeat/item.xml +68 -0
- package/tests/conformance/fixtures/responseProcessing_deleteValue_repeat/manifest.json +17 -0
- package/tests/conformance/fixtures/responseProcessing_equalRounded_tolerance/cases.json +39 -0
- package/tests/conformance/fixtures/responseProcessing_equalRounded_tolerance/item.xml +39 -0
- package/tests/conformance/fixtures/responseProcessing_equalRounded_tolerance/manifest.json +17 -0
- package/tests/conformance/fixtures/responseProcessing_exitResponse/cases.json +12 -0
- package/tests/conformance/fixtures/responseProcessing_exitResponse/item.xml +25 -0
- package/tests/conformance/fixtures/responseProcessing_exitResponse/manifest.json +12 -0
- package/tests/conformance/fixtures/responseProcessing_inside_duration_statsOperator/cases.json +26 -0
- package/tests/conformance/fixtures/responseProcessing_inside_duration_statsOperator/item.xml +134 -0
- package/tests/conformance/fixtures/responseProcessing_inside_duration_statsOperator/manifest.json +16 -0
- package/tests/conformance/fixtures/responseProcessing_lookupTable_interpolationTable/cases.json +27 -0
- package/tests/conformance/fixtures/responseProcessing_lookupTable_interpolationTable/item.xml +33 -0
- package/tests/conformance/fixtures/responseProcessing_lookupTable_interpolationTable/manifest.json +13 -0
- package/tests/conformance/fixtures/responseProcessing_lookupTable_matchTable/cases.json +22 -0
- package/tests/conformance/fixtures/responseProcessing_lookupTable_matchTable/item.xml +33 -0
- package/tests/conformance/fixtures/responseProcessing_lookupTable_matchTable/manifest.json +13 -0
- package/tests/conformance/fixtures/responseProcessing_mapOutcome_basic/cases.json +27 -0
- package/tests/conformance/fixtures/responseProcessing_mapOutcome_basic/item.xml +40 -0
- package/tests/conformance/fixtures/responseProcessing_mapOutcome_basic/manifest.json +18 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponsePoint_basic/cases.json +22 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponsePoint_basic/item.xml +33 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponsePoint_basic/manifest.json +12 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_ordered/cases.json +29 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_ordered/item.xml +26 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_ordered/manifest.json +7 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_whitespace/cases.json +23 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_whitespace/item.xml +28 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_whitespace/manifest.json +11 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponse_pair_unordered/cases.json +29 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponse_pair_unordered/item.xml +26 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponse_pair_unordered/manifest.json +7 -0
- package/tests/conformance/fixtures/responseProcessing_mathOperator_integerUtils/cases.json +31 -0
- package/tests/conformance/fixtures/responseProcessing_mathOperator_integerUtils/item.xml +102 -0
- package/tests/conformance/fixtures/responseProcessing_mathOperator_integerUtils/manifest.json +18 -0
- package/tests/conformance/fixtures/responseProcessing_math_max_min_round_truncate/cases.json +22 -0
- package/tests/conformance/fixtures/responseProcessing_math_max_min_round_truncate/item.xml +45 -0
- package/tests/conformance/fixtures/responseProcessing_math_max_min_round_truncate/manifest.json +21 -0
- package/tests/conformance/fixtures/responseProcessing_misc_math_string_stats/cases.json +26 -0
- package/tests/conformance/fixtures/responseProcessing_misc_math_string_stats/item.xml +157 -0
- package/tests/conformance/fixtures/responseProcessing_misc_math_string_stats/manifest.json +22 -0
- package/tests/conformance/fixtures/responseProcessing_notEqual_basic/cases.json +22 -0
- package/tests/conformance/fixtures/responseProcessing_notEqual_basic/item.xml +39 -0
- package/tests/conformance/fixtures/responseProcessing_notEqual_basic/manifest.json +18 -0
- package/tests/conformance/fixtures/responseProcessing_patternMatch_caseSensitive/cases.json +22 -0
- package/tests/conformance/fixtures/responseProcessing_patternMatch_caseSensitive/item.xml +51 -0
- package/tests/conformance/fixtures/responseProcessing_patternMatch_caseSensitive/manifest.json +19 -0
- package/tests/conformance/fixtures/responseProcessing_preCondition/cases.json +31 -0
- package/tests/conformance/fixtures/responseProcessing_preCondition/item.xml +44 -0
- package/tests/conformance/fixtures/responseProcessing_preCondition/manifest.json +12 -0
- package/tests/conformance/fixtures/responseProcessing_random_lookupOutcomeValue/cases.json +27 -0
- package/tests/conformance/fixtures/responseProcessing_random_lookupOutcomeValue/item.xml +42 -0
- package/tests/conformance/fixtures/responseProcessing_random_lookupOutcomeValue/manifest.json +14 -0
- package/tests/conformance/fixtures/responseProcessing_record_fieldValue/cases.json +12 -0
- package/tests/conformance/fixtures/responseProcessing_record_fieldValue/item.xml +40 -0
- package/tests/conformance/fixtures/responseProcessing_record_fieldValue/manifest.json +17 -0
- package/tests/conformance/fixtures/responseProcessing_responseCondition_toBoolean/cases.json +17 -0
- package/tests/conformance/fixtures/responseProcessing_responseCondition_toBoolean/item.xml +63 -0
- package/tests/conformance/fixtures/responseProcessing_responseCondition_toBoolean/manifest.json +9 -0
- package/tests/conformance/fixtures/responseProcessing_responseProcessingFragment/cases.json +12 -0
- package/tests/conformance/fixtures/responseProcessing_responseProcessingFragment/item.xml +40 -0
- package/tests/conformance/fixtures/responseProcessing_responseProcessingFragment/manifest.json +13 -0
- package/tests/conformance/fixtures/responseProcessing_setDefaultValue/cases.json +15 -0
- package/tests/conformance/fixtures/responseProcessing_setDefaultValue/item.xml +67 -0
- package/tests/conformance/fixtures/responseProcessing_setDefaultValue/manifest.json +9 -0
- package/tests/conformance/fixtures/responseProcessing_setResponseValue_setDefaultValue/cases.json +27 -0
- package/tests/conformance/fixtures/responseProcessing_setResponseValue_setDefaultValue/item.xml +69 -0
- package/tests/conformance/fixtures/responseProcessing_setResponseValue_setDefaultValue/manifest.json +10 -0
- package/tests/conformance/fixtures/responseProcessing_subtract_divide/cases.json +15 -0
- package/tests/conformance/fixtures/responseProcessing_subtract_divide/item.xml +35 -0
- package/tests/conformance/fixtures/responseProcessing_subtract_divide/manifest.json +11 -0
- package/tests/conformance/fixtures/responseProcessing_template_map_response/cases.json +17 -0
- package/tests/conformance/fixtures/responseProcessing_template_map_response/item.xml +31 -0
- package/tests/conformance/fixtures/responseProcessing_template_map_response/manifest.json +8 -0
- package/tests/conformance/fixtures/responseProcessing_template_map_response_point/cases.json +22 -0
- package/tests/conformance/fixtures/responseProcessing_template_map_response_point/item.xml +27 -0
- package/tests/conformance/fixtures/responseProcessing_template_map_response_point/manifest.json +8 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_correct/cases.json +17 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_correct/item.xml +34 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_correct/manifest.json +8 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_correct_directedPair/cases.json +22 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_correct_directedPair/item.xml +30 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_correct_directedPair/manifest.json +7 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_correct_two_responses/cases.json +17 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_correct_two_responses/item.xml +30 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_correct_two_responses/manifest.json +9 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_nothing/cases.json +17 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_nothing/item.xml +30 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_nothing/manifest.json +8 -0
- package/tests/conformance/fixtures/responseProcessing_xiInclude/cases.json +14 -0
- package/tests/conformance/fixtures/responseProcessing_xiInclude/item.xml +25 -0
- package/tests/conformance/fixtures/responseProcessing_xiInclude/manifest.json +9 -0
- package/tests/conformance/fixtures/stringMatch_caseSensitive_substring/cases.json +12 -0
- package/tests/conformance/fixtures/stringMatch_caseSensitive_substring/item.xml +52 -0
- package/tests/conformance/fixtures/stringMatch_caseSensitive_substring/manifest.json +14 -0
- package/tests/conformance/fixtures/templateProcessing_exitTemplate/cases.json +12 -0
- package/tests/conformance/fixtures/templateProcessing_exitTemplate/item.xml +48 -0
- package/tests/conformance/fixtures/templateProcessing_exitTemplate/manifest.json +13 -0
- package/tests/conformance/fixtures/templateProcessing_setCorrectResponse/cases.json +27 -0
- package/tests/conformance/fixtures/templateProcessing_setCorrectResponse/item.xml +74 -0
- package/tests/conformance/fixtures/templateProcessing_setCorrectResponse/manifest.json +22 -0
- package/tests/conformance/fixtures/templateProcessing_templateCondition_branching/cases.json +17 -0
- package/tests/conformance/fixtures/templateProcessing_templateCondition_branching/item.xml +133 -0
- package/tests/conformance/fixtures/templateProcessing_templateCondition_branching/manifest.json +22 -0
- package/tests/conformance/fixtures/templateProcessing_templateCondition_toBoolean/cases.json +12 -0
- package/tests/conformance/fixtures/templateProcessing_templateCondition_toBoolean/item.xml +107 -0
- package/tests/conformance/fixtures/templateProcessing_templateCondition_toBoolean/manifest.json +16 -0
- package/tests/conformance/fixtures/templateProcessing_templateConstraint/cases.json +15 -0
- package/tests/conformance/fixtures/templateProcessing_templateConstraint/item.xml +52 -0
- package/tests/conformance/fixtures/templateProcessing_templateConstraint/manifest.json +14 -0
- package/tests/conformance/fixtures/template_randomFloat_roundTo_mathConstant/cases.json +16 -0
- package/tests/conformance/fixtures/template_randomFloat_roundTo_mathConstant/item.xml +49 -0
- package/tests/conformance/fixtures/template_randomFloat_roundTo_mathConstant/manifest.json +15 -0
- package/tests/conformance/fixtures/template_randomInteger_printedVariable/cases.json +16 -0
- package/tests/conformance/fixtures/template_randomInteger_printedVariable/item.xml +38 -0
- package/tests/conformance/fixtures/template_randomInteger_printedVariable/manifest.json +13 -0
- package/tests/conformance/harness.ts +84 -0
- package/tests/conformance/run-fixtures.test.ts +127 -0
- package/tests/conformance/scripts/normalize-covers.ts +152 -0
- package/tests/conformance/types.ts +53 -0
- package/tests/core/Player.test.ts +563 -0
- package/tests/core/adaptiveItems.test.ts +442 -0
- package/tests/core/correctResponse.test.ts +280 -0
- package/tests/core/interaction-plumbing.test.ts +141 -0
- package/tests/core/modalFeedback.test.ts +308 -0
- package/tests/core/outcome-reset.test.ts +43 -0
- package/tests/extraction/extractors/associateExtractor.test.ts +182 -0
- package/tests/extraction/extractors/choiceExtractor.test.ts +239 -0
- package/tests/extraction/extractors/customExtractor.test.ts +83 -0
- package/tests/extraction/extractors/drawingExtractor.test.ts +94 -0
- package/tests/extraction/extractors/endAttemptExtractor.test.ts +188 -0
- package/tests/extraction/extractors/extendedTextExtractor.test.ts +178 -0
- package/tests/extraction/extractors/gapMatchExtractor.test.ts +318 -0
- package/tests/extraction/extractors/graphicAssociateExtractor.test.ts +260 -0
- package/tests/extraction/extractors/graphicGapMatchExtractor.test.ts +320 -0
- package/tests/extraction/extractors/graphicOrderExtractor.test.ts +223 -0
- package/tests/extraction/extractors/hotspotExtractor.test.ts +298 -0
- package/tests/extraction/extractors/hottextExtractor.test.ts +240 -0
- package/tests/extraction/extractors/inlineChoiceExtractor.test.ts +292 -0
- package/tests/extraction/extractors/matchExtractor.test.ts +241 -0
- package/tests/extraction/extractors/mediaExtractor.test.ts +295 -0
- package/tests/extraction/extractors/orderExtractor.test.ts +212 -0
- package/tests/extraction/extractors/positionObjectExtractor.test.ts +363 -0
- package/tests/extraction/extractors/selectPointExtractor.test.ts +214 -0
- package/tests/extraction/extractors/sliderExtractor.test.ts +293 -0
- package/tests/extraction/extractors/textEntryExtractor.test.ts +133 -0
- package/tests/extraction/extractors/uploadExtractor.test.ts +119 -0
- package/tests/extraction/test-utils.ts +57 -0
- package/tests/iframe/host.test.ts +145 -0
- package/tests/iframe/protocol.test.ts +42 -0
- package/tests/performance/player-benchmarks.bench.ts +191 -0
- package/tests/security/dos-limits.test.ts +56 -0
- package/tests/security/xss-prevention.test.ts +522 -0
- package/tsconfig.json +20 -0
- package/tsconfig.svelte.json +14 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for standardGraphicOrderExtractor
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, expect, test } from 'bun:test';
|
|
6
|
+
import { standardGraphicOrderExtractor } from '../../../src/extraction/extractors/graphicOrderExtractor.js';
|
|
7
|
+
import { createTestContext, parseQTI } from '../test-utils.js';
|
|
8
|
+
|
|
9
|
+
describe('standardGraphicOrderExtractor', () => {
|
|
10
|
+
test('extracts graphicOrderInteraction with image', () => {
|
|
11
|
+
const xml = `
|
|
12
|
+
<graphicOrderInteraction responseIdentifier="RESPONSE">
|
|
13
|
+
<prompt>Order the layers from bottom to top</prompt>
|
|
14
|
+
<object data="layers.png" type="image/png" width="400" height="300"/>
|
|
15
|
+
<hotspotChoice identifier="A" shape="rect" coords="50,50,150,100">Layer A</hotspotChoice>
|
|
16
|
+
<hotspotChoice identifier="B" shape="rect" coords="50,150,150,200">Layer B</hotspotChoice>
|
|
17
|
+
</graphicOrderInteraction>
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
const element = parseQTI(xml);
|
|
21
|
+
const context = createTestContext(element, 'RESPONSE');
|
|
22
|
+
|
|
23
|
+
const result = standardGraphicOrderExtractor.extract(element, context);
|
|
24
|
+
|
|
25
|
+
expect(result.prompt).toBe('Order the layers from bottom to top');
|
|
26
|
+
expect(result.imageData?.type).toBe('image');
|
|
27
|
+
expect(result.imageData?.src).toBe('layers.png');
|
|
28
|
+
expect(result.imageData?.width).toBe('400');
|
|
29
|
+
expect(result.imageData?.height).toBe('300');
|
|
30
|
+
expect(result.hotspotChoices).toHaveLength(2);
|
|
31
|
+
expect(result.hotspotChoices[0].identifier).toBe('A');
|
|
32
|
+
expect(result.hotspotChoices[0].label).toBe('Layer A');
|
|
33
|
+
expect(result.hotspotChoices[0].shape).toBe('rect');
|
|
34
|
+
expect(result.hotspotChoices[0].coords).toBe('50,50,150,100');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('extracts graphicOrderInteraction with SVG', () => {
|
|
38
|
+
const xml = `
|
|
39
|
+
<graphicOrderInteraction responseIdentifier="RESPONSE">
|
|
40
|
+
<prompt>Order the elements</prompt>
|
|
41
|
+
<object type="image/svg+xml" width="500" height="400">
|
|
42
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 400">
|
|
43
|
+
<rect width="500" height="400" fill="#eee"/>
|
|
44
|
+
</svg>
|
|
45
|
+
</object>
|
|
46
|
+
<hotspotChoice identifier="X" shape="circle" coords="100,100,30">Item X</hotspotChoice>
|
|
47
|
+
</graphicOrderInteraction>
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
const element = parseQTI(xml);
|
|
51
|
+
const context = createTestContext(element, 'RESPONSE');
|
|
52
|
+
|
|
53
|
+
const result = standardGraphicOrderExtractor.extract(element, context);
|
|
54
|
+
|
|
55
|
+
expect(result.imageData?.type).toBe('svg');
|
|
56
|
+
expect(result.imageData?.content).toContain('<svg');
|
|
57
|
+
expect(result.imageData?.width).toBe('500');
|
|
58
|
+
expect(result.imageData?.height).toBe('400');
|
|
59
|
+
expect(result.hotspotChoices).toHaveLength(1);
|
|
60
|
+
expect(result.hotspotChoices[0].identifier).toBe('X');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('handles multiple hotspot choices', () => {
|
|
64
|
+
const xml = `
|
|
65
|
+
<graphicOrderInteraction responseIdentifier="RESPONSE">
|
|
66
|
+
<object data="diagram.png" type="image/png" width="600" height="400"/>
|
|
67
|
+
<hotspotChoice identifier="FIRST" shape="rect" coords="0,0,100,100">First</hotspotChoice>
|
|
68
|
+
<hotspotChoice identifier="SECOND" shape="rect" coords="100,0,200,100">Second</hotspotChoice>
|
|
69
|
+
<hotspotChoice identifier="THIRD" shape="rect" coords="200,0,300,100">Third</hotspotChoice>
|
|
70
|
+
<hotspotChoice identifier="FOURTH" shape="rect" coords="300,0,400,100">Fourth</hotspotChoice>
|
|
71
|
+
</graphicOrderInteraction>
|
|
72
|
+
`;
|
|
73
|
+
|
|
74
|
+
const element = parseQTI(xml);
|
|
75
|
+
const context = createTestContext(element, 'RESPONSE');
|
|
76
|
+
|
|
77
|
+
const result = standardGraphicOrderExtractor.extract(element, context);
|
|
78
|
+
|
|
79
|
+
expect(result.hotspotChoices).toHaveLength(4);
|
|
80
|
+
expect(result.hotspotChoices.map((c) => c.identifier)).toEqual([
|
|
81
|
+
'FIRST',
|
|
82
|
+
'SECOND',
|
|
83
|
+
'THIRD',
|
|
84
|
+
'FOURTH',
|
|
85
|
+
]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('uses default values when attributes are missing', () => {
|
|
89
|
+
const xml = `
|
|
90
|
+
<graphicOrderInteraction responseIdentifier="RESPONSE">
|
|
91
|
+
<object data="test.png" type="image/png"/>
|
|
92
|
+
<hotspotChoice identifier="A">Choice A</hotspotChoice>
|
|
93
|
+
</graphicOrderInteraction>
|
|
94
|
+
`;
|
|
95
|
+
|
|
96
|
+
const element = parseQTI(xml);
|
|
97
|
+
const context = createTestContext(element, 'RESPONSE');
|
|
98
|
+
|
|
99
|
+
const result = standardGraphicOrderExtractor.extract(element, context);
|
|
100
|
+
|
|
101
|
+
expect(result.imageData?.width).toBe('500');
|
|
102
|
+
expect(result.imageData?.height).toBe('300');
|
|
103
|
+
expect(result.hotspotChoices[0].shape).toBe('rect');
|
|
104
|
+
expect(result.hotspotChoices[0].coords).toBe('0,0,50,50');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('uses identifier as label if text content is empty', () => {
|
|
108
|
+
const xml = `
|
|
109
|
+
<graphicOrderInteraction responseIdentifier="RESPONSE">
|
|
110
|
+
<object data="test.png" type="image/png"/>
|
|
111
|
+
<hotspotChoice identifier="ITEM_A" shape="rect" coords="0,0,50,50"/>
|
|
112
|
+
</graphicOrderInteraction>
|
|
113
|
+
`;
|
|
114
|
+
|
|
115
|
+
const element = parseQTI(xml);
|
|
116
|
+
const context = createTestContext(element, 'RESPONSE');
|
|
117
|
+
|
|
118
|
+
const result = standardGraphicOrderExtractor.extract(element, context);
|
|
119
|
+
|
|
120
|
+
expect(result.hotspotChoices[0].label).toBe('ITEM_A');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('handles missing prompt', () => {
|
|
124
|
+
const xml = `
|
|
125
|
+
<graphicOrderInteraction responseIdentifier="RESPONSE">
|
|
126
|
+
<object data="test.png" type="image/png"/>
|
|
127
|
+
<hotspotChoice identifier="A">Choice A</hotspotChoice>
|
|
128
|
+
</graphicOrderInteraction>
|
|
129
|
+
`;
|
|
130
|
+
|
|
131
|
+
const element = parseQTI(xml);
|
|
132
|
+
const context = createTestContext(element, 'RESPONSE');
|
|
133
|
+
|
|
134
|
+
const result = standardGraphicOrderExtractor.extract(element, context);
|
|
135
|
+
|
|
136
|
+
expect(result.prompt).toBeNull();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe('canHandle predicate', () => {
|
|
140
|
+
test('handles graphicOrderInteraction element', () => {
|
|
141
|
+
const xml = `
|
|
142
|
+
<graphicOrderInteraction responseIdentifier="RESPONSE">
|
|
143
|
+
<hotspotChoice identifier="A">A</hotspotChoice>
|
|
144
|
+
</graphicOrderInteraction>
|
|
145
|
+
`;
|
|
146
|
+
const element = parseQTI(xml);
|
|
147
|
+
const context = createTestContext(element);
|
|
148
|
+
|
|
149
|
+
expect(standardGraphicOrderExtractor.canHandle(element, context)).toBe(true);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('rejects non-graphicOrderInteraction elements', () => {
|
|
153
|
+
const xml = `<orderInteraction responseIdentifier="RESPONSE" />`;
|
|
154
|
+
const element = parseQTI(xml);
|
|
155
|
+
const context = createTestContext(element);
|
|
156
|
+
|
|
157
|
+
expect(standardGraphicOrderExtractor.canHandle(element, context)).toBe(false);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
describe('validation', () => {
|
|
162
|
+
test('validates correct graphicOrder data', () => {
|
|
163
|
+
const data = {
|
|
164
|
+
hotspotChoices: [
|
|
165
|
+
{ identifier: 'A', label: 'A', shape: 'rect', coords: '0,0,100,100' },
|
|
166
|
+
{ identifier: 'B', label: 'B', shape: 'rect', coords: '100,0,200,100' },
|
|
167
|
+
],
|
|
168
|
+
imageData: { type: 'image', src: 'test.png', width: '500', height: '400' },
|
|
169
|
+
prompt: null,
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const validation = standardGraphicOrderExtractor.validate!(data);
|
|
173
|
+
|
|
174
|
+
expect(validation.valid).toBe(true);
|
|
175
|
+
expect(validation.errors).toBeUndefined();
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('reports error for insufficient hotspots', () => {
|
|
179
|
+
const data = {
|
|
180
|
+
hotspotChoices: [{ identifier: 'A', label: 'A', shape: 'rect', coords: '0,0,100,100' }],
|
|
181
|
+
imageData: { type: 'image', src: 'test.png', width: '500', height: '400' },
|
|
182
|
+
prompt: null,
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const validation = standardGraphicOrderExtractor.validate!(data);
|
|
186
|
+
|
|
187
|
+
expect(validation.valid).toBe(false);
|
|
188
|
+
expect(validation.errors).toContain('graphicOrderInteraction must have at least 2 hotspots');
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('reports error for duplicate identifiers', () => {
|
|
192
|
+
const data = {
|
|
193
|
+
hotspotChoices: [
|
|
194
|
+
{ identifier: 'A', label: 'A', shape: 'rect', coords: '0,0,100,100' },
|
|
195
|
+
{ identifier: 'A', label: 'B', shape: 'rect', coords: '100,0,200,100' },
|
|
196
|
+
],
|
|
197
|
+
imageData: { type: 'image', src: 'test.png', width: '500', height: '400' },
|
|
198
|
+
prompt: null,
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const validation = standardGraphicOrderExtractor.validate!(data);
|
|
202
|
+
|
|
203
|
+
expect(validation.valid).toBe(false);
|
|
204
|
+
expect(validation.errors).toContain('Duplicate hotspot identifier: A');
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test('reports warning for missing image data', () => {
|
|
208
|
+
const data = {
|
|
209
|
+
hotspotChoices: [
|
|
210
|
+
{ identifier: 'A', label: 'A', shape: 'rect', coords: '0,0,100,100' },
|
|
211
|
+
{ identifier: 'B', label: 'B', shape: 'rect', coords: '100,0,200,100' },
|
|
212
|
+
],
|
|
213
|
+
imageData: null,
|
|
214
|
+
prompt: null,
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const validation = standardGraphicOrderExtractor.validate!(data);
|
|
218
|
+
|
|
219
|
+
expect(validation.valid).toBe(true);
|
|
220
|
+
expect(validation.warnings).toContain('graphicOrderInteraction has no image data');
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
});
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for standardHotspotExtractor
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, expect, test } from 'bun:test';
|
|
6
|
+
import { standardHotspotExtractor } from '../../../src/extraction/extractors/hotspotExtractor.js';
|
|
7
|
+
import { createTestContext, parseQTI } from '../test-utils.js';
|
|
8
|
+
|
|
9
|
+
describe('standardHotspotExtractor', () => {
|
|
10
|
+
test('extracts basic hotspot interaction with image', () => {
|
|
11
|
+
const xml = `
|
|
12
|
+
<hotspotInteraction responseIdentifier="RESPONSE" maxChoices="1">
|
|
13
|
+
<prompt>Click on the correct area</prompt>
|
|
14
|
+
<object type="image/png" data="image.png" width="400" height="300" />
|
|
15
|
+
<hotspotChoice identifier="H1" shape="rect" coords="10,10,100,100" />
|
|
16
|
+
<hotspotChoice identifier="H2" shape="circle" coords="200,150,50" />
|
|
17
|
+
</hotspotInteraction>
|
|
18
|
+
`;
|
|
19
|
+
const element = parseQTI(xml);
|
|
20
|
+
const context = createTestContext(element, 'RESPONSE');
|
|
21
|
+
|
|
22
|
+
const result = standardHotspotExtractor.extract(element, context);
|
|
23
|
+
|
|
24
|
+
expect(result.maxChoices).toBe(1);
|
|
25
|
+
expect(result.prompt).toBe('Click on the correct area');
|
|
26
|
+
expect(result.hotspotChoices).toHaveLength(2);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('extracts image data correctly', () => {
|
|
30
|
+
const xml = `
|
|
31
|
+
<hotspotInteraction responseIdentifier="RESPONSE" maxChoices="1">
|
|
32
|
+
<object type="image/png" data="test.png" width="500" height="400" />
|
|
33
|
+
<hotspotChoice identifier="H1" shape="rect" coords="0,0,100,100" />
|
|
34
|
+
</hotspotInteraction>
|
|
35
|
+
`;
|
|
36
|
+
const element = parseQTI(xml);
|
|
37
|
+
const context = createTestContext(element, 'RESPONSE');
|
|
38
|
+
|
|
39
|
+
const result = standardHotspotExtractor.extract(element, context);
|
|
40
|
+
|
|
41
|
+
expect(result.imageData).not.toBe(null);
|
|
42
|
+
expect(result.imageData?.type).toBe('image');
|
|
43
|
+
expect(result.imageData?.src).toBe('test.png');
|
|
44
|
+
expect(result.imageData?.width).toBe('500');
|
|
45
|
+
expect(result.imageData?.height).toBe('400');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('extracts SVG data correctly', () => {
|
|
49
|
+
const xml = `
|
|
50
|
+
<hotspotInteraction responseIdentifier="RESPONSE" maxChoices="1">
|
|
51
|
+
<object type="image/svg+xml" width="300" height="200">
|
|
52
|
+
<svg xmlns="http://www.w3.org/2000/svg">
|
|
53
|
+
<circle cx="50" cy="50" r="40" />
|
|
54
|
+
</svg>
|
|
55
|
+
</object>
|
|
56
|
+
<hotspotChoice identifier="H1" shape="circle" coords="50,50,40" />
|
|
57
|
+
</hotspotInteraction>
|
|
58
|
+
`;
|
|
59
|
+
const element = parseQTI(xml);
|
|
60
|
+
const context = createTestContext(element, 'RESPONSE');
|
|
61
|
+
|
|
62
|
+
const result = standardHotspotExtractor.extract(element, context);
|
|
63
|
+
|
|
64
|
+
expect(result.imageData).not.toBe(null);
|
|
65
|
+
expect(result.imageData?.type).toBe('svg');
|
|
66
|
+
expect(result.imageData?.content).toContain('circle');
|
|
67
|
+
expect(result.imageData?.width).toBe('300');
|
|
68
|
+
expect(result.imageData?.height).toBe('200');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('extracts hotspot choices with different shapes', () => {
|
|
72
|
+
const xml = `
|
|
73
|
+
<hotspotInteraction responseIdentifier="RESPONSE" maxChoices="3">
|
|
74
|
+
<object type="image/png" data="map.png" />
|
|
75
|
+
<hotspotChoice identifier="RECT" shape="rect" coords="10,10,100,100" />
|
|
76
|
+
<hotspotChoice identifier="CIRCLE" shape="circle" coords="200,200,50" />
|
|
77
|
+
<hotspotChoice identifier="POLY" shape="poly" coords="300,100,350,150,300,200" />
|
|
78
|
+
</hotspotInteraction>
|
|
79
|
+
`;
|
|
80
|
+
const element = parseQTI(xml);
|
|
81
|
+
const context = createTestContext(element, 'RESPONSE');
|
|
82
|
+
|
|
83
|
+
const result = standardHotspotExtractor.extract(element, context);
|
|
84
|
+
|
|
85
|
+
expect(result.hotspotChoices).toHaveLength(3);
|
|
86
|
+
expect(result.hotspotChoices[0]).toEqual({
|
|
87
|
+
identifier: 'RECT',
|
|
88
|
+
shape: 'rect',
|
|
89
|
+
coords: '10,10,100,100',
|
|
90
|
+
});
|
|
91
|
+
expect(result.hotspotChoices[1]).toEqual({
|
|
92
|
+
identifier: 'CIRCLE',
|
|
93
|
+
shape: 'circle',
|
|
94
|
+
coords: '200,200,50',
|
|
95
|
+
});
|
|
96
|
+
expect(result.hotspotChoices[2]).toEqual({
|
|
97
|
+
identifier: 'POLY',
|
|
98
|
+
shape: 'poly',
|
|
99
|
+
coords: '300,100,350,150,300,200',
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('uses default shape when not specified', () => {
|
|
104
|
+
const xml = `
|
|
105
|
+
<hotspotInteraction responseIdentifier="RESPONSE" maxChoices="1">
|
|
106
|
+
<object type="image/png" data="image.png" />
|
|
107
|
+
<hotspotChoice identifier="H1" coords="10,10,100,100" />
|
|
108
|
+
</hotspotInteraction>
|
|
109
|
+
`;
|
|
110
|
+
const element = parseQTI(xml);
|
|
111
|
+
const context = createTestContext(element, 'RESPONSE');
|
|
112
|
+
|
|
113
|
+
const result = standardHotspotExtractor.extract(element, context);
|
|
114
|
+
|
|
115
|
+
expect(result.hotspotChoices[0].shape).toBe('rect');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('handles multiple choice selection (maxChoices > 1)', () => {
|
|
119
|
+
const xml = `
|
|
120
|
+
<hotspotInteraction responseIdentifier="RESPONSE" maxChoices="3">
|
|
121
|
+
<object type="image/png" data="image.png" />
|
|
122
|
+
<hotspotChoice identifier="H1" shape="rect" coords="0,0,50,50" />
|
|
123
|
+
<hotspotChoice identifier="H2" shape="rect" coords="60,0,110,50" />
|
|
124
|
+
<hotspotChoice identifier="H3" shape="rect" coords="120,0,170,50" />
|
|
125
|
+
</hotspotInteraction>
|
|
126
|
+
`;
|
|
127
|
+
const element = parseQTI(xml);
|
|
128
|
+
const context = createTestContext(element, 'RESPONSE');
|
|
129
|
+
|
|
130
|
+
const result = standardHotspotExtractor.extract(element, context);
|
|
131
|
+
|
|
132
|
+
expect(result.maxChoices).toBe(3);
|
|
133
|
+
expect(result.hotspotChoices).toHaveLength(3);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('handles interaction without prompt', () => {
|
|
137
|
+
const xml = `
|
|
138
|
+
<hotspotInteraction responseIdentifier="RESPONSE" maxChoices="1">
|
|
139
|
+
<object type="image/png" data="image.png" />
|
|
140
|
+
<hotspotChoice identifier="H1" shape="rect" coords="0,0,100,100" />
|
|
141
|
+
</hotspotInteraction>
|
|
142
|
+
`;
|
|
143
|
+
const element = parseQTI(xml);
|
|
144
|
+
const context = createTestContext(element, 'RESPONSE');
|
|
145
|
+
|
|
146
|
+
const result = standardHotspotExtractor.extract(element, context);
|
|
147
|
+
|
|
148
|
+
expect(result.prompt).toBe(null);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('handles interaction without object element', () => {
|
|
152
|
+
const xml = `
|
|
153
|
+
<hotspotInteraction responseIdentifier="RESPONSE" maxChoices="1">
|
|
154
|
+
<hotspotChoice identifier="H1" shape="rect" coords="0,0,100,100" />
|
|
155
|
+
</hotspotInteraction>
|
|
156
|
+
`;
|
|
157
|
+
const element = parseQTI(xml);
|
|
158
|
+
const context = createTestContext(element, 'RESPONSE');
|
|
159
|
+
|
|
160
|
+
const result = standardHotspotExtractor.extract(element, context);
|
|
161
|
+
|
|
162
|
+
expect(result.imageData).toBe(null);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('uses default maxChoices when not specified', () => {
|
|
166
|
+
const xml = `
|
|
167
|
+
<hotspotInteraction responseIdentifier="RESPONSE">
|
|
168
|
+
<object type="image/png" data="image.png" />
|
|
169
|
+
<hotspotChoice identifier="H1" shape="rect" coords="0,0,100,100" />
|
|
170
|
+
</hotspotInteraction>
|
|
171
|
+
`;
|
|
172
|
+
const element = parseQTI(xml);
|
|
173
|
+
const context = createTestContext(element, 'RESPONSE');
|
|
174
|
+
|
|
175
|
+
const result = standardHotspotExtractor.extract(element, context);
|
|
176
|
+
|
|
177
|
+
expect(result.maxChoices).toBe(1);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test('handles image with default dimensions', () => {
|
|
181
|
+
const xml = `
|
|
182
|
+
<hotspotInteraction responseIdentifier="RESPONSE" maxChoices="1">
|
|
183
|
+
<object type="image/png" data="image.png" />
|
|
184
|
+
<hotspotChoice identifier="H1" shape="rect" coords="0,0,100,100" />
|
|
185
|
+
</hotspotInteraction>
|
|
186
|
+
`;
|
|
187
|
+
const element = parseQTI(xml);
|
|
188
|
+
const context = createTestContext(element, 'RESPONSE');
|
|
189
|
+
|
|
190
|
+
const result = standardHotspotExtractor.extract(element, context);
|
|
191
|
+
|
|
192
|
+
expect(result.imageData?.width).toBe('auto');
|
|
193
|
+
expect(result.imageData?.height).toBe('auto');
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe('canHandle predicate', () => {
|
|
197
|
+
test('handles hotspotInteraction element', () => {
|
|
198
|
+
const xml = `
|
|
199
|
+
<hotspotInteraction responseIdentifier="RESPONSE">
|
|
200
|
+
<hotspotChoice identifier="H1" />
|
|
201
|
+
</hotspotInteraction>
|
|
202
|
+
`;
|
|
203
|
+
const element = parseQTI(xml);
|
|
204
|
+
const context = createTestContext(element);
|
|
205
|
+
|
|
206
|
+
expect(standardHotspotExtractor.canHandle(element, context)).toBe(true);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test('rejects non-hotspotInteraction elements', () => {
|
|
210
|
+
const xml = `<choiceInteraction responseIdentifier="RESPONSE" />`;
|
|
211
|
+
const element = parseQTI(xml);
|
|
212
|
+
const context = createTestContext(element);
|
|
213
|
+
|
|
214
|
+
expect(standardHotspotExtractor.canHandle(element, context)).toBe(false);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
describe('validation', () => {
|
|
219
|
+
test('validates correct hotspot data', () => {
|
|
220
|
+
const data = {
|
|
221
|
+
hotspotChoices: [
|
|
222
|
+
{ identifier: 'H1', shape: 'rect', coords: '0,0,100,100' },
|
|
223
|
+
{ identifier: 'H2', shape: 'circle', coords: '200,200,50' },
|
|
224
|
+
],
|
|
225
|
+
imageData: { type: 'image', src: 'test.png', width: '500', height: '400' },
|
|
226
|
+
maxChoices: 1,
|
|
227
|
+
prompt: null,
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const validation = standardHotspotExtractor.validate!(data);
|
|
231
|
+
|
|
232
|
+
expect(validation.valid).toBe(true);
|
|
233
|
+
expect(validation.errors).toBeUndefined();
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test('reports error for empty hotspotChoices', () => {
|
|
237
|
+
const data = {
|
|
238
|
+
hotspotChoices: [],
|
|
239
|
+
imageData: { type: 'image', src: 'test.png', width: '500', height: '400' },
|
|
240
|
+
maxChoices: 1,
|
|
241
|
+
prompt: null,
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const validation = standardHotspotExtractor.validate!(data);
|
|
245
|
+
|
|
246
|
+
expect(validation.valid).toBe(false);
|
|
247
|
+
expect(validation.errors).toContain('hotspotInteraction must have at least one hotspot');
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test('reports warning for missing image data', () => {
|
|
251
|
+
const data = {
|
|
252
|
+
hotspotChoices: [{ identifier: 'H1', shape: 'rect', coords: '0,0,100,100' }],
|
|
253
|
+
imageData: null,
|
|
254
|
+
maxChoices: 1,
|
|
255
|
+
prompt: null,
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const validation = standardHotspotExtractor.validate!(data);
|
|
259
|
+
|
|
260
|
+
expect(validation.valid).toBe(true);
|
|
261
|
+
expect(validation.warnings).toContain('hotspotInteraction has no image data');
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test('reports error for duplicate hotspot identifiers', () => {
|
|
265
|
+
const data = {
|
|
266
|
+
hotspotChoices: [
|
|
267
|
+
{ identifier: 'H1', shape: 'rect', coords: '0,0,100,100' },
|
|
268
|
+
{ identifier: 'H1', shape: 'circle', coords: '200,200,50' },
|
|
269
|
+
],
|
|
270
|
+
imageData: { type: 'image', src: 'test.png', width: '500', height: '400' },
|
|
271
|
+
maxChoices: 1,
|
|
272
|
+
prompt: null,
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
const validation = standardHotspotExtractor.validate!(data);
|
|
276
|
+
|
|
277
|
+
expect(validation.valid).toBe(false);
|
|
278
|
+
expect(validation.errors).toContain('Duplicate hotspot identifier: H1');
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test('reports warning when maxChoices exceeds hotspot count', () => {
|
|
282
|
+
const data = {
|
|
283
|
+
hotspotChoices: [
|
|
284
|
+
{ identifier: 'H1', shape: 'rect', coords: '0,0,100,100' },
|
|
285
|
+
{ identifier: 'H2', shape: 'circle', coords: '200,200,50' },
|
|
286
|
+
],
|
|
287
|
+
imageData: { type: 'image', src: 'test.png', width: '500', height: '400' },
|
|
288
|
+
maxChoices: 5,
|
|
289
|
+
prompt: null,
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
const validation = standardHotspotExtractor.validate!(data);
|
|
293
|
+
|
|
294
|
+
expect(validation.valid).toBe(true);
|
|
295
|
+
expect(validation.warnings).toContain('maxChoices (5) exceeds the number of hotspots (2)');
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
});
|