"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _immutable = require("immutable");

var actions = _interopRequireWildcard(require("../../actions/bankSearch"));

var _bankSearch2 = _interopRequireDefault(require("../bankSearch"));

describe('search reducer', function () {
  var active = function active() {
    return (0, _bankSearch2.default)((0, _bankSearch2.default)(null, {}), actions.reset('42'));
  };

  describe('update', function () {
    it('updates the search text', function () {
      var initialState = active();
      var action = actions.update('example');
      var nextState = (0, _bankSearch2.default)(initialState, action);
      expect(nextState.get('text')).to.eq('example');
    });
  });
  describe('toggle', function () {
    it('toggles filters on / off', function () {
      var initialState = active();
      var action = actions.toggle('interactionTypes', '8');
      var firstState = (0, _bankSearch2.default)(initialState, action);
      expect(firstState.get('interactionTypes').toJS()).to.deep.eq(['8']);
      var toggleOther = actions.toggle('interactionTypes', '9');
      var middleState = (0, _bankSearch2.default)(firstState, toggleOther);
      expect(middleState.get('interactionTypes').toJS()).to.deep.eq(['8', '9']);
      var finalState = (0, _bankSearch2.default)(middleState, action);
      expect(finalState.get('interactionTypes').toJS()).to.deep.eq(['9']);
    });
  });
  describe('setFilter', function () {
    it('can set the value of filters', function () {
      var initialState = active();
      var action = actions.setFilter('tags', [{
        id: '8'
      }]);
      var state = (0, _bankSearch2.default)(initialState, action);
      expect(state.get('tags')).to.deep.eq([{
        id: '8'
      }]);
    });
  });
  describe('reset', function () {
    it('resets all search state', function () {
      var initialState = active();
      var update = actions.update('example');
      var toggle = actions.toggle('interactionTypes', '8');
      var searching = (0, _bankSearch2.default)((0, _bankSearch2.default)(initialState, update), toggle);
      var reset = (0, _bankSearch2.default)(searching, actions.reset());
      expect(reset.get('text', null)).to.eq(null);
      expect(reset.get('interactionTypes', (0, _immutable.List)()).toJS()).to.deep.eq([]);
    });
  });
});