/*eslint-env jest*/
jest.dontMock('../RouteControls')

//Use CommonJS require instead of import to prevent Babel hoisting above
//dontMock.  See https://github.com/facebook/jest/issues/377
const React = require('react/addons')
const TestUtils = require('react/lib/ReactTestUtils')
const RouteControls = require('../RouteControls')
const MenuItem = require('react-bootstrap/lib/MenuItem')
const DropdownButton = require('react-bootstrap/lib/DropdownButton')
const sd = require('skin-deep')

describe('RouteControls', () => {
    var ParkingLotActions = {}
    var ParkingLots = {}
    ParkingLots.parkinglots = [{name: 'P8', id: 1}]
    beforeEach(() => {
        ParkingLotActions.setActiveParkingLot = jest.genMockFunction()
    })

    it('Calls the setActiveParkingLot function prop when a parking lot is selected',
        () => {
            let instance = TestUtils.renderIntoDocument(
               <RouteControls ParkingLots={ParkingLots}
                ParkingLotActions={ParkingLotActions}/>
            )
            let li = TestUtils.findRenderedDOMComponentWithTag(instance, 'li')
            TestUtils.Simulate.select(li)
            expect(ParkingLotActions.setActiveParkingLot.mock.calls.length)
                .toEqual(1)
    })

    it('Should render one list item when passed a single parking lot prop',
        () => {
            const tree = sd.shallowRender(React.createElement(RouteControls,
                                                {ParkingLots: ParkingLots}))
            const vdom = tree.getRenderOutput()
            const input = vdom.props.children
            const dropDown = input.props.children.filter(dropDown => TestUtils
                .isElementOfType(dropDown, DropdownButton))
            const menuItems = dropDown[0].props.children.filter(menuItem => TestUtils
                .isElementOfType(menuItem, MenuItem))
            expect(menuItems.length).toEqual(1)
    })
})

@@ -1225,33 +1225,33 @@
        .toEqual(
-1
+2
 )%0A    %7D)%0A%0A    it
@@ -1486,16 +1486,102 @@
 kingLots
+,%0A                                                ParkingLotActions: ParkingLotActions
 %7D))%0A    
@@ -1949,16 +1949,16 @@
 uItem))%0A
-
         
@@ -2003,12 +2003,607 @@
 )%0A    %7D)
+%0A%0A    it('Should clear the active parking lot when the component is mounted',%0A       () =%3E %7B%0A            const shallowRenderer = TestUtils.createRenderer()%0A            shallowRenderer.render(React.createElement(RouteControls,%0A                                                %7BParkingLots: ParkingLots,%0A                                        ParkingLotActions: ParkingLotActions%7D))%0A            expect(ParkingLotActions.setActiveParkingLot.mock.calls.length)%0A                .toEqual(1)%0A            expect(ParkingLotActions.setActiveParkingLot.mock.calls%5B0%5D)%0A                   .toEqual(%7B%7D)%0A    %7D)
 %0A%7D)%0A

Test update to handle mounting and firing active parking lot.