"use strict";

var _react = _interopRequireDefault(require("react"));

var uut = _interopRequireWildcard(require("../index"));

var _treeSelector = require("../tree-selector");

var _enzyme = _interopRequireWildcard(require("enzyme"));

var _enzymeAdapterReact = _interopRequireDefault(require("enzyme-adapter-react-16"));

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

_enzyme.default.configure({
  adapter: new _enzymeAdapterReact.default()
});
/*
root
  +- a
  +- b
*/


var treeSelector = new _treeSelector.TreeSelector({
  parent: function parent(id) {
    return {
      a: 'root',
      b: 'root'
    }[id];
  },
  children: function children(id) {
    return {
      root: ['a', 'b']
    }[id];
  },
  name: function name(id) {
    return {
      root: 'Root',
      a: 'Node A',
      b: 'Node B'
    }[id];
  }
});
describe('Tree', function () {
  it('should render all content', function () {
    var wrapper = (0, _enzyme.render)(_react.default.createElement(uut.Tree, {
      treeStructure: treeSelector,
      rootVisible: false,
      selection: treeSelector.createMap(function (_) {
        return 1;
      }),
      expansion: treeSelector.createMap(function (id) {
        return id === 'root';
      })
    }));
    expect(wrapper.find('.vs-leafContent').text()).toEqual('Node ANode B');
  });
  it('should use the labelContent property', function () {
    var labelContent = function labelContent(id) {
      return "label ".concat(id, "-");
    };

    var wrapper = (0, _enzyme.render)(_react.default.createElement(uut.Tree, {
      treeStructure: treeSelector,
      rootVisible: false,
      selection: treeSelector.createMap(function (_) {
        return 1;
      }),
      expansion: treeSelector.createMap(function (id) {
        return id === 'root';
      }),
      labelContent: labelContent
    }));
    expect(wrapper.find('.vs-leafContent').text()).toEqual('label a-label b-');
  });
  it('should pass the highlight property to the labelContent function', function () {
    var ok = false;

    var labelContent = function labelContent(id, highlight) {
      ok = highlight === 'test';
      return "label ".concat(id, "-");
    };

    (0, _enzyme.render)(_react.default.createElement(uut.Tree, {
      treeStructure: treeSelector,
      rootVisible: false,
      selection: treeSelector.createMap(function (_) {
        return 1;
      }),
      expansion: treeSelector.createMap(function (id) {
        return id === 'root';
      }),
      labelContent: labelContent,
      highlight: 'test'
    }));
    expect(ok).toEqual(true);
  });
  it('should render checkbox content correctly', function () {
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(uut.Tree, {
      treeStructure: treeSelector,
      rootVisible: true,
      selection: {
        root: -1,
        a: 1,
        b: 0
      },
      expansion: treeSelector.createMap(function (id) {
        return id === 'root';
      })
    }));
    [-1, 1, 0].forEach(function (value, index) {
      return expect(wrapper.find('TriStateCheckbox').get(index).props.value).toEqual(value);
    });
  });
  it('should render with arbitrary data-id prop', function () {
    var wrapper = (0, _enzyme.render)(_react.default.createElement(uut.Tree, {
      treeStructure: treeSelector,
      rootVisible: false,
      selection: treeSelector.createMap(function (_) {
        return 1;
      }),
      expansion: treeSelector.createMap(function (id) {
        return id === 'root';
      }),
      "data-id": "test"
    }));
    expect(wrapper.find('.vs-tree[data-id="test"] .vs-leafContent').text()).toEqual('Node ANode B');
  });
});