@qti-components/test 2.0.0-next.31 → 2.0.0-next.32
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.
|
@@ -11,6 +11,18 @@ export const TestProcessingMixin = (superClass) => {
|
|
|
11
11
|
e.stopPropagation();
|
|
12
12
|
});
|
|
13
13
|
listenPublic(this, 'qc-test-submit', () => this.submit());
|
|
14
|
+
// QTI 3 info model §2.9: the test's outcome processing runs each time the candidate submits an
|
|
15
|
+
// item in an individual part, after the item's response processing, so branch rules and
|
|
16
|
+
// pre-conditions read test outcomes that include it (impl. guide §4.5.3, step 1). Registered
|
|
17
|
+
// after the base mixin's listener, so the test context already holds the item's new values.
|
|
18
|
+
// A simultaneous part is processed when the part is submitted (roadmap 1, T6).
|
|
19
|
+
this.addEventListener('qti-item-context-updated', (e) => {
|
|
20
|
+
if (!e.detail?.responseProcessed)
|
|
21
|
+
return;
|
|
22
|
+
if (this.#submissionModeOf(e.detail.itemContext?.identifier) !== 'individual')
|
|
23
|
+
return;
|
|
24
|
+
this.outcomeProcessing();
|
|
25
|
+
});
|
|
14
26
|
// wordt aangeroepen vanuit de processingtemplate
|
|
15
27
|
this.addEventListener('qti-set-outcome-value', (e) => {
|
|
16
28
|
const { outcomeIdentifier, value } = e.detail;
|
|
@@ -18,6 +30,17 @@ export const TestProcessingMixin = (superClass) => {
|
|
|
18
30
|
e.stopPropagation();
|
|
19
31
|
});
|
|
20
32
|
}
|
|
33
|
+
/** The `submission-mode` of the test part that holds this item-ref; null when it is not in the test. */
|
|
34
|
+
#submissionModeOf(itemRefIdentifier) {
|
|
35
|
+
if (!itemRefIdentifier || !this._testElement)
|
|
36
|
+
return null;
|
|
37
|
+
const part = this._testElement
|
|
38
|
+
.querySelector(`qti-assessment-item-ref[identifier="${CSS.escape(itemRefIdentifier)}"]`)
|
|
39
|
+
?.closest('qti-test-part');
|
|
40
|
+
if (!part)
|
|
41
|
+
return null;
|
|
42
|
+
return part.getAttribute('submission-mode') === 'simultaneous' ? 'simultaneous' : 'individual';
|
|
43
|
+
}
|
|
21
44
|
outcomeProcessing() {
|
|
22
45
|
// Inside the loaded test: `test-container` renders it into its own shadow root, which a
|
|
23
46
|
// `querySelector` on this element does not reach. Without a loaded test, look in the light DOM.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-processing.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-processing.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAiBhE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAA2C,UAAa,EAAE,EAAE;IAC7F,MAAe,qBAAsB,SAAQ,UAAU;QACrD,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YACf,IAAI,CAAC,gBAAgB,CAAC,uBAAuB,EAAE,CAAC,CAAiC,EAAE,EAAE;gBACnF,IAAI,CAAC,WAAW,GAAG;oBACjB,GAAG,IAAI,CAAC,WAAW;oBACnB,oBAAoB,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,oBAAoB,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;iBAC5F,CAAC;gBACF,CAAC,CAAC,eAAe,EAAE,CAAC;YACtB,CAAC,CAAC,CAAC;YACH,YAAY,CAAC,IAAI,EAAE,gBAAgB,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YAC1D,iDAAiD;YACjD,IAAI,CAAC,gBAAgB,CACnB,uBAAuB,EACvB,CAAC,CAAuE,EAAE,EAAE;gBAC1E,MAAM,EAAE,iBAAiB,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC;gBAC9C,IAAI,CAAC,qBAAqB,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;gBACrD,CAAC,CAAC,eAAe,EAAE,CAAC;YACt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HAAmH;QAE5G,qBAAqB,CAAC,UAAkB,EAAE,KAAoC;YACnF,MAAM,eAAe,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;YACpD,IAAI,CAAC,eAAe,EAAE,CAAC;gBACrB,OAAO,CAAC,IAAI,CAAC,uCAAuC,UAAU,uBAAuB,CAAC,CAAC;gBACvF,OAAO;YACT,CAAC;YACD,IAAI,CAAC,WAAW,GAAG;gBACjB,GAAG,IAAI,CAAC,WAAW;gBACnB,oBAAoB,EAAE,IAAI,CAAC,WAAW,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE;oBACnE,IAAI,CAAC,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;wBAChC,OAAO,CAAC,CAAC;oBACX,CAAC;oBACD,OAAO;wBACL,GAAG,CAAC;wBACJ,KAAK,EAAE,eAAe,CAAC,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAe,CAAC;qBACxF,CAAC;gBACJ,CAAC,CAAC;aACH,CAAC;QACJ,CAAC;QAEM,UAAU,CAAC,UAAkB;YAClC,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAoB,CAAC;QACzD,CAAC;QACM,WAAW,CAAC,UAAkB;YACnC,OAAO,IAAI,CAAC,WAAW,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,IAAI,IAAI,CAAC;QAC/F,CAAC;KAEF;IAED,OAAO,qBAAiE,CAAC;AAC3E,CAAC,CAAC","sourcesContent":["import { dispatchPublic, listenPublic } from '../public-events';\n\nimport type { QtiOutcomeProcessing } from '../components/qti-outcome-processing/qti-outcome-processing';\nimport type { QtiTestFeedback } from '../components/qti-test-feedback/qti-test-feedback';\nimport type { OutcomeVariable, VariableDeclaration } from '@qti-components/base';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\ndeclare class TestProcessingInterface {\n updateOutcomeVariable(identifier: string, value: string | string[] | undefined): void;\n getOutcome(identifier: string): Readonly<OutcomeVariable>;\n getVariable(identifier: string): Readonly<VariableDeclaration<string | string[] | null>>;\n outcomeProcessing(): boolean;\n submit(): boolean;\n getTestFeedback(access?: 'atEnd' | 'during'): QtiTestFeedback[];\n}\nexport const TestProcessingMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestProcessingElement extends superClass implements TestProcessingInterface {\n constructor(...args: any[]) {\n super(...args);\n this.addEventListener('qti-register-variable', (e: CustomEvent<{ variable: any }>) => {\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: [...(this.testContext.testOutcomeVariables || []), e.detail.variable]\n };\n e.stopPropagation();\n });\n listenPublic(this, 'qc-test-submit', () => this.submit());\n // wordt aangeroepen vanuit de processingtemplate\n this.addEventListener(\n 'qti-set-outcome-value',\n (e: CustomEvent<{ outcomeIdentifier: string; value: string | string[] }>) => {\n const { outcomeIdentifier, value } = e.detail;\n this.updateOutcomeVariable(outcomeIdentifier, value);\n e.stopPropagation();\n }\n );\n }\n\n outcomeProcessing(): boolean {\n // Inside the loaded test: `test-container` renders it into its own shadow root, which a\n // `querySelector` on this element does not reach. Without a loaded test, look in the light DOM.\n const outcomeProcessor = (this._testElement ?? this).querySelector(\n 'qti-outcome-processing'\n ) as unknown as QtiOutcomeProcessing;\n if (!outcomeProcessor) return false;\n // QTI starts every run of the test's outcome processing from the declared defaults, so an\n // accumulating rule (`SCORE_TOTAL = sum + SCORE_TOTAL`) gives the same total on every run.\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v => ({\n ...v,\n value: v.defaultValue ?? null\n }))\n };\n outcomeProcessor.process();\n return true;\n }\n\n /**\n * Ends the test for scoring: runs `outcomeProcessing()`, then tells the host with\n * `qc-test-submitted`. Returns false, and sends nothing, when the test has no outcome processing.\n */\n submit(): boolean {\n if (!this.outcomeProcessing()) return false;\n dispatchPublic(this, 'qc-test-submitted', {});\n return true;\n }\n\n /**\n * The `qti-test-feedback` elements that apply now, read from the test outcomes: run\n * `outcomeProcessing()` first. `access` narrows them to the end of the test (`atEnd`) or to\n * while it runs (`during`); without it, both.\n */\n getTestFeedback(access?: 'atEnd' | 'during'): QtiTestFeedback[] {\n const feedback = Array.from(\n (this._testElement ?? this).querySelectorAll<QtiTestFeedback>('qti-test-feedback') ?? []\n );\n return feedback.filter(\n fb => (!access || fb.access === access) && fb.matches(this.getOutcome(fb.outcomeIdentifier)?.value)\n );\n }\n\n /* --------------------------- ENABLED WHEN UNIT TESTING OUTCOME PROCESSING ------------------------------------ */\n\n public updateOutcomeVariable(identifier: string, value: string | string[] | undefined) {\n const outcomeVariable = this.getOutcome(identifier);\n if (!outcomeVariable) {\n console.warn(`Can not set qti-outcome-identifier: ${identifier}, it is not available`);\n return;\n }\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v => {\n if (v.identifier !== identifier) {\n return v;\n }\n return {\n ...v,\n value: outcomeVariable.cardinality === 'single' ? value : [...v.value, value as string]\n };\n })\n };\n }\n\n public getOutcome(identifier: string): Readonly<OutcomeVariable> {\n return this.getVariable(identifier) as OutcomeVariable;\n }\n public getVariable(identifier: string): Readonly<VariableDeclaration<string | string[] | null>> {\n return this.testContext.testOutcomeVariables?.find(v => v.identifier === identifier) || null;\n }\n /* --------------------------- ENABLED WHEN UNIT TESTING OUTCOME PROCESSING ------------------------------------ */\n }\n\n return TestProcessingElement as Constructor<TestProcessingInterface> & T;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"test-processing.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-processing.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAiBhE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAA2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C,UAAU,CAAoB,CAAC;QACzD,CAAC;QACM,WAAW,CAAC,UAAkB;YACnC,OAAO,IAAI,CAAC,WAAW,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,IAAI,IAAI,CAAC;QAC/F,CAAC;KAEF;IAED,OAAO,qBAAiE,CAAC;AAC3E,CAAC,CAAC","sourcesContent":["import { dispatchPublic, listenPublic } from '../public-events';\n\nimport type { QtiOutcomeProcessing } from '../components/qti-outcome-processing/qti-outcome-processing';\nimport type { QtiTestFeedback } from '../components/qti-test-feedback/qti-test-feedback';\nimport type { OutcomeVariable, VariableDeclaration } from '@qti-components/base';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\ndeclare class TestProcessingInterface {\n updateOutcomeVariable(identifier: string, value: string | string[] | undefined): void;\n getOutcome(identifier: string): Readonly<OutcomeVariable>;\n getVariable(identifier: string): Readonly<VariableDeclaration<string | string[] | null>>;\n outcomeProcessing(): boolean;\n submit(): boolean;\n getTestFeedback(access?: 'atEnd' | 'during'): QtiTestFeedback[];\n}\nexport const TestProcessingMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestProcessingElement extends superClass implements TestProcessingInterface {\n constructor(...args: any[]) {\n super(...args);\n this.addEventListener('qti-register-variable', (e: CustomEvent<{ variable: any }>) => {\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: [...(this.testContext.testOutcomeVariables || []), e.detail.variable]\n };\n e.stopPropagation();\n });\n listenPublic(this, 'qc-test-submit', () => this.submit());\n // QTI 3 info model §2.9: the test's outcome processing runs each time the candidate submits an\n // item in an individual part, after the item's response processing, so branch rules and\n // pre-conditions read test outcomes that include it (impl. guide §4.5.3, step 1). Registered\n // after the base mixin's listener, so the test context already holds the item's new values.\n // A simultaneous part is processed when the part is submitted (roadmap 1, T6).\n this.addEventListener(\n 'qti-item-context-updated',\n (e: CustomEvent<{ itemContext: { identifier: string }; responseProcessed?: boolean }>) => {\n if (!e.detail?.responseProcessed) return;\n if (this.#submissionModeOf(e.detail.itemContext?.identifier) !== 'individual') return;\n this.outcomeProcessing();\n }\n );\n // wordt aangeroepen vanuit de processingtemplate\n this.addEventListener(\n 'qti-set-outcome-value',\n (e: CustomEvent<{ outcomeIdentifier: string; value: string | string[] }>) => {\n const { outcomeIdentifier, value } = e.detail;\n this.updateOutcomeVariable(outcomeIdentifier, value);\n e.stopPropagation();\n }\n );\n }\n\n /** The `submission-mode` of the test part that holds this item-ref; null when it is not in the test. */\n #submissionModeOf(itemRefIdentifier: string | undefined): 'individual' | 'simultaneous' | null {\n if (!itemRefIdentifier || !this._testElement) return null;\n const part = this._testElement\n .querySelector(`qti-assessment-item-ref[identifier=\"${CSS.escape(itemRefIdentifier)}\"]`)\n ?.closest('qti-test-part');\n if (!part) return null;\n return part.getAttribute('submission-mode') === 'simultaneous' ? 'simultaneous' : 'individual';\n }\n\n outcomeProcessing(): boolean {\n // Inside the loaded test: `test-container` renders it into its own shadow root, which a\n // `querySelector` on this element does not reach. Without a loaded test, look in the light DOM.\n const outcomeProcessor = (this._testElement ?? this).querySelector(\n 'qti-outcome-processing'\n ) as unknown as QtiOutcomeProcessing;\n if (!outcomeProcessor) return false;\n // QTI starts every run of the test's outcome processing from the declared defaults, so an\n // accumulating rule (`SCORE_TOTAL = sum + SCORE_TOTAL`) gives the same total on every run.\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v => ({\n ...v,\n value: v.defaultValue ?? null\n }))\n };\n outcomeProcessor.process();\n return true;\n }\n\n /**\n * Ends the test for scoring: runs `outcomeProcessing()`, then tells the host with\n * `qc-test-submitted`. Returns false, and sends nothing, when the test has no outcome processing.\n */\n submit(): boolean {\n if (!this.outcomeProcessing()) return false;\n dispatchPublic(this, 'qc-test-submitted', {});\n return true;\n }\n\n /**\n * The `qti-test-feedback` elements that apply now, read from the test outcomes: run\n * `outcomeProcessing()` first. `access` narrows them to the end of the test (`atEnd`) or to\n * while it runs (`during`); without it, both.\n */\n getTestFeedback(access?: 'atEnd' | 'during'): QtiTestFeedback[] {\n const feedback = Array.from(\n (this._testElement ?? this).querySelectorAll<QtiTestFeedback>('qti-test-feedback') ?? []\n );\n return feedback.filter(\n fb => (!access || fb.access === access) && fb.matches(this.getOutcome(fb.outcomeIdentifier)?.value)\n );\n }\n\n /* --------------------------- ENABLED WHEN UNIT TESTING OUTCOME PROCESSING ------------------------------------ */\n\n public updateOutcomeVariable(identifier: string, value: string | string[] | undefined) {\n const outcomeVariable = this.getOutcome(identifier);\n if (!outcomeVariable) {\n console.warn(`Can not set qti-outcome-identifier: ${identifier}, it is not available`);\n return;\n }\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v => {\n if (v.identifier !== identifier) {\n return v;\n }\n return {\n ...v,\n value: outcomeVariable.cardinality === 'single' ? value : [...v.value, value as string]\n };\n })\n };\n }\n\n public getOutcome(identifier: string): Readonly<OutcomeVariable> {\n return this.getVariable(identifier) as OutcomeVariable;\n }\n public getVariable(identifier: string): Readonly<VariableDeclaration<string | string[] | null>> {\n return this.testContext.testOutcomeVariables?.find(v => v.identifier === identifier) || null;\n }\n /* --------------------------- ENABLED WHEN UNIT TESTING OUTCOME PROCESSING ------------------------------------ */\n }\n\n return TestProcessingElement as Constructor<TestProcessingInterface> & T;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qti-components/test",
|
|
3
3
|
"description": "QTI test utilities",
|
|
4
|
-
"version": "2.0.0-next.
|
|
4
|
+
"version": "2.0.0-next.32",
|
|
5
5
|
"author": "",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@heximal/templates": "^0.1.5",
|
|
8
8
|
"@qti-components/base": "^3.0.0-next.16",
|
|
9
|
-
"@qti-components/delivery": "^0.1.0-next.
|
|
9
|
+
"@qti-components/delivery": "^0.1.0-next.11",
|
|
10
10
|
"@qti-components/elements": "^2.0.0-next.7",
|
|
11
11
|
"@qti-components/interactions": "^1.10.5-next.8",
|
|
12
12
|
"@qti-components/processing": "^1.6.1-next.5",
|