"use strict";

var _filter11 = require("../filter");

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

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var treeSelector = new _treeSelector.TreeSelector({
  rootId: function rootId() {
    return 'root';
  },
  parent: function parent(nodeId) {
    return {
      a1: 'root',
      a2: 'root',
      a11: 'a1',
      a12: 'a1',
      a111: 'a11',
      a112: 'a11',
      a113: 'a11',
      a21: 'a2',
      a22: 'a2'
    }[nodeId];
  },
  children: function children(nodeId) {
    return {
      root: ['a1', 'a2'],
      a1: ['a11', 'a12'],
      a2: ['a21', 'a22'],
      a11: ['a111', 'a112', 'a113']
    }[nodeId];
  },
  name: function name(nodeId) {
    return {
      root: 'root',
      a1: 'aaa',
      a2: 'bbb',
      a11: 'aaa ccc',
      a12: 'aaa ddd',
      a21: 'eee fff jjj',
      a22: 'ggg xxx yyy',
      a111: 'hhh',
      a112: 'iii',
      a113: 'jjj'
    }[nodeId];
  }
});
var filter = (0, _filter11.createFilter)(treeSelector, 3);
/*
root -> root
  + a1 -> aaa
    + a11 -> aaa ccc
      + a111 -> hhh
      + a112 -> iii
      + a113 -> jjj
    + a12 -> aaa ddd
  + a2 -> bbb
    + a21 -> eee fff jjj
    + a22 -> ggg xxx yyy
 */

test('Matches leaf node', function () {
  var _filter = filter('ggg'),
      _filter2 = _slicedToArray(_filter, 2),
      filteredOut = _filter2[0],
      expanded = _filter2[1];

  expect(filteredOut).toHaveProperty('a1', true);
  expect(filteredOut).toHaveProperty('a21', true);
  expect(filteredOut).not.toHaveProperty('root', true);
  expect(filteredOut).not.toHaveProperty('a2', true);
  expect(filteredOut).not.toHaveProperty('a22', true);
  expect(expanded).toHaveProperty('root', true);
  expect(expanded).toHaveProperty('a2', true);
});
test('Matches non-leaf node', function () {
  var _filter3 = filter('bbb'),
      _filter4 = _slicedToArray(_filter3, 2),
      filteredOut = _filter4[0],
      expanded = _filter4[1];

  expect(filteredOut).toHaveProperty('a1', true);
  expect(filteredOut).not.toHaveProperty('root', true);
  expect(filteredOut).not.toHaveProperty('a2', true);
  expect(expanded).toHaveProperty('root', true);
  expect(expanded).toHaveProperty('a2', false);
});
test('Matches at non-leaf and leaf node', function () {
  var _filter5 = filter('aaa'),
      _filter6 = _slicedToArray(_filter5, 2),
      filteredOut = _filter6[0],
      expanded = _filter6[1];

  expect(filteredOut).toHaveProperty('a2', true);
  expect(filteredOut).not.toHaveProperty('root', true);
  expect(filteredOut).not.toHaveProperty('a1', true);
  expect(filteredOut).not.toHaveProperty('a11', true);
  expect(expanded).toHaveProperty('root', true);
  expect(expanded).toHaveProperty('a1', true);
  expect(expanded).toHaveProperty('a11', false);
});
test('Matches in multiple branches', function () {
  var _filter7 = filter('jjj'),
      _filter8 = _slicedToArray(_filter7, 2),
      filteredOut = _filter8[0],
      expanded = _filter8[1];

  expect(filteredOut).toHaveProperty('a111', true);
  expect(filteredOut).toHaveProperty('a112', true);
  expect(filteredOut).toHaveProperty('a22', true);
  expect(filteredOut).not.toHaveProperty('root', true);
  expect(filteredOut).not.toHaveProperty('a1', true);
  expect(filteredOut).not.toHaveProperty('a11', true);
  expect(filteredOut).not.toHaveProperty('a113', true);
  expect(filteredOut).not.toHaveProperty('a2', true);
  expect(filteredOut).not.toHaveProperty('a21', true);
  expect(expanded).toHaveProperty('root', true);
  expect(expanded).toHaveProperty('a1', true);
  expect(expanded).toHaveProperty('a11', true);
  expect(expanded).toHaveProperty('a2', true);
});
test('Matches multiple snippets of text', function () {
  var _filter9 = filter('eee ggg'),
      _filter10 = _slicedToArray(_filter9, 2),
      filteredOut = _filter10[0],
      expanded = _filter10[1];

  expect(filteredOut).toHaveProperty('a1', true);
  expect(filteredOut).not.toHaveProperty('root', true);
  expect(filteredOut).not.toHaveProperty('a2', true);
  expect(filteredOut).not.toHaveProperty('a21', true);
  expect(filteredOut).not.toHaveProperty('a22', true);
  expect(expanded).toHaveProperty('root', true);
  expect(expanded).toHaveProperty('a2', true);
});