-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as React from 'react'; | ||
import { Tooltip } from '..'; | ||
import { View } from 'react-native'; | ||
|
||
const MyComponent = () => ( | ||
<Tooltip title="Tooltip"> | ||
<View /> | ||
</Tooltip> | ||
); | ||
|
||
export default MyComponent; |
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,38 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from 'react-native-testing-library'; | ||
import { View } from 'react-native'; | ||
import Tooltip from '../Tooltip'; | ||
import Provider from '../../core/Provider'; | ||
|
||
jest.mock('react-native/Libraries/ReactNative/UIManager', () => ({ | ||
measure: () => {}, | ||
})); | ||
|
||
jest.useFakeTimers(); | ||
|
||
describe('Tooltip', () => { | ||
it('renders properly', () => { | ||
const tree = render( | ||
<Tooltip title="Tooltip View"> | ||
<View /> | ||
</Tooltip> | ||
); | ||
|
||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('shows a tooltip when child element is longPressed', () => { | ||
const { getByTestId, getByText } = render( | ||
<Provider> | ||
<Tooltip title="Tooltip View"> | ||
<View testID="TooltipChild" /> | ||
</Tooltip> | ||
</Provider> | ||
); | ||
|
||
fireEvent(getByTestId('TooltipChild'), 'touchStart'); | ||
jest.runAllTimers(); | ||
|
||
expect(getByText('Tooltip View')).toBeDefined(); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
src/components/__tests__/__snapshots__/Tooltip.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Tooltip renders properly 1`] = ` | ||
<View> | ||
<View | ||
onTouchCancel={[Function]} | ||
onTouchEndCapture={[Function]} | ||
onTouchStart={[Function]} | ||
> | ||
<View | ||
delayLongPress={500} | ||
onLongPress={[Function]} | ||
/> | ||
</View> | ||
</View> | ||
`; |
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,12 @@ | ||
import * as React from 'react'; | ||
import { StyleProp, ViewStyle } from 'react-native'; | ||
import { ThemeShape, IconSource } from '../types'; | ||
|
||
export interface TooltipProps { | ||
title: string; | ||
children: React.ReactNode; | ||
delayLongPress?: number; | ||
style?: StyleProp<ViewStyle>; | ||
} | ||
|
||
export declare class Tooltip extends React.Component<TooltipProps> {} |
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