"use strict";

var _chai = require("chai");

var _immutable = require("immutable");

var _immutableHelpers = require("../immutableHelpers");

describe('immutableHelpers', function () {
  describe('keyBy', function () {
    it('converts a list to map keyed by value', function () {
      var item1 = {
        someKey: 'bar',
        value: 'qux'
      };
      var item2 = {
        someKey: 'woz',
        value: 'quux'
      };
      var immutableList = (0, _immutable.fromJS)([item1, item2]);
      (0, _chai.expect)((0, _immutableHelpers.keyBy)(immutableList, 'someKey').equals((0, _immutable.fromJS)({
        bar: item1,
        woz: item2
      }))).to.be.true();
    });
  });
  describe('compact', function () {
    it('removes falsey values', function () {
      var immutableList = (0, _immutable.fromJS)([1, null, 2, false, 3, void 0, 4]);
      (0, _chai.expect)((0, _immutableHelpers.compact)(immutableList).equals((0, _immutable.fromJS)([1, 2, 3, 4]))).to.be.true();
    });
  });
  describe('mergeDeepOnlyMaps', function () {
    it('deep merges maps', function () {
      var oldMap = (0, _immutable.fromJS)({
        value: false,
        otherValue: true,
        deep: {
          value: false
        }
      });
      var newMap = (0, _immutable.fromJS)({
        value: true,
        deep: {
          value: true
        }
      });
      (0, _chai.expect)(oldMap.mergeWith(_immutableHelpers.mergeDeepOnlyMaps, newMap).equals((0, _immutable.fromJS)({
        value: true,
        otherValue: true,
        deep: {
          value: true
        }
      }))).to.be.true();
    });
    it('shallow merges lists', function () {
      var oldMap = (0, _immutable.fromJS)({
        odd: [1, 3, 5],
        even: [2, 4, 6],
        tens: [10, 20, 30]
      });
      var newMap = (0, _immutable.fromJS)({
        odd: [3],
        even: []
      });
      (0, _chai.expect)(oldMap.mergeWith(_immutableHelpers.mergeDeepOnlyMaps, newMap).equals((0, _immutable.fromJS)({
        odd: [3],
        even: [],
        tens: [10, 20, 30]
      }))).to.be.true();
    });
  });
});