forked from ant-design/ant-design-mobile
-
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.
Fix PickerView that accept one-dimensional array as data property (an…
…t-design#2815) * fix: transform one-dimensional-array to multi-dimensional-array * docs: add example about one-dimensional array as `data` property * test: update test snap for new example * test: add unit test for PickerView * docs: add example for cascade usage * test: update demo snapshot
- Loading branch information
1 parent
1ecad9b
commit 8b10644
Showing
4 changed files
with
393 additions
and
43 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
210 changes: 182 additions & 28 deletions
210
components/picker-view/__tests__/__snapshots__/demo.test.js.snap
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 |
---|---|---|
@@ -1,10 +1,92 @@ | ||
// import React from 'react'; | ||
// import PickerView from '../index'; | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import PickerView from '../index'; | ||
|
||
const createMap = label => ({ label, value: label }); | ||
|
||
describe('PickerView', () => { | ||
// No need to render Snapshot again, because of `./demo.test.js` | ||
it('trigger event correctly', () => { | ||
// todos: write test! | ||
expect(true).toBe(true); | ||
const dataWithoutCascade = [ | ||
['2018', '2019', '2020'].map(createMap), | ||
['Blade_Runner', 'Before_Midnight', 'Shutter_Island'].map(createMap), | ||
]; | ||
|
||
const oneDimenData = ['2018', '2019', '2020'].map(createMap); | ||
|
||
describe('with one-dimensional data', () => { | ||
const wrapper = mount(<PickerView data={oneDimenData} cascade={false} />); | ||
|
||
it('should render <PickerView /> component', () => { | ||
expect(wrapper.exists('.am-picker')).toBe(true); | ||
}); | ||
|
||
it('should contain value match data', () => { | ||
expect( | ||
oneDimenData.some( | ||
({ value }, ii) => | ||
!( | ||
wrapper | ||
.find('.am-picker-col-item') | ||
.at(ii) | ||
.text() === value | ||
), | ||
), | ||
).toBe(false); | ||
}); | ||
|
||
it('should select default value', () => { | ||
expect( | ||
wrapper.find('.am-picker-col-item-selected').text() === | ||
oneDimenData[0].value, | ||
).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('without cascade effect', () => { | ||
const wrapper = mount( | ||
<PickerView data={dataWithoutCascade} cascade={false} />, | ||
); | ||
|
||
it('should render <PickerView /> component', () => { | ||
expect(wrapper.exists('.am-picker')).toBe(true); | ||
}); | ||
|
||
it('should contain the same length column to data', () => { | ||
expect(wrapper.find('.am-picker').children()).toHaveLength( | ||
dataWithoutCascade.length, | ||
); | ||
}); | ||
|
||
it('should contain value match data', () => { | ||
expect( | ||
dataWithoutCascade.some((col, i) => | ||
col.some( | ||
({ value }, ii) => | ||
!( | ||
wrapper | ||
.find('.am-picker') | ||
.childAt(i) | ||
.find('.am-picker-col-item') | ||
.at(ii) | ||
.text() === value | ||
), | ||
), | ||
), | ||
).toBe(false); | ||
}); | ||
|
||
it('should select default value', () => { | ||
expect( | ||
dataWithoutCascade.some( | ||
(col, i) => | ||
!( | ||
wrapper | ||
.find('.am-picker') | ||
.childAt(i) | ||
.find('.am-picker-col-item-selected') | ||
.text() === col[0].value | ||
), | ||
), | ||
).toBe(false); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.