import React from 'react';
import { expect } from 'chai';
import { shallow, mount, render } from 'enzyme';
import Datagrid from '../src/components/datagrid.jsx';
import sinon from 'sinon';
import form from './forms/empty.json';

var components = require('./forms/componentSpec.js');

describe('Datagrid', function () {
  describe(' Datagrid component', function () {
    var component= {
      "input": true,
      "tree": true,
      "components": [],
      "tableView": true,
      "label": "testLabel",
      "key": "testLabel",
      "protected": true,
      "persistent": true,
      "type": "datagrid",
      "conditional": {
        "show": "",
        "when": null,
        "eq": ""
      },
      "addAnother": "",
      "condensed": true,
      "hover": true,
      "bordered": true,
      "striped": true,
      "isNew": false
    };
    var attachToForm = sinon.spy();

    it('Renders a basic datagrid', function (done) {
      const element = shallow(<Datagrid
      component={component}
      attachToForm={attachToForm}
        />)
      expect(element.hasClass('form-group form-field-type-datagrid')).to.equal(true);
      done();
    });

    it('Check with label for datagrid component', function (done) {
      component.label = 'My datagrid';
      const element = shallow(<Datagrid
        component={component}
        attachToForm={attachToForm}
      />).find('.formio-data-grid');

      //Need to take the count of default label.
      expect(element.find('.control-label').length).to.equal(2);
      done();
    });

    it('Check without label for datagrid component', function (done) {
      component.label = '';
      const element = shallow(<Datagrid
        component={component}
        attachToForm={attachToForm}
      />).find('.formio-data-grid');

      //Need to take the count of default label.
      expect(element.find('.control-label').length).to.equal(1);
      done();
    });

    it('Check the without table classes of datagrid element ', function (done) {
      const element = shallow(<Datagrid
        component={component}
        attachToForm={attachToForm}
      />).find('table');
      expect(element.hasClass('table datagrid-table')).to.equal(true);
      done();
    });

    it('Check the with table classes of datagrid element ', function (done) {
      component.condensed = true;
      component.hover = true;
      component.bordered = true;
      component.striped = true;

      const element = shallow(<Datagrid
        component={component}
        attachToForm={attachToForm}
      />).find('table');
      expect(element.hasClass('table datagrid-table table-striped table-bordered table-hover table-condensed')).to.equal(true);
      done();
    });

    it('Check the nested components of datagrid', function (done) {
      component.components = [
        components.textfeild,
        components.password,
        components.phoneNumber
      ];
      const element = shallow(<Datagrid
      component={component}
      attachToForm={attachToForm}
        />).find('.table');

      //To test type of nested components of datagrid
      for (var i= 0; i<component.components.length; i++) {
        expect(element.node.props.children[1].props.children[0].props.children[0][i].props.children.props.component.type).to.equal(component.components[i].type);
      }
      done();

    });

//TODO:- Need to write the test case for add another and remove component scenario. Currently test gets fail on both add and remove component scenario.
    
    //it('Check with label for datagrid component', function (done) {
    //  component.components = [
    //    components.textfeild,
    //    components.password,
    //    components.phoneNumber
    //  ];
    //  const element = shallow(<Datagrid
    //    component={component}
    //    attachToForm={attachToForm}
    //  />).find('.datagrid-add');
    //  element.find('a').simulate('click');
    //  done();
    //});

  });

});

@@ -3352,17 +3352,17 @@
   %7D);%0A%0A/
-/
+*
 TODO:- N
@@ -3505,443 +3505,86 @@
 ario
-.%0A    %0A    //it('Check with label for datagrid component', function (done) %7B%0A    //  component.components = %5B%0A    //    components.textfeild,%0A    //    components.password,%0A    //    components.phoneNumber%0A    //  %5D;%0A    //  const element = shallow(%3CDatagrid%0A    //    component=%7Bcomponent%7D%0A    //    attachToForm=%7BattachToForm%7D%0A    //  /%3E).find('.datagrid-add');%0A    //  element.find('a').simulate('click');%0A    //  done();%0A    //%7D);%0A
+,%0A because we shallow the child component and try to call the parent method.*/
 %0A  %7D

Remove the implementation of add another and remove button test case scenario.