/* global describe, it, expect */

import React from 'react'
import ReactDOM from 'react-dom'
import TestUtils from 'react-addons-test-utils'
import {Linear, Circular} from '../'

describe('Progress', () => {
  describe('Linear', () => {
    it('should work', (done) => {
      const instance = TestUtils.renderIntoDocument(<Linear />)
      // use setTimeout to make component is rendered
      window.setTimeout(() => {
        const node = ReactDOM.findDOMNode(instance)
        expect(node).toBeTruthy()
        done()
      }, 100)
    })

    it('should render a progress bar with given percentage', (done) => {
      const instance = TestUtils.renderIntoDocument(<Linear percentage={50} />)
      window.setTimeout(() => {
        const inner = TestUtils.findRenderedDOMComponentWithClass(instance, 'Progress-linear-inner')
        expect(inner.style.width).toBe('50%')
        done()
      }, 100)
    })

    it('should remove itself from the DOM when done', (done) => {
      const instance = TestUtils.renderIntoDocument(<Linear />)
      // use setTimeout to make component is rendered
      window.setTimeout(() => {
        const node = ReactDOM.findDOMNode(instance)
        expect(node).toBeTruthy()
        // let it be done
        instance.componentWillReceiveProps({
          percentage: 100
        })
        window.setTimeout(() => {
          const node = ReactDOM.findDOMNode(instance)
          expect(node).toBeFalsy()
          done()
        }, 1500)
      }, 100)
    }, 10000)

    // make sure else path is taken for test coverage
    it('should not remove itself from the DOM when below 100 percent', (done) => {
      const instance = TestUtils.renderIntoDocument(<Linear />)
      window.setTimeout(() => {
        const node = ReactDOM.findDOMNode(instance)
        expect(node).toBeTruthy
        instance.componentWillReceiveProps({
          percentage: 99
        })
        window.setTimeout(() => {
          const node = ReactDOM.findDOMNode(instance)
          // different to test above
          expect(node).toBeTruthy()
          done()
        }, 1500)
      })
    })
  })

  describe('Circular', () => {
    it('should work', () => {
      const instance = TestUtils.renderIntoDocument(<Circular />)
      const node = ReactDOM.findDOMNode(instance)
      expect(node).toBeTruthy()
    })

    it('should render circular progress with given percentage', () => {
      const instance = TestUtils.renderIntoDocument(<Circular percentage={50} />)
      const inner = TestUtils.findRenderedDOMComponentWithClass(instance, 'Progress-circular-path')
      expect(parseFloat(inner.style.strokeDasharray)).toBeCloseTo(2 * Math.PI * 30)
      expect(inner.style.strokeDashoffset).toBeCloseTo(Math.PI * 30)
    })
  })
})

@@ -65,80 +65,28 @@
 ort 
-ReactDOM from 'react-dom'%0Aimport TestUtils from 'react-addons-test-utils
+%7Bmount%7D from 'enzyme
 '%0Aim
@@ -229,45 +229,21 @@
 nst 
-instance = TestUtils.renderIntoDocume
+wrapper = mou
 nt(%3C
@@ -351,84 +351,62 @@
     
-const node = ReactDOM.findDOMNode(instance)%0A        expect(node).toBeTruthy(
+expect(wrapper.find('.Progress-linear').length).toBe(1
 )%0A  
@@ -529,45 +529,21 @@
 nst 
-instance = TestUtils.renderIntoDocume
+wrapper = mou
 nt(%3C
@@ -613,77 +613,30 @@
     
-const inner = TestUtils.findRenderedDOMComponentWithClass(instance, '
+expect(wrapper.find('.
 Prog
@@ -658,29 +658,13 @@
 er')
-%0A        expect(inner
+.node
 .sty
@@ -804,230 +804,130 @@
 nst 
-instance = TestUtils.renderIntoDocument(%3CLinear /%3E)%0A      // use setTimeout to make component is rendered%0A      window.setTimeout(() =%3E %7B%0A        const node = ReactDOM.findDOMNode(instance)%0A        expect(node).toBeTruthy(
+wrapper = mount(%3CLinear /%3E)%0A      window.setTimeout(() =%3E %7B%0A        expect(wrapper.find('.Progress-linear').length).toBe(1
 )%0A  
@@ -962,37 +962,19 @@
     
-instance.componentWillReceive
+wrapper.set
 Prop
@@ -1062,85 +1062,62 @@
     
-const node = ReactDOM.findDOMNode(instance)%0A          expect(node).toBeFalsy(
+expect(wrapper.find('.Progress-linear').length).toBe(0
 )%0A  
@@ -1330,45 +1330,21 @@
 nst 
-instance = TestUtils.renderIntoDocume
+wrapper = mou
 nt(%3C
@@ -1398,324 +1398,262 @@
     
-const node = ReactDOM.findDOMNode(instance)%0A        expect(node).toBeTruthy%0A        instance.componentWillReceiveProps(%7B%0A          percentage: 99%0A        %7D)%0A        window.setTimeout(() =%3E %7B%0A          const node = ReactDOM.findDOMNode(instance)%0A          // different to test above%0A          expect(node).toBeTruthy(
+expect(wrapper.find('.Progress-linear').length).toBe(1)%0A        wrapper.setProps(%7B%0A          percentage: 99%0A        %7D)%0A        window.setTimeout(() =%3E %7B%0A          // different to test above%0A          expect(wrapper.find('.Progress-linear').length).toBe(1
 )%0A  
@@ -1687,24 +1687,29 @@
 500)%0A      %7D
+, 100
 )%0A    %7D)%0A  %7D
@@ -1788,142 +1788,100 @@
 nst 
-instance = TestUtils.renderIntoDocument(%3CCircular /%3E)%0A      const node = ReactDOM.findDOMNode(instance)%0A      expect(node).toBeTruthy(
+wrapper = mount(%3CCircular /%3E)%0A      expect(wrapper.find('.Progress-circular').length).toBe(1
 )%0A  
@@ -1974,45 +1974,21 @@
 nst 
-instance = TestUtils.renderIntoDocume
+wrapper = mou
 nt(%3C
@@ -2040,63 +2040,23 @@
 r = 
-TestUtils.findRenderedDOMComponentWithClass(instance, '
+wrapper.find('.
 Prog
@@ -2098,32 +2098,37 @@
 arseFloat(inner.
+node.
 style.strokeDash
@@ -2184,16 +2184,21 @@
 t(inner.
+node.
 style.st

rewrite tests using enzyme