-
Notifications
You must be signed in to change notification settings - Fork 735
Add ChipDriver and associated basic tests for Chip component #3717
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
56bf4cf
Add ChipDriver and associated basic tests for Chip component
adids1221 23a2e1a
Add ChipDriver export
adids1221 10066c4
Enhance ChipDriver to include getStyle method for dismiss and icon dr…
adids1221 03c7ebc
fixed sanity test
adids1221 369125c
Chip test check to ddefault icon, dismiss icon and label styles
adids1221 74acebc
removed the todo comments
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,57 @@ | ||
import React from 'react'; | ||
import {render} from '@testing-library/react-native'; | ||
import {ChipDriver} from '../chip.driver'; | ||
import Chip, {ChipProps} from '../index'; | ||
import Assets from '../../../assets'; | ||
import {Colors} from '../../../style'; | ||
|
||
const testID = 'test-chip'; | ||
|
||
const getDriver = (props?: ChipProps) => { | ||
const renderTree = render(<Chip testID={testID} {...props}/>); | ||
return ChipDriver({renderTree, testID}); | ||
}; | ||
|
||
describe('Chip', () => { | ||
describe('sanity', () => { | ||
it('should render Chip', () => { | ||
const driver = getDriver(); | ||
expect(driver.exists()).toBeTruthy(); | ||
expect(driver.getIcon().exists()).toBeFalsy(); | ||
expect(driver.getLabel().exists()).toBeFalsy(); | ||
expect(driver.getDismissIcon().exists()).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('Label', () => { | ||
it('should render label', () => { | ||
const driver = getDriver({label: 'test'}); | ||
expect(driver.getLabel().exists()).toBeTruthy(); | ||
expect(driver.getLabel().getText()).toEqual('test'); | ||
expect(driver.getLabel().getStyle().color).toEqual(Colors.$textDefault); | ||
}); | ||
}); | ||
|
||
describe('Dismiss Icon', () => { | ||
it('should render dismiss icon', () => { | ||
const driver = getDriver({onDismiss: () => {}}); | ||
expect(driver.getDismissIcon().exists()).toBeTruthy(); | ||
expect(driver.getDismissIcon().getStyle().tintColor).toEqual(Colors.$iconDefault); | ||
}); | ||
}); | ||
|
||
describe('Icon', () => { | ||
it('should render icon', () => { | ||
const driver = getDriver({iconSource: Assets.internal.icons.check}); | ||
expect(driver.getIcon().exists()).toBeTruthy(); | ||
expect(driver.getIcon().getStyle().tintColor).toEqual(Colors.$iconDefault); | ||
}); | ||
}); | ||
|
||
it('should render with label, icon and dismiss icon', () => { | ||
const driver = getDriver({label: 'test', iconSource: Assets.internal.icons.check, onDismiss: () => {}}); | ||
expect(driver.getLabel().exists()).toBeTruthy(); | ||
expect(driver.getIcon().exists()).toBeTruthy(); | ||
expect(driver.getDismissIcon().exists()).toBeTruthy(); | ||
}); | ||
}); |
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,54 @@ | ||
import {StyleSheet} from 'react-native'; | ||
import {useComponentDriver, ComponentProps} from '../../testkit/new/Component.driver'; | ||
import {TextDriver} from '../text/Text.driver.new'; | ||
import {ImageDriver} from '../image/Image.driver.new'; | ||
|
||
export const ChipDriver = (props: ComponentProps) => { | ||
const driver = useComponentDriver(props); | ||
|
||
const labelDriver = TextDriver({ | ||
renderTree: props.renderTree, | ||
testID: `${props.testID}.label` | ||
}); | ||
|
||
const dismissIconDriver = ImageDriver({ | ||
renderTree: props.renderTree, | ||
testID: `${props.testID}.dismissIcon` | ||
}); | ||
|
||
const iconDriver = ImageDriver({ | ||
renderTree: props.renderTree, | ||
testID: `${props.testID}.icon` | ||
}); | ||
|
||
const getLabel = () => { | ||
return {...labelDriver}; | ||
}; | ||
|
||
const getDismissIcon = () => { | ||
const exists = (): boolean => { | ||
return dismissIconDriver.exists(); | ||
}; | ||
const getStyle = () => { | ||
return StyleSheet.flatten(dismissIconDriver.getElement().props.style); | ||
}; | ||
return {...dismissIconDriver, exists, getStyle}; | ||
}; | ||
|
||
const getIcon = () => { | ||
const exists = (): boolean => { | ||
return iconDriver.exists(); | ||
}; | ||
const getStyle = () => { | ||
return StyleSheet.flatten(iconDriver.getElement().props.style); | ||
}; | ||
return {...iconDriver, exists, getStyle}; | ||
}; | ||
|
||
return { | ||
...driver, | ||
getLabel, | ||
getDismissIcon, | ||
getIcon | ||
}; | ||
}; |
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
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.