'use strict';

import commonModule from '..';

describe('chunk filter', () => {
  beforeEach(angular.mock.module(commonModule));

  describe('with even distribution', () => {
    it('should chunk rows evenly', angular.mock.inject(($filter) => {
      const arr = ['a', 'b', 'c', 'd'];
      const sut = $filter('chunk')(arr, 2);
      expect(sut.length).toEqual(2);
      expect(sut[0]).toEqual(['a', 'b']);
      expect(sut[1]).toEqual(['c', 'd']);
    }));
  });

  describe('with odd distribution', () => {
    it('should leave the lest row partially filled', angular.mock.inject(($filter) => {
      const arr = ['a', 'b', 'c', 'd'];
      const sut = $filter('chunk')(arr, 3);
      expect(sut.length).toEqual(2);
      expect(sut[0]).toEqual(['a', 'b', 'c']);
      expect(sut[1]).toEqual(['d']);
    }));
  });

  describe('with empty array', () => {
    it('should return empty array', angular.mock.inject(($filter) => {
      const arr = [];
      const sut = $filter('chunk')(arr, 3);
      expect(sut.length).toEqual(0);
      expect(sut).toEqual([]);
    }));
  });
});
