"use strict";

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

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

var _immutable = require("immutable");

var _banks = _interopRequireDefault(require("../banks"));

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

describe('banks reducer', function () {
  describe('addBanks', function () {
    it('updates state correctly', function () {
      var initialState = (0, _immutable.fromJS)({
        1: {
          id: '1',
          name: 'Uno'
        },
        2: {
          id: '2',
          name: 'Due'
        }
      });
      var action = actions.addBanks([{
        id: '2',
        name: 'Dos'
      }, {
        id: '3',
        name: 'Tres'
      }]);
      var nextState = (0, _banks.default)(initialState, action);
      expect(nextState.getIn(['1', 'name'])).to.eq('Uno');
      expect(nextState.getIn(['2', 'name'])).to.eq('Dos');
    });
  });
  describe('setBankFilters', function () {
    it('updates filters for the given bank', function () {
      var initialState = (0, _immutable.fromJS)({
        '1': {
          id: '1',
          name: 'Uno',
          filters: null
        },
        '2': {
          id: '2',
          name: 'Due',
          filters: null
        }
      });
      var action = actions.setBankFilters('1', {
        some: 'filters'
      });
      var nextState = (0, _banks.default)(initialState, action);
      expect(nextState.getIn(['1', 'filters'])).to.deep.eq({
        some: 'filters'
      });
      expect(nextState.getIn(['2', 'filters'])).to.eq(null);
    });
  });
  describe('associateBankEntries', function () {
    it('updates state correctly', function () {
      var initialState = (0, _immutable.fromJS)({
        1: {
          id: '1',
          name: 'Uno'
        }
      });
      var action = actions.associateEntries('1', [2, 3]);
      var nextState = (0, _banks.default)(initialState, action);
      expect(nextState.getIn(['1', 'bankEntries']).toJS()).to.eql([2, 3]);
    });
    it('associates unique entry ids', function () {
      var initialState = (0, _immutable.fromJS)({
        1: {
          id: '1',
          name: 'Uno',
          bankEntries: (0, _immutable.Set)([2, 3])
        }
      });
      var action = actions.associateEntries('1', [3, 4]);
      var nextState = (0, _banks.default)(initialState, action);
      expect(nextState.getIn(['1', 'bankEntries']).toJS()).to.eql([2, 3, 4]);
    });
  });
  describe('disassociateBankEntry', function () {
    it('updates state correctly', function () {
      var initialState = (0, _immutable.fromJS)({
        1: {
          id: '1',
          name: 'Uno',
          bankEntries: (0, _immutable.Set)([2, 3])
        }
      });
      var action = actions.disassociateEntry('1', 2);
      var nextState = (0, _banks.default)(initialState, action);
      expect(nextState.getIn(['1', 'bankEntries']).toJS()).to.eql([3]);
    });
  });
  describe('removeBank', function () {
    it('updates state correctly', function () {
      var initialState = (0, _immutable.fromJS)({
        1: 'foo',
        2: 'bar'
      });
      var action = actions.removeBank('1');
      var nextState = (0, _banks.default)(initialState, action);
      expect(nextState.get('2')).to.equal('bar');
      expect(nextState.get('1')).to.be.undefined();
    });
  });
  describe('archivebank', function () {
    it('updates state correctly', function () {
      var initialState = (0, _immutable.fromJS)({
        1: {
          foo: 'bar'
        },
        2: 'baz'
      });
      var action = actions.archiveBank('1');
      var nextState = (0, _banks.default)(initialState, action);
      expect(nextState.get('2')).to.equal('baz');
      expect(nextState.get('1').toJS()).to.deep.equal({
        foo: 'bar',
        archived: true
      });
    });
  });
});