-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
<TooltipIconButton> Tests #179
Merged
pablo-mayrgundter
merged 8 commits into
bldrs-ai:main
from
oo-bldrs:tooltip-icon-button-tests
May 3, 2022
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
da5a8cc
Create manual mock for testing React components
oogali 10c6311
Convert component to ES6 arrow function
oogali 5ca67c4
Add tests for <TooltipIconButton>
oogali 52ef1e8
Refactor to remove redundant inline wrapper
oogali 7109ef1
Add internal attribute to support testing
oogali 873ca9b
Add missing blank lines after imports
oogali ea79655
Reorder file context so name of first object corresponds with filename
oogali 7eccbeb
Merge branch 'bldrs-ai:main' into tooltip-icon-button-tests
oogali File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react' | ||
import {fireEvent, render} from '@testing-library/react' | ||
import {TooltipIconButton} from './Buttons' | ||
import QuestionIcon from '../assets/2D_Icons/Question.svg' | ||
import {MockComponent} from '../__mocks__/MockComponent' | ||
|
||
|
||
describe('<TooltipIconButton />', () => { | ||
pablo-mayrgundter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
test('should throw error if missing required props', () => { | ||
expect(() => render(<MockComponent> | ||
<TooltipIconButton/> | ||
</MockComponent>)).toThrow('Arg 0 is not defined') | ||
}) | ||
|
||
test('should render successfully', async () => { | ||
const rendered = render(<MockComponent> | ||
<TooltipIconButton | ||
data-testid={'test-button'} | ||
title={'Hello. Is it me you\'re looking for?'} | ||
onClick={() => {}} | ||
icon={<QuestionIcon/>} | ||
/> | ||
</MockComponent>) | ||
|
||
const button = rendered.getByTestId('test-button') | ||
fireEvent.mouseOver(button) | ||
|
||
const tooltip = await rendered.findByRole('tooltip') | ||
expect(tooltip).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import useTheme from '../Theme' | ||
import {ThemeProvider} from '@mui/material/styles' | ||
import React, {createContext} from 'react' | ||
|
||
|
||
/** | ||
* @param {Object} children React component(s) | ||
* @return {Object} React component | ||
*/ | ||
export const MockComponent = ({children}) => { | ||
pablo-mayrgundter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const {theme, colorMode} = useTheme() | ||
|
||
return ( | ||
<ColorModeContext.Provider value={colorMode}> | ||
<ThemeProvider theme={theme}> | ||
{children} | ||
</ThemeProvider> | ||
</ColorModeContext.Provider> | ||
) | ||
} | ||
|
||
const ColorModeContext = createContext({ | ||
toggleColorMode: () => {}, | ||
}) |
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.
So we were using more modern syntax but there was something about function that worked better. I forget what. Is there a reason to prefer const here besides shorter?
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 suggest reverting this to function as it's more consistent with the rest of our code. I think the rule we're using is "top-level exported functions should use function keyword". I'll add that to styleguide.
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.
https://github.com/bldrs-ai/Share/wiki/Style-Guide