forked from callstack/react-native-paper
-
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.
refactor: add unit test and adjust icon example screen (callstack#4135)
- Loading branch information
1 parent
8c933fd
commit 41ee87b
Showing
5 changed files
with
85 additions
and
10 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
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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react'; | ||
import { Image } from 'react-native'; | ||
|
||
import { render } from '@testing-library/react-native'; | ||
|
||
import Icon from '../Icon'; | ||
|
||
const ICON_SIZE = 24; | ||
|
||
describe('Icon Component', () => { | ||
it('renders correctly with image source', () => { | ||
const source = { uri: 'https://picsum.photos/700' }; | ||
const { getByTestId } = render( | ||
<Icon source={source} size={ICON_SIZE} testID="image-icon" /> | ||
); | ||
const imageIcon = getByTestId('image-icon'); | ||
|
||
expect(imageIcon).toBeOnTheScreen(); | ||
expect(imageIcon).toHaveStyle({ width: ICON_SIZE, height: ICON_SIZE }); | ||
}); | ||
|
||
it('renders correctly with string source', () => { | ||
const source = 'camera'; | ||
const { getByTestId } = render( | ||
<Icon source={source} size={ICON_SIZE} testID="camera-icon" /> | ||
); | ||
const icon = getByTestId('camera-icon'); | ||
|
||
expect(icon).toBeOnTheScreen(); | ||
expect(icon).toHaveStyle({ fontSize: ICON_SIZE, lineHeight: ICON_SIZE }); | ||
}); | ||
|
||
it('renders correctly with function source', () => { | ||
const source = ({ size, testID }: { size: number; testID: string }) => ( | ||
<Image | ||
accessibilityIgnoresInvertColors | ||
source={{ uri: 'https://picsum.photos/700' }} | ||
style={{ width: size, height: size }} | ||
testID={testID} | ||
/> | ||
); | ||
const { getByTestId } = render( | ||
<Icon source={source} size={ICON_SIZE} testID="function-icon" /> | ||
); | ||
|
||
const functionIcon = getByTestId('function-icon'); | ||
|
||
expect(functionIcon).toHaveStyle({ width: ICON_SIZE, height: ICON_SIZE }); | ||
expect(functionIcon).toBeOnTheScreen(); | ||
}); | ||
}); |
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