"use strict";

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

var _ = require("..");

var _sortingHelper = require("../sortingHelper");

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

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

var _ramda = require("ramda");

var _LoadingAnimation = _interopRequireDefault(require("../../../LoadingAnimation"));

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 }; }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }

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

function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }

_enzyme.default.configure({
  adapter: new _enzymeAdapterReact.default()
});

describe('DataTable', function () {
  describe('Top Level Header', function () {
    it('should display tool bar', function () {
      var renderToolbar = jest.fn(function () {
        return _react.default.createElement("div", {
          id: "test"
        }, "TEST");
      });
      var data = [{
        id: 0,
        row: [1, 2, 3],
        selected: false
      }, {
        id: 1,
        row: [4, 5, 6],
        selected: true
      }];
      var dataWithoutIds = [{
        row: data[0].row,
        selected: data[0].selected
      }, {
        row: data[1].row,
        selected: data[1].selected
      }];
      var columns = [{
        label: 'hello'
      }];
      var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
        renderToolbar: renderToolbar,
        data: data,
        columns: columns
      }));
      expect(renderToolbar.mock.calls).toEqual([[{
        data: dataWithoutIds,
        columns: columns
      }]]);
      expect(wrapper.find('div#test').text()).toEqual('TEST');
    });
  });
  describe('headers', function () {
    it('should render when there are columns', function () {
      var label1 = 'label1';
      var label2 = 'label2';
      var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
        columns: [{
          label: label1
        }, {
          label: label2
        }]
      }));
      expect(wrapper.find('th').map(function (node) {
        return (0, _ramda.trim)(node.text());
      })).toEqual([label1, label2]);
    });
    it('should render with width when there is a width for columns', function () {
      var width1 = '100%';
      var width2 = '99%';
      var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
        columns: [{
          label: '',
          width: width1
        }, {
          label: '',
          width: width2
        }]
      }));
      expect(wrapper.find('th').map(function (node) {
        return node.prop('style');
      })).toEqual([{
        width: width1
      }, {
        width: width2
      }]);
    });
  });
  describe('rows', function () {
    it('should say "No data available." when there is no data', function () {
      var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
        data: []
      }));
      expect(wrapper.find('td')).toHaveLength(0);
      expect(wrapper.find('div.vs-data-table-no-data-label').text()).toEqual('No data available.');
    });
    it('should use the overridden label when there is no data', function () {
      var noDataLabel = 'I have no data';
      var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
        data: [],
        noDataLabel: noDataLabel
      }));
      expect(wrapper.find('td')).toHaveLength(0);
      expect(wrapper.find('div.vs-data-table-no-data-label').text()).toEqual(noDataLabel);
    });
    it('should render when there is data', function () {
      var data1 = 'data1';
      var data2 = 'data2';
      var data3 = 'data3';
      var data4 = 'data4';
      var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
        data: [{
          id: 0,
          row: [data1, data2],
          selected: false
        }, {
          id: 1,
          row: [data3, data4],
          selected: false
        }]
      }));
      expect(wrapper.find('td').map(function (node) {
        return node.text();
      })).toEqual([data1, data2, data3, data4]);
      expect(wrapper.find(_LoadingAnimation.default)).toHaveLength(0);
    });
    it('should have clickable cell', function () {
      var targetLabel = 'target';
      var targetData = 'target data';
      var columns = [{
        label: '1'
      }, {
        label: '2'
      }, {
        label: targetLabel,
        clickable: true
      }, {
        label: '4'
      }];
      var onClick = jest.fn();
      var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
        columns: columns,
        data: [{
          id: 0,
          row: [1, 2, 3, 4],
          selected: false
        }, {
          id: 1,
          row: [1, 2, 3, 4],
          selected: false
        }, {
          id: 2,
          row: [1, 2, targetData, 4],
          selected: false
        }, {
          id: 3,
          row: [1, 2, 3, 4],
          selected: false
        }],
        onClick: onClick
      }));
      var targetTD = wrapper.find('a').filterWhere(function (node) {
        return node.text() === targetData;
      });
      targetTD.simulate('click');
      expect(onClick.mock.calls).toEqual([[{
        label: targetLabel,
        rowIndex: 2,
        value: targetData
      }]]);
    });
    it('should not be able to click on regular td', function () {
      var targetLabel = 'target';
      var targetData = 'target data';
      var columns = [{
        label: targetLabel
      }, {
        label: '1',
        clickable: true
      }];
      var onClick = jest.fn();
      var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
        columns: columns,
        data: [{
          id: 0,
          row: [targetData, 2],
          selected: false
        }, {
          id: 1,
          row: [1, 2],
          selected: false
        }],
        onClick: onClick
      }));
      var targetTD = wrapper.find('td.vs-cell').filterWhere(function (node) {
        return node.text() === targetData;
      });
      targetTD.simulate('click');
      expect(onClick.mock.calls).toHaveLength(0);
    });
    describe('displaying custom cell', function () {
      it('should display custom cell when there is renderCell function', function () {
        var label = 'change';
        var targetData = 'value';

        var renderCell = function renderCell(value) {
          return "test ".concat(value);
        };

        var columns = [{
          label: label,
          renderCell: renderCell
        }];
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          columns: columns,
          data: [{
            id: 0,
            row: [targetData],
            selected: false
          }]
        }));
        var targetTD = wrapper.find('td.vs-cell').filterWhere(function (node) {
          return node.text() === "test value";
        });
        expect(targetTD).toHaveLength(1);
      });
    });
    describe("selecting rows", function () {
      it("should not display any selectable rows if table is not selectable", function () {
        var data = [{
          id: 0,
          row: [1],
          selected: true
        }, {
          id: 1,
          row: [2],
          selected: false
        }];
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          data: data,
          selectable: false
        }));
        var rowCheckboxes = wrapper.find("input[aria-label='Select row from data table']");
        var selectAllCheckbox = wrapper.find("input[aria-label='Select all from data table']");
        expect(rowCheckboxes).toHaveLength(0);
        expect(selectAllCheckbox).toHaveLength(0);
      });
      it("should display selected rows", function () {
        var data = [{
          id: 0,
          row: [1],
          selected: true
        }, {
          id: 1,
          row: [2],
          selected: false
        }];
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          data: data,
          selectable: true
        }));
        var firstRowSelected = wrapper.find("input[aria-label='Select row from data table']").at(0).prop("checked");
        var secondRowSelected = wrapper.find("input[aria-label='Select row from data table']").at(1).prop("checked");
        expect(firstRowSelected).toEqual(true);
        expect(secondRowSelected).toEqual(false);
      });
      it("should select one row", function () {
        var onSelect = jest.fn();
        var data = [{
          id: 0,
          row: [1],
          selected: false
        }, {
          id: 1,
          row: [2],
          selected: false
        }];
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          data: data,
          selectable: true,
          onSelect: onSelect
        }));
        wrapper.find("input[aria-label='Select row from data table']").at(0).simulate('change');
        expect(onSelect).lastCalledWith({
          data: [{
            id: 0,
            row: [1],
            selected: true
          }, {
            id: 1,
            row: [2],
            selected: false
          }]
        });
      });
      it("should check selected all checkbox when all rows are selected", function () {
        var data = [{
          id: 0,
          row: [1],
          selected: true
        }, {
          id: 1,
          row: [2],
          selected: true
        }];
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          data: data,
          selectable: true
        }));
        var selectedAllRowsCheckbox = wrapper.find("input[aria-label='Select all from data table']").prop("checked");
        expect(selectedAllRowsCheckbox).toEqual(true);
      });
      it("should uncheck selected all checkbox when some rows are not selected", function () {
        var data = [{
          id: 0,
          row: [1],
          selected: true
        }, {
          id: 1,
          row: [2],
          selected: false
        }];
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          data: data,
          selectable: true
        }));
        var selectedAllRowsCheckbox = wrapper.find("input[aria-label='Select all from data table']").prop("checked");
        expect(selectedAllRowsCheckbox).toEqual(false);
      });
      it("should select all rows at once when clicking on select all checkbox", function () {
        var data = [{
          id: 0,
          row: [1],
          selected: false
        }, {
          id: 1,
          row: [2],
          selected: false
        }];
        var onSelect = jest.fn();
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          data: data,
          selectable: true,
          onSelect: onSelect
        }));
        var selectedAllRowsCheckbox = wrapper.find("input[aria-label='Select all from data table']");
        selectedAllRowsCheckbox.simulate('change');
        expect(onSelect).lastCalledWith({
          data: [{
            id: 0,
            row: [1],
            selected: true
          }, {
            id: 1,
            row: [2],
            selected: true
          }]
        });
      });
      it("should unselect all rows at once when clicking on select all checkbox", function () {
        var data = [{
          id: 0,
          row: [1],
          selected: true
        }, {
          id: 1,
          row: [2],
          selected: true
        }];
        var onSelect = jest.fn();
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          data: data,
          selectable: true,
          onSelect: onSelect
        }));
        var selectedAllRowsCheckbox = wrapper.find("input[aria-label='Select all from data table']");
        selectedAllRowsCheckbox.simulate('change');
        expect(onSelect).lastCalledWith({
          data: [{
            id: 0,
            row: [1],
            selected: false
          }, {
            id: 1,
            row: [2],
            selected: false
          }]
        });
      });
    });
  });
  describe('pagination', function () {
    it('should not render if pagination is not enabled', function () {
      var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, null));
      expect(wrapper.find('Pagination')).toHaveLength(0);
    });
    it('should render if pagination is enabled', function () {
      var onPageChange = jest.fn();
      var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
        onPageChange: onPageChange,
        pagination: true
      }));
      var paginationWrapper = wrapper.find('Pagination');
      var paginationProps = paginationWrapper.props();
      expect(paginationWrapper).toHaveLength(1);
      expect(paginationProps).toEqual({
        rowsPerPage: 25,
        page: 1,
        onChange: onPageChange,
        className: 'vs-table-pagination',
        numberOfRows: 0
      });
    });
    it('should pass translation templates to pagination', function () {
      var onPageChange = jest.fn();
      var rowsPerPageTemplate = 'number of rows template';
      var totalRecordsTemplate = 'total records template';
      var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
        onPageChange: onPageChange,
        pagination: true,
        rowsPerPageTemplate: rowsPerPageTemplate,
        totalRecordsTemplate: totalRecordsTemplate
      }));
      var paginationWrapper = wrapper.find('Pagination');
      var paginationProps = paginationWrapper.props();
      expect(paginationWrapper).toHaveLength(1);
      expect(paginationProps).toEqual({
        rowsPerPage: 25,
        page: 1,
        onChange: onPageChange,
        className: 'vs-table-pagination',
        numberOfRows: 0,
        rowsPerPageTemplate: rowsPerPageTemplate,
        totalRecordsTemplate: totalRecordsTemplate
      });
    });
    describe('Rendering Rows', function () {
      var group1 = (0, _ramda.range)(1, 26);
      var group2 = (0, _ramda.range)(26, 51);
      var group3 = (0, _ramda.range)(51, 76);
      var groupedData1 = group1.map(function (number) {
        return {
          id: number,
          row: [number],
          selected: false
        };
      });
      var groupedData2 = group2.map(function (number) {
        return {
          id: number,
          row: [number],
          selected: false
        };
      });
      var groupedData3 = group3.map(function (number) {
        return {
          id: number,
          row: [number],
          selected: false
        };
      });
      it('should render a fixed number of rows when pagination is enabled', function () {
        var onPageChange = jest.fn();
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          rowsPerPage: 25,
          page: 2,
          data: [].concat(_toConsumableArray(groupedData1), _toConsumableArray(groupedData2), _toConsumableArray(groupedData3)),
          onPageChange: onPageChange,
          pagination: true
        }));
        expect(wrapper.find('td').map(function (node) {
          return node.text();
        })).toEqual(group2.map(function (number) {
          return number.toString();
        }));
      });
      it('should render a all the rows when pagination is disabled', function () {
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          rowsPerPage: 25,
          page: 2,
          data: [].concat(_toConsumableArray(groupedData1), _toConsumableArray(groupedData2), _toConsumableArray(groupedData3))
        }));
        expect(wrapper.find('td').map(function (node) {
          return node.text();
        })).toEqual([].concat(_toConsumableArray(group1), _toConsumableArray(group2), _toConsumableArray(group3)).map(function (number) {
          return number.toString();
        }));
      });
    });
  });
  describe('sorting', function () {
    describe('when displaying headers', function () {
      it('should not render any sortable style if sortable is not enabled', function () {
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          columns: [{
            label: 'id'
          }],
          sortingOption: {
            label: 'id',
            order: _sortingHelper.DESCENDING
          }
        }));
        expect(wrapper.find('MenuUpIcon')).toHaveLength(0);
        expect(wrapper.find('MenuDownIcon')).toHaveLength(0);
        expect(wrapper.find('th.vs-data-table-header-sorted')).toHaveLength(0);
        expect(wrapper.find('th.vs-data-table-header-sortable')).toHaveLength(0);
      });
      it('should bold header if the column is sorted', function () {
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          columns: [{
            label: 'id'
          }],
          sortingOption: {
            label: 'id',
            order: _sortingHelper.DESCENDING
          },
          sortable: true
        }));
        var targetHeader = wrapper.find('th.vs-data-table-header-sorted');
        expect(targetHeader).toHaveLength(1);
        expect((0, _ramda.trim)(targetHeader.text())).toEqual('id');
      });
      it('should not bold header if the column is not sorted', function () {
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          columns: [{
            label: 'id'
          }],
          sortingOption: {
            label: 'id2',
            order: _sortingHelper.DESCENDING
          },
          sortable: true
        }));
        var targetHeader = wrapper.find('th.vs-data-table-header-sorted');
        expect(targetHeader).toHaveLength(0);
      });
      it('should render the arrow up icon', function () {
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          columns: [{
            label: 'id'
          }, {
            label: 'first name'
          }, {
            label: 'last name'
          }],
          sortingOption: {
            label: 'first name',
            order: _sortingHelper.ASCENDING
          },
          sortable: true
        }));
        var targetHeaderWrapper = wrapper.find('th.vs-data-table-header-sortable').filterWhere(function (node) {
          return (0, _ramda.trim)(node.text()) === 'first name';
        });
        expect(targetHeaderWrapper.find('ArrowUpIcon')).toHaveLength(1);
      });
      it('should render default arrow down icon for non sorted header', function () {
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          columns: [{
            label: 'id'
          }, {
            label: 'first name'
          }, {
            label: 'last name'
          }],
          sortingOption: {
            label: 'first name',
            order: _sortingHelper.ASCENDING
          },
          sortable: true
        }));
        var otherHeadersWrapper = wrapper.find('th.vs-data-table-header-sortable').filterWhere(function (node) {
          return (0, _ramda.trim)(node.text()) !== 'first name';
        });
        expect((0, _ramda.sum)(otherHeadersWrapper.map(function (node) {
          return node.find('ArrowDownIcon').length;
        }))).toEqual(2);
      });
      it('should render arrow down icon', function () {
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          columns: [{
            label: 'id'
          }, {
            label: 'first name'
          }, {
            label: 'last name'
          }],
          sortingOption: {
            label: 'first name',
            order: _sortingHelper.DESCENDING
          },
          sortable: true
        }));
        var targetHeaderWrapper = wrapper.find('th.vs-data-table-header-sortable').filterWhere(function (node) {
          return (0, _ramda.trim)(node.text()) === 'first name';
        });
        expect(targetHeaderWrapper.find('ArrowDownIcon')).toHaveLength(1);
      });
    });
    describe('when clicking on sorted header', function () {
      it('should not be clickable when sortable is not enabled', function () {
        var label = 'id';
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          columns: [{
            label: label
          }],
          sortingOption: {
            label: label,
            order: _sortingHelper.DESCENDING
          }
        }));
        var targetHeaderWrapper = wrapper.find('th').filterWhere(function (node) {
          return (0, _ramda.trim)(node.text()) === label;
        });
        expect(targetHeaderWrapper.prop('onClick')).toEqual(undefined);
      });
      it('should callback with the sorting option', function () {
        var onSort = jest.fn();
        var label = 'first name';
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          columns: [{
            label: label
          }],
          sortingOption: {
            label: label,
            order: _sortingHelper.DESCENDING
          },
          onSort: onSort,
          sortable: true
        }));
        var targetHeaderWrapper = wrapper.find('th.vs-data-table-header-sortable').filterWhere(function (node) {
          return (0, _ramda.trim)(node.text()) === label;
        });
        targetHeaderWrapper.simulate('click');
        expect(onSort.mock.calls[0][0].sortingOption).toEqual({
          label: label,
          order: _sortingHelper.ASCENDING
        });
      });
      it('should callback with alternate sorting order', function () {
        var onSort = jest.fn();
        var label = 'first name';
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          columns: [{
            label: label
          }],
          sortingOption: {
            label: label,
            order: _sortingHelper.ASCENDING
          },
          onSort: onSort,
          sortable: true
        }));
        var targetHeaderWrapper = wrapper.find('th.vs-data-table-header-sortable').filterWhere(function (node) {
          return (0, _ramda.trim)(node.text()) === label;
        });
        targetHeaderWrapper.simulate('click');
        expect(onSort.mock.calls[0][0].sortingOption).toEqual({
          label: label,
          order: _sortingHelper.DESCENDING
        });
      });
      it('should callback with the descending sorting data on non sorted header', function () {
        var onSort = jest.fn();
        var first = 'a';
        var second = 'b';
        var third = 'c';
        var label = 'id';
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          columns: [{
            label: label
          }],
          sortingOption: {
            label: 'NOT YOUR TARGET HEADER',
            order: _sortingHelper.DESCENDING
          },
          data: [{
            id: 0,
            row: [second],
            selected: false
          }, {
            id: 1,
            row: [first],
            selected: false
          }, {
            id: 2,
            row: [third],
            selected: false
          }],
          onSort: onSort,
          sortable: true
        }));
        var targetHeaderWrapper = wrapper.find('th.vs-data-table-header-sortable').filterWhere(function (node) {
          return (0, _ramda.trim)(node.text()) === label;
        });
        targetHeaderWrapper.simulate('click');
        expect(onSort.mock.calls[0][0].data).toEqual([{
          id: 2,
          row: [third],
          selected: false
        }, {
          id: 0,
          row: [second],
          selected: false
        }, {
          id: 1,
          row: [first],
          selected: false
        }]);
      });
      it('should callback with the ascending sorting data', function () {
        var onSort = jest.fn();
        var first = 'a';
        var second = 'b';
        var third = 'c';
        var label = 'id';
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          columns: [{
            label: label
          }],
          sortingOption: {
            label: label,
            order: _sortingHelper.DESCENDING
          },
          data: [{
            id: 0,
            row: [second],
            selected: false
          }, {
            id: 1,
            row: [first],
            selected: false
          }, {
            id: 2,
            row: [third],
            selected: false
          }],
          onSort: onSort,
          sortable: true
        }));
        var targetHeaderWrapper = wrapper.find('th.vs-data-table-header-sortable').filterWhere(function (node) {
          return (0, _ramda.trim)(node.text()) === label;
        });
        targetHeaderWrapper.simulate('click');
        expect(onSort.mock.calls[0][0].data).toEqual([{
          id: 1,
          row: [first],
          selected: false
        }, {
          id: 0,
          row: [second],
          selected: false
        }, {
          id: 2,
          row: [third],
          selected: false
        }]);
      });
      it('should callback with the descending sorting data', function () {
        var onSort = jest.fn();
        var label = 'first name';
        var first = 'a';
        var second = 'b';
        var third = 'c';
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          columns: [{
            label: label
          }],
          sortingOption: {
            label: label,
            order: _sortingHelper.ASCENDING
          },
          data: [{
            id: 0,
            row: [second],
            selected: false
          }, {
            id: 1,
            row: [first],
            selected: false
          }, {
            id: 2,
            row: [third],
            selected: false
          }],
          onSort: onSort,
          sortable: true
        }));
        var targetHeaderWrapper = wrapper.find('th.vs-data-table-header-sortable').filterWhere(function (node) {
          return (0, _ramda.trim)(node.text()) === label;
        });
        targetHeaderWrapper.simulate('click');
        expect(onSort.mock.calls[0][0].data).toEqual([{
          id: 2,
          row: [third],
          selected: false
        }, {
          id: 0,
          row: [second],
          selected: false
        }, {
          id: 1,
          row: [first],
          selected: false
        }]);
      });
    });
    describe('when clicking on non-sorted header', function () {
      it('should callback with default sorting order', function () {
        var onSort = jest.fn();
        var label = 'first name';
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          columns: [{
            label: label
          }],
          onSort: onSort,
          sortable: true
        }));
        var targetHeaderWrapper = wrapper.find('th.vs-data-table-header-sortable').filterWhere(function (node) {
          return (0, _ramda.trim)(node.text()) === label;
        });
        targetHeaderWrapper.simulate('click');
        expect(onSort.mock.calls[0][0].sortingOption).toEqual({
          label: label,
          order: _sortingHelper.DESCENDING
        });
      });
      it('should callback with default sorting order and ignore the sorted header', function () {
        var onSort = jest.fn();
        var label = 'first name';
        var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
          columns: [{
            label: label
          }],
          onSort: onSort,
          sortingOption: {
            label: 'id',
            order: _sortingHelper.ASCENDING
          },
          sortable: true
        }));
        var targetHeaderWrapper = wrapper.find('th.vs-data-table-header-sortable').filterWhere(function (node) {
          return (0, _ramda.trim)(node.text()) === label;
        });
        targetHeaderWrapper.simulate('click');
        expect(onSort.mock.calls[0][0].sortingOption).toEqual({
          label: label,
          order: _sortingHelper.DESCENDING
        });
      });
    });
  });
  describe('loading animation', function () {
    it('should render with loadingMessage when isLoading is true', function () {
      var loadingMessage = 'Loading data...';
      var wrapper = (0, _enzyme.mount)(_react.default.createElement(_.DataTable, {
        isLoading: true,
        pagination: true,
        loadingMessage: loadingMessage
      }));
      expect(wrapper.find(_LoadingAnimation.default)).toHaveLength(1);
      expect(wrapper.find(_LoadingAnimation.default).prop('loadingMessage')).toEqual(loadingMessage);
      expect(wrapper.find('Pagination')).toHaveLength(0);
      expect(wrapper.find('Table')).toHaveLength(0);
    });
  });
});