All files / src/ui taskReference.ts

100% Statements 29/29
100% Branches 5/5
100% Functions 3/3
100% Lines 29/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46                      2x 2x 2x   2x 2x 2x 2x 2x     2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x     2x 1609x 1609x 1609x 1609x 1609x 1609x  
/**
 * The `?` on a task's row that names what the task re-implements
 * (`analysis/references.ts`), and what its tip says.
 *
 * The mark and the tip are `questionMark.ts`'s, which the landing page's
 * example sessions share. What is the row's own is the colour — the answer at
 * a glance, green where the validation found the task identical or equivalent
 * to its reference, the text's own colour where it is untested — and the
 * tip's words: the method, how it came out, and the DOI as a link.
 */
 
import { isValidated, type TaskReference } from '../analysis/references'
import { el } from './dom'
import { questionMark } from './questionMark'
 
const STATUS: Record<TaskReference['agreement'], string> = {
  identical: 'Identical in the validation',
  equivalent: 'Equivalent in the validation',
  untested: 'Not validated yet',
}
 
/** The tip's words: the method, then how it came out and its DOI. */
function fill(box: HTMLElement, reference: TaskReference): void {
  box.replaceChildren(
    el('p', { class: 'question-tip-text', text: reference.method }),
    el(
      'p',
      { class: 'question-tip-note' },
      `${STATUS[reference.agreement]} · `,
      el('a', {
        text: `doi:${reference.doi}`,
        attrs: { href: `https://doi.org/${reference.doi}`, target: '_blank', rel: 'noopener noreferrer' },
      }),
    ),
  )
}
 
/** The `?` for a task that re-implements `reference`. */
export function referenceMark(reference: TaskReference): HTMLElement {
  return questionMark({
    class: `task-ref${isValidated(reference) ? ' is-validated' : ''}`,
    label: `${reference.method} ${STATUS[reference.agreement]}.`,
    fill: (box) => fill(box, reference),
  })
}