import { expect } from 'chai';
import getContactsReducer, {
  getSearchFilterReducer,
  getSourceFilterReducer,
  getPageNumberReducer,
} from './getContactsReducer';

import { AllContactSourceName } from '../../lib/contactHelper';
import getModuleStatusReducer from '../../lib/getModuleStatusReducer';

import actionTypes from './actionTypes';

describe('Contacts :: getSearchFilterReducer', () => {
  it('getSearchFilterReducer should be a function', () => {
    expect(getSearchFilterReducer).to.be.a('function');
  });
  it('getSearchFilterReducer should return a reducer', () => {
    expect(getSearchFilterReducer()).to.be.a('function');
  });
  describe('searchFilterReducer', () => {
    const reducer = getSearchFilterReducer(actionTypes);
    it('should have initial state of blank string', () => {
      expect(reducer(undefined, {})).to.equal('');
    });
    it('should return original state of actionTypes is not recognized', () => {
      const originalState = {};
      expect(reducer(originalState, { type: 'foo' }))
        .to.equal(originalState);
    });
    it('should return new filter on updateFilter', () => {
      expect(reducer('foo', {
        type: actionTypes.updateFilter,
        searchFilter: 'test',
      })).to.equal('test');
    });
    it('should return blank string on resetSuccess', () => {
      expect(reducer('foo', {
        type: actionTypes.resetSuccess,
      })).to.equal('');
    });
    it('should return original filter when searchFilter is undefined on updateFilter', () => {
      expect(reducer('foo', {
        type: actionTypes.updateFilter,
        searchFilter: undefined,
      })).to.equal('foo');
    });
    it('should return original filter when searchFilter is null on updateFilter', () => {
      expect(reducer('foo', {
        type: actionTypes.updateFilter,
        searchFilter: null,
      })).to.equal('foo');
    });
  });
});

describe('Contacts :: getSourceFilterReducer', () => {
  it('getSourceFilterReducer should be a function', () => {
    expect(getSourceFilterReducer).to.be.a('function');
  });
  it('getSourceFilterReducer should return a reducer', () => {
    expect(getSourceFilterReducer()).to.be.a('function');
  });
  describe('sourceFilterReducer', () => {
    const reducer = getSourceFilterReducer(actionTypes);
    it('should have initial state of AllContactSourceName', () => {
      expect(reducer(undefined, {})).to.equal(AllContactSourceName);
    });
    it('should return original state of actionTypes is not recognized', () => {
      const originalState = {};
      expect(reducer(originalState, { type: 'foo' }))
        .to.equal(originalState);
    });
    it('should return sourceFilter on updateFilter', () => {
      expect(reducer('foo', {
        type: actionTypes.updateFilter,
        sourceFilter: 'test',
      })).to.equal('test');
    });
    it('should return AllContactSourceName on resetSuccess', () => {
      expect(reducer('foo', {
        type: actionTypes.resetSuccess,
      })).to.equal(AllContactSourceName);
    });
    it('should return original filter when sourceFilter is undefined on updateFilter', () => {
      expect(reducer('foo', {
        type: actionTypes.updateFilter,
        sourceFilter: undefined,
      })).to.equal('foo');
    });
    it('should return original filter when sourceFilter is null on updateFilter', () => {
      expect(reducer('foo', {
        type: actionTypes.updateFilter,
        sourceFilter: null,
      })).to.equal('foo');
    });
  });
});

describe('Contacts :: getPageNumberReducer', () => {
  it('getPageNumberReducer should be a function', () => {
    expect(getPageNumberReducer).to.be.a('function');
  });
  it('getPageNumberReducer should return a reducer', () => {
    expect(getPageNumberReducer()).to.be.a('function');
  });
  describe('pageNumberReducer', () => {
    const reducer = getPageNumberReducer(actionTypes);
    it('should have initial state of one', () => {
      expect(reducer(undefined, {})).to.equal(1);
    });
    it('should return original state of actionTypes is not recognized', () => {
      const originalState = {};
      expect(reducer(originalState, { type: 'foo' }))
        .to.equal(originalState);
    });
    it('should return blank string on resetSuccess', () => {
      expect(reducer(2, {
        type: actionTypes.resetSuccess,
      })).to.equal(1);
    });
    it('should return new pageNumber on updateFilter', () => {
      expect(reducer(1, {
        type: actionTypes.updateFilter,
        pageNumber: 3,
      })).to.equal(3);
    });
    it('should return original page when pageNumber is undefined on updateFilter', () => {
      expect(reducer(5, {
        type: actionTypes.updateFilter,
        pageNumber: undefined,
      })).to.equal(5);
    });
    it('should return original page when pageNumber is zero on updateFilter', () => {
      expect(reducer(3, {
        type: actionTypes.updateFilter,
        searchFilter: 0,
      })).to.equal(3);
    });
  });
});

