/*
 * Copyright (c) 2016, Globo.com <https://github.com/globocom/megadraft-table-plugin>
 *
 * License: MIT
 */

import React from "react";
import TestUtils from "react-addons-test-utils";
import * as Table from "reactabular-table";
import {unmountComponentAtNode} from "react-dom";

import {mount} from "enzyme";
import chai from "chai";
import sinon from "sinon";

import TableView from "../src/TableView";

const expect = chai.expect;

describe("TableView", function() {
    const rowsWithOneCell = [["00"]];
    const rowsWithTwoCells = [["00"],["10"]];
    const rowsWithTwoCellsId =[["c00"]]
    const firstColumnName = "c0";

    const createTable = function(rows){
        return mount(<TableView rows={rows}/>);
    }

    it("should have one column", function() {
      let tableView = createTable(rowsWithOneCell);
      expect(tableView.instance().state.columns.length).to.be.equal(rowsWithOneCell[0].length);
    });

    it("should have one row", function() {
      let tableView = createTable(rowsWithOneCell);
      expect(tableView.instance().state.rows.length).to.be.equal(rowsWithOneCell[0].length);
    });

    it("should have one cell value", function() {
      let tableView = createTable(rowsWithOneCell);
      expect(tableView.instance().state.rows[0][firstColumnName]).to.be.equal(rowsWithOneCell[0][0]);
    });

    it("should have column property value with same name as row key", function() {
      const propertyName = firstColumnName;
      let tableView = createTable(rowsWithOneCell);
      expect(tableView.instance().state.rows[0]).to.have.property(propertyName);
      expect(tableView.instance().state.columns[0].property).to.be.equal(propertyName);
    });

    it("should have two rows with one column", function() {
      let tableView = createTable(rowsWithTwoCells);
      for(let i=0; i<rowsWithTwoCells.length ;i++) {
        expect(tableView.instance().state.rows[i][firstColumnName]).to.be.equal(rowsWithTwoCells[i][0]);
      }
      expect(tableView.instance().state.columns).to.have.lengthOf(rowsWithTwoCells[0].length);
    });

    it("should have correct ids for two rows", function() {
      let tableView = createTable(rowsWithTwoCells).instance();
      expect(tableView.buildRowId(firstColumnName, 0, 0)).to.be.equal(tableView.state.rows[0].id);
      expect(tableView.buildRowId(firstColumnName, 1, 0)).to.be.equal(tableView.state.rows[1].id);
    });
})

@@ -594,41 +594,148 @@
 0%22%5D%5D
-%0A    const firstColumnName = %22c0%22
+;%0A    const twoRowsWithTwoColumns = %5B%5B%2200%22, %2201%22%5D, %5B%2210%22, %2211%22%5D%5D;%0A    const firstColumnName = %22c0%22;%0A    const twoColumnsNames = %5B%22c0%22, %22c1%22%5D
 ;%0A%0A 
@@ -819,16 +819,27 @@
 rows%7D/%3E)
+.instance()
 ;%0A    %7D%0A
@@ -956,35 +956,24 @@
 t(tableView.
-instance().
 state.column
@@ -1145,35 +1145,24 @@
 t(tableView.
-instance().
 state.rows.l
@@ -1338,35 +1338,24 @@
 t(tableView.
-instance().
 state.rows%5B0
@@ -1617,35 +1617,24 @@
 t(tableView.
-instance().
 state.rows%5B0
@@ -1687,35 +1687,24 @@
 t(tableView.
-instance().
 state.column
@@ -1941,35 +1941,24 @@
 t(tableView.
-instance().
 state.rows%5Bi
@@ -2049,19 +2049,8 @@
 iew.
-instance().
 stat
@@ -2226,27 +2226,16 @@
 woCells)
-.instance()
 ;%0A      
@@ -2434,11 +2434,382 @@
     %7D);%0A
+%0A    it(%22should have two rows and two columns%22, function() %7B%0A      let tableView = createTable(twoRowsWithTwoColumns);%0A      for(let i=0; i%3CtwoRowsWithTwoColumns.length; i++) %7B%0A        for(let j=0; j%3CtwoRowsWithTwoColumns%5Bi%5D.length; j++) %7B%0A          expect(tableView.state.rows%5Bi%5D%5BtwoColumnsNames%5Bj%5D%5D).to.be.equal(twoRowsWithTwoColumns%5Bi%5D%5Bj%5D);%0A        %7D%0A      %7D%0A    %7D);%0A%0A
 %7D)%0A

Test for two rows and two columns.