Files
vu/tests/calendar/commemorations.test.ts
T
will f43f030a6a Fix ordinary-Sunday precedence and unify getDayLabel's commemoration rendering
Two related fixes surfaced while chasing why St. Gregory Thaumaturgus
appeared to be misdated on Nov 18:

- calendar/commemorations.ts's `ordinary-sunday` case was transferring a
  Semiduplex (or lower) saint off the Sunday instead of commemorating it
  in place — an earlier, unverified guess. Live-verified against both
  Tridentine 1906 and Divino Afflatu 1954 (St. Gregory Thaumaturgus, St.
  Clement, St. Apollinaris, St. Thomas Becket, all real cases): the saint
  stays and is commemorated on the Sunday itself, same as Simplex, never
  pushed to the next open day. This is what was actually moving Gregory
  onto Nov 18 — not a data error. `applyChristmasOctaveSunday`'s own
  Dec 26-29 special case needed a matching adjustment (per its own
  documented intent, the displaced saint there is deliberately *not*
  commemorated in place, since he reappears in full on Dec 30 instead).

- getDayLabel had five branches, each hand-assembling its own
  filter/format logic for which commemorations to show — which is why
  the octave phrasing, the closing-day title, and a missing Sunday
  commemoration turned into three separate bugs earlier instead of one.
  Replaced with a single shared `collectCommemorations` used by every
  branch. This also exposed that the sanctoral-winner branch never
  showed any commemorated saint at all, and every other branch only
  showed the *first* one (`.find()`), silently dropping real collisions
  — both now show every commemorated saint, matching this app's own
  generous-commemoration design.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-18 10:59:50 -04:00

166 lines
8.4 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { decideOccurrence, compareFeastClass, isAtLeast } from '../../src/calendar/commemorations';
import type { SanctoralIdentity } from '../../src/calendar/types';
function saint(rank: SanctoralIdentity['rank']): SanctoralIdentity {
return { id: 'x', name: 'St. Ereden', rank };
}
describe('compareFeastClass / isAtLeast', () => {
it('orders the seven ranks low to high, with vigil between simplex and semiduplex', () => {
expect(compareFeastClass('simplex', 'vigil')).toBeLessThan(0);
expect(compareFeastClass('vigil', 'semiduplex')).toBeLessThan(0);
expect(compareFeastClass('semiduplex', 'duplex')).toBeLessThan(0);
expect(compareFeastClass('duplex-1-classis', 'simplex')).toBeGreaterThan(0);
expect(compareFeastClass('duplex', 'duplex')).toBe(0);
});
it('isAtLeast is inclusive of the threshold itself', () => {
expect(isAtLeast('duplex-majus', 'duplex-majus')).toBe(true);
expect(isAtLeast('duplex', 'duplex-majus')).toBe(false);
});
});
describe('decideOccurrence — no candidate', () => {
it('temporal wins trivially when nothing is assigned to the date', () => {
expect(decideOccurrence('ordinary-feria', 'some-feria-id', null)).toEqual({
winner: { kind: 'temporal', id: 'some-feria-id' },
commemorations: [],
});
});
});
describe('decideOccurrence — ordinary-feria', () => {
it('always yields to any real feast, uncommemorated, whatever its rank', () => {
for (const rank of ['simplex', 'vigil', 'semiduplex', 'duplex', 'duplex-1-classis'] as const) {
const result = decideOccurrence('ordinary-feria', 'id', saint(rank));
expect(result.winner).toEqual({ kind: 'sanctoral', id: 'x', name: 'St. Ereden', rank });
expect(result.commemorations).toEqual([]);
expect(result.transfer).toBeUndefined();
}
});
});
describe('decideOccurrence — privileged-feria-minor', () => {
it('semiduplex or higher wins outright, the feria is commemorated in return', () => {
// Verified: St. Nicholas, Semiduplex, outright wins against an
// ordinary (non-Ember) Advent Saturday in the real Monastic 1617
// engine, with the feria itself commemorated back.
for (const rank of ['semiduplex', 'duplex', 'duplex-1-classis'] as const) {
const result = decideOccurrence('privileged-feria-minor', 'id', saint(rank));
expect(result.winner).toEqual({ kind: 'sanctoral', id: 'x', name: 'St. Ereden', rank });
expect(result.commemorations).toEqual([{ kind: 'temporal', id: 'id' }]);
expect(result.transfer).toBeUndefined();
}
});
it('simplex or vigil stays and is commemorated, not transferred', () => {
// Verified: St. Bibiana, Simplex, merely commemorated under an
// ordinary Advent feria in the real Monastic 1617 engine.
for (const rank of ['simplex', 'vigil'] as const) {
const result = decideOccurrence('privileged-feria-minor', 'id', saint(rank));
expect(result.winner).toEqual({ kind: 'temporal', id: 'id' });
expect(result.commemorations).toEqual([{ kind: 'sanctoral', id: 'x', name: 'St. Ereden', rank }]);
expect(result.transfer).toBeUndefined();
}
});
});
describe('decideOccurrence — privileged-feria', () => {
it('behaves exactly like an ordinary Sunday — duplex or higher wins outright, the feria is commemorated in return', () => {
// Verified: St. Gregory the Great, plain Duplex, outright wins against
// a Lenten Ember Saturday in the real Monastic 1617 engine.
const result = decideOccurrence('privileged-feria', 'id', saint('duplex'));
expect(result.winner).toEqual({ kind: 'sanctoral', id: 'x', name: 'St. Ereden', rank: 'duplex' });
expect(result.commemorations).toEqual([{ kind: 'temporal', id: 'id' }]);
});
it('simplex stays and is commemorated, not transferred', () => {
const result = decideOccurrence('privileged-feria', 'id', saint('simplex'));
expect(result.winner).toEqual({ kind: 'temporal', id: 'id' });
expect(result.commemorations).toEqual([{ kind: 'sanctoral', id: 'x', name: 'St. Ereden', rank: 'simplex' }]);
});
it('semiduplex/vigil get nothing here — transfer instead', () => {
const result = decideOccurrence('privileged-feria', 'id', saint('semiduplex'));
expect(result.commemorations).toEqual([]);
expect(result.transfer).toEqual({ candidate: saint('semiduplex'), direction: 'forward' });
});
});
describe('decideOccurrence — privileged-feria-major', () => {
it('is never displaced, same as privileged-sunday — duplex-majus and up are commemorated', () => {
// Verified: St. Mark, Duplex II. classis, only ever commemorated —
// never wins outright — within the Easter Octave.
for (const rank of ['duplex-majus', 'duplex-2-classis', 'duplex-1-classis'] as const) {
const result = decideOccurrence('privileged-feria-major', 'id', saint(rank));
expect(result.winner).toEqual({ kind: 'temporal', id: 'id' });
expect(result.commemorations).toEqual([{ kind: 'sanctoral', id: 'x', name: 'St. Ereden', rank }]);
}
});
it('yields nothing short of duplex-majus — transfers instead', () => {
const result = decideOccurrence('privileged-feria-major', 'id', saint('duplex'));
expect(result.winner).toEqual({ kind: 'temporal', id: 'id' });
expect(result.commemorations).toEqual([]);
expect(result.transfer).toEqual({ candidate: saint('duplex'), direction: 'forward' });
});
});
describe('decideOccurrence — ordinary-sunday', () => {
it('duplex or higher wins outright, and the Sunday itself is commemorated', () => {
const result = decideOccurrence('ordinary-sunday', 'post-epiphany-2', saint('duplex'));
expect(result.winner).toEqual({ kind: 'sanctoral', id: 'x', name: 'St. Ereden', rank: 'duplex' });
expect(result.commemorations).toEqual([{ kind: 'temporal', id: 'post-epiphany-2' }]);
expect(result.transfer).toBeUndefined();
});
it('simplex stays and is commemorated, not transferred', () => {
const result = decideOccurrence('ordinary-sunday', 'post-epiphany-2', saint('simplex'));
expect(result.winner).toEqual({ kind: 'temporal', id: 'post-epiphany-2' });
expect(result.commemorations).toEqual([{ kind: 'sanctoral', id: 'x', name: 'St. Ereden', rank: 'simplex' }]);
expect(result.transfer).toBeUndefined();
});
it('semiduplex stays and is commemorated, not transferred', () => {
// Live-verified (both Tridentine 1906 and Divino Afflatu 1954): St.
// Gregory Thaumaturgus (Semiduplex) lands on the 6th Sunday after
// Epiphany and is commemorated right there, not pushed to the next
// open day — same treatment as Simplex above, not a separate
// "too important to merely commemorate" tier.
const result = decideOccurrence('ordinary-sunday', 'post-epiphany-2', saint('semiduplex'));
expect(result.winner).toEqual({ kind: 'temporal', id: 'post-epiphany-2' });
expect(result.commemorations).toEqual([{ kind: 'sanctoral', id: 'x', name: 'St. Ereden', rank: 'semiduplex' }]);
expect(result.transfer).toBeUndefined();
});
it('vigil gets nothing here — transfers backward', () => {
const result = decideOccurrence('ordinary-sunday', 'post-epiphany-2', saint('vigil'));
expect(result.transfer).toEqual({ candidate: saint('vigil'), direction: 'backward' });
});
});
describe('decideOccurrence — privileged-sunday', () => {
it('is never displaced; duplex-majus and up are commemorated', () => {
for (const rank of ['duplex-majus', 'duplex-2-classis', 'duplex-1-classis'] as const) {
const result = decideOccurrence('privileged-sunday', 'advent-1', saint(rank));
expect(result.winner).toEqual({ kind: 'temporal', id: 'advent-1' });
expect(result.commemorations).toEqual([{ kind: 'sanctoral', id: 'x', name: 'St. Ereden', rank }]);
expect(result.transfer).toBeUndefined();
}
});
it('duplex, semiduplex, and simplex all transfer forward — no bare commemoration here', () => {
for (const rank of ['duplex', 'semiduplex', 'simplex'] as const) {
const result = decideOccurrence('privileged-sunday', 'advent-1', saint(rank));
expect(result.commemorations).toEqual([]);
expect(result.transfer).toEqual({ candidate: saint(rank), direction: 'forward' });
}
});
it('vigil transfers backward, same as on an ordinary Sunday', () => {
const result = decideOccurrence('privileged-sunday', 'advent-1', saint('vigil'));
expect(result.transfer).toEqual({ candidate: saint('vigil'), direction: 'backward' });
});
});