All files / skin-lr2/src/state test-support.ts

100% Statements 14/14
92.85% Branches 13/14
100% Functions 5/5
100% Lines 9/9

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 47 48 49 50 51 52 53 54 55 56            27x                                       22x 22x           22x 22x 22x 22x               13x                 14x    
import { createEmptyJSON, type BeMusicEvent, type BeMusicJSON } from '@be-music/chart-source';
import type { CourseDefinition } from '@be-music/player-engine/course';
import type { LibraryChart, LibraryCourse } from '@be-music/player-scene-model';
 
/** A library chart for tests: an empty chart, with `overrides` applied. */
export function makeChart(overrides: Partial<LibraryChart> = {}): LibraryChart {
  return {
    id: 'test:song',
    sourceId: 'test',
    sourceLabel: 'test',
    sourceKind: 'files',
    chartPath: 'test/song.bms',
    directoryLabel: 'test',
    fileLabel: 'song.bms',
    title: 'Untitled',
    totalNotes: 0,
    chart: createEmptyJSON(),
    ...overrides,
  };
}
 
/** A chart with one object on each of `channels`, and the `#DIFFICULTY` / `#RANK` / bmson mode hint given. */
export function makeChartWith(
  options: { channels?: readonly string[]; difficulty?: number; rank?: number; modeHint?: string },
  overrides: Partial<LibraryChart> = {},
): LibraryChart {
  const chart: BeMusicJSON = createEmptyJSON();
  chart.events = (options.channels ?? []).map((channel, index): BeMusicEvent => ({
    measure: 1,
    channel,
    position: [index, Math.max(1, options.channels?.length ?? 1)],
    value: '01',
  }));
  if (options.difficulty !== undefined) chart.metadata.difficulty = options.difficulty;
  if (options.rank !== undefined) chart.metadata.rank = options.rank;
  if (options.modeHint !== undefined) chart.bmson.info.modeHint = options.modeHint;
  return makeChart({ chart, ...overrides });
}
 
/** A course bar for tests: a grade course, playable, with one stage per title. */
export function makeCourse(
  overrides: Partial<LibraryCourse> = {},
  titles: readonly string[] = ['stage'],
): LibraryCourse {
  const definition: CourseDefinition = {
    name: 'Dan',
    kind: 'grade',
    stages: [],
    constraints: [],
    trophies: [],
    release: false,
    source: { format: 'beatoraja-json' },
  };
  return { id: 'dan#0', definition, stages: titles.map((title) => ({ title })), playable: true, ...overrides };
}