diff --git a/design/scorm.md b/design/scorm.md index 668ec920..67dd3392 100644 --- a/design/scorm.md +++ b/design/scorm.md @@ -308,7 +308,9 @@ one row each; an LMS added here gets a row there. the package and plans its parts, and returns the facts, the main library with the version its `preloadedDependencies` give it (`mainLibraryOf`), the title, the size, the parts and their size from the pack's index, with `write`, which fetches the files and writes the zip, as often as - asked; `buildScormInPage` is the two at once. A refusal comes at planning, by name, before + asked, hashing the package for the build stamp on the first write only, since the package and + its parts are the same for every write (#142); `buildScormInPage` is the two at once, and a + `title` given to the plan is the plan's and its writes' default. A refusal comes at planning, by name, before anything but the pack's index is fetched. **The title** is `title` on both builders and `--title` on the command, cleaned by `scormTitle` as `h5p.json`'s is, an empty one leaving the package's; it goes into the manifest's organisation and item, which the LMS lists, and the @@ -317,7 +319,9 @@ one row each; an LMS added here gets a row there. works in steps where it holds `#files`, a list, and `#build`, a button, as both pages here do: ① choose, ② review, ③ download, each step the closest `[data-step]` around them, shown once it can be reached. A file chosen or dropped gets a row (the same file twice, by name, size and date, - is one), whose facts sit in a live region (`role="status"`) from the moment the row appears, so + is one), during a build too, since a drop lands anywhere on the page: it is read at once and + waits for the next Build, where it was dropped without a word until #142. Its facts sit in a + live region (`role="status"`) from the moment the row appears, so that what the reading found is announced. Every row is drawn again on any change, a key typed in a title among them, so the page writes a region's text, and `#status`'s, only when it changes: written again as it was, a region may be read out again, and a test types a title key @@ -352,7 +356,9 @@ one row each; an LMS added here gets a row there. and each answer's latency as ISO 8601 durations to the hundredth; each answer with its words in `description` (250 characters, as text, the character references a question writes read: `’` came through as itself in Moodle until then), an id that is a URI as 2004 asks, - `urn:uuid:` and the part's id, `learner_response`, `incorrect` where 1.2 says `wrong`, + `urn:uuid:` and the part's id, the type before the pattern and `learner_response`, which 2004 + refuses without one (408), so an answer whose statement names no type has neither (#142), + `incorrect` where 1.2 says `wrong`, `timestamp` in UTC, and `long-fill-in` and `other` kept as themselves; `suspend_data` up to 64,000 characters, compressed as in 1.2. **A 2004 session always ends `suspend`**, finished or not, where 1.2 ends a finished one with nothing. Measured in Moodle 4.5 with `normal` @@ -380,24 +386,28 @@ one row each; an LMS added here gets a row there. its second question, finished completed and passed at 66.67 (scaled 0.6667), the gradebook 66.67, the total time the two sessions' sum, the four answers with their ids and words; a launch after the finish resumed with the result kept. With a mark of 80, the same 66.67 - failed in 2004 and in 1.2, the gradebook still 66.67; with completion as 100, a finish with - no score recorded 100 and passed in both, the gradebook 100. In SCORM Cloud, through its v2 - API: both 2004 zips imported as `SCORM20044THEDITION` with no parser warnings; the same two - sessions resumed on the second question, the registration completed and passed at 66.67, and - a launch after the finish kept it; a mark of 80 failed at 66.67 with completion still - completed, where 1.2 shows a failed attempt as incomplete; a finish with no score, completed, - passed and 100; and 1.2 with a mark of 80 failed at 66.67, the registration incomplete as for - any failed 1.2 attempt there. The finishes with no score were the element's `finished` - dispatched in the SCO's frame, as the tests do, since no package here finishes without one. + failed in 2004 and in 1.2, the gradebook still 66.67; with completion as 100 in a zip that + also held the mark of 80, a finish with no score recorded 100 and passed in both, the + gradebook 100. In SCORM Cloud, through its v2 API: both 2004 zips imported as + `SCORM20044THEDITION` with no parser warnings; the same two sessions resumed on the second + question, the registration completed and passed at 66.67, and a launch after the finish kept + it; a mark of 80 failed at 66.67 with completion still completed, where 1.2 shows a failed + attempt as incomplete; a finish with no score, in the zip with the mark of 80 and completion + as 100, completed, passed and 100; and 1.2 with a mark of 80 failed at 66.67, the + registration incomplete as for any failed 1.2 attempt there. The finishes with no score were + the element's `finished` dispatched in the SCO's frame, as the tests do, since no package here + finishes without one. Completion as 100 without a mark ran in no LMS: it gives `completed` + and 100, and in 2004 leaves success `unknown`, which a test holds (#142). `scorm-page.test.ts` drives the written site's page in Chromium: a chosen file read into its row and built on Build, the download, which is the command's zip and plays unpacked; three files at once, a refusal in its row beside two that build, a title given, each row's zip and the zip of - all, a row taken out, a title changed after the build; files dropped, the same one only once; - and a page with only the four elements, which builds at once and refuses in `#notice`. - `scorm-browser.test.ts` holds the plan's facts to the command's zip, two writes of one plan - under two titles to the same zip but for the manifest and the page, and a title given to the - page's builder to the command's `--title`, entry for entry. + all, a row taken out, a title changed after the build; files dropped, the same one only once, + and one dropped during a build, which waits for the next; and a page with only the four + elements, which builds at once and refuses in `#notice`. `scorm-browser.test.ts` holds the + plan's facts to the command's zip, two writes of one plan under two titles to the same zip but + for the manifest and the page, a title given to the page's builder to the command's `--title`, + entry for entry, and a title given to the plan to its writes, which hash the package once. `tests/scorm.test.ts` checks the zip, the parts it carries, its stored entries' local headers and its refusals in Node. In Chromium it plays the unpacked zip under a page that holds the API and @@ -424,7 +434,8 @@ frames the launch page, as Moodle's player does. It covers: content's pass, and an LMS's own mark that wins over the zip's; completion as 100, passing a mark; and, under a page that holds `API_1484_11`, the quiz played to the end in 2004 with its answers, the session suspended and resumed with the result kept, a state past 4,096 - characters kept, and a score held to the LMS's passing score; + characters kept, a score held to the LMS's passing score, and an answer's type written before + its pattern and response, and neither for an answer that names no type; - playing with no LMS. Not covered: diff --git a/packages/embed/README.md b/packages/embed/README.md index c8ac76a6..ed99b671 100644 --- a/packages/embed/README.md +++ b/packages/embed/README.md @@ -270,9 +270,9 @@ export, which `libraries=pack` then plays from) or `packBase` (the folder of a c `buildScorm` from `@missing-elements/h5p-embed/scorm` is `--scorm`: it takes `h5p`, `out`, `force`, `title`, and the options, `scormVersion` (`'1.2'`, the default, or `'2004'`), `passMark` (0 to 100, or `null`) and `completionScore` (`false` by default), and returns the zip's -path, its title, its `scormVersion`, size, the `libraries` it carries from the pack, and `build`, -the stamp saved state is kept against. Every entry ships with TypeScript -declarations. +path, its title, the options as written into it (`scormVersion`, `passMark` kept to the +hundredth, `completionScore`), size, the `libraries` it carries from the pack, and `build`, the +stamp saved state is kept against. Every entry ships with TypeScript declarations. `buildScormInPage` from `@missing-elements/h5p-embed/scorm/browser` is the same build in a page: it takes `file`, a `File` or `Blob`; `base`, the folder with the player's three files and @@ -283,12 +283,13 @@ beside the player as the written site does, where a page that gives the template compressor gets the one at `base`, or a zip without it that keeps the saved state plain, as 1.4 did; `version` and `packVersion`, for the zip's notice; `title` and the options, as `buildScorm` -takes them; and `onProgress`. It returns the zip as a `Blob`, with its `name`, `title`, -`scormVersion`, `libraries`, `build` and `size`. `planScormInPage`, from the same module, takes the same options and stops before -anything is written: it reads the package and returns what its zip will hold, its `title`, +takes them; and `onProgress`. It returns the zip as a `Blob`, with its `name`, `title`, the +options as `buildScorm` returns them, `libraries`, `build` and `size`. `planScormInPage`, from +the same module, takes the same options and stops before anything is written: it reads the +package and returns what its zip will hold, its `title` (the one given, else the package's), `mainLibrary`, `size`, the `libraries` from the pack and their `librariesSize`, or refuses it as the build would, and `write({ title, scormVersion, passMark, completionScore })` then writes the -zip, as often as asked. `startScormPage` +zip, as often as asked, each of the four defaulting to the plan's. `startScormPage` from `@missing-elements/h5p-embed/scorm-page.js` is the page's script, which reads the page's `#file`, `#status`, `#download` and `#notice`, and works in steps where the page also holds `#files`, the list it puts a row in for each file, and `#build`, the button that builds them, and diff --git a/packages/embed/bin/h5p-embed.mjs b/packages/embed/bin/h5p-embed.mjs index 63cb6e92..dce26b7c 100755 --- a/packages/embed/bin/h5p-embed.mjs +++ b/packages/embed/bin/h5p-embed.mjs @@ -119,7 +119,8 @@ if (values.scorm !== undefined) { }) const count = zip.libraries.length const supplied = count > 0 ? `, the H5P runtime and ${count} ${count === 1 ? 'library' : 'libraries'} from the library pack, which it does not carry` : ' and the H5P runtime' - const graded = [values['pass-mark'] !== undefined ? `pass mark ${Number(values['pass-mark'])}` : null, values['completion-score'] ? 'completion counts as 100' : null].filter(Boolean) + // The options as written into the zip, the mark kept to the hundredth, not as typed. + const graded = [zip.passMark !== null ? `pass mark ${zip.passMark}` : null, zip.completionScore ? 'completion counts as 100' : null].filter(Boolean) console.log(`Wrote ${shown(zip.out)} (${megabytes(zip.size)}): "${zip.title}" as a SCORM ${zip.scormVersion === '2004' ? '2004 4th Edition' : '1.2'} package${graded.length ? ` (${graded.join(', ')})` : ''}, with the player ${zip.version}${supplied}. diff --git a/packages/embed/lib/scorm-browser.mjs b/packages/embed/lib/scorm-browser.mjs index 0dde2982..a4f57cbd 100644 --- a/packages/embed/lib/scorm-browser.mjs +++ b/packages/embed/lib/scorm-browser.mjs @@ -66,6 +66,8 @@ import { EmbedError, PLAYER_FILES } from './shared.mjs' * @property {string} version the player's version, as given * @property {string[]} libraries the folders of the libraries the zip carries from the pack * @property {'1.2' | '2004'} scormVersion the SCORM version it was written for + * @property {number | null} passMark the pass mark it holds a score to, as `buildScorm` returns it + * @property {boolean} completionScore whether content that finishes without a score counts as 100 * @property {string} build the build stamp, as `buildScorm` returns it * @property {number} size the zip's size in bytes */ @@ -76,8 +78,8 @@ import { EmbedError, PLAYER_FILES } from './shared.mjs' * @typedef {object} PlannedScorm * @property {string} name the package's file name * @property {number} size the package's size in bytes - * @property {string} title the title the zip takes unless `write` is given another: `h5p.json`'s, - * or the file's name + * @property {string} title the title the zip takes unless `write` is given another: the one given + * to the plan, else `h5p.json`'s, else the file's name * @property {{ machineName: string, majorVersion?: number, minorVersion?: number } | null} mainLibrary * the package's main library, as `h5p.json` names it, with the version its dependencies give * it; `null` when it names none @@ -85,9 +87,10 @@ import { EmbedError, PLAYER_FILES } from './shared.mjs' * none for a package that carries its own * @property {number} librariesSize their archives' size in bytes, as the pack's index gives it * @property {(options?: { title?: string, scormVersion?: '1.2' | '2004', passMark?: number | null, completionScore?: boolean, onProgress?: (progress: ScormProgress) => void }) => Promise} write - * fetches the parts, the player and the runtime, and writes the zip, under `title` when one is - * given, and with the version and the grading options given, each defaulting to the plan's, as - * `onProgress` does. It can be called again, for another title or other options + * fetches the parts, the player and the runtime, and writes the zip, under the title and with + * the version and the grading options given, each defaulting to the plan's, as `onProgress` + * does. It can be called again, for another title or other options; the package is hashed for + * the build stamp on the first call only */ /** @@ -167,10 +170,13 @@ export async function planScormInPage(options) { throw error } const stem = name.replace(/\.[^.]+$/, '') - const defaultTitle = scormTitle(manifest, stem) + // A title given to the plan is the plan's, and its writes' unless they give another. + const plannedTitle = scormTitle(manifest, stem, options.title) + /** @type {string | null} the build stamp, from the first write on */ + let stamp = null /** @type {PlannedScorm['write']} */ - const write = async ({ title: chosen, onProgress: report = onProgress, ...given } = {}) => { + const write = async ({ title: chosen = options.title, onProgress: report = onProgress, ...given } = {}) => { const title = scormTitle(manifest, stem, chosen) const scorm = scormOptions({ ...planned, ...Object.fromEntries(Object.entries(given).filter(([, value]) => value !== undefined)) }) const { assets = {}, version = 'unknown', packVersion = null } = options @@ -214,21 +220,22 @@ export async function planScormInPage(options) { librariesText: parts.length === 0 ? null : assets.libraries !== undefined ? asBlob(assets.libraries) : await blob(at('libraries.txt'), "The pack's licence list") } - // The whole package in memory once, for its hash: `crypto.subtle` takes no stream. - const build = await buildStamp(await sha256Hex(await file.arrayBuffer()), parts) + // The whole package in memory once, for its hash: `crypto.subtle` takes no stream. Once per + // plan, too: the package and its parts are the same for every write. + const build = (stamp ??= await buildStamp(await sha256Hex(await file.arrayBuffer()), parts)) const { entries, xml } = scormEntries({ manifest, source: name, title, build, version, packVersion, parts, files, options: scorm }) report({ step: 'writing' }) const zip = new ZipWriter(new BlobWriter('application/zip'), { useWebWorkers: false }) await addScormEntries(zip, { entries, xml }) const out = await zip.close() - return { blob: out, name: `${stem}.scorm.zip`, title, version, libraries: parts.map((part) => part.folder), scormVersion: scorm.scormVersion, build, size: out.size } + return { blob: out, name: `${stem}.scorm.zip`, title, version, libraries: parts.map((part) => part.folder), ...scorm, build, size: out.size } } return { name, size: file.size, - title: defaultTitle, + title: plannedTitle, mainLibrary: mainLibraryOf(manifest), libraries: parts.map((part) => part.folder), librariesSize: parts.reduce((sum, part) => sum + part.size, 0), @@ -244,5 +251,5 @@ export async function planScormInPage(options) { * @returns {Promise} */ export async function buildScormInPage(options) { - return (await planScormInPage(options)).write({ title: options?.title }) + return (await planScormInPage(options)).write() } diff --git a/packages/embed/lib/scorm.mjs b/packages/embed/lib/scorm.mjs index a50e1a32..42c6c267 100644 --- a/packages/embed/lib/scorm.mjs +++ b/packages/embed/lib/scorm.mjs @@ -84,6 +84,9 @@ async function filesUnder(dir) { * @property {string[]} libraries the folders of the libraries the zip carries from the library * pack, for a package that does not carry them itself; none for one that does * @property {'1.2' | '2004'} scormVersion the SCORM version it was written for + * @property {number | null} passMark the pass mark it holds a score to, out of 100 and kept to the + * hundredth; `null` for the content's own result + * @property {boolean} completionScore whether content that finishes without a score counts as 100 * @property {string} build the first 16 hex digits of the package's SHA-256, or, with libraries * from the pack, of one over its and theirs: a learner's saved place is kept against it, and * handed back only to the same package playing with the same libraries @@ -172,5 +175,5 @@ export async function buildScorm({ h5p, out, force = false, title: chosen, scorm throw error } - return { out: target, title, version, libraries: parts.map((part) => part.folder), scormVersion: options.scormVersion, build, size: (await stat(target)).size } + return { out: target, title, version, libraries: parts.map((part) => part.folder), ...options, build, size: (await stat(target)).size } } diff --git a/packages/embed/scorm/scorm.js b/packages/embed/scorm/scorm.js index 3f2df386..e991ea64 100644 --- a/packages/embed/scorm/scorm.js +++ b/packages/embed/scorm/scorm.js @@ -468,10 +468,13 @@ function recordAnswer(statement) { const types = /** @type {Record} */ (scorm2004 ? INTERACTION_TYPES_2004 : INTERACTION_TYPES) const type = typeof definition?.interactionType === 'string' ? types[definition.interactionType] : undefined if (type) set(at('type'), type) + // 2004 takes a pattern and a response only after the type that gives their form, and refuses + // them without one (408); 1.2 takes them as they come. + const typed = Boolean(type) || !scorm2004 const pattern = Array.isArray(definition?.correctResponsesPattern) ? definition.correctResponsesPattern[0] : undefined - if (typeof pattern === 'string') set(at('correct_responses.0.pattern'), pattern.slice(0, FEEDBACK_LIMIT)) + if (typed && typeof pattern === 'string') set(at('correct_responses.0.pattern'), pattern.slice(0, FEEDBACK_LIMIT)) const result = statement.result ?? {} - if (typeof result.response === 'string') set(at(scorm2004 ? 'learner_response' : 'student_response'), result.response.slice(0, FEEDBACK_LIMIT)) + if (typed && typeof result.response === 'string') set(at(scorm2004 ? 'learner_response' : 'student_response'), result.response.slice(0, FEEDBACK_LIMIT)) set(at('result'), outcomeOf(result)) if (typeof result.score?.max === 'number') set(at('weighting'), String(result.score.max)) const latency = latencyOf(result.duration) diff --git a/packages/embed/site/scorm-page.js b/packages/embed/site/scorm-page.js index 2e849fab..18e0e470 100644 --- a/packages/embed/site/scorm-page.js +++ b/packages/embed/site/scorm-page.js @@ -15,7 +15,8 @@ * A page that also holds `#files`, a list, and `#build`, a button, as both pages here do, works in * steps. Each file chosen gets a row in the list, which says what its zip will hold, or why none * can be written, and takes the title the LMS lists it by; nothing is written until `#build` is - * pressed, which writes the rows one after another; `#download` is then the zip, or, for several, + * pressed, which writes the rows one after another, and a file chosen or dropped meanwhile gets its + * row and waits for the next press; `#download` is then the zip, or, for several, * one zip that holds them all, while each row links its own. Where the page also holds the * options, radios named `scorm-version` (`1.2` or `2004`), `#pass-mark` and `#completion-score`, * every zip is written with them, and changing one takes back the zips written before. The @@ -316,7 +317,6 @@ function inSteps(options, list, button) { const options = chosen() button.textContent = several ? `Build ${count} SCORM ${count === 1 ? 'package' : 'packages'}` : 'Build the SCORM package' button.disabled = busy || pending.length === 0 || options === null || rows.some((entry) => !entry.plan && !entry.error) - input.disabled = busy for (const field of [...versions, passMarkField, completionField]) if (field) field.disabled = busy if (passMarkField) passMarkField.setAttribute('aria-invalid', String(options === null)) if (!busy && options === null) { @@ -398,9 +398,12 @@ function inSteps(options, list, button) { if (rows.includes(entry)) void refresh() } - /** @param {File[]} files */ + /** + * Files chosen or dropped, each a row; while a build runs too, since a drop lands anywhere on the + * page: read at once, and left for the next Build. + * @param {File[]} files + */ const add = (files) => { - if (busy) return notice.hidden = true for (const file of files) { // The same file twice is one row. diff --git a/packages/embed/tests/package-types.ts b/packages/embed/tests/package-types.ts index 9663bf71..4caf555d 100644 --- a/packages/embed/tests/package-types.ts +++ b/packages/embed/tests/package-types.ts @@ -26,6 +26,8 @@ export async function asACallerWould(): Promise { // One package as a SCORM zip, for an LMS. const zip: BuiltScorm = await buildScorm({ h5p: 'course.h5p', out: 'course.scorm.zip', force: true, title: 'Week 3', scormVersion: '2004', passMark: 80, completionScore: true }) const scorm: '1.2' | '2004' = zip.scormVersion + const mark: number | null = zip.passMark + const counted: boolean = zip.completionScore // @ts-expect-error the version is 1.2 or 2004 await buildScorm({ h5p: 'course.h5p', out: 'course.scorm.zip', scormVersion: '1.3' }) const build: string = zip.build @@ -40,12 +42,13 @@ export async function asACallerWould(): Promise { const plan: PlannedScorm = await planScormInPage({ file: new Blob([]), name: 'course.h5p', pack }) const main: string | undefined = plan.mainLibrary?.machineName const retitled: PageScorm = await plan.write({ title: 'Week 3', scormVersion: '2004', passMark: null, completionScore: false, onProgress: ({ step }) => step }) + const pageMark: number | null = retitled.passMark // @ts-expect-error a title is text await plan.write({ title: 3 }) startScormPage({ pack, version: '1.4.0', packVersion: '1.0.1' }) // @ts-expect-error the package is a `file`, not a path await buildScormInPage({ h5p: 'course.h5p' }) - void [hosts, build, fromPack, blob, main, retitled, scorm, parseOrigin, new EmbedError('refused') instanceof Error] + void [hosts, build, fromPack, blob, main, retitled, scorm, mark, counted, pageMark, parseOrigin, new EmbedError('refused') instanceof Error] return site.csp } diff --git a/packages/embed/tests/scorm-browser.test.ts b/packages/embed/tests/scorm-browser.test.ts index dba22adf..983ccbe2 100644 --- a/packages/embed/tests/scorm-browser.test.ts +++ b/packages/embed/tests/scorm-browser.test.ts @@ -2,7 +2,7 @@ import { cp, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises' import { createRequire } from 'node:module' import { tmpdir } from 'node:os' import { join } from 'node:path' -import { afterAll, beforeAll, describe, expect, it } from 'vitest' +import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest' import { buildSite } from '../lib/build.mjs' import { buildScormInPage, planScormInPage, type ScormProgress } from '../lib/scorm-browser.mjs' import { buildScorm } from '../lib/scorm.mjs' @@ -140,13 +140,30 @@ describe('built in a page', () => { await expect(buildScormInPage({ file: await picked(quiz, 'quiz.h5p'), ...onSite(site), title: ' \t ' })).resolves.toMatchObject({ title: 'Do you know what just happened?' }) }) + it('takes a title given to the plan for its writes, and hashes the package once however often it is written', async () => { + const size = (await readFile(quiz)).length + const digest = vi.spyOn(crypto.subtle, 'digest') + try { + const plan = await planScormInPage({ file: await picked(quiz, 'quiz.h5p'), ...onSite(site), title: 'Week 3: the quiz' }) + expect(plan.title).toBe('Week 3: the quiz') + const first = await plan.write() + const second = await plan.write({ title: 'Week 4' }) + expect(first.title).toBe('Week 3: the quiz') + expect(second).toMatchObject({ title: 'Week 4', build: first.build }) + // The whole package, hashed for the build stamp: on the first write only. + expect(digest.mock.calls.filter(([, data]) => data.byteLength === size)).toHaveLength(1) + } finally { + digest.mockRestore() + } + }) + it("writes the command's zip with the command's options, and refuses them with a launch page from before them", async () => { const options = { scormVersion: '2004' as const, passMark: 80, completionScore: true } const built = await buildScormInPage({ file: await picked(formulas, 'formulas.h5p'), ...onSite(site), ...options }) const out = join(dir, 'formulas.2004.page.zip') await writeFile(out, new Uint8Array(await built.blob.arrayBuffer())) const command = await buildScorm({ h5p: formulas, out: join(dir, 'formulas.2004.cli.zip'), ...options }) - expect(built).toMatchObject({ scormVersion: '2004', build: command.build }) + expect(built).toMatchObject({ scormVersion: '2004', passMark: 80, completionScore: true, build: command.build }) await expectSameZip(out, command.out) // A plan written under other options, as the page's options step changes them. diff --git a/packages/embed/tests/scorm-page.test.ts b/packages/embed/tests/scorm-page.test.ts index a69e9226..e7b10c85 100644 --- a/packages/embed/tests/scorm-page.test.ts +++ b/packages/embed/tests/scorm-page.test.ts @@ -268,6 +268,36 @@ describe('the SCORM page', () => { await context.close() }) + it('takes a file dropped while it builds, and leaves it for the next Build', async () => { + const context = await browser.newContext() + const page = await context.newPage() + await page.goto(`${site.origin}/scorm.html`) + await page.setInputFiles('#file', quiz) + await read(page, 1) + // Fetched before the build, so that the drop lands while the zip is written. + await page.evaluate(async () => { + ;(window as unknown as { later: File }).later = new File([await (await fetch('/packages/formulas.h5p')).blob()], 'formulas.h5p', { lastModified: 1 }) + }) + await page.locator('#build').click() + const during = await page.evaluate(() => { + const building = document.querySelector('#files > li[data-state="building"]') !== null + const transfer = new DataTransfer() + transfer.items.add((window as unknown as { later: File }).later) + document.body.dispatchEvent(new DragEvent('drop', { dataTransfer: transfer, bubbles: true, cancelable: true })) + return { building, rows: document.querySelectorAll('#files > li').length, choosable: !(document.querySelector('#file') as HTMLInputElement).disabled } + }) + expect(during).toEqual({ building: true, rows: 2, choosable: true }) + + // The build goes on with what it was given; the file dropped is read, and waits. + await page.waitForFunction(() => document.querySelector('#files > li[data-state="built"]') && !document.querySelector('#files > li[data-state="reading"], #files > li[data-state="building"]'), null, { timeout: 120_000 }) + expect(await rowOf(page, 'quiz.h5p').getAttribute('data-state')).toBe('built') + expect(await rowOf(page, 'formulas.h5p').getAttribute('data-state')).toBe('planned') + expect(await page.locator('#status').textContent()).toBe('One SCORM 1.2 package, with its link above; 1 more to build.') + expect(await page.locator('#build').textContent()).toBe('Build 1 SCORM package') + expect(await page.locator('#build').isDisabled()).toBe(false) + await context.close() + }) + it("builds at once on a page with only the elements of embed 1.5's, and shows a refusal in #notice", async () => { const context = await browser.newContext() const page = await context.newPage() diff --git a/packages/embed/tests/scorm.test.ts b/packages/embed/tests/scorm.test.ts index 5c27685e..21ebc67f 100644 --- a/packages/embed/tests/scorm.test.ts +++ b/packages/embed/tests/scorm.test.ts @@ -167,7 +167,7 @@ describe('the package', () => { it('writes none of the options unless asked: SCORM 1.2, the content\'s own result, and nothing in the page', async () => { const out = join(dir, 'plain-options.zip') - expect(await buildScorm({ h5p: quiz, out })).toMatchObject({ scormVersion: '1.2' }) + expect(await buildScorm({ h5p: quiz, out })).toMatchObject({ scormVersion: '1.2', passMark: null, completionScore: false }) const zip = await entriesOf(out) const xml = await zip.text('imsmanifest.xml') expect(xml).toContain('1.2') @@ -190,7 +190,7 @@ describe('the package', () => { const out = join(dir, 'quiz-2004.zip') // A mark kept to the hundredth, as the score is, and to the ten-thousandth as a measure. - expect(await buildScorm({ h5p: quiz, out, scormVersion: '2004', passMark: 66.666 })).toMatchObject({ scormVersion: '2004' }) + expect(await buildScorm({ h5p: quiz, out, scormVersion: '2004', passMark: 66.666 })).toMatchObject({ scormVersion: '2004', passMark: 66.67, completionScore: false }) const zip = await entriesOf(out) const xml = await zip.text('imsmanifest.xml') expect(xml).toContain('xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"') @@ -267,10 +267,11 @@ describe('the command', () => { it('writes SCORM 2004 with a pass mark and completion as 100 as the flags say, and refuses what is not one', async () => { const cwd = join(dir, 'cli-options') await mkdir(cwd) - const { stdout } = await run(process.execPath, [bin, '--scorm', quiz, '--scorm-version', '2004', '--pass-mark', '80', '--completion-score'], { cwd }) - expect(stdout).toContain('"Do you know what just happened?" as a SCORM 2004 4th Edition package (pass mark 80, completion counts as 100)') + const { stdout } = await run(process.execPath, [bin, '--scorm', quiz, '--scorm-version', '2004', '--pass-mark', '66.666', '--completion-score'], { cwd }) + // The mark as the zip holds it, to the hundredth. + expect(stdout).toContain('"Do you know what just happened?" as a SCORM 2004 4th Edition package (pass mark 66.67, completion counts as 100)') const zip = await entriesOf(join(cwd, 'quiz.scorm.zip')) - expect(await zip.text('imsmanifest.xml')).toContain('0.8') + expect(await zip.text('imsmanifest.xml')).toContain('0.6667') await zip.close() for (const [flags, said] of [ @@ -1049,6 +1050,27 @@ describe('in an LMS', () => { await other.context.close() }) + it('writes a SCORM 2004 answer\'s pattern and response after its type, and neither for an answer that names no type', async () => { + const { context, page } = await lmsPage('/lms2004.html') + const { sco } = await launch(page, '/s2004/index.html') + await answer(sco, 'typed', 'Which rivers cross Germany?') + // 2004 refuses either before the type that gives its form (408). + const written = (await calls(page)).filter((call) => call[0] === 'SetValue' && call[1].startsWith('cmi.interactions.0.')).map((call) => call[1]) + const typedAt = written.indexOf('cmi.interactions.0.type') + expect(typedAt).toBeGreaterThan(-1) + expect(typedAt).toBeLessThan(written.indexOf('cmi.interactions.0.correct_responses.0.pattern')) + expect(typedAt).toBeLessThan(written.indexOf('cmi.interactions.0.learner_response')) + + // An answer whose statement names no type is kept, without the two. + await answer(sco, 'untyped', 'Which rivers cross France?', { interactionType: undefined }) + const kept = await values(page) + expect(kept).toMatchObject({ 'cmi.interactions.1.id': 'urn:h5p:untyped', 'cmi.interactions.1.description': 'Which rivers cross France?', 'cmi.interactions.1.result': 'incorrect', 'cmi.interactions.1.weighting': '2' }) + expect(kept['cmi.interactions.1.type']).toBeUndefined() + expect(kept['cmi.interactions.1.correct_responses.0.pattern']).toBeUndefined() + expect(kept['cmi.interactions.1.learner_response']).toBeUndefined() + await context.close() + }) + it('plays with no LMS around it, and reports nothing', async () => { const context = await browser.newContext() const page = await context.newPage()