/* eslint-env jest */
import React from 'react'
import { shallow } from 'enzyme'
import { UndoRedo } from '../UndoRedo'
import { isUndoAvailable, isRedoAvailable } from '../../streets/undo_stack'

jest.mock('../../streets/undo_stack')

describe('UndoRedo', () => {
  it('renders two buttons', () => {
    const wrapper = shallow(<UndoRedo locale={{}} />)
    expect(wrapper.find('button').length).toEqual(2)
  })

  it('checks if undo or redo is available when undo position changes', () => {
    // `<UndoRedo>` is mounted with initial props
    const wrapper = shallow(<UndoRedo undo={{ position: 0, stack: [] }} />)

    // Send new props to `<UndoRedo>`
    // It doesn't really matter what we set props to.
    wrapper.setProps({
      undo: {
        position: 1,
        stack: []
      }
    })

    expect(isUndoAvailable).toBeCalled()
    expect(isRedoAvailable).toBeCalled()

    // Clear mocks for future tests
    isUndoAvailable.mockClear()
    isRedoAvailable.mockClear()
  })

  it('checks if undo or redo is available when undo stack changes', () => {
    // `<UndoRedo>` is mounted with initial props
    const wrapper = shallow(<UndoRedo undo={{ position: 0, stack: [] }} />)

    // Send new props to `<UndoRedo>`
    // It doesn't really matter what we set props to.
    wrapper.setProps({
      undo: {
        position: 0,
        stack: [{ foo: 'bar' }]
      }
    })

    expect(isUndoAvailable).toBeCalled()
    expect(isRedoAvailable).toBeCalled()

    // Clear mocks for future tests
    isUndoAvailable.mockClear()
    isRedoAvailable.mockClear()
  })

  it('renders undo button enabled', () => {
    // `<UndoRedo>` is mounted with initial props
    const wrapper = shallow(<UndoRedo undo={{ position: 0, stack: [] }} />)

    // Initial button state at mount time is disabled
    const disabled1 = wrapper.find('button').last().prop('disabled')
    expect(disabled1).toEqual(true)

    // Send new props to `<UndoRedo>`
    // It doesn't really matter what we set props to. The mock implementation
    // of `isUndoAvailable` currently only returns `true`
    wrapper.setProps({
      undo: {
        position: 1,
        stack: [{ foo: 'bar' }]
      }
    })

    // Button state should become enabled
    const disabled2 = wrapper.find('button').first().prop('disabled')
    expect(disabled2).toEqual(false)
  })

  it('renders redo button disabled', () => {
    // `<UndoRedo>` is mounted with initial props
    const wrapper = shallow(<UndoRedo undo={{ position: 0, stack: [] }} />)

    // Initial button state at mount time is disabled
    const disabled1 = wrapper.find('button').last().prop('disabled')
    expect(disabled1).toEqual(true)

    // Send new props to `<UndoRedo>`
    // It doesn't really matter what we set props to. The mock implementation
    // of `isRedoAvailable` currently only returns `false`
    wrapper.setProps({
      undo: {
        position: 0,
        stack: []
      }
    })

    // Button state should remain disabled
    const disabled2 = wrapper.find('button').last().prop('disabled')
    expect(disabled2).toEqual(true)
  })
})

@@ -57,16 +57,24 @@
  shallow
+WithIntl
  %7D from 
@@ -78,14 +78,59 @@
 om '
-enzyme
+../../../../test/helpers/intl-enzyme-test-helper.js
 '%0Aim
@@ -280,16 +280,104 @@
 _stack')
+%0Ajest.mock('../../store/actions/undo', () =%3E (%7B%0A  undo: jest.fn(),%0A  redo: jest.fn()%0A%7D))
 %0A%0Adescri
@@ -454,32 +454,40 @@
 rapper = shallow
+WithIntl
 (%3CUndoRedo local
@@ -704,32 +704,40 @@
 rapper = shallow
+WithIntl
 (%3CUndoRedo undo=
@@ -739,36 +739,34 @@
 undo
-=%7B%7B p
+P
 osition
-: 0, stack: %5B%5D %7D
+=%7B0%7D undoStack=%7B%5B%5D
 %7D /%3E
@@ -889,37 +889,25 @@
 %7B%0A      undo
-: %7B%0A        p
+P
 osition: 1,%0A
@@ -904,35 +904,37 @@
 ition: 1,%0A      
- 
- s
+undoS
 tack: %5B%5D%0A      %7D
@@ -922,32 +922,24 @@
 doStack: %5B%5D%0A
-      %7D%0A
     %7D)%0A%0A    
@@ -1268,32 +1268,40 @@
 rapper = shallow
+WithIntl
 (%3CUndoRedo undo=
@@ -1303,36 +1303,34 @@
 undo
-=%7B%7B p
+P
 osition
-: 0, stack: %5B%5D %7D
+=%7B0%7D undoStack=%7B%5B%5D
 %7D /%3E
@@ -1453,37 +1453,25 @@
 %7B%0A      undo
-: %7B%0A        p
+P
 osition: 0,%0A
@@ -1468,35 +1468,37 @@
 ition: 0,%0A      
- 
- s
+undoS
 tack: %5B%7B foo: 'b
@@ -1500,32 +1500,24 @@
 o: 'bar' %7D%5D%0A
-      %7D%0A
     %7D)%0A%0A    
@@ -1814,32 +1814,40 @@
 rapper = shallow
+WithIntl
 (%3CUndoRedo undo=
@@ -1849,36 +1849,34 @@
 undo
-=%7B%7B p
+P
 osition
-: 0, stack: %5B%5D %7D
+=%7B0%7D undoStack=%7B%5B%5D
 %7D /%3E
@@ -2241,37 +2241,25 @@
 %7B%0A      undo
-: %7B%0A        p
+P
 osition: 1,%0A
@@ -2260,27 +2260,29 @@
 n: 1,%0A      
- 
- s
+undoS
 tack: %5B%7B foo
@@ -2292,24 +2292,16 @@
 bar' %7D%5D%0A
-      %7D%0A
     %7D)%0A%0A
@@ -2577,16 +2577,24 @@
  shallow
+WithIntl
 (%3CUndoRe
@@ -2604,36 +2604,34 @@
 undo
-=%7B%7B p
+P
 osition
-: 0, stack: %5B%5D %7D
+=%7B0%7D undoStack=%7B%5B%5D
 %7D /%3E
@@ -3005,21 +3005,9 @@
 undo
-: %7B%0A        p
+P
 osit
@@ -3024,11 +3024,13 @@
     
- 
- s
+undoS
 tack
@@ -3038,16 +3038,8 @@
  %5B%5D%0A
-      %7D%0A
     

update tests