-
Notifications
You must be signed in to change notification settings - Fork 734
WheelPicker - add driver #2903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
WheelPicker - add driver #2903
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
327bcb4
WheelPicker - add driver
Inbal-Tish ee9c00a
rename function
Inbal-Tish a582fd0
Adding SectionsWheelPicker driver
Inbal-Tish e829a3c
remove extra const
Inbal-Tish 9daa05d
move listdriver to top
Inbal-Tish 5c44fa8
Update src/components/WheelPicker/__tests__/index.spec.tsx
Inbal-Tish ab4e3b6
Update src/components/WheelPicker/__tests__/index.spec.tsx
Inbal-Tish 4a235d5
Update src/components/WheelPicker/__tests__/index.spec.tsx
adids1221 e6c97d7
Update src/components/sectionsWheelPicker/mockSections.ts
adids1221 8c6c893
Update src/components/sectionsWheelPicker/mockSections.ts
adids1221 a3b0aa8
Update src/components/sectionsWheelPicker/mockSections.ts
adids1221 d0fbf42
Merge branch 'master' into tests/Driver_WheelPicker
adids1221 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 {FlatListProps} from 'react-native'; | ||
import {WheelPickerProps, WheelPickerItemProps} from './index'; | ||
import {useComponentDriver, ComponentProps} from '../../testkit/new/Component.driver'; | ||
import {useScrollableDriver} from '../../testkit/new/useScrollable.driver'; | ||
import {TextDriver} from '../../components/Text/Text.driver.new'; | ||
|
||
export const WheelPickerDriver = (props: ComponentProps) => { | ||
const driver = useComponentDriver<WheelPickerProps>(props); | ||
|
||
const listDriver = useScrollableDriver<FlatListProps<WheelPickerItemProps>>(useComponentDriver({ | ||
renderTree: props.renderTree, | ||
testID: `${props.testID}.list` | ||
})); | ||
|
||
const moveToItem = (index: number, numberOfRows: number, itemHeight: number) => { | ||
listDriver.triggerEvent('onMomentumScrollEnd', { | ||
contentOffset: {x: 0, y: itemHeight * index}, | ||
contentSize: {height: numberOfRows * itemHeight, width: 400}, | ||
layoutMeasurement: {height: 100, width: 400} | ||
}); | ||
}; | ||
|
||
const getListHeight = () => { | ||
//@ts-expect-error | ||
return listDriver.getProps().height; | ||
}; | ||
|
||
const labelDriver = TextDriver({ | ||
renderTree: props.renderTree, | ||
testID: `${props.testID}.label` | ||
}); | ||
|
||
const getLabel = () => { | ||
return labelDriver.getText(); | ||
}; | ||
|
||
return {...driver, ...listDriver, getListHeight, moveToItem, getLabel}; | ||
}; |
This file contains hidden or 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,25 @@ | ||
import {useComponentDriver, ComponentProps} from '../../testkit/new/Component.driver'; | ||
// import {usePressableDriver} from '../../testkit'; | ||
import {TextDriver} from '../../components/Text/Text.driver.new'; | ||
// import {WheelPickerItemProps} from './index'; | ||
|
||
|
||
export const WheelPickerItemDriver = (props: ComponentProps) => { | ||
const driver = useComponentDriver(props); | ||
// const driver = usePressableDriver<WheelPickerItemProps>(useComponentDriver(props)); | ||
|
||
const labelDriver = TextDriver({ | ||
renderTree: props.renderTree, | ||
testID: `${props.testID}.text` | ||
}); | ||
|
||
const getLabel = () => { | ||
return labelDriver.getText(); | ||
}; | ||
|
||
const getLabelStyle = () => { | ||
return labelDriver.getStyle(); // NOTE: when there's active/inactive colors the color will be animated sharedValue instead of string | ||
}; | ||
|
||
return {...driver, getLabel, getLabelStyle}; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,108 @@ | ||
import _ from 'lodash'; | ||
import React from 'react'; | ||
import {render/* , act, waitFor */} from '@testing-library/react-native'; | ||
import {Colors} from '../../../style'; | ||
import WheelPicker from '../index'; | ||
import {WheelPickerDriver} from '../WheelPicker.driver'; | ||
import {WheelPickerItemDriver} from '../WheelPickerItem.driver'; | ||
|
||
const ITEM_HEIGHT = 50; | ||
const NUM_OF_ROWS = 10; | ||
const testID = 'wheel'; | ||
const onChange = jest.fn(); | ||
|
||
const TestCase = props => { | ||
return ( | ||
<WheelPicker | ||
testID={testID} | ||
items={_.times(60, i => i).map(item => ({label: `item #${item}`, value: item, testID: `${item}`}))} | ||
initialValue={0} | ||
onChange={onChange} | ||
numberOfVisibleRows={NUM_OF_ROWS} | ||
itemHeight={ITEM_HEIGHT} | ||
activeTextColor={Colors.red30} | ||
inactiveTextColor={Colors.blue30} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
describe('WheelPicker', () => { | ||
beforeEach(() => { | ||
onChange.mockClear(); | ||
}); | ||
|
||
describe('FlatList', () => { | ||
it('should present $NUM_OF_ROWS rows', () => { | ||
const renderTree = render(<TestCase/>); | ||
const driver = WheelPickerDriver({renderTree, testID}); | ||
expect(driver.getListHeight()).toBe(NUM_OF_ROWS * ITEM_HEIGHT); | ||
}); | ||
|
||
it('should call onChange after scrolling ends', () => { | ||
const renderTree = render(<TestCase/>); | ||
const driver = WheelPickerDriver({renderTree, testID}); | ||
|
||
driver.moveToItem(4, NUM_OF_ROWS, ITEM_HEIGHT); | ||
expect(onChange).toHaveBeenCalledWith(4, 4); | ||
|
||
driver.moveToItem(7, NUM_OF_ROWS, ITEM_HEIGHT); | ||
expect(onChange).toHaveBeenCalledWith(7, 7); | ||
}); | ||
}); | ||
|
||
describe('initialValue', () => { | ||
it('should not call onChange when initialValue is updated', () => { | ||
const renderTree = render(<TestCase/>); | ||
renderTree.rerender(<TestCase initialValue={2}/>); | ||
expect(onChange).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('label', () => { | ||
it('should return label', () => { | ||
const label = 'Hours'; | ||
const renderTree = render(<TestCase label={label}/>); | ||
const driver = WheelPickerDriver({renderTree, testID}); | ||
expect(driver.getLabel()).toEqual(label); | ||
}); | ||
}); | ||
|
||
describe('PickerItem', () => { | ||
it('should get first item\'s label', () => { | ||
const renderTree = render(<TestCase/>); | ||
const index = 0; | ||
const driver = WheelPickerItemDriver({renderTree, testID: `${index}`}); | ||
expect(driver.getLabel()).toEqual('item #0'); | ||
}); | ||
|
||
it('should get first item\'s text style when no active/inactive colors', () => { | ||
const renderTree = render(<TestCase textStyle={{color: Colors.green30}}/>); | ||
const index = 0; | ||
const driver = WheelPickerItemDriver({renderTree, testID: `${index}`}); | ||
expect(driver.getLabelStyle()?.color).toEqual(Colors.green30); | ||
}); | ||
|
||
//TODO: Fix these test's using AnimatedStyle mocking | ||
// it('should call onChange after second item is pressed', async () => { | ||
// const renderTree = render(<TestCase/>); | ||
// const index = 1; | ||
// const driver = WheelPickerItemDriver({renderTree, testID: `${index}`}); | ||
|
||
// driver.press(); | ||
|
||
// expect(await onChange).toHaveBeenCalledTimes(1); | ||
// expect(onChange).toHaveBeenCalledWith(1); | ||
// }); | ||
|
||
// it('should not call onChange after first item is pressed', async () => { | ||
// const renderTree = render(<TestCase/>); | ||
// const index = 0; | ||
// const driver = WheelPickerItemDriver({renderTree, testID: `${index}`}); | ||
|
||
// driver.press(); | ||
|
||
// expect(onChange).not.toHaveBeenCalledTimes(1); | ||
// }); | ||
}); | ||
}); |
This file contains hidden or 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
21 changes: 21 additions & 0 deletions
21
src/components/sectionsWheelPicker/SectionsWheelPicker.driver.tsx
This file contains hidden or 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,21 @@ | ||
import _ from 'lodash'; | ||
import {useComponentDriver, ComponentProps} from '../../testkit/new/Component.driver'; | ||
import {WheelPickerDriver} from '../WheelPicker/WheelPicker.driver'; | ||
import {SectionsWheelPickerProps} from './index'; | ||
|
||
export const SectionsWheelPickerDriver = (props: ComponentProps) => { | ||
const driver = useComponentDriver<SectionsWheelPickerProps>(props); | ||
const sections = driver.getProps().children as SectionsWheelPickerProps; | ||
const sectionsDrivers = _.map(sections, (_, index) => { | ||
const sectionTestID = `${props.testID}.${index}`; | ||
return WheelPickerDriver({ | ||
renderTree: props.renderTree, | ||
testID: sectionTestID | ||
}); | ||
}); | ||
|
||
|
||
|
||
|
||
return {...driver, sections, sectionsDrivers}; | ||
}; |
41 changes: 41 additions & 0 deletions
41
src/components/sectionsWheelPicker/__tests__/index.spec.tsx
This file contains hidden or 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,41 @@ | ||
import _ from 'lodash'; | ||
import React from 'react'; | ||
import SectionsWheelPicker from '../index'; | ||
import {render} from '@testing-library/react-native'; | ||
import {SectionsWheelPickerDriver} from '../SectionsWheelPicker.driver'; | ||
import {sections, labels} from '../mockSections'; | ||
|
||
const testID = 'sectionsWheel'; | ||
const onChange = jest.fn(); | ||
|
||
const TestCase = props => { | ||
return ( | ||
<SectionsWheelPicker | ||
testID={testID} | ||
numberOfVisibleRows={4} | ||
sections={sections} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
describe('SectionsWheelPicker', () => { | ||
beforeEach(() => { | ||
onChange.mockClear(); | ||
}); | ||
|
||
it('should present 3 sections', () => { | ||
const renderTree = render(<TestCase/>); | ||
const driver = SectionsWheelPickerDriver({renderTree, testID}); | ||
expect(driver.sectionsDrivers.length).toBe(3); | ||
}); | ||
|
||
it('should have 3 labels', () => { | ||
const renderTree = render(<TestCase/>); | ||
const driver = SectionsWheelPickerDriver({renderTree, testID}); | ||
const sectionsDrivers = driver.sectionsDrivers; | ||
_.map(sectionsDrivers, (sectionDriver, index) => { | ||
expect(sectionDriver.getLabel()).toBe(labels[index]); | ||
}); | ||
}); | ||
}); |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.