describe('getContactsReducer', () => {
  it('should be a function', () => {
    expect(getContactsReducer).to.be.a('function');
  });
  it('should return a reducer', () => {
    expect(getContactsReducer(actionTypes)).to.be.a('function');
  });
  it('should return a combined reducer', () => {
    const reducer = getContactsReducer(actionTypes);
    const statusReducer = getModuleStatusReducer(actionTypes);
    const searchFilterReducer = getSearchFilterReducer(actionTypes);
    const sourceFilterReducer = getSourceFilterReducer(actionTypes);
    const pageNumberReducer = getPageNumberReducer(actionTypes);
    expect(reducer(undefined, {})).to.deep.equal({
      status: statusReducer(undefined, {}),
      searchFilter: searchFilterReducer(undefined, {}),
      sourceFilter: sourceFilterReducer(undefined, {}),
      pageNumber: pageNumberReducer(undefined, {}),
    });
  });
});

@@ -109,32 +109,8 @@
 er,%0A
-  getPageNumberReducer,%0A
 %7D fr
@@ -3483,1493 +3483,8 @@
 );%0A%0A
-describe('Contacts :: getPageNumberReducer', () =%3E %7B%0A  it('getPageNumberReducer should be a function', () =%3E %7B%0A    expect(getPageNumberReducer).to.be.a('function');%0A  %7D);%0A  it('getPageNumberReducer should return a reducer', () =%3E %7B%0A    expect(getPageNumberReducer()).to.be.a('function');%0A  %7D);%0A  describe('pageNumberReducer', () =%3E %7B%0A    const reducer = getPageNumberReducer(actionTypes);%0A    it('should have initial state of one', () =%3E %7B%0A      expect(reducer(undefined, %7B%7D)).to.equal(1);%0A    %7D);%0A    it('should return original state of actionTypes is not recognized', () =%3E %7B%0A      const originalState = %7B%7D;%0A      expect(reducer(originalState, %7B type: 'foo' %7D))%0A        .to.equal(originalState);%0A    %7D);%0A    it('should return blank string on resetSuccess', () =%3E %7B%0A      expect(reducer(2, %7B%0A        type: actionTypes.resetSuccess,%0A      %7D)).to.equal(1);%0A    %7D);%0A    it('should return new pageNumber on updateFilter', () =%3E %7B%0A      expect(reducer(1, %7B%0A        type: actionTypes.updateFilter,%0A        pageNumber: 3,%0A      %7D)).to.equal(3);%0A    %7D);%0A    it('should return original page when pageNumber is undefined on updateFilter', () =%3E %7B%0A      expect(reducer(5, %7B%0A        type: actionTypes.updateFilter,%0A        pageNumber: undefined,%0A      %7D)).to.equal(5);%0A    %7D);%0A    it('should return original page when pageNumber is zero on updateFilter', () =%3E %7B%0A      expect(reducer(3, %7B%0A        type: actionTypes.updateFilter,%0A        searchFilter: 0,%0A      %7D)).to.equal(3);%0A    %7D);%0A  %7D);%0A%7D);%0A%0A
 desc
@@ -3514,24 +3514,24 @@
 r', () =%3E %7B%0A
+
   it('should
@@ -4031,73 +4031,8 @@
 s);%0A
-    const pageNumberReducer = getPageNumberReducer(actionTypes);%0A
     
@@ -4174,24 +4174,24 @@
 fined, %7B%7D),%0A
+
       source
@@ -4238,60 +4238,8 @@
 %7D),%0A
-      pageNumber: pageNumberReducer(undefined, %7B%7D),%0A
     

remove unneed tests (#875)