import { describe, expect, it } from 'vitest'
import { buildPaginationItems } from './pagination'

describe('buildPaginationItems', () => {
  it('returns no items for a single page', () => {
    expect(buildPaginationItems(1, 1)).toEqual([])
  })

  it('returns all pages when the range is small', () => {
    expect(buildPaginationItems(2, 5)).toEqual([
      { type: 'page', page: 1 },
      { type: 'page', page: 2 },
      { type: 'page', page: 3 },
      { type: 'page', page: 4 },
      { type: 'page', page: 5 },
    ])
  })

  it('inserts ellipsis around the active page on large ranges', () => {
    expect(buildPaginationItems(10, 20)).toEqual([
      { type: 'page', page: 1 },
      { type: 'ellipsis', key: 'ellipsis-1-9' },
      { type: 'page', page: 9 },
      { type: 'page', page: 10 },
      { type: 'page', page: 11 },
      { type: 'ellipsis', key: 'ellipsis-11-20' },
      { type: 'page', page: 20 },
    ])
  })
})
