-
Notifications
You must be signed in to change notification settings - Fork 734
POC Export of testkits #1925
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
POC Export of testkits #1925
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
201e284
POC Export of testkits
017f980
Added semicolon
eec321e
Some more testing
af351bc
Testing builds again
30071e4
Babel build
7c7cd87
Added testkit
dc7117f
Added testkit to npmignore unignore
43763a2
Type fix wip
7eae64a
Removed .js file
b52ef46
Changed structure
d12d63b
Amit's Solution
feb1cbd
Fixed types & main
3284323
Added drivers to export
33a2cde
Added Basic testkit for `Swtich` component
efaf60d
Fixed AccessibilityState
79ab237
removed comment
c986d0b
Fixed packagejson testkit
7b2f295
Merge branch 'master' into poc/exported-testkit
ethanshar 7034da2
Move Switch spec into __tests__ folder
ethanshar e8d524a
Restructure and cleanup testkit components drivers
ethanshar 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 |
---|---|---|
|
@@ -247,4 +247,6 @@ index.ios.js | |
*.ts | ||
*.tsx | ||
# include the .d.ts files | ||
!*.d.ts | ||
!*.d.ts | ||
|
||
!testkit/*.ts |
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
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
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
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
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
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,113 @@ | ||
import React from 'react'; | ||
import {render} from '@testing-library/react-native'; | ||
import Switch, {SwitchProps} from '../index'; | ||
import {SwitchDriver} from '../switch.driver'; | ||
import View from '../../view'; | ||
|
||
describe('Switch', () => { | ||
|
||
const renderSwitch = (testID: string, props: Partial<SwitchProps>) => { | ||
const defaultProps: SwitchProps = { | ||
testID, | ||
value: false, | ||
onValueChange: jest.fn(), | ||
disabled: false | ||
}; | ||
const component = render(<View><Switch {...defaultProps} {...props}/></View>); | ||
const driver = SwitchDriver({ | ||
wrappedComponent: component, | ||
testID | ||
}); | ||
|
||
return {driver}; | ||
}; | ||
|
||
|
||
it('Should fire onChange event', () => { | ||
const testId = 'switch-comp'; | ||
const onChange = jest.fn(); | ||
const {driver} = renderSwitch(testId, {onValueChange: onChange}); | ||
driver.press(); | ||
expect(onChange).toHaveBeenCalled(); | ||
}); | ||
|
||
it('Should fire onChange event with false value when toggling off', () => { | ||
const testId = 'switch-comp'; | ||
const onChange = jest.fn(); | ||
const {driver} = renderSwitch(testId, {onValueChange: onChange, value: true}); | ||
driver.press(); | ||
expect(onChange).toHaveBeenCalledWith(false); | ||
}); | ||
it('Should fire onChange event with true value when toggling on', () => { | ||
const testId = 'switch-comp'; | ||
const onChange = jest.fn(); | ||
const {driver} = renderSwitch(testId, {onValueChange: onChange, value: false}); | ||
driver.press(); | ||
expect(onChange).toHaveBeenCalledWith(true); | ||
}); | ||
|
||
it('Should not fire onChange when disabled', () => { | ||
const testId = 'switch-comp'; | ||
const onValueChange = jest.fn(); | ||
const {driver} = renderSwitch(testId, {disabled: true, onValueChange}); | ||
|
||
driver.press(); | ||
expect(onValueChange).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('Accessibility value should be true when checked', () => { | ||
const testId = 'switch-comp'; | ||
const {driver} = renderSwitch(testId, {value: true}); | ||
|
||
expect(driver.getAccessibilityValue()).toBe(true); | ||
}); | ||
|
||
it('Accessibility value should be false when not checked', () => { | ||
const testId = 'switch-comp'; | ||
const {driver} = renderSwitch(testId, {value: false}); | ||
|
||
expect(driver.isChecked()).toBe(false); | ||
}); | ||
|
||
it('Accessibility value should be checked when checked', () => { | ||
const testId = 'switch-comp'; | ||
const {driver} = renderSwitch(testId, {value: true}); | ||
|
||
expect(driver.isChecked()).toBe(true); | ||
}); | ||
|
||
it('Accessibility value should be false when not checked', () => { | ||
const testId = 'switch-comp'; | ||
const {driver} = renderSwitch(testId, {value: false}); | ||
|
||
expect(driver.getAccessibilityValue()).toBe(false); | ||
}); | ||
|
||
it('Should be disabled', () => { | ||
const testId = 'switch-comp'; | ||
const {driver} = renderSwitch(testId, {disabled: true}); | ||
|
||
expect(driver.isDisabled()).toBe(true); | ||
}); | ||
|
||
it('Should be disabled', () => { | ||
const testId = 'switch-comp'; | ||
const {driver} = renderSwitch(testId, {disabled: false}); | ||
|
||
expect(driver.isDisabled()).toBe(false); | ||
}); | ||
|
||
it('Should pass correct color when on', () => { | ||
const testId = 'switch-comp'; | ||
const {driver} = renderSwitch(testId, {value: true, onColor: 'red'}); | ||
|
||
expect(driver.getColor()).toBe('red'); | ||
}); | ||
|
||
it('Should pass correct color when off', () => { | ||
const testId = 'switch-comp'; | ||
const {driver} = renderSwitch(testId, {value: false, offColor: 'red'}); | ||
|
||
expect(driver.getColor()).toBe('red'); | ||
}); | ||
}); |
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
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,15 @@ | ||
import {RenderAPI, fireEvent} from '@testing-library/react-native'; | ||
|
||
export const SwitchDriver = ({wrappedComponent, testID}: {wrappedComponent: RenderAPI; testID: string}) => { | ||
const switchComp = wrappedComponent.getByTestId(testID); | ||
|
||
return { | ||
exists: () => !!switchComp, | ||
getRootElement: () => switchComp, | ||
press: () => fireEvent(switchComp, 'press'), | ||
getAccessibilityValue: () => switchComp.props.accessibilityValue.text === '1', | ||
isDisabled: () => switchComp.props.accessibilityState.disabled === true, | ||
isChecked: () => switchComp.props.accessibilityState.checked === 'checked', | ||
getColor: () => switchComp.props.style.backgroundColor | ||
}; | ||
}; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed accessibilityState to follow Accessibility docs of react-native
https://reactnative.dev/docs/accessibility#accessibilitystate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double checked with building & running the app locally, I see no errors regarding this change so I guess it's ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I tried testing with Accessibility Inspector locally but it doesn't show the state value so I'll verify again on real device after we merge