import React from 'react';
import { mount } from 'enzyme';
import Axis from '../../../src/components/Axis';
import { createMockAxis, createMockChart } from '../../test-utils';

describe('<Axis />', function ()  {
  beforeEach(function () {
    this.axis = createMockAxis();
    this.otherAxis = createMockAxis();

    const getStub = sinon.stub();
    getStub.withArgs('myAxis').returns(this.axis);
    getStub.withArgs('myOtherAxis').returns(this.otherAxis);

    this.chart = createMockChart(getStub);

    this.context = {
      chart: this.chart
    };
  });

  describe('when mounted', function () {
    it('adds an X axis using the addAxis method', function () {
      mount(<Axis id="myAxis" dimension="x" />, {context: this.context});
      expect(this.chart.addAxis).to.have.been.calledWith(
        { id: 'myAxis' }, true, true
      );
    });

    it('adds a Y axis using the addAxis method', function () {
      mount(<Axis id="myAxis" dimension="y" />, {context: this.context});
      expect(this.chart.addAxis).to.have.been.calledWith(
        { id: 'myAxis' }, false, true
      );
    });

    it('adds should pass additional props through to Highcharts addAxis method', function () {
      mount(<Axis id="myAxis" dimension="x" min={10} max={100} reversed />, {context: this.context});
      expect(this.chart.addAxis).to.have.been.calledWith(
        { id: 'myAxis', min: 10, max: 100, reversed: true }, true, true
      );
    });
  });

  describe('update', function () {
    it('should update the correct axis if the component props change', function () {
      const wrapper = mount(<Axis id="myAxis" dimension="x" />, {context: this.context});
      wrapper.setProps({ id: 'myAxis', dimension: 'x', newPropName: 'newPropValue' });
      expect(this.axis.update).to.have.been.calledWith({
        newPropName: 'newPropValue'
      });
      expect(this.otherAxis.update).not.to.have.been.called;
    });
  });

  describe('when unmounted', function () {
    it('removes the correct axis', function () {
      const wrapper = mount(<Axis id="myAxis" dimension="x" />, {context: this.context});
      wrapper.unmount();
      expect(this.axis.remove).to.have.been.called;
      expect(this.otherAxis.remove).not.to.have.been.called;
    });
  });

  describe('children', function () {
    it('should pass the ID of the axis to the children', function () {
      const child = mount(<Axis id="myAxis" dimension="x"><Axis.Title /></Axis>, {context: this.context}).children();
      expect(child.props()).to.eql(
        { dimension: 'x', axisId: 'myAxis' }
      );
    });
  });
});

@@ -102,75 +102,12 @@
 Axis
-';%0Aimport %7B createMockAxis, createMockChart %7D from '../../test-util
+/Axi
 s';%0A
@@ -184,313 +184,90 @@
 is.a
+ddA
 xis = 
-createMockAxis();%0A    this.otherAxis = createMockAxis();%0A%0A    const getStub = sinon.stub();%0A    getStub.withArgs('myAxis').returns(this.axis);%0A    getStub.withArgs('myOtherAxis').returns(this.otherAxis);%0A%0A    this.chart = createMockChart(getStub);%0A%0A    this.context = %7B%0A      chart: this.chart%0A    %7D
+sinon.spy();%0A    this.remove = sinon.spy();%0A    this.update = sinon.spy()
 ;%0A  
@@ -424,35 +424,33 @@
 %22x%22 
-/%3E, %7Bcontext: this.context%7D
+addAxis=%7Bthis.addAxis%7D /%3E
 );%0A 
@@ -458,38 +458,32 @@
     expect(this.
-chart.
 addAxis).to.have
@@ -666,35 +666,33 @@
 %22y%22 
-/%3E, %7Bcontext: this.context%7D
+addAxis=%7Bthis.addAxis%7D /%3E
 );%0A 
@@ -700,38 +700,32 @@
     expect(this.
-chart.
 addAxis).to.have
@@ -969,35 +969,33 @@
 sed 
-/%3E, %7Bcontext: this.context%7D
+addAxis=%7Bthis.addAxis%7D /%3E
 );%0A 
@@ -1015,14 +1015,8 @@
 his.
-chart.
 addA
@@ -1198,32 +1198,24 @@
  update the 
-correct 
 axis if the 
@@ -1317,35 +1317,54 @@
 %22x%22 
-/%3E, %7Bcontext: this.context%7D
+addAxis=%7Bthis.addAxis%7D update=%7Bthis.update%7D /%3E
 );%0A 
@@ -1467,21 +1467,16 @@
 ct(this.
-axis.
 update).
@@ -1551,69 +1551,8 @@
 %7D);%0A
-      expect(this.otherAxis.update).not.to.have.been.called;%0A
     
@@ -1629,16 +1629,8 @@
 the 
-correct 
 axis
@@ -1710,35 +1710,54 @@
 %22x%22 
-/%3E, %7Bcontext: this.context%7D
+addAxis=%7Bthis.addAxis%7D remove=%7Bthis.remove%7D /%3E
 );%0A 
@@ -1802,13 +1802,8 @@
 his.
-axis.
 remo
@@ -1831,69 +1831,8 @@
 ed;%0A
-      expect(this.otherAxis.remove).not.to.have.been.called;%0A
     
@@ -1966,100 +1966,152 @@
 nst 
-child = mount(%3CAxis id=%22myAxis%22 dimension=%22x%22%3E%3CAxis.Title /%3E%3C/Axis%3E, %7Bcontext: this.context%7D
+ChildComponent = props =%3E (%3Cdiv /%3E);%0A%0A      const child = mount(%3CAxis id=%22myAxis%22 dimension=%22x%22 addAxis=%7Bthis.addAxis%7D%3E%3CChildComponent /%3E%3C/Axis%3E
 ).ch

Fix Axis tests