"use strict";

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

var _enzyme = require("enzyme");

var _index = require("../index.js");

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

/*
Copyright (c) 2018 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
var DATA = [['1', 'Sarah', 'Brown', 31, '100 Broadway st. New York City, New York'], ['2', 'Jane', 'Smith', 32, '100 Market st. San Francisco, California'], ['3', 'Joe', 'Black', 33, '100 Macquarie st. Sydney, Australia']];
var COLUMNS = ['ID', 'First Name', 'Last Name', 'Age', 'Address'];
describe('Table', function () {
  it('renders expected number of rows', function () {
    var wrapper = (0, _enzyme.shallow)(_react.default.createElement(_index.Table, {
      columns: COLUMNS,
      data: DATA
    }));
    expect(wrapper.find(_index.StyledRow)).toHaveLength(DATA.length);
  });
  it('renders expected number of columns', function () {
    var wrapper = (0, _enzyme.shallow)(_react.default.createElement(_index.Table, {
      columns: COLUMNS,
      data: DATA
    }));
    var cells = wrapper.find(_index.StyledRow).first().find(_index.StyledCell);
    expect(cells).toHaveLength(DATA[0].length);
  });
  it('applies correct aria attributes to table container', function () {
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.Table, {
      columns: COLUMNS,
      data: DATA
    }));
    var container = wrapper.find(_index.StyledTable);
    expect(container.getDOMNode().getAttribute('role')).toBe('grid');
    expect(container.getDOMNode().getAttribute('aria-colcount')).toBe(COLUMNS.length.toString());
    expect(container.getDOMNode().getAttribute('aria-rowcount')).toBe(DATA.length.toString());
  });
  it('applies correct role attribute to table head', function () {
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.Table, {
      columns: COLUMNS,
      data: DATA
    }));
    var head = wrapper.find(_index.StyledHead);
    expect(head.getDOMNode().getAttribute('role')).toBe('row');
  });
  it('applies correct role attribute to table head cell', function () {
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.Table, {
      columns: COLUMNS,
      data: DATA
    }));
    var headCell = wrapper.find(_index.StyledHeadCell).first();
    expect(headCell.getDOMNode().getAttribute('role')).toBe('columnheader');
  });
  it('applies correct role attribute to table body', function () {
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.Table, {
      columns: COLUMNS,
      data: DATA
    }));
    var body = wrapper.find(_index.StyledBody);
    expect(body.getDOMNode().getAttribute('role')).toBe('rowgroup');
  });
  it('applies correct role attribute to table row', function () {
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.Table, {
      columns: COLUMNS,
      data: DATA
    }));
    var row = wrapper.find(_index.StyledRow).first();
    expect(row.getDOMNode().getAttribute('role')).toBe('row');
  });
  it('applies correct role attribute to table cell', function () {
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.Table, {
      columns: COLUMNS,
      data: DATA
    }));
    var cell = wrapper.find(_index.StyledCell).first();
    expect(cell.getDOMNode().getAttribute('role')).toBe('gridcell');
  });
});