-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for Search and RoutePanel. Use snapshot testing.
- Loading branch information
Benjamin Tran Dinh
committed
Jun 14, 2017
1 parent
47f16cc
commit ea9d17d
Showing
16 changed files
with
514 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
|
||
import {RoutePanel} from './RoutePanel'; | ||
import {bikeRoute, walkingRoute} from './fixtures/RoutePanel.fixtures.js'; | ||
|
||
it('bike route renders correctly', () => { | ||
|
||
const component = renderer.create( | ||
<RoutePanel | ||
mapboxAccessToken='test' | ||
modality='bike' | ||
route={bikeRoute} | ||
routeStatus='idle' | ||
/> | ||
); | ||
|
||
let tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('walking route renders correctly', () => { | ||
|
||
const component = renderer.create( | ||
<RoutePanel | ||
mapboxAccessToken='test' | ||
modality='walk' | ||
route={walkingRoute} | ||
routeStatus='idle' | ||
/> | ||
); | ||
|
||
let tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('pending route renders correctly', () => { | ||
|
||
const component = renderer.create( | ||
<RoutePanel | ||
mapboxAccessToken='test' | ||
modality='walk' | ||
route={null} | ||
routeStatus='pending' | ||
/> | ||
); | ||
|
||
let tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('error route renders correctly', () => { | ||
|
||
const component = renderer.create( | ||
<RoutePanel | ||
mapboxAccessToken='test' | ||
modality='walk' | ||
route={null} | ||
routeStatus='error' | ||
/> | ||
); | ||
|
||
let tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import {shallow} from 'enzyme'; | ||
import {createStore} from 'redux'; | ||
import {Provider} from 'react-redux'; | ||
import {defaultState} from '../reducers/index'; | ||
import reducer from '../reducers/index'; | ||
|
||
import {Search} from './Search'; | ||
import ConnectedSearch from './Search'; | ||
import {placeInfo, searchLocation} from './fixtures/Search.fixtures.js'; | ||
|
||
it('renders correctly with search location', () => { | ||
|
||
const component = renderer.create( | ||
<Search | ||
getPlaceInfo={() => {}} | ||
placeInfo={placeInfo} | ||
resetStateKeys={() => {}} | ||
searchLocation={searchLocation} | ||
searchString='Paris' | ||
setDirectionsLocation={() => {}} | ||
setMode={() => {}} | ||
setPlaceInfo={() => {}} | ||
setSearchLocation={() => {}} | ||
triggerMapUpdate={() => {}} | ||
writeSearch={() => {}} | ||
/> | ||
); | ||
|
||
let tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders correctly without search location', () => { | ||
|
||
let store = createStore(reducer, defaultState); | ||
|
||
const component = renderer.create( | ||
<Provider store={store}> | ||
<ConnectedSearch/> | ||
</Provider> | ||
); | ||
|
||
let tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('behaves correctly on clicking directions', () => { | ||
|
||
const setDirectionsLocation = jest.fn(); | ||
const setMode = jest.fn(); | ||
|
||
const search = shallow( | ||
<Search | ||
getPlaceInfo={() => {}} | ||
placeInfo={placeInfo} | ||
resetStateKeys={() => {}} | ||
searchLocation={searchLocation} | ||
searchString='Paris' | ||
setDirectionsLocation={setDirectionsLocation} | ||
setMode={setMode} | ||
setPlaceInfo={() => {}} | ||
setSearchLocation={() => {}} | ||
triggerMapUpdate={() => {}} | ||
writeSearch={() => {}} | ||
/> | ||
); | ||
|
||
search.find('#search-directions').simulate('click'); | ||
expect(setDirectionsLocation).toBeCalledWith('to', searchLocation); | ||
expect(setMode).toBeCalledWith('directions'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.