Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: test by pages/ScheduleDetail/Page.tsx
- Loading branch information
1 parent
c2b1b44
commit 4b332e1
Showing
3 changed files
with
142 additions
and
22 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
82 changes: 68 additions & 14 deletions
82
PeperomiaNative/src/components/pages/ScheduleDetail/__tests__/Page.test.tsx
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 |
---|---|---|
@@ -1,24 +1,78 @@ | ||
import React from 'react'; | ||
import { Alert } from 'react-native'; | ||
import { shallow, ShallowWrapper } from 'enzyme'; | ||
import Page from '../Page'; | ||
import Loading from '../../../molecules/ScheduleDetail/Loading'; | ||
import Card from '../../../molecules/ScheduleDetail/Card'; | ||
import Connected, { ScheduleDetailPage, ScheduleDetailType } from '../Page'; | ||
import { mockData } from './mockData'; | ||
|
||
describe('components/pages/ScheduleDetail/Page.tsx', () => { | ||
let wrapper: ShallowWrapper; | ||
|
||
const propsData = () => ({ | ||
...mockData, | ||
loading: false, | ||
onDismiss: jest.fn(), | ||
onDelete: jest.fn(), | ||
onCreateScheduleDetail: jest.fn(), | ||
}); | ||
let wrapper: ShallowWrapper<ScheduleDetailType>; | ||
|
||
describe('Connected', () => { | ||
const propsData = () => ({ | ||
...mockData, | ||
loading: false, | ||
onDismiss: jest.fn(), | ||
onDelete: jest.fn(), | ||
onCreateScheduleDetail: jest.fn(), | ||
}); | ||
|
||
beforeEach(() => { | ||
wrapper = shallow(<Page {...propsData()} />); | ||
it('正常に表示されている', () => { | ||
wrapper = shallow(<Connected {...propsData()} />); | ||
|
||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
it('正常に表示されている', () => { | ||
expect(wrapper).toMatchSnapshot(); | ||
describe('ScheduleDetailPage', () => { | ||
const showActionSheetWithOptions = jest.fn(); | ||
const onCreateScheduleDetail = jest.fn(); | ||
const onDelete = jest.fn(); | ||
|
||
const propsData = () => ({ | ||
...mockData, | ||
loading: false, | ||
onDismiss: jest.fn(), | ||
onDelete, | ||
onCreateScheduleDetail, | ||
showActionSheetWithOptions, | ||
}); | ||
|
||
it('正常に表示されている', () => { | ||
wrapper = shallow(<ScheduleDetailPage {...propsData()} />); | ||
|
||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
it('Loadingが表示されている', () => { | ||
wrapper = shallow(<ScheduleDetailPage {...propsData()} loading />); | ||
|
||
expect(wrapper.find(Loading).exists()).toBeTruthy(); | ||
}); | ||
|
||
describe('onOpenActionSheet', () => { | ||
wrapper = shallow(<ScheduleDetailPage {...propsData()} />); | ||
|
||
wrapper | ||
.find(Card) | ||
.props() | ||
.onOpenActionSheet(); | ||
|
||
it('編集', () => { | ||
showActionSheetWithOptions.mock.calls[0][1](0); | ||
|
||
expect(onCreateScheduleDetail.mock.calls.length).toBe(1); | ||
}); | ||
|
||
it('削除', () => { | ||
const alertMock = jest.fn(); | ||
jest.spyOn(Alert, 'alert').mockImplementation(alertMock); | ||
|
||
showActionSheetWithOptions.mock.calls[0][1](1); | ||
alertMock.mock.calls[0][2][1].onPress(); | ||
|
||
expect(onDelete.mock.calls.length).toBe(1); | ||
}); | ||
}); | ||
}); | ||
}); |
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