/*
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.
*/
import React from 'react';
import { mount, shallow } from 'enzyme';
import { Table, StyledTable, StyledHead, StyledHeadCell, StyledBody, StyledRow, StyledCell } from '../index.js';
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 = shallow(React.createElement(Table, {
      columns: COLUMNS,
      data: DATA
    }));
    expect(wrapper.find(StyledRow)).toHaveLength(DATA.length);
  });
  it('renders expected number of columns', function () {
    var wrapper = shallow(React.createElement(Table, {
      columns: COLUMNS,
      data: DATA
    }));
    var cells = wrapper.find(StyledRow).first().find(StyledCell);
    expect(cells).toHaveLength(DATA[0].length);
  });
  it('applies correct aria attributes to table container', function () {
    var wrapper = mount(React.createElement(Table, {
      columns: COLUMNS,
      data: DATA
    }));
    var container = wrapper.find(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 = mount(React.createElement(Table, {
      columns: COLUMNS,
      data: DATA
    }));
    var head = wrapper.find(StyledHead);
    expect(head.getDOMNode().getAttribute('role')).toBe('row');
  });
  it('applies correct role attribute to table head cell', function () {
    var wrapper = mount(React.createElement(Table, {
      columns: COLUMNS,
      data: DATA
    }));
    var headCell = wrapper.find(StyledHeadCell).first();
    expect(headCell.getDOMNode().getAttribute('role')).toBe('columnheader');
  });
  it('applies correct role attribute to table body', function () {
    var wrapper = mount(React.createElement(Table, {
      columns: COLUMNS,
      data: DATA
    }));
    var body = wrapper.find(StyledBody);
    expect(body.getDOMNode().getAttribute('role')).toBe('rowgroup');
  });
  it('applies correct role attribute to table row', function () {
    var wrapper = mount(React.createElement(Table, {
      columns: COLUMNS,
      data: DATA
    }));
    var row = wrapper.find(StyledRow).first();
    expect(row.getDOMNode().getAttribute('role')).toBe('row');
  });
  it('applies correct role attribute to table cell', function () {
    var wrapper = mount(React.createElement(Table, {
      columns: COLUMNS,
      data: DATA
    }));
    var cell = wrapper.find(StyledCell).first();
    expect(cell.getDOMNode().getAttribute('role')).toBe('gridcell');
  });
});