diff --git a/design/author.md b/design/author.md index 02df5ea0..6a704bc6 100644 --- a/design/author.md +++ b/design/author.md @@ -455,13 +455,35 @@ text to the content check's rules, and `apps/skills` plays every example untrust answers, Multimedia Choice's options; Find the Hotspot's areas are refused already), two answers or statements alike as a learner reads them, without tags or entities and in any case (Multiple Choice, a Single Choice Set question, a Summary set), a text with no gap (Fill in the - Blanks, Drag the Words, Mark the Words), and a picture with no alt text where its field is - optional (`ALT_TEXTS`, held to the pack's fields by `build.test.ts`; H5P.Image's is required). + Blanks, Drag the Words, Mark the Words), a picture with no alt text where its field is + optional (`ALT_TEXTS`, held to the pack's fields by `build.test.ts`; H5P.Image's is required), + and what goes stale when a content is changed and a setting kept (#268): a number of items + drawn at random (Question Set's `poolSize`, Memory Game's `numCardsToUse`, Crossword's + `poolSize`) or to find (Find Multiple Hotspots' `numberHotspots`), said with both numbers below + the list's length, since it may be meant, and at or above it as drawing nothing now; and a part + named by what is not there: a Course Presentation button's slide, a Drag and Drop zone's right + element or an element's zone, and an element no zone it can reach takes as right, Agamotto's + start image, a Virtual Tour's scene id, a Personality Quiz answer's personality. Each note says + what its library does, read in the library's script, not its field's label: Find Multiple + Hotspots does not use a number above its hotspots, Agamotto holds a start image to those there + are, and Personality Quiz takes a name only as its personality has it, parted at ", ". In + ChatGPT a quiz of six questions came with `poolSize` 3 after the chat was asked to add + questions, and showed three (2026-11-23); whether its first source had it is not known. The + outline's first line says a draw's how many of how many. One function, `drawOf`, works + out what each draw shows, for the notes and the outline: Question Set shuffles whenever + `poolSize` is set, Memory Game draws pairs, at least 2, and Crossword keeps the words fixed on + the grid and draws only among the rest. Not looked for: a select tied to the + content, as Multiple Choice's single or multiple answers; Advanced Blanks' gaps against its + list and its snippets by name; a Game Map restriction's stage id; video times (#260). Each says what to write. `lib/mistakes.mjs` runs in `checkContent`, so a build says them and so does a check of saved content, and every type file's example says none. Of the owner's 88 real packages, the 79 checked against their own libraries give 36 notes of a picture with no alt text in 8 packages, and 4 of answers alike in one, a test whose answers all read "Test"; no - question with no answer marked correct, and no text with no gap. + question with no answer marked correct, and no text with no gap. The notes of #268 fire in none + of the 88, of which 18 hold a Course Presentation, 15 a Drag and Drop, 12 a Question Set, 2 a + Virtual Tour and 1 a Crossword; none holds a Memory Game, a Personality Quiz, an Agamotto or a + Find Multiple Hotspots, so for those four it says nothing. One Drag and Drop there names two + elements right in a zone they cannot be dropped in, beside the one they can: left unsaid. - **A source names the version of its type it was built with, and the build writes that** (#219, the owner's calls). A source handed over beside a package is built again later, on the build page or by a newer release, with a newer pack. So a build hands back the source with diff --git a/packages/author/lib/mistakes.mjs b/packages/author/lib/mistakes.mjs index 49326ae7..da5a4491 100644 --- a/packages/author/lib/mistakes.mjs +++ b/packages/author/lib/mistakes.mjs @@ -3,7 +3,10 @@ import { blanksGaps } from './types.mjs' /** * What builds and is almost surely a mistake (#241, item 4 of #219): no answer marked correct, two - * answers alike, a text with no gap, a picture with no alt text where its field is optional. H5P + * answers alike, a text with no gap, a picture with no alt text where its field is optional. And + * what goes stale when a chat changes a content and leaves a setting as it was (#268): a number + * of items to draw or to find that is not below how many there are, and a part named by its + * number, id or name that is not there. H5P * allows each, so each is a note and not a problem, and nothing about the content is judged: whether * an answer is right stays the person's. Run by `checkContent` on content as H5P stores it, so a * build says them, and so does a check of saved content. @@ -23,6 +26,76 @@ function plain(value) { return typeof value === 'string' ? decodeEntities(stripTags(value)).replace(/\s+/g, ' ').trim().toLowerCase() : '' } +/** @param {unknown} value */ +const count = (value) => (Array.isArray(value) ? value.length : 0) + +/** + * What a draw shows, where a setting shows some of a list's items picked at random each time, as + * each library works it out (#268): + * - Question Set (questionset.js): `poolSize` above 0 shuffles the questions and keeps that many, + * so it also shows them in a random order where it keeps them all. + * - Memory Game (memory-game.js): `numCardsToUse` pairs, at least 2. + * - Crossword (h5p-crossword.js): `poolSize` 0 is all, else at least 2; the words fixed on the + * grid are always kept, and the others drawn to make up the rest; a word without an answer or + * a clue is left out first. + * @param {string} library + * @param {unknown} params as H5P stores them + * @returns {{ at: string, what: string, used: number, total: number, shown: number, fixed: number, shuffles: boolean } | null} + * `at`, the setting's path in the parameters; `used`, the number the library draws; null where + * nothing is drawn + * @internal + */ +export function drawOf(library, params) { + if (!isObject(params)) return null + if (library === 'H5P.QuestionSet') { + const total = count(params.questions) + if (typeof params.poolSize !== 'number' || !(params.poolSize > 0) || !total) return null + // `slice(0, poolSize)`, which drops a fraction. + const used = Math.trunc(params.poolSize) + return { at: 'poolSize', what: 'questions', used, total, shown: Math.min(used, total), fixed: 0, shuffles: true } + } + if (library === 'H5P.MemoryGame') { + const total = count(params.cards) + const setting = params.behaviour?.numCardsToUse + if (typeof setting !== 'number' || !(setting >= 1) || !total) return null + const used = Math.max(2, Math.trunc(setting)) + return { at: 'behaviour.numCardsToUse', what: 'pairs', used, total, shown: Math.min(used, total), fixed: 0, shuffles: false } + } + if (library === 'H5P.Crossword') { + const setting = params.behaviour?.poolSize + const words = Array.isArray(params.words) ? params.words.filter((/** @type {any} */ word) => word?.answer && word?.clue) : [] + if (typeof setting !== 'number' || !setting || !words.length) return null + // `Math.max(2, poolSize)`, then a `splice` that drops a fraction. + const used = Math.trunc(Math.max(2, setting)) + const fixed = words.filter((/** @type {any} */ word) => word.fixWord && word.row !== undefined && word.column !== undefined && word.orientation !== undefined).length + const shown = fixed + Math.min(Math.max(0, used - fixed), words.length - fixed) + return { at: 'behaviour.poolSize', what: 'words', used, total: words.length, shown, fixed, shuffles: false } + } + return null +} + +/** + * A draw's note: below the list's length, what it shows, since it may be meant; at or above it, + * that it leaves none out now and would once items are added, what a chat that adds items and + * keeps the setting gets. + * @param {string} library @param {Record} params @param {string} path @param {Note} note + */ +function noteDraw(library, params, path, note) { + const draw = drawOf(library, params) + if (!draw) return + const { what, used, total, shown, fixed } = draw + const at = `${path}.${draw.at}` + const order = draw.shuffles ? ' but shows them in a random order' : '' + const random = draw.shuffles ? ', and set randomQuestions for a random order' : '' + if (shown < total) { + if (!fixed) note(at, `shows ${shown} of the ${total} ${what} each time, drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws`) + else if (shown === fixed) note(at, `shows only the ${fixed} ${what} fixed on the grid, and never the other ${total - fixed}: leave it out to show them all`) + else note(at, `shows ${shown} of the ${total} ${what} each time, the ${fixed} fixed on the grid and ${shown - fixed} of the other ${total - fixed} drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws`) + } + else if (used === total) note(at, `is the number of ${what}, ${total}, so it leaves none out${order}, and one added later would leave one out at random: leave it out${random}`) + else note(at, `is above the number of ${what}, ${total}, so it leaves none out${order} until more than ${used} are, and then leaves some out at random: leave it out${random}`) +} + /** * Each item of a list that reads as an earlier one does. * @param {unknown} items @@ -100,6 +173,118 @@ const CHECKS = { 'H5P.MultiMediaChoice'(params, path, note) { if (noneCorrect(params.options)) note(`${path}.options`, 'marks no option correct, so no learner can score: set "correct": true on the right one') }, + // `poolSize`, labelled "Number of questions to be shown", is how many are drawn at random: in + // ChatGPT a quiz of six came with it at 3 after the chat was asked to add questions (#268). + 'H5P.QuestionSet'(params, path, note) { + noteDraw('H5P.QuestionSet', params, path, note) + }, + 'H5P.MemoryGame'(params, path, note) { + noteDraw('H5P.MemoryGame', params, path, note) + }, + 'H5P.Crossword'(params, path, note) { + noteDraw('H5P.Crossword', params, path, note) + }, + // The task ends at this many found. Above the number of hotspots, right or not, the library + // does not use it (image-multiple-hotspot-question.js). + 'H5P.ImageMultipleHotspotQuestion'(params, path, note) { + const settings = params.imageMultipleHotspotQuestion?.hotspotSettings + const wanted = settings?.numberHotspots + const spots = Array.isArray(settings?.hotspot) ? settings.hotspot : [] + const correct = spots.filter((/** @type {any} */ spot) => spot?.userSettings?.correct === true).length + if (typeof wanted !== 'number' || wanted < 1 || !correct) return + const at = `${path}.imageMultipleHotspotQuestion.hotspotSettings.numberHotspots` + if (wanted > spots.length) note(at, `is above the number of hotspots, ${spots.length}, so it is not used: leave it out`) + else if (wanted > correct) note(at, `asks for ${wanted} hotspots, and ${correct} ${correct === 1 ? 'is' : 'are'} marked correct, so no learner can finish: leave it out, or mark more correct`) + else if (wanted < correct) note(at, `ends the task once ${wanted} of the ${correct} correct hotspots are found: leave it out to ask for all of them, or tell the user`) + else note(at, `is the number of correct hotspots, ${correct}, so it changes nothing, and one added later would not be asked for: leave it out`) + }, + // A button that goes to a slide by its number: one that is not there goes nowhere. + 'H5P.CoursePresentation'(params, path, note) { + const slides = params.presentation?.slides + if (!Array.isArray(slides)) return + slides.forEach((/** @type {any} */ slide, /** @type {number} */ i) => { + if (!Array.isArray(slide?.elements)) return + slide.elements.forEach((/** @type {any} */ element, /** @type {number} */ j) => { + const to = element?.goToSlide + if ((element?.goToSlideType ?? 'specified') !== 'specified' || typeof to !== 'number') return + if (!Number.isInteger(to) || to < 1 || to > slides.length) note(`${path}.presentation.slides[${i}].elements[${j}].goToSlide`, `goes to slide ${to}, and there ${slides.length === 1 ? 'is 1 slide' : `are ${slides.length} slides`}, so the button has no slide to go to: name a slide by its number, from 1`) + }) + }) + }, + // A drop zone names its right elements, and an element the zones it can be dropped in, by + // their place in the other list, as text (h5p-drag-question.js reads both). An element that + // can be dropped in none of the zones it is right in can never be put right. One that can be + // in some of them is left: a real package of the owner's names two elements right in a zone + // they cannot reach, beside the one they can, and plays as meant. + 'H5P.DragQuestion'(params, path, note) { + const task = params.question?.task + const elements = Array.isArray(task?.elements) ? task.elements : [] + const zones = Array.isArray(task?.dropZones) ? task.dropZones : [] + const at = `${path}.question.task` + /** @param {unknown} named @param {number} total */ + const placed = (named, total) => { const index = Number(named); return typeof named !== 'boolean' && named !== '' && Number.isInteger(index) && index >= 0 && index < total } + const none = (/** @type {number} */ total, /** @type {string} */ one) => (total === 1 ? `is 1 ${one}` : `are ${total} ${one}s`) + zones.forEach((/** @type {any} */ zone, /** @type {number} */ i) => { + if (!Array.isArray(zone?.correctElements)) return + zone.correctElements.forEach((/** @type {any} */ named, /** @type {number} */ j) => { + if (!placed(named, elements.length)) return note(`${at}.dropZones[${i}].correctElements[${j}]`, `names element ${JSON.stringify(named)}, and there ${none(elements.length, 'element')}, counted from 0: name each by its place in elements`) + }) + }) + elements.forEach((/** @type {any} */ element, /** @type {number} */ e) => { + if (!Array.isArray(element?.dropZones)) return + const right = zones.flatMap((/** @type {any} */ zone, /** @type {number} */ i) => (Array.isArray(zone?.correctElements) && zone.correctElements.map(String).includes(String(e)) ? [i] : [])) + const allowed = new Set(element.dropZones.map(String)) + if (right.length && !right.some((/** @type {number} */ i) => allowed.has(String(i)))) note(`${at}.elements[${e}].dropZones`, `lets the element be dropped in ${element.dropZones.length ? `zone ${element.dropZones.join(', ')}` : 'no zone'}, and it is right only in zone ${right.join(', ')}, so no learner can put it right: name ${right.length === 1 ? 'that zone' : 'one of those zones'} in its dropZones`) + }) + elements.forEach((/** @type {any} */ element, /** @type {number} */ i) => { + if (!Array.isArray(element?.dropZones)) return + element.dropZones.forEach((/** @type {any} */ named, /** @type {number} */ j) => { + if (!placed(named, zones.length)) note(`${at}.elements[${i}].dropZones[${j}]`, `names drop zone ${JSON.stringify(named)}, and there ${none(zones.length, 'drop zone')}, counted from 0: name each by its place in dropZones`) + }) + }) + }, + // Held to the images there are (h5p-agamotto.js constrains it), so nothing breaks: it starts + // elsewhere than written. A fraction never gets here: its field takes a whole number, which + // the build holds it to. + 'H5P.Agamotto'(params, path, note) { + const start = params.behaviour?.startImage + const items = count(params.items) + if (typeof start === 'number' && items && (start < 1 || start > items)) note(`${path}.behaviour.startImage`, `is image ${start}, and there ${items === 1 ? 'is 1 image' : `are ${items} images`}, so it starts at the ${start < 1 ? 'first' : 'last'}: name one by its number, from 1, or leave it out`) + }, + // A tour's scenes are named by their ids: where it starts, and where a "go to scene" leads. + 'H5P.ThreeImage'(params, path, note) { + const tour = params.threeImage + if (!Array.isArray(tour?.scenes)) return + const ids = new Set(tour.scenes.map((/** @type {any} */ scene) => scene?.sceneId).filter((/** @type {any} */ id) => id !== undefined)) + const listed = [...ids].join(', ') + if (tour.startSceneId !== undefined && !ids.has(tour.startSceneId)) note(`${path}.threeImage.startSceneId`, `is ${tour.startSceneId}, which no scene has; the scenes' ids are ${listed}: name the scene the tour starts on by its sceneId`) + tour.scenes.forEach((/** @type {any} */ scene, /** @type {number} */ i) => { + if (!Array.isArray(scene?.interactions)) return + scene.interactions.forEach((/** @type {any} */ interaction, /** @type {number} */ j) => { + const action = interaction?.action + const to = action?.params?.nextSceneId + if (!/^H5P\.GoToScene\b/.test(String(action?.library ?? '')) || to === undefined || ids.has(to)) return + note(`${path}.threeImage.scenes[${i}].interactions[${j}].action.params.nextSceneId`, `is ${to}, which no scene has; the scenes' ids are ${listed}: name the scene it goes to by its sceneId`) + }) + }) + }, + // An answer names its personalities by name. The library splits the text at ", " and counts a + // name only where it is a personality's exactly (personalityQuiz.js: `split(', ')`, `===`), so + // another capital, a comma with no space after it, or a personality renamed counts for none; + // the answer's other names still count. + 'H5P.PersonalityQuiz'(params, path, note) { + if (!Array.isArray(params.personalities) || !Array.isArray(params.questions)) return + const names = new Set(params.personalities.map((/** @type {any} */ one) => one?.name).filter((/** @type {any} */ name) => typeof name === 'string' && name)) + params.questions.forEach((/** @type {any} */ question, /** @type {number} */ i) => { + if (!Array.isArray(question?.answers)) return + question.answers.forEach((/** @type {any} */ answer, /** @type {number} */ j) => { + if (typeof answer?.personality !== 'string' || !answer.personality) return + // An empty part, after a comma at the end, names nothing and is not said. + const unknown = answer.personality.split(', ').filter((/** @type {any} */ name) => name && !names.has(name)) + if (unknown.length) note(`${path}.questions[${i}].answers[${j}].personality`, `names ${unknown.map((/** @type {any} */ name) => JSON.stringify(name)).join(', ')}, which no personality is called exactly, so ${unknown.length === 1 ? 'that name counts' : 'those names count'} for none: write each name as its personality has it, capitals too, with a comma and a space between two`) + }) + }) + }, 'H5P.SingleChoiceSet'(params, path, note) { if (!Array.isArray(params.choices)) return params.choices.forEach((choice, i) => alike(choice?.answers, (answer) => answer, `${path}.choices[${i}].answers`, 'answer', note)) diff --git a/packages/author/lib/outline.mjs b/packages/author/lib/outline.mjs index 234c6380..1233b29f 100644 --- a/packages/author/lib/outline.mjs +++ b/packages/author/lib/outline.mjs @@ -1,5 +1,6 @@ import { isInterfaceText } from './schema.mjs' import { decodeEntities, editorWidget, tagsIn, takesMarkup } from './text.mjs' +import { drawOf } from './mistakes.mjs' import { questionTitle } from './types.mjs' /** @@ -168,7 +169,18 @@ export function outlineOf(libraries, content, { limit = Infinity } = {}) { */ const walkFields = (fields, params, depth, type, path, bare = false) => { if (!isObject(params)) return - if (!path) semanticsOf.set(type, fields) + if (!path) { + semanticsOf.set(type, fields) + // A setting that shows only some of a list's items, which a chat that adds items may keep + // as it was (#268): the type's first line says how many of how many, as its library draws. + const draw = drawOf(type, params) + if (draw && draw.shown < draw.total) { + const { shown, total, fixed, what } = draw + emit(depth, !fixed ? `Shows ${shown} of the ${total} ${what} each time, drawn at random` + : shown === fixed ? `Shows only the ${fixed} ${what} fixed on the grid, of ${total}` + : `Shows ${shown} of the ${total} ${what} each time: the ${fixed} fixed on the grid, and ${shown - fixed} drawn at random`) + } + } for (const field of fields) walk(field, params[field.name], depth, type, path ? `${path}.${field.name}` : field.name, bare, params) } diff --git a/packages/author/tests/build.test.ts b/packages/author/tests/build.test.ts index 16153190..45a3d79b 100644 --- a/packages/author/tests/build.test.ts +++ b/packages/author/tests/build.test.ts @@ -638,6 +638,90 @@ describe('notes for what builds and is almost surely a mistake (#241)', () => { ]) }) + it('says where a quiz\'s pool leaves questions out, or draws none (#268)', async () => { + const question = (text: string) => ({ library: 'H5P.TrueFalse', params: { question: text, correct: 'true' } }) + const questions = ['The Danube reaches the Black Sea.', 'The Seine flows through Paris.', 'The Volga is in Europe.'].map(question) + const quiz = (poolSize?: number) => notesOf({ ...META, type: 'H5P.QuestionSet', params: { questions, ...(poolSize === undefined ? {} : { poolSize }) } }) + expect(await quiz(2)).toEqual([ + { path: 'params.poolSize', message: 'shows 2 of the 3 questions each time, drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws' } + ]) + // As many as there are leaves none out, though Question Set still shuffles them, and is what + // hides a question added later; more, once there are more still. + expect(await quiz(3)).toEqual([ + { path: 'params.poolSize', message: 'is the number of questions, 3, so it leaves none out but shows them in a random order, and one added later would leave one out at random: leave it out, and set randomQuestions for a random order' } + ]) + expect(await quiz(5)).toEqual([ + { path: 'params.poolSize', message: 'is above the number of questions, 3, so it leaves none out but shows them in a random order until more than 5 are, and then leaves some out at random: leave it out, and set randomQuestions for a random order' } + ]) + expect(await quiz()).toEqual([]) + }) + + it('says where a memory game or a crossword draws, as a quiz does (#268)', async () => { + const card = (text: string) => ({ image: { path: 'river.png' }, imageAlt: text }) + const at = await mkdtemp(join(dir, 'cards-')) + await writeFile(join(at, 'river.png'), png(64, 48)) + expect(await notesOf({ ...META, type: 'H5P.MemoryGame', params: { cards: [card('A river'), card('A lake'), card('A sea')], behaviour: { numCardsToUse: 2 } } }, at)).toEqual([ + { path: 'params.behaviour.numCardsToUse', message: 'shows 2 of the 3 pairs each time, drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws' } + ]) + const word = (clue: string, answer: string) => ({ clue, answer }) + expect(await notesOf({ ...META, type: 'H5P.Crossword', params: { words: [word('A long river', 'Danube'), word('Through Paris', 'Seine')], behaviour: { poolSize: 2 } } })).toEqual([ + { path: 'params.behaviour.poolSize', message: 'is the number of words, 2, so it leaves none out, and one added later would leave one out at random: leave it out' } + ]) + // Words fixed on the grid are always kept, and the others drawn to make up the rest. + const fixed = (clue: string, answer: string, row: number) => ({ clue, answer, fixWord: true, row, column: 1, orientation: 'across' }) + const fourWords = [fixed('A long river', 'Danube', 1), fixed('Through Paris', 'Seine', 3), word('Through Rome', 'Tiber'), word('Through London', 'Thames')] + expect(await notesOf({ ...META, type: 'H5P.Crossword', params: { words: fourWords, behaviour: { poolSize: 3 } } })).toEqual([ + { path: 'params.behaviour.poolSize', message: 'shows 3 of the 4 words each time, the 2 fixed on the grid and 1 of the other 2 drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws' } + ]) + expect(await notesOf({ ...META, type: 'H5P.Crossword', params: { words: fourWords, behaviour: { poolSize: 2 } } })).toEqual([ + { path: 'params.behaviour.poolSize', message: 'shows only the 2 words fixed on the grid, and never the other 2: leave it out to show them all' } + ]) + }) + + it('says where a part is named by a number, an id or a name that is not there (#268)', async () => { + const text = (html: string) => ({ action: { library: 'H5P.AdvancedText', params: { text: html } } }) + // A Course Presentation button to slide 3 of 2. + expect(await notesOf({ ...META, type: 'H5P.CoursePresentation', params: { presentation: { slides: [ + { elements: [text('

Rivers

'), { goToSlideType: 'specified', goToSlide: 3, x: 10, y: 10, width: 20, height: 10 }] }, + { elements: [text('

Lakes

')] } + ] } } })).toEqual([ + { path: 'params.presentation.slides[0].elements[1].goToSlide', message: 'goes to slide 3, and there are 2 slides, so the button has no slide to go to: name a slide by its number, from 1' } + ]) + // Agamotto: a start image past the last is held to the last; a fraction is refused already. + const at = await mkdtemp(join(dir, 'agamotto-')) + await writeFile(join(at, 'river.png'), png(64, 48)) + const image = (alt: string) => ({ image: { library: 'H5P.Image', params: { file: { path: 'river.png' }, alt } }, labelText: alt }) + const agamotto = (startImage: number) => notesOf({ ...META, type: 'H5P.Agamotto', params: { items: [image('Spring'), image('Summer')], behaviour: { startImage } } }, at) + expect(await agamotto(3)).toEqual([ + { path: 'params.behaviour.startImage', message: 'is image 3, and there are 2 images, so it starts at the last: name one by its number, from 1, or leave it out' } + ]) + await expect(agamotto(1.5)).rejects.toThrow('params.behaviour.startImage: takes a whole number') + expect(await agamotto(2)).toEqual([]) + // Drag and Drop: a right element and a zone that are not there, and an element that can be + // dropped in none of the zones it is right in. + const element = (text: string, zones: string[]) => ({ type: { library: 'H5P.AdvancedText', params: { text: `

${text}

` } }, x: 5, y: 5, width: 10, height: 3, dropZones: zones }) + const zone = (label: string, right: string[]) => ({ label, x: 40, y: 10, width: 20, height: 10, correctElements: right }) + expect(await notesOf({ ...META, type: 'H5P.DragQuestion', params: { question: { settings: { size: { width: 620, height: 310 } }, task: { + elements: [element('Danube', ['0']), element('Garda', ['0']), element('Seine', ['0', '3'])], + dropZones: [zone('Rivers', ['0', '2', '5']), zone('Lakes', ['1'])] + } } } })).toEqual([ + { path: 'params.question.task.dropZones[0].correctElements[2]', message: 'names element "5", and there are 3 elements, counted from 0: name each by its place in elements' }, + { path: 'params.question.task.elements[1].dropZones', message: 'lets the element be dropped in zone 0, and it is right only in zone 1, so no learner can put it right: name that zone in its dropZones' }, + { path: 'params.question.task.elements[2].dropZones[1]', message: 'names drop zone "3", and there are 2 drop zones, counted from 0: name each by its place in dropZones' } + ]) + // A Personality Quiz answer naming a personality renamed since, and one in another case: the + // library takes a name only as its personality has it, and parts two at a comma and a space. + expect(await notesOf({ ...META, type: 'H5P.PersonalityQuiz', params: { + titleScreen: { title: { text: 'Which traveller are you?' } }, + personalities: [{ name: 'Explorer', description: 'Goes far.' }, { name: 'Builder', description: 'Makes things.' }], + questions: [{ text: 'On a free day you…', answers: [{ text: 'walk somewhere new', personality: 'Explorer' }, { text: 'fix something', personality: 'Maker, builder' }, { text: 'do both', personality: 'Explorer, Builder, ' }, { text: 'roam', personality: 'Explorer, Wanderer' }] }] + } })).toEqual([ + { path: 'params.questions[0].answers[1].personality', message: 'names "Maker", "builder", which no personality is called exactly, so those names count for none: write each name as its personality has it, capitals too, with a comma and a space between two' }, + // A comma at the end names nothing; a known name beside an unknown one still counts. + { path: 'params.questions[0].answers[3].personality', message: 'names "Wanderer", which no personality is called exactly, so that name counts for none: write each name as its personality has it, capitals too, with a comma and a space between two' } + ]) + }) + it('says where a choice of pictures marks none correct', async () => { const at = await mkdtemp(join(dir, 'pictures-')) await writeFile(join(at, 'delta.png'), png(64, 48)) diff --git a/packages/author/tests/confine.test.ts b/packages/author/tests/confine.test.ts index e643fbf4..db78e132 100644 --- a/packages/author/tests/confine.test.ts +++ b/packages/author/tests/confine.test.ts @@ -285,6 +285,23 @@ describe('outline', () => { expect(await outline({ ...quiz, language: 'de' })).toBe(expected) }) + it('says first how many of how many a quiz, a memory game or a crossword shows, where it draws (#268)', async () => { + const question = (text: string) => ({ library: 'H5P.TrueFalse', params: { question: text, correct: 'true' } }) + const questions = ['Water is wet.', 'Ice is cold.', 'Steam is hot.'].map(question) + expect((await outline({ type: 'H5P.QuestionSet', params: { questions, poolSize: 2 } })).split('\n')[0]).toBe('Shows 2 of the 3 questions each time, drawn at random') + // At or above the number of questions it draws nothing, and says nothing. + expect((await outline({ type: 'H5P.QuestionSet', params: { questions, poolSize: 3 } })).split('\n')[0]).toBe(' Question 1') + const words = [{ clue: 'A long river', answer: 'Danube' }, { clue: 'Through Paris', answer: 'Seine' }, { clue: 'Through Rome', answer: 'Tiber' }] + expect((await outline({ type: 'H5P.Crossword', params: { words, behaviour: { poolSize: 2 } } })).split('\n')[0]).toBe('Shows 2 of the 3 words each time, drawn at random') + // A crossword's words fixed on the grid are always among them. + const fixedWords = [{ ...words[0], fixWord: true, row: 1, column: 1, orientation: 'across' }, ...words.slice(1)] + expect((await outline({ type: 'H5P.Crossword', params: { words: fixedWords, behaviour: { poolSize: 2 } } })).split('\n')[0]).toBe('Shows 2 of the 3 words each time: the 1 fixed on the grid, and 1 drawn at random') + // A memory game counts pairs. + const pair = (alt: string) => ({ image: { path: 'in.png' }, imageAlt: alt }) + const game = await buildPackage({ ...META, type: 'H5P.MemoryGame', params: { cards: [pair('A river'), pair('A lake'), pair('A sea')], behaviour: { numCardsToUse: 2 } } }, undefined, { check: true, base: allowed }) + expect(game.outline.split('\n')[0]).toBe('Shows 2 of the 3 pairs each time, drawn at random') + }) + it('keeps a text\'s paragraphs, lines and list items apart, and numbers slides, with each slide\'s keyword', async () => { const text = (html: string) => ({ action: { library: 'H5P.AdvancedText', params: { text: html } } }) expect(await outline({ diff --git a/skills/h5p-author/references/types/H5P.MemoryGame.md b/skills/h5p-author/references/types/H5P.MemoryGame.md index 3c6760b6..a0a43ad8 100644 --- a/skills/h5p-author/references/types/H5P.MemoryGame.md +++ b/skills/h5p-author/references/types/H5P.MemoryGame.md @@ -5,6 +5,7 @@ Cards face down, turned two at a time, until every pair is found. - Each item of `cards` is a pair: `image` and `imageAlt`, and, for a pair of two different pictures, `match` and `matchAlt`. Without `match` the pair is two copies of `image`. - `description` is shown when the pair is found: say what it shows. - Square-ish pictures work best; at least two cards. +- `behaviour.numCardsToUse` is not the number of cards: it shows only that many pairs, drawn at random each time. Leave it out unless the user asks for a random draw. ## Example diff --git a/skills/h5p-author/references/types/H5P.QuestionSet.md b/skills/h5p-author/references/types/H5P.QuestionSet.md index c884785c..f9058e41 100644 --- a/skills/h5p-author/references/types/H5P.QuestionSet.md +++ b/skills/h5p-author/references/types/H5P.QuestionSet.md @@ -5,7 +5,7 @@ A quiz: questions one after another, then a result page with the score. - Each item of `questions` is sub-content: `{ "library": "H5P.MultiChoice", "params": { … }, "metadata": { "title": "…" } }`. Write each question's `params` from its own type file. The result page lists questions by `metadata.title`; without one a question is "Question 2" in the content's language. - `passPercentage` is the pass mark; `endGame.overallFeedback` holds the score ranges' messages. Question Set 1.21 draws neither on its result page, an H5P bug (h5p/h5p-question-set#183): screen readers announce the message, and a learner sees only the score. Tell the user. - An intro screen: `introPage.showIntroPage: true`, with `title` and `introduction`. -- `randomQuestions` shuffles them; `poolSize` draws that many from the list each time. +- `randomQuestions` shuffles them. `poolSize` is not the number of questions: it shows only that many, drawn at random each time, and leaves the rest out. Leave it out unless the user asks for a random draw. - Its navigation and result screen ("Previous", "Next", "Results", "Score") are English in all but one or two of its 48 translations; the build lists what stayed English. ## Example