import { describe, expect, it } from 'vitest'
import { createSampleData } from './sampleData'
import { dashboardStats, goalProgress, sortedUpcoming } from './domain'

describe('domain calculations', () => {
  it('derives goal progress without storing duplicate values', () => {
    const state = createSampleData()
    expect(goalProgress('goal-typescript', state.tasks)).toBe(33)
    expect(goalProgress('unknown', state.tasks)).toBe(0)
  })

  it('derives dashboard statistics', () => {
    const state = createSampleData()
    expect(dashboardStats(state)).toMatchObject({ goals: 4, completed: 2, active: 2 })
  })

  it('orders incomplete dated tasks chronologically', () => {
    const state = createSampleData()
    const upcoming = sortedUpcoming(state.tasks)
    expect(upcoming.every((task) => task.status !== 'done')).toBe(true)
    expect(upcoming.map((task) => task.dueDate)).toEqual([...upcoming.map((task) => task.dueDate)].sort())
  })
})
