-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(productViewMissing): ent-3913 apply platform appNavClick
* testing, mock appNavClick * productViewMissing, useRouter, setAppNav * platformActions, expose setAppNav * platformServices, expose appNavClick, replace navigation * useRouter, pass useHistory, proxy useHistory push, setAppNav
- Loading branch information
Showing
17 changed files
with
252 additions
and
79 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
16 changes: 15 additions & 1 deletion
16
src/components/productView/__tests__/__snapshots__/productViewMissing.test.js.snap
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`useRouter should apply a hook for useHistory: push, config route 1`] = ` | ||
Array [ | ||
Array [ | ||
Object { | ||
"meta": Object { | ||
"appName": undefined, | ||
"id": "rhel", | ||
"secondaryNav": undefined, | ||
}, | ||
"payload": Promise {}, | ||
"type": "PLATFORM_SET_NAV", | ||
}, | ||
], | ||
] | ||
`; | ||
|
||
exports[`useRouter should apply a hook for useHistory: push, unique route 1`] = ` | ||
Array [ | ||
Array [ | ||
"/lorem/ipsum", | ||
undefined, | ||
], | ||
] | ||
`; | ||
|
||
exports[`useRouter should return specific properties: specific properties 1`] = ` | ||
Object { | ||
"useHistory": [Function], | ||
"useLocation": [Function], | ||
"useParams": [Function], | ||
"useRouteMatch": [Function], | ||
} | ||
`; |
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 { routerHooks } from '../useRouter'; | ||
|
||
describe('useRouter', () => { | ||
it('should return specific properties', () => { | ||
expect(routerHooks).toMatchSnapshot('specific properties'); | ||
}); | ||
|
||
it('should apply a hook for useHistory', () => { | ||
const mockDispatch = jest.fn(); | ||
const mockHistoryPush = jest.fn(); | ||
const mockUseHistory = mockHook(() => | ||
routerHooks.useHistory({ | ||
useDispatch: () => action => action(mockDispatch), | ||
useHistory: () => ({ push: mockHistoryPush }) | ||
}) | ||
); | ||
|
||
mockUseHistory.push('rhel'); | ||
expect(mockDispatch.mock.calls).toMatchSnapshot('push, config route'); | ||
|
||
mockUseHistory.push('/lorem/ipsum'); | ||
expect(mockHistoryPush.mock.calls).toMatchSnapshot('push, unique route'); | ||
}); | ||
}); |
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,49 @@ | ||
import { useHistory as useHistoryRRD, useLocation, useParams, useRouteMatch } from 'react-router-dom'; | ||
import { routerHelpers } from '../components/router/routerHelpers'; | ||
import { reduxActions, useDispatch } from '../redux'; | ||
import { helpers } from '../common/helpers'; | ||
|
||
/** | ||
* ToDo: reevaluate this alternative pattern of passing library hooks as options | ||
* We did this as a test to see if its more convenient for unit testing instead of | ||
* having to spy or mock entire resources. | ||
*/ | ||
/** | ||
* Pass useHistory methods. Proxy useHistory push with Platform specific navigation update. | ||
* | ||
* @param {object} hooks | ||
* @param {Function} hooks.useHistory | ||
* @param {Function} hooks.useDispatch | ||
* @returns {object<history>} | ||
*/ | ||
const useHistory = ({ | ||
useHistory: useAliasHistory = useHistoryRRD, | ||
useDispatch: useAliasDispatch = useDispatch | ||
} = {}) => { | ||
const history = useAliasHistory(); | ||
const dispatch = useAliasDispatch(); | ||
|
||
return { | ||
...history, | ||
push: (pathLocation, historyState) => { | ||
const pathName = (typeof pathLocation === 'string' && pathLocation) || pathLocation?.pathname; | ||
const { productParameter, id, routeHref } = routerHelpers.getRouteConfig({ pathName, id: pathName }); | ||
const { hash, search } = window.location; | ||
|
||
if (!helpers.DEV_MODE && productParameter) { | ||
return dispatch(reduxActions.platform.setAppNav(id)); | ||
} | ||
|
||
return history.push(routeHref || (pathName && `${pathName}${search}${hash}`) || pathLocation, historyState); | ||
} | ||
}; | ||
}; | ||
|
||
const routerHooks = { | ||
useHistory, | ||
useLocation, | ||
useParams, | ||
useRouteMatch | ||
}; | ||
|
||
export { routerHooks as default, routerHooks, useHistory, useLocation, useParams, useRouteMatch }; |
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
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
Oops, something went wrong.