-
Notifications
You must be signed in to change notification settings - Fork 340
feat(router): optional router in NavRouter and withNavRouter #4161
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
80cc0c7
feat(router): optional router in NavRouter and withNavRouter
rafalmaksymiuk 3fd107d
feat: Small updates after review
rafalmaksymiuk ac9f196
feat(router): Making sure that features are passed down
rafalmaksymiuk 217b7be
Merge branch 'master' into FROFRA-36
rafalmaksymiuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
56 changes: 36 additions & 20 deletions
56
src/elements/common/nav-router/__tests__/withNavRouter.test.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -1,41 +1,57 @@ | ||
| import * as React from 'react'; | ||
| import { shallow } from 'enzyme'; | ||
| import { createMemoryHistory } from 'history'; | ||
| import NavRouter from '../NavRouter'; | ||
| import { render } from '@testing-library/react'; | ||
| import withNavRouter from '../withNavRouter'; | ||
| import { WithNavRouterProps } from '../types'; | ||
|
|
||
| jest.mock('../NavRouter', () => ({ children }: { children: React.ReactNode }) => ( | ||
| <div data-testid="nav-router-wrapper">{children}</div> | ||
| )); | ||
|
|
||
| type Props = { | ||
| value?: string; | ||
| }; | ||
|
|
||
| describe('src/eleemnts/common/nav-router/withNavRouter', () => { | ||
| const TestComponent = ({ value }: Props) => <div>{`Test ${value}`}</div>; | ||
| const TestComponent = ({ value }: Props) => <div data-testid="test-component">{`Test ${value}`}</div>; | ||
| const WrappedComponent = withNavRouter(TestComponent); | ||
|
|
||
| const getWrapper = (props?: Props & WithNavRouterProps) => shallow(<WrappedComponent {...props} />); | ||
| const renderComponent = (props?: Props & WithNavRouterProps) => | ||
| render(<WrappedComponent {...props} />); | ||
|
|
||
| test('should wrap component with NavRouter', () => { | ||
| const wrapper = getWrapper(); | ||
| const { getByTestId } = renderComponent(); | ||
|
|
||
| expect(getByTestId('test-component')).toBeInTheDocument(); | ||
| expect(getByTestId('test-component')).toHaveTextContent('Test undefined'); | ||
| expect(getByTestId('nav-router-wrapper')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('should pass props to wrapped component', () => { | ||
| const { getByTestId } = renderComponent({ value: 'test-value' }); | ||
|
|
||
| expect(wrapper.find(NavRouter)).toBeTruthy(); | ||
| expect(wrapper.find(TestComponent)).toBeTruthy(); | ||
| expect(getByTestId('test-component')).toBeInTheDocument(); | ||
| expect(getByTestId('test-component')).toHaveTextContent('Test test-value'); | ||
| }); | ||
|
|
||
| test('should provide the appropriate props to NavRouter and the wrapped component', () => { | ||
| const history = createMemoryHistory(); | ||
| const initialEntries = ['foo']; | ||
| const value = 'foo'; | ||
| const wrapper = getWrapper({ | ||
| history, | ||
| initialEntries, | ||
| value, | ||
| describe('when routerDisabled feature flag is enabled', () => { | ||
| test('should return unwrapped component when feature flag is true', () => { | ||
| const features = { routerDisabled: { value: true } }; | ||
| const { getByTestId, queryByTestId } = renderComponent({ features }); | ||
|
|
||
| expect(getByTestId('test-component')).toBeInTheDocument(); | ||
| expect(getByTestId('test-component')).toHaveTextContent('Test undefined'); | ||
| expect(queryByTestId('nav-router-wrapper')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('should pass features prop to NavRouter when router is enabled', () => { | ||
| const features = { routerDisabled: { value: false } }; | ||
| const { getByTestId } = renderComponent({ features }); | ||
|
|
||
| expect(getByTestId('test-component')).toBeInTheDocument(); | ||
| expect(getByTestId('test-component')).toHaveTextContent('Test undefined'); | ||
| expect(getByTestId('nav-router-wrapper')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| const navRouter = wrapper.find(NavRouter); | ||
| expect(navRouter.prop('history')).toEqual(history); | ||
| expect(navRouter.prop('initialEntries')).toEqual(initialEntries); | ||
|
|
||
| expect(wrapper.find(TestComponent).prop('value')).toEqual(value); | ||
| }); | ||
| }); | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| import { History } from 'history'; | ||
| import { FeatureConfig } from '../feature-checking'; | ||
|
|
||
| export type WithNavRouterProps = { | ||
| features?: FeatureConfig; | ||
| history?: History; | ||
| initialEntries?: History.LocationDescriptor[]; | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.