Skip to content

Commit

Permalink
test: add tests for Tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
brunohkbx committed May 25, 2019
1 parent ce61ac0 commit 0b69d2a
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
11 changes: 11 additions & 0 deletions __ts-tests__/Tooltip.test.tsx
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;
38 changes: 38 additions & 0 deletions src/components/__tests__/Tooltip.test.js
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 src/components/__tests__/__snapshots__/Tooltip.test.js.snap
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>
`;
12 changes: 12 additions & 0 deletions typings/components/Tooltip.d.ts
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> {}
1 change: 1 addition & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ export * from './components/TextInput';
export * from './components/ToggleButton';
export * from './components/TouchableRipple';
export * from './components/Typography';
export * from './components/Tooltip';

export { Avatar, Colors, List, Drawer };

0 comments on commit 0b69d2a

Please sign in to comment.