import { generatePages, getDisplayState } from '../utils';

describe('generatePages', () => {
  describe('when total page < 7', () => {
    it('returns full pages', () => {
      expect(generatePages({ current: 1, total: 6 })).toEqual([
        1,
        2,
        3,
        4,
        5,
        6,
      ]);
    });
  });

  describe('when total page = 7', () => {
    it('returns full pages', () => {
      expect(generatePages({ current: 2, total: 7 })).toEqual([
        1,
        2,
        3,
        4,
        5,
        6,
        7,
      ]);
    });
  });

  describe('when total page > 7', () => {
    describe('when current page < 5', () => {
      it('returns first 5 and the rest with spreading symbol', () => {
        expect(generatePages({ current: 4, total: 8 })).toEqual([
          1,
          2,
          3,
          4,
          5,
          '-',
          8,
        ]);
        expect(generatePages({ current: 1, total: 8 })).toEqual([
          1,
          2,
          3,
          4,
          5,
          '-',
          8,
        ]);
      });
    });

    describe('when current page = 5', () => {
      it('returns spreading symbol after first page and the last 5 pages', () => {
        expect(generatePages({ current: 5, total: 8 })).toEqual([
          1,
          '-',
          4,
          5,
          6,
          7,
          8,
        ]);
      });
    });

    describe('when current page > 5', () => {
      describe('when current page in the last 5 items', () => {
        it('returns first page, spreading symbol and the last 5 pages', () => {
          expect(generatePages({ current: 6, total: 8 })).toEqual([
            1,
            '-',
            4,
            5,
            6,
            7,
            8,
          ]);
        });
      });

      describe('when current page NOT in the last 5 items', () => {
        it('returns a spreading symbol after first page & another spreading symbol before last page', () => {
          expect(generatePages({ current: 6, total: 10 })).toEqual([
            1,
            '-',
            5,
            6,
            7,
            '-',
            10,
          ]);
        });
      });
    });
  });
});

describe('getDisplayState', () => {
  it.each`
    current | pageNumber | expected
    ${1}    | ${'-'}     | ${'spreading'}
    ${1}    | ${1}       | ${'activePage'}
    ${1}    | ${2}       | ${'pageNumber'}
  `('returns correctly', ({ current, pageNumber, expected }) => {
    expect(getDisplayState({ current, pageNumber })).toEqual(expected);
  });
});
