-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add disabled as prop to support visibilty modes of tooltip (#300)
* add disabled as prop to support visibilty modes of tooltip * added unit tests for tip component * typo fix
- Loading branch information
Showing
5 changed files
with
153 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import React from 'react'; | ||
import '@testing-library/jest-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import { ThemeProvider } from 'styled-components'; | ||
import { themes } from '../../themes'; | ||
import { Tip } from './Tip'; | ||
import { Button } from '../Button/Button'; | ||
|
||
describe('Tip', () => { | ||
it('triggers by hovering the wrapped button', () => { | ||
render( | ||
<ThemeProvider theme={themes['light']}> | ||
<Tip content="tip" data-testid="tip" active={false}> | ||
<Button>Button</Button> | ||
</Tip> | ||
</ThemeProvider> | ||
); | ||
|
||
const button = screen.getByText(/button/i); | ||
userEvent.hover(button).then(() => { | ||
const tip = screen.getByTestId('tip'); | ||
expect(tip).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('triggers by clicking the wrapped button', () => { | ||
render( | ||
<ThemeProvider theme={themes['light']}> | ||
<Tip content="tip" data-testid="tip" trigger="click"> | ||
<Button>Button</Button> | ||
</Tip> | ||
</ThemeProvider> | ||
); | ||
|
||
const button = screen.getByText(/Button/i); | ||
|
||
expect(button).toBeInTheDocument(); | ||
|
||
userEvent.click(button).then(() => { | ||
const tip = screen.getByTestId('tip'); | ||
expect(tip).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('has a text content', () => { | ||
render( | ||
<ThemeProvider theme={themes['light']}> | ||
<Tip content="this is a text" data-testid="tip" active> | ||
<Button>Button</Button> | ||
</Tip> | ||
</ThemeProvider> | ||
); | ||
|
||
const tip = screen.getByText('this is a text'); | ||
expect(tip).toHaveTextContent('this is a text'); | ||
}); | ||
|
||
it('is not visible on hovering the wrapped button when disabled', () => { | ||
render( | ||
<ThemeProvider theme={themes['light']}> | ||
<Tip content="tip" data-testid="tip" disabled> | ||
<Button>Button</Button> | ||
</Tip> | ||
</ThemeProvider> | ||
); | ||
const button = screen.getByText(/Button/i); | ||
userEvent.hover(button).then(() => { | ||
const tip = screen.getByTestId('tip'); | ||
expect(tip).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('can recieve children component as prop and render them', () => { | ||
render( | ||
<ThemeProvider theme={themes['light']}> | ||
<Tip | ||
content="tip" | ||
data-testid="tip" | ||
children={<Button>Button</Button>} | ||
/> | ||
</ThemeProvider> | ||
); | ||
|
||
const button = screen.getByText(/Button/i); | ||
expect(button).toBeInTheDocument(); | ||
|
||
userEvent.hover(button).then(() => { | ||
const tip = screen.getByTestId('tip'); | ||
expect(tip).toBeInTheDocument(); | ||
}); | ||
}); |
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