This repository has been archived by the owner on Feb 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#105): added test cases for ListView and Container
- Loading branch information
Andreas Gasser
committed
May 6, 2019
1 parent
d598f2d
commit 16ca23c
Showing
6 changed files
with
139 additions
and
3 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
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,38 @@ | ||
import { __testables__ } from '../Container'; | ||
import { listImages } from '../../../redux/images'; | ||
|
||
const { select, mapDispatchToProps, mapKeyToValue } = __testables__; | ||
|
||
describe('images list container test suite', () => { | ||
const expectedInitialState = { | ||
images: [], | ||
addImageRequest: undefined, | ||
}; | ||
|
||
const initialProps = { | ||
match: { | ||
params: { | ||
id: null, | ||
}, | ||
}, | ||
location: { | ||
search: '', | ||
}, | ||
}; | ||
|
||
it('should return container state', () => { | ||
const state = select({}, initialProps); | ||
expect(state).toEqual(expectedInitialState); | ||
|
||
expect(Object.keys(state)).toEqual([ | ||
'images', | ||
'addImageRequest', | ||
]); | ||
}); | ||
|
||
it('should return redux actions', () => { | ||
expect(mapDispatchToProps).toEqual({ | ||
listImages, | ||
}); | ||
}); | ||
}); |
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,94 @@ | ||
/* globals testUtils */ | ||
import React from 'react'; | ||
import { mount, shallow } from 'enzyme'; | ||
import { Provider } from 'react-redux'; | ||
import toJson from 'enzyme-to-json'; | ||
import 'jest-styled-components'; | ||
|
||
import ListView from '../ListView'; | ||
import ImageList from '../ImageList'; | ||
import AddImageButton from '../../AddImageButton'; | ||
|
||
import * as Paths from '../../../paths'; | ||
|
||
const { createMockStore } = testUtils; | ||
|
||
describe('ListView test suite', () => { | ||
|
||
const initialProps = { | ||
history: { | ||
push: jest.fn(), | ||
}, | ||
images: [], | ||
onImageClick: jest.fn(), | ||
addImageRequest: { | ||
error: null, | ||
loading: false, | ||
}, | ||
}; | ||
|
||
const mockStore = createMockStore(); | ||
|
||
afterEach(() => { | ||
// clear mocks | ||
initialProps.history.push.mockClear(); | ||
initialProps.onImageClick.mockClear(); | ||
}); | ||
|
||
const getListView = (props) => { | ||
const store = mockStore(); | ||
const provider = mount( | ||
<Provider store={store}> | ||
<ListView | ||
{...initialProps} | ||
{...props} | ||
/> | ||
</Provider> | ||
); | ||
|
||
const wrapper = provider.find(ListView); | ||
return wrapper; | ||
}; | ||
|
||
it('should render', () => { | ||
const wrapper = getListView(); | ||
expect(wrapper.exists()).toBeTruthy(); | ||
}); | ||
|
||
it('should render AddImageButton', () => { | ||
const wrapper = getListView(); | ||
expect(wrapper.exists()).toBeTruthy(); | ||
|
||
const addImageButton = wrapper.find(AddImageButton); | ||
expect(addImageButton.exists()).toBeTruthy(); | ||
}); | ||
|
||
it('should render ImageList with props', () => { | ||
const wrapper = getListView(); | ||
expect(wrapper.exists()).toBeTruthy(); | ||
|
||
const imageList = wrapper.find(ImageList); | ||
expect(imageList.exists()).toBeTruthy(); | ||
|
||
const props = imageList.props(); | ||
expect(props.images).toEqual(initialProps.images); | ||
expect(props.addImageRequest).toEqual(initialProps.addImageRequest); | ||
}); | ||
|
||
it('should move to image detail view after image upload', () => { | ||
const imageId = '2a2bdf23-e73f-4a2a-913e-da29926a195c'; | ||
const wrapper = getListView(); | ||
expect(wrapper.exists()).toBeTruthy(); | ||
|
||
const imageList = wrapper.find(ImageList); | ||
expect(imageList.exists()).toBeTruthy(); | ||
|
||
expect(initialProps.history.push).not.toHaveBeenCalled(); | ||
|
||
// fire event | ||
imageList.props().onImageClick({ id: imageId }); | ||
|
||
expect(initialProps.history.push).toHaveBeenCalled(); | ||
expect(initialProps.history.push).toHaveBeenCalledWith(Paths.GET_IMAGES_DETAIL(imageId)); | ||
}); | ||
}); |
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