import { describe, expect, it } from 'vitest' import { nextPlanYear, parsePlanName, planGardensOf, planNameFor, planYearOf } from './plan' describe('plan names', () => { it('round-trips the default copy name', () => { expect(planNameFor('Home Garden', 2027)).toBe('Home Garden — 2027') expect(parsePlanName('Home Garden — 2027')).toEqual({ base: 'Home Garden', year: 2027 }) }) it('accepts a plain hyphen or en dash with spaces around it', () => { expect(parsePlanName('Back forty - 2028')).toEqual({ base: 'Back forty', year: 2028 }) expect(parsePlanName('Back forty – 2028')).toEqual({ base: 'Back forty', year: 2028 }) }) it('does not read a bare year or an unspaced dash as a plan', () => { expect(parsePlanName('2027')).toBeNull() expect(parsePlanName('Plot-2027')).toBeNull() expect(parsePlanName('Home Garden')).toBeNull() }) it('tags only this year and later as plans', () => { const now = new Date(2026, 7, 22) expect(planYearOf('Home Garden — 2027', now)).toBe(2027) expect(planYearOf('Home Garden — 2026', now)).toBe(2026) expect(planYearOf('Home Garden — 2024', now)).toBeNull() }) it('finds a garden’s plan copies in year order', () => { const gardens = [ { id: 1, name: 'Home Garden' }, { id: 2, name: 'Home Garden — 2028' }, { id: 3, name: 'Home Garden — 2027' }, { id: 4, name: 'Balcony — 2027' }, ] expect(planGardensOf('Home Garden', gardens).map((g) => g.id)).toEqual([3, 2]) }) }) describe('nextPlanYear', () => { it('skips years that already have a plan copy, however the dash was typed', () => { const names = ['Back Yard', 'Back Yard — 2027', 'Back Yard - 2028', 'Front Strip — 2029'] expect(nextPlanYear('Back Yard', names, 2027)).toBe(2029) expect(nextPlanYear('Front Strip', names, 2027)).toBe(2027) }) it('is the starting year when nothing is taken', () => { expect(nextPlanYear('Plot', [], 2030)).toBe(2030) }) })