-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into input-jl-money
- Loading branch information
Showing
10 changed files
with
272 additions
and
101 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
33 changes: 33 additions & 0 deletions
33
src/components/atoms/ConditionalWrapper/ConditionalWrapper.test.tsx
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,33 @@ | ||
import * as React from 'react'; | ||
import { render, RenderResult } from '@testing-library/react'; | ||
import { ConditionalWrapper } from './ConditionalWrapper'; | ||
|
||
describe('ConditionalWrapper', () => { | ||
const wrapperFunction = (children: React.ReactNode): JSX.Element => <div className="wrapper">{children}</div>; | ||
|
||
it('renders without crashing', () => { | ||
render( | ||
<ConditionalWrapper condition={false} wrapper={wrapperFunction}> | ||
Test | ||
</ConditionalWrapper>, | ||
); | ||
}); | ||
|
||
it('does not wrap children when condition is false', () => { | ||
const { container }: RenderResult = render( | ||
<ConditionalWrapper condition={false} wrapper={wrapperFunction}> | ||
Test | ||
</ConditionalWrapper>, | ||
); | ||
expect(container.querySelector('.wrapper')).toBeNull(); | ||
}); | ||
|
||
it('wraps children when condition is true', () => { | ||
const { container }: RenderResult = render( | ||
<ConditionalWrapper condition={true} wrapper={wrapperFunction}> | ||
Test | ||
</ConditionalWrapper>, | ||
); | ||
expect(container.querySelector('.wrapper')).not.toBeNull(); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
src/components/atoms/ConditionalWrapper/ConditionalWrapper.tsx
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'; | ||
|
||
export interface ConditionalWrapperProps { | ||
condition: boolean; | ||
wrapper: (children: React.ReactNode) => JSX.Element; | ||
} | ||
|
||
export const ConditionalWrapper = ({ | ||
condition, | ||
wrapper, | ||
children, | ||
}: React.PropsWithChildren<ConditionalWrapperProps>) => (condition ? wrapper(children) : <>{children}</>); |
Oops, something went wrong.