Skip to content

Commit

Permalink
Calendar: Make generator tests produce easily-readable snapshots
Browse files Browse the repository at this point in the history
This makes it easier to verify that the snapshots are actually correct.

I left one raw dump to verify the actual object.
  • Loading branch information
SLaks committed Oct 13, 2024
1 parent 1791b1c commit 5cc9402
Show file tree
Hide file tree
Showing 5 changed files with 334 additions and 817 deletions.
67 changes: 48 additions & 19 deletions src/calendar-model/generator.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import test from 'ava'
import { UserSettings } from './user-settings.ts'
import { LeiningGenerator } from './generator.ts'
import { HDate, months } from '@hebcal/core'
import { LeiningDate } from './model-types.ts'
import { HDate, Locale, months } from '@hebcal/core'
import { LeiningAliyah, LeiningDate } from './model-types.ts'
import hebrewNumeralFromInteger from '../hebrew-numeral.ts'
import { Ref } from '../ref.ts'
import { getBookName } from './hebcal-conversions.ts'

const testSettings: UserSettings = {
ashkenazi: true,
Expand All @@ -26,43 +29,69 @@ for (let year = 5780; year < 5800; year++) {

test('generates יום כיפור', (t) => {
t.snapshot(
stripDate(generator.createLeiningDate(new HDate(10, months.TISHREI, 5784)))
dumpLeiningDate(new HDate(10, months.TISHREI, 5784)),
'These tests verify the returned information, in easily readable format'
)
})

test('generates שמחת תורה', (t) => {
t.snapshot(
stripDate(generator.createLeiningDate(new HDate(23, months.TISHREI, 5784)))
)
t.snapshot(dumpLeiningDate(new HDate(23, months.TISHREI, 5784)))
})

test('generates תענית אסתר', (t) => {
t.snapshot(
stripDate(generator.createLeiningDate(new HDate(13, months.ADAR_II, 5785)))
)
t.snapshot(dumpLeiningDate(new HDate(13, months.ADAR_II, 5785)))
})

test('generates פורים', (t) => {
t.snapshot(
stripDate(generator.createLeiningDate(new HDate(14, months.ADAR_II, 5784)))
)
t.snapshot(dumpLeiningDate(new HDate(14, months.ADAR_II, 5784)))
})

test('generates ערב תשעה באב', (t) => {
t.snapshot(
stripDate(generator.createLeiningDate(new HDate(8, months.AV, 5784)))
)
t.snapshot(dumpLeiningDate(new HDate(8, months.AV, 5784)))
})

test('generates תשעה באב', (t) => {
t.snapshot(
stripDate(generator.createLeiningDate(new HDate(9, months.AV, 5784)))
)
t.snapshot(dumpLeiningDate(new HDate(9, months.AV, 5784)))
})

test('generates שבת ראש חודש חנוכה', (t) => {
t.snapshot(dumpLeiningDate(new HDate(30, months.KISLEV, 5782)))
})

/** Prints the information in a `LeiningDate`, to be easily readable in the Markdown snapshot. */
function dumpLeiningDate(date: HDate) {
const ld = generator.createLeiningDate(date)
if (!ld) return null
return {
date: ld.id,
title: ld.title,
leinings: ld.leinings.map((o) => ({
isParsha: o.isParsha,
runs: o.runs.map((r) => ({
id: r.id,
type: r.type,
scroll: r.scroll,
aliyot: r.aliyot.map(
// TODO(haftara): Render book name, once we have those
(a) =>
`${a.index}: ${bookName(a)} ${dumpRef(a.start)} - ${dumpRef(a.end)}`
),
})),
})),
}
}
function bookName(a: LeiningAliyah) {
return Locale.gettext(getBookName(a.start), 'he-x-nonikud')
}

function dumpRef(ref: Ref) {
return `${hebrewNumeralFromInteger(ref.c)}:${hebrewNumeralFromInteger(ref.v)}`
}

test('generates the full LeiningDate object for יום כיפור', (t) => {
t.snapshot(
stripDate(generator.createLeiningDate(new HDate(30, months.KISLEV, 5782)))
stripDate(generator.createLeiningDate(new HDate(10, months.TISHREI, 5784))),
'This test verified the full structure of the LeiningDate interface'
)
})

Expand Down
Loading

0 comments on commit 5cc9402

Please sign in to comment.