@looker/api-explorer 0.9.35 → 0.9.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +56 -1
- package/dist/bundle.js +1 -1
- package/dist/bundle.js.map +1 -1
- package/e2e/MethodScene.spec.ts +80 -0
- package/e2e/diffScene.spec.ts +28 -20
- package/e2e/e2e.spec.ts +45 -7
- package/lib/ApiExplorer.js +24 -5
- package/lib/ApiExplorer.js.map +1 -1
- package/lib/components/DocMarkdown/DocMarkdown.js +9 -7
- package/lib/components/DocMarkdown/DocMarkdown.js.map +1 -1
- package/lib/components/DocSDKs/DocDeclarations.js +10 -15
- package/lib/components/DocSDKs/DocDeclarations.js.map +1 -1
- package/lib/components/SelectorContainer/ApiSpecSelector.js +6 -2
- package/lib/components/SelectorContainer/ApiSpecSelector.js.map +1 -1
- package/lib/components/SelectorContainer/SdkLanguageSelector.js +20 -21
- package/lib/components/SelectorContainer/SdkLanguageSelector.js.map +1 -1
- package/lib/components/SelectorContainer/SelectorContainer.js +4 -1
- package/lib/components/SelectorContainer/SelectorContainer.js.map +1 -1
- package/lib/components/SelectorContainer/utils.d.ts +2 -0
- package/lib/components/SelectorContainer/utils.js +32 -0
- package/lib/components/SelectorContainer/utils.js.map +1 -0
- package/lib/components/SideNav/SideNav.js +37 -16
- package/lib/components/SideNav/SideNav.js.map +1 -1
- package/lib/components/SideNav/SideNavMethods.js +9 -6
- package/lib/components/SideNav/SideNavMethods.js.map +1 -1
- package/lib/components/SideNav/SideNavTypes.js +7 -4
- package/lib/components/SideNav/SideNavTypes.js.map +1 -1
- package/lib/components/index.d.ts +0 -1
- package/lib/components/index.js +0 -8
- package/lib/components/index.js.map +1 -1
- package/lib/esm/ApiExplorer.js +26 -7
- package/lib/esm/ApiExplorer.js.map +1 -1
- package/lib/esm/components/DocMarkdown/DocMarkdown.js +6 -4
- package/lib/esm/components/DocMarkdown/DocMarkdown.js.map +1 -1
- package/lib/esm/components/DocSDKs/DocDeclarations.js +9 -14
- package/lib/esm/components/DocSDKs/DocDeclarations.js.map +1 -1
- package/lib/esm/components/SelectorContainer/ApiSpecSelector.js +6 -3
- package/lib/esm/components/SelectorContainer/ApiSpecSelector.js.map +1 -1
- package/lib/esm/components/SelectorContainer/SdkLanguageSelector.js +16 -18
- package/lib/esm/components/SelectorContainer/SdkLanguageSelector.js.map +1 -1
- package/lib/esm/components/SelectorContainer/SelectorContainer.js +5 -2
- package/lib/esm/components/SelectorContainer/SelectorContainer.js.map +1 -1
- package/lib/esm/components/SelectorContainer/utils.js +22 -0
- package/lib/esm/components/SelectorContainer/utils.js.map +1 -0
- package/lib/esm/components/SideNav/SideNav.js +40 -20
- package/lib/esm/components/SideNav/SideNav.js.map +1 -1
- package/lib/esm/components/SideNav/SideNavMethods.js +9 -6
- package/lib/esm/components/SideNav/SideNavMethods.js.map +1 -1
- package/lib/esm/components/SideNav/SideNavTypes.js +9 -6
- package/lib/esm/components/SideNav/SideNavTypes.js.map +1 -1
- package/lib/esm/components/index.js +0 -1
- package/lib/esm/components/index.js.map +1 -1
- package/lib/esm/routes/AppRouter.js +6 -4
- package/lib/esm/routes/AppRouter.js.map +1 -1
- package/lib/esm/scenes/DiffScene/DiffScene.js +11 -9
- package/lib/esm/scenes/DiffScene/DiffScene.js.map +1 -1
- package/lib/esm/scenes/DiffScene/DocDiff/DiffItem.js +5 -4
- package/lib/esm/scenes/DiffScene/DocDiff/DiffItem.js.map +1 -1
- package/lib/esm/scenes/DiffScene/DocDiff/DocDiff.js +4 -4
- package/lib/esm/scenes/DiffScene/DocDiff/DocDiff.js.map +1 -1
- package/lib/esm/scenes/ErrorDetailScene/ErrorDetailScene.js +31 -0
- package/lib/esm/scenes/ErrorDetailScene/ErrorDetailScene.js.map +1 -0
- package/lib/esm/scenes/ErrorDetailScene/index.js +2 -0
- package/lib/esm/scenes/ErrorDetailScene/index.js.map +1 -0
- package/lib/esm/scenes/MethodScene/MethodScene.js +30 -10
- package/lib/esm/scenes/MethodScene/MethodScene.js.map +1 -1
- package/lib/esm/{components → scenes/MethodScene/components}/DocResponses/DocResponseTypes.js +1 -1
- package/lib/esm/scenes/MethodScene/components/DocResponses/DocResponseTypes.js.map +1 -0
- package/lib/esm/scenes/MethodScene/components/DocResponses/DocResponses.js +73 -0
- package/lib/esm/scenes/MethodScene/components/DocResponses/DocResponses.js.map +1 -0
- package/lib/esm/{components → scenes/MethodScene/components}/DocResponses/index.js +0 -0
- package/lib/esm/scenes/MethodScene/components/DocResponses/index.js.map +1 -0
- package/lib/esm/{components → scenes/MethodScene/components}/DocResponses/utils.js +0 -0
- package/lib/esm/scenes/MethodScene/components/DocResponses/utils.js.map +1 -0
- package/lib/esm/scenes/MethodScene/components/index.js +1 -0
- package/lib/esm/scenes/MethodScene/components/index.js.map +1 -1
- package/lib/esm/scenes/MethodTagScene/MethodTagScene.js +38 -10
- package/lib/esm/scenes/MethodTagScene/MethodTagScene.js.map +1 -1
- package/lib/esm/scenes/TypeScene/TypeScene.js +7 -1
- package/lib/esm/scenes/TypeScene/TypeScene.js.map +1 -1
- package/lib/esm/scenes/TypeTagScene/TypeTagScene.js +39 -12
- package/lib/esm/scenes/TypeTagScene/TypeTagScene.js.map +1 -1
- package/lib/esm/scenes/index.js +1 -0
- package/lib/esm/scenes/index.js.map +1 -1
- package/lib/esm/scenes/utils/hooks/index.js +2 -0
- package/lib/esm/scenes/utils/hooks/index.js.map +1 -0
- package/lib/esm/scenes/utils/hooks/tagStoreSync.js +37 -0
- package/lib/esm/scenes/utils/hooks/tagStoreSync.js.map +1 -0
- package/lib/esm/scenes/utils/index.js +2 -0
- package/lib/esm/scenes/utils/index.js.map +1 -0
- package/lib/esm/state/settings/selectors.js +1 -0
- package/lib/esm/state/settings/selectors.js.map +1 -1
- package/lib/esm/state/settings/slice.js +6 -1
- package/lib/esm/state/settings/slice.js.map +1 -1
- package/lib/esm/utils/hooks/globalStoreSync.js +53 -0
- package/lib/esm/utils/hooks/globalStoreSync.js.map +1 -0
- package/lib/esm/utils/hooks/index.js +4 -0
- package/lib/esm/utils/hooks/index.js.map +1 -0
- package/lib/esm/utils/hooks/navigation.js +72 -0
- package/lib/esm/utils/hooks/navigation.js.map +1 -0
- package/lib/esm/utils/hooks/useQuery.js +9 -0
- package/lib/esm/utils/hooks/useQuery.js.map +1 -0
- package/lib/esm/utils/index.js +2 -0
- package/lib/esm/utils/index.js.map +1 -1
- package/lib/esm/utils/path.js +23 -2
- package/lib/esm/utils/path.js.map +1 -1
- package/lib/esm/utils/sdkLanguage.js +42 -0
- package/lib/esm/utils/sdkLanguage.js.map +1 -0
- package/lib/routes/AppRouter.d.ts +1 -2
- package/lib/routes/AppRouter.js +5 -3
- package/lib/routes/AppRouter.js.map +1 -1
- package/lib/scenes/DiffScene/DiffScene.d.ts +0 -2
- package/lib/scenes/DiffScene/DiffScene.js +8 -6
- package/lib/scenes/DiffScene/DiffScene.js.map +1 -1
- package/lib/scenes/DiffScene/DocDiff/DiffItem.js +4 -4
- package/lib/scenes/DiffScene/DocDiff/DiffItem.js.map +1 -1
- package/lib/scenes/DiffScene/DocDiff/DocDiff.js +4 -4
- package/lib/scenes/DiffScene/DocDiff/DocDiff.js.map +1 -1
- package/lib/scenes/ErrorDetailScene/ErrorDetailScene.d.ts +7 -0
- package/lib/scenes/ErrorDetailScene/ErrorDetailScene.js +47 -0
- package/lib/scenes/ErrorDetailScene/ErrorDetailScene.js.map +1 -0
- package/lib/scenes/ErrorDetailScene/index.d.ts +1 -0
- package/lib/scenes/ErrorDetailScene/index.js +14 -0
- package/lib/{components/DocResponses → scenes/ErrorDetailScene}/index.js.map +1 -1
- package/lib/scenes/MethodScene/MethodScene.js +25 -5
- package/lib/scenes/MethodScene/MethodScene.js.map +1 -1
- package/lib/{components → scenes/MethodScene/components}/DocResponses/DocResponseTypes.d.ts +2 -2
- package/lib/{components → scenes/MethodScene/components}/DocResponses/DocResponseTypes.js +2 -2
- package/lib/scenes/MethodScene/components/DocResponses/DocResponseTypes.js.map +1 -0
- package/lib/scenes/MethodScene/components/DocResponses/DocResponses.d.ts +9 -0
- package/lib/scenes/MethodScene/components/DocResponses/DocResponses.js +93 -0
- package/lib/scenes/MethodScene/components/DocResponses/DocResponses.js.map +1 -0
- package/lib/{components → scenes/MethodScene/components}/DocResponses/index.d.ts +0 -0
- package/lib/{components → scenes/MethodScene/components}/DocResponses/index.js +0 -0
- package/lib/scenes/MethodScene/components/DocResponses/index.js.map +1 -0
- package/lib/{components → scenes/MethodScene/components}/DocResponses/utils.d.ts +0 -0
- package/lib/{components → scenes/MethodScene/components}/DocResponses/utils.js +0 -0
- package/lib/scenes/MethodScene/components/DocResponses/utils.js.map +1 -0
- package/lib/scenes/MethodScene/components/index.d.ts +1 -0
- package/lib/scenes/MethodScene/components/index.js +8 -0
- package/lib/scenes/MethodScene/components/index.js.map +1 -1
- package/lib/scenes/MethodTagScene/MethodTagScene.js +42 -11
- package/lib/scenes/MethodTagScene/MethodTagScene.js.map +1 -1
- package/lib/scenes/TypeScene/TypeScene.js +8 -1
- package/lib/scenes/TypeScene/TypeScene.js.map +1 -1
- package/lib/scenes/TypeTagScene/TypeTagScene.js +42 -12
- package/lib/scenes/TypeTagScene/TypeTagScene.js.map +1 -1
- package/lib/scenes/index.d.ts +1 -0
- package/lib/scenes/index.js +8 -0
- package/lib/scenes/index.js.map +1 -1
- package/lib/scenes/utils/hooks/index.d.ts +1 -0
- package/lib/scenes/utils/hooks/index.js +14 -0
- package/lib/scenes/utils/hooks/index.js.map +1 -0
- package/lib/scenes/utils/hooks/tagStoreSync.d.ts +1 -0
- package/lib/scenes/utils/hooks/tagStoreSync.js +51 -0
- package/lib/scenes/utils/hooks/tagStoreSync.js.map +1 -0
- package/lib/scenes/utils/index.d.ts +1 -0
- package/lib/scenes/utils/index.js +14 -0
- package/lib/scenes/utils/index.js.map +1 -0
- package/lib/state/settings/selectors.d.ts +2 -1
- package/lib/state/settings/selectors.js +5 -1
- package/lib/state/settings/selectors.js.map +1 -1
- package/lib/state/settings/slice.d.ts +7 -1
- package/lib/state/settings/slice.js +6 -1
- package/lib/state/settings/slice.js.map +1 -1
- package/lib/test-data/index.d.ts +1 -0
- package/lib/test-data/index.js +14 -0
- package/lib/test-data/index.js.map +1 -1
- package/lib/test-data/sdkLanguages.d.ts +10 -0
- package/lib/test-data/sdkLanguages.js +19 -0
- package/lib/test-data/sdkLanguages.js.map +1 -0
- package/lib/utils/hooks/globalStoreSync.d.ts +1 -0
- package/lib/utils/hooks/globalStoreSync.js +67 -0
- package/lib/utils/hooks/globalStoreSync.js.map +1 -0
- package/lib/utils/hooks/index.d.ts +3 -0
- package/lib/utils/hooks/index.js +30 -0
- package/lib/utils/hooks/index.js.map +1 -0
- package/lib/utils/hooks/navigation.d.ts +11 -0
- package/lib/utils/hooks/navigation.js +83 -0
- package/lib/utils/hooks/navigation.js.map +1 -0
- package/lib/utils/hooks/useQuery.d.ts +1 -0
- package/lib/utils/hooks/useQuery.js +20 -0
- package/lib/utils/hooks/useQuery.js.map +1 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +38 -1
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/path.d.ts +6 -2
- package/lib/utils/path.js +34 -3
- package/lib/utils/path.js.map +1 -1
- package/lib/utils/sdkLanguage.d.ts +6 -0
- package/lib/utils/sdkLanguage.js +59 -0
- package/lib/utils/sdkLanguage.js.map +1 -0
- package/package.json +14 -14
- package/src/ApiExplorer.tsx +18 -7
- package/src/components/DocMarkdown/DocMarkdown.tsx +4 -4
- package/src/components/DocSDKs/DocDeclarations.tsx +11 -22
- package/src/components/DocSDKs/DocSDKs.spec.tsx +4 -1
- package/src/components/Header/Header.spec.tsx +1 -1
- package/src/components/SelectorContainer/ApiSpecSelector.spec.tsx +5 -2
- package/src/components/SelectorContainer/ApiSpecSelector.tsx +4 -3
- package/src/components/SelectorContainer/SdkLanguageSelector.spec.tsx +60 -33
- package/src/components/SelectorContainer/SdkLanguageSelector.tsx +15 -22
- package/src/components/SelectorContainer/SelectorContainer.spec.tsx +1 -1
- package/src/components/SelectorContainer/SelectorContainer.tsx +18 -15
- package/src/components/SelectorContainer/utils.ts +45 -0
- package/src/components/SideNav/SideNav.spec.tsx +39 -5
- package/src/components/SideNav/SideNav.tsx +42 -29
- package/src/components/SideNav/SideNavMethods.spec.tsx +5 -0
- package/src/components/SideNav/SideNavMethods.tsx +11 -8
- package/src/components/SideNav/SideNavTypes.spec.tsx +9 -2
- package/src/components/SideNav/SideNavTypes.tsx +10 -8
- package/src/components/index.ts +0 -1
- package/src/routes/AppRouter.tsx +7 -5
- package/src/scenes/DiffScene/DiffScene.tsx +10 -10
- package/src/scenes/DiffScene/DocDiff/DiffItem.spec.tsx +4 -3
- package/src/scenes/DiffScene/DocDiff/DiffItem.tsx +3 -4
- package/src/scenes/DiffScene/DocDiff/DocDiff.spec.tsx +73 -2
- package/src/scenes/DiffScene/DocDiff/DocDiff.tsx +4 -4
- package/src/scenes/ErrorDetailScene/ErrorDetailScene.tsx +72 -0
- package/src/scenes/ErrorDetailScene/index.ts +26 -0
- package/src/scenes/MethodScene/MethodScene.tsx +23 -8
- package/src/{components → scenes/MethodScene/components}/DocResponses/DocResponseTypes.tsx +3 -6
- package/src/scenes/MethodScene/components/DocResponses/DocResponses.spec.tsx +153 -0
- package/src/scenes/MethodScene/components/DocResponses/DocResponses.tsx +103 -0
- package/src/{components → scenes/MethodScene/components}/DocResponses/index.ts +0 -0
- package/src/{components → scenes/MethodScene/components}/DocResponses/utils.spec.ts +1 -1
- package/src/{components → scenes/MethodScene/components}/DocResponses/utils.ts +0 -0
- package/src/scenes/MethodScene/components/index.ts +1 -0
- package/src/scenes/MethodTagScene/MethodTagScene.spec.tsx +25 -14
- package/src/scenes/MethodTagScene/MethodTagScene.tsx +42 -10
- package/src/scenes/TypeScene/TypeScene.tsx +8 -2
- package/src/scenes/TypeTagScene/TypeTagScene.spec.tsx +21 -11
- package/src/scenes/TypeTagScene/TypeTagScene.tsx +46 -13
- package/src/scenes/index.ts +1 -0
- package/src/scenes/utils/hooks/index.ts +27 -0
- package/src/scenes/utils/hooks/tagStoreSync.spec.ts +102 -0
- package/src/scenes/utils/hooks/tagStoreSync.ts +68 -0
- package/src/scenes/utils/index.ts +27 -0
- package/src/state/settings/selectors.spec.ts +5 -1
- package/src/state/settings/selectors.ts +3 -0
- package/src/state/settings/slice.ts +6 -0
- package/src/test-data/index.ts +1 -0
- package/src/test-data/sdkLanguages.ts +36 -0
- package/src/utils/hooks/globalStoreSync.spec.tsx +146 -0
- package/src/utils/hooks/globalStoreSync.ts +77 -0
- package/src/utils/hooks/index.ts +28 -0
- package/src/utils/hooks/navigation.spec.ts +118 -0
- package/src/utils/hooks/navigation.ts +121 -0
- package/src/utils/hooks/useQuery.ts +36 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/path.spec.ts +92 -3
- package/src/utils/path.ts +46 -4
- package/src/utils/sdkLanguage.spec.ts +69 -0
- package/src/utils/sdkLanguage.ts +63 -0
- package/lib/components/DocResponses/DocResponseTypes.js.map +0 -1
- package/lib/components/DocResponses/DocResponses.d.ts +0 -8
- package/lib/components/DocResponses/DocResponses.js +0 -46
- package/lib/components/DocResponses/DocResponses.js.map +0 -1
- package/lib/components/DocResponses/utils.js.map +0 -1
- package/lib/esm/components/DocResponses/DocResponseTypes.js.map +0 -1
- package/lib/esm/components/DocResponses/DocResponses.js +0 -30
- package/lib/esm/components/DocResponses/DocResponses.js.map +0 -1
- package/lib/esm/components/DocResponses/index.js.map +0 -1
- package/lib/esm/components/DocResponses/utils.js.map +0 -1
- package/src/components/DocResponses/DocResponses.spec.tsx +0 -60
- package/src/components/DocResponses/DocResponses.tsx +0 -69
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2022 Looker Data Sciences, Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
24
|
+
|
|
25
|
+
*/
|
|
26
|
+
import { useLocation } from 'react-router-dom'
|
|
27
|
+
import { useSelector } from 'react-redux'
|
|
28
|
+
import { useEffect } from 'react'
|
|
29
|
+
import {
|
|
30
|
+
selectTagFilter,
|
|
31
|
+
useSettingActions,
|
|
32
|
+
useSettingStoreState,
|
|
33
|
+
} from '../../../state'
|
|
34
|
+
import { isValidFilter, useNavigation } from '../../../utils'
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Hook for syncing tag scene URL params with the Redux store
|
|
38
|
+
*
|
|
39
|
+
* Tag scene specific search parameters: 't'
|
|
40
|
+
*/
|
|
41
|
+
export const useTagStoreSync = () => {
|
|
42
|
+
const location = useLocation()
|
|
43
|
+
const { navigate } = useNavigation()
|
|
44
|
+
const { setTagFilterAction } = useSettingActions()
|
|
45
|
+
const { initialized } = useSettingStoreState()
|
|
46
|
+
const selectedTagFilter = useSelector(selectTagFilter)
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (initialized) {
|
|
50
|
+
const params = new URLSearchParams(location.search)
|
|
51
|
+
|
|
52
|
+
// syncing verb filter on tag scene page
|
|
53
|
+
const verbParam = params.get('t') || 'ALL'
|
|
54
|
+
const validVerbParam = isValidFilter(location.pathname, verbParam)
|
|
55
|
+
if (validVerbParam) {
|
|
56
|
+
setTagFilterAction({ tagFilter: verbParam.toUpperCase() })
|
|
57
|
+
} else {
|
|
58
|
+
// must confirm store tag filter param is valid for tag type before updating
|
|
59
|
+
const verb = isValidFilter(location.pathname, selectedTagFilter)
|
|
60
|
+
? selectedTagFilter
|
|
61
|
+
: 'ALL'
|
|
62
|
+
navigate(location.pathname, {
|
|
63
|
+
t: verb === 'ALL' ? null : verb.toLowerCase(),
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}, [initialized])
|
|
68
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2021 Looker Data Sciences, Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
24
|
+
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
export { useTagStoreSync } from './hooks'
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
*/
|
|
26
26
|
import { createTestStore, preloadedState } from '../../test-utils'
|
|
27
|
-
import { selectSdkLanguage, isInitialized } from './selectors'
|
|
27
|
+
import { selectSdkLanguage, isInitialized, selectTagFilter } from './selectors'
|
|
28
28
|
|
|
29
29
|
const testStore = createTestStore()
|
|
30
30
|
|
|
@@ -37,6 +37,10 @@ describe('Settings selectors', () => {
|
|
|
37
37
|
)
|
|
38
38
|
})
|
|
39
39
|
|
|
40
|
+
test('selectTagFilter selects', () => {
|
|
41
|
+
expect(selectTagFilter(state)).toEqual(preloadedState.settings.tagFilter)
|
|
42
|
+
})
|
|
43
|
+
|
|
40
44
|
test('isInitialized selects', () => {
|
|
41
45
|
expect(isInitialized(state)).toEqual(preloadedState.settings.initialized)
|
|
42
46
|
})
|
|
@@ -36,5 +36,8 @@ export const selectSearchPattern = (state: RootState) =>
|
|
|
36
36
|
export const selectSearchCriteria = (state: RootState) =>
|
|
37
37
|
selectSettingsState(state).searchCriteria
|
|
38
38
|
|
|
39
|
+
export const selectTagFilter = (state: RootState) =>
|
|
40
|
+
selectSettingsState(state).tagFilter
|
|
41
|
+
|
|
39
42
|
export const isInitialized = (state: RootState) =>
|
|
40
43
|
selectSettingsState(state).initialized
|
|
@@ -38,6 +38,7 @@ export interface UserDefinedSettings {
|
|
|
38
38
|
export interface SettingState extends UserDefinedSettings {
|
|
39
39
|
searchPattern: string
|
|
40
40
|
searchCriteria: SearchCriterionTerm[]
|
|
41
|
+
tagFilter: string
|
|
41
42
|
initialized: boolean
|
|
42
43
|
error?: Error
|
|
43
44
|
}
|
|
@@ -46,6 +47,7 @@ export const defaultSettings = {
|
|
|
46
47
|
sdkLanguage: 'Python',
|
|
47
48
|
searchPattern: '',
|
|
48
49
|
searchCriteria: setToCriteria(SearchAll) as SearchCriterionTerm[],
|
|
50
|
+
tagFilter: 'ALL',
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
export const defaultSettingsState: SettingState = {
|
|
@@ -55,6 +57,7 @@ export const defaultSettingsState: SettingState = {
|
|
|
55
57
|
|
|
56
58
|
type SetSearchPatternAction = Pick<SettingState, 'searchPattern'>
|
|
57
59
|
type SetSdkLanguageAction = Pick<SettingState, 'sdkLanguage'>
|
|
60
|
+
type SetTagFilterAction = Pick<SettingState, 'tagFilter'>
|
|
58
61
|
|
|
59
62
|
export type InitSuccessPayload = UserDefinedSettings
|
|
60
63
|
|
|
@@ -84,6 +87,9 @@ export const settingsSlice = createSlice({
|
|
|
84
87
|
) {
|
|
85
88
|
state.searchPattern = action.payload.searchPattern
|
|
86
89
|
},
|
|
90
|
+
setTagFilterAction(state, action: PayloadAction<SetTagFilterAction>) {
|
|
91
|
+
state.tagFilter = action.payload.tagFilter
|
|
92
|
+
},
|
|
87
93
|
},
|
|
88
94
|
})
|
|
89
95
|
|
package/src/test-data/index.ts
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2022 Looker Data Sciences, Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
24
|
+
|
|
25
|
+
*/
|
|
26
|
+
export const sdkLanguageMapping = {
|
|
27
|
+
py: 'Python',
|
|
28
|
+
ts: 'TypeScript',
|
|
29
|
+
cs: 'C#',
|
|
30
|
+
kt: 'Kotlin',
|
|
31
|
+
swift: 'Swift',
|
|
32
|
+
go: 'Go',
|
|
33
|
+
all: 'All',
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const languages = Object.values(sdkLanguageMapping)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2022 Looker Data Sciences, Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
24
|
+
|
|
25
|
+
*/
|
|
26
|
+
import { renderHook } from '@testing-library/react-hooks'
|
|
27
|
+
import { useHistory } from 'react-router-dom'
|
|
28
|
+
import type { Location } from 'history'
|
|
29
|
+
import * as reactRedux from 'react-redux'
|
|
30
|
+
import * as routerLocation from 'react-router-dom'
|
|
31
|
+
import { createTestStore, withReduxProvider } from '../../test-utils'
|
|
32
|
+
import { useGlobalStoreSync } from './globalStoreSync'
|
|
33
|
+
|
|
34
|
+
jest.mock('react-router', () => {
|
|
35
|
+
const ReactRouterDOM = jest.requireActual('react-router-dom')
|
|
36
|
+
return {
|
|
37
|
+
...ReactRouterDOM,
|
|
38
|
+
useHistory: jest.fn().mockReturnValue({ push: jest.fn(), location }),
|
|
39
|
+
useLocation: jest.fn().mockReturnValue({ pathname: '/', search: '' }),
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
describe('useGlobalStoreSync', () => {
|
|
44
|
+
const mockDispatch = jest.fn()
|
|
45
|
+
|
|
46
|
+
afterEach(() => {
|
|
47
|
+
jest.clearAllMocks()
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('does nothing if uninitialized', () => {
|
|
51
|
+
const { push } = useHistory()
|
|
52
|
+
const wrapper = ({ children }: any) => withReduxProvider(children)
|
|
53
|
+
renderHook(() => useGlobalStoreSync(), { wrapper })
|
|
54
|
+
expect(push).not.toHaveBeenCalled()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
describe('search', () => {
|
|
58
|
+
test('updates store search pattern with url search pattern if present', () => {
|
|
59
|
+
const { push } = useHistory()
|
|
60
|
+
const store = createTestStore({
|
|
61
|
+
settings: {
|
|
62
|
+
initialized: true,
|
|
63
|
+
},
|
|
64
|
+
})
|
|
65
|
+
jest.spyOn(routerLocation, 'useLocation').mockReturnValue({
|
|
66
|
+
pathname: '/',
|
|
67
|
+
search: `s=patternFromUrl`,
|
|
68
|
+
} as unknown as Location)
|
|
69
|
+
jest.spyOn(reactRedux, 'useDispatch').mockReturnValue(mockDispatch)
|
|
70
|
+
const wrapper = ({ children }: any) => withReduxProvider(children, store)
|
|
71
|
+
renderHook(() => useGlobalStoreSync(), { wrapper })
|
|
72
|
+
expect(mockDispatch).toHaveBeenCalledWith({
|
|
73
|
+
payload: { searchPattern: 'patternFromUrl' },
|
|
74
|
+
type: 'settings/setSearchPatternAction',
|
|
75
|
+
})
|
|
76
|
+
expect(push).toHaveBeenCalledWith({ pathname: '/', search: 'sdk=py' })
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
describe('sdk', () => {
|
|
81
|
+
test('syncs url sdk param with sdk in store', () => {
|
|
82
|
+
const { push } = useHistory()
|
|
83
|
+
const store = createTestStore({
|
|
84
|
+
settings: {
|
|
85
|
+
initialized: true,
|
|
86
|
+
sdkLanguage: 'Kotlin',
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
const wrapper = ({ children }: any) => withReduxProvider(children, store)
|
|
90
|
+
renderHook(() => useGlobalStoreSync(), { wrapper })
|
|
91
|
+
expect(push).toHaveBeenCalledWith({
|
|
92
|
+
pathname: '/',
|
|
93
|
+
search: 'sdk=kt',
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
test.each([
|
|
98
|
+
['alias', 'kt'],
|
|
99
|
+
['language', 'kotlin'],
|
|
100
|
+
])(
|
|
101
|
+
'overrides store with sdk full name given valid url sdk %s',
|
|
102
|
+
(_, param) => {
|
|
103
|
+
const { push } = useHistory()
|
|
104
|
+
const store = createTestStore({
|
|
105
|
+
settings: {
|
|
106
|
+
initialized: true,
|
|
107
|
+
},
|
|
108
|
+
})
|
|
109
|
+
jest.spyOn(routerLocation, 'useLocation').mockReturnValue({
|
|
110
|
+
pathname: '/',
|
|
111
|
+
search: `sdk=${param}`,
|
|
112
|
+
} as unknown as Location)
|
|
113
|
+
jest.spyOn(reactRedux, 'useDispatch').mockReturnValue(mockDispatch)
|
|
114
|
+
const wrapper = ({ children }: any) =>
|
|
115
|
+
withReduxProvider(children, store)
|
|
116
|
+
renderHook(() => useGlobalStoreSync(), { wrapper })
|
|
117
|
+
expect(push).not.toHaveBeenCalled()
|
|
118
|
+
expect(mockDispatch).toHaveBeenLastCalledWith({
|
|
119
|
+
payload: { sdkLanguage: 'Kotlin' },
|
|
120
|
+
type: 'settings/setSdkLanguageAction',
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
test('updates url sdk param with store sdk for invalid url sdk param', () => {
|
|
126
|
+
const { push } = useHistory()
|
|
127
|
+
const store = createTestStore({
|
|
128
|
+
settings: {
|
|
129
|
+
initialized: true,
|
|
130
|
+
},
|
|
131
|
+
})
|
|
132
|
+
jest.spyOn(routerLocation, 'useLocation').mockReturnValue({
|
|
133
|
+
pathname: '/',
|
|
134
|
+
search: `sdk=invalid`,
|
|
135
|
+
} as unknown as Location)
|
|
136
|
+
jest.spyOn(reactRedux, 'useDispatch').mockReturnValue(mockDispatch)
|
|
137
|
+
const wrapper = ({ children }: any) => withReduxProvider(children, store)
|
|
138
|
+
renderHook(() => useGlobalStoreSync(), { wrapper })
|
|
139
|
+
expect(mockDispatch).not.toHaveBeenCalled()
|
|
140
|
+
expect(push).toHaveBeenCalledWith({
|
|
141
|
+
pathname: '/',
|
|
142
|
+
search: `sdk=py`,
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
})
|
|
146
|
+
})
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2022 Looker Data Sciences, Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
24
|
+
|
|
25
|
+
*/
|
|
26
|
+
import { useLocation } from 'react-router-dom'
|
|
27
|
+
import { useEffect } from 'react'
|
|
28
|
+
import { useSelector } from 'react-redux'
|
|
29
|
+
import { allAlias, findSdk, useNavigation } from '../index'
|
|
30
|
+
import {
|
|
31
|
+
selectSdkLanguage,
|
|
32
|
+
useSettingActions,
|
|
33
|
+
useSettingStoreState,
|
|
34
|
+
} from '../../state'
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Hook for syncing global URL params with the Redux store
|
|
38
|
+
* Global search parameters: 's', 'sdk'
|
|
39
|
+
*/
|
|
40
|
+
export const useGlobalStoreSync = () => {
|
|
41
|
+
const location = useLocation()
|
|
42
|
+
const { navigate } = useNavigation()
|
|
43
|
+
const { setSdkLanguageAction, setSearchPatternAction } = useSettingActions()
|
|
44
|
+
const { initialized } = useSettingStoreState()
|
|
45
|
+
const selectedSdkLanguage = useSelector(selectSdkLanguage)
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (initialized) {
|
|
49
|
+
const params = new URLSearchParams(location.search)
|
|
50
|
+
|
|
51
|
+
// syncing search query
|
|
52
|
+
const searchParam = params.get('s')
|
|
53
|
+
if (searchParam) {
|
|
54
|
+
setSearchPatternAction({
|
|
55
|
+
searchPattern: searchParam,
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// syncing SDK language selection
|
|
60
|
+
const sdkParam = params.get('sdk') || ''
|
|
61
|
+
const sdk = findSdk(sdkParam)
|
|
62
|
+
const validSdkParam =
|
|
63
|
+
!sdkParam.localeCompare(sdk.alias, 'en', { sensitivity: 'base' }) ||
|
|
64
|
+
!sdkParam.localeCompare(sdk.language, 'en', { sensitivity: 'base' })
|
|
65
|
+
if (validSdkParam) {
|
|
66
|
+
setSdkLanguageAction({
|
|
67
|
+
sdkLanguage: sdk.language,
|
|
68
|
+
})
|
|
69
|
+
} else {
|
|
70
|
+
const { alias } = findSdk(selectedSdkLanguage)
|
|
71
|
+
navigate(location.pathname, {
|
|
72
|
+
sdk: alias === allAlias ? null : alias,
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}, [initialized])
|
|
77
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2021 Looker Data Sciences, Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
24
|
+
|
|
25
|
+
*/
|
|
26
|
+
export { useNavigation } from './navigation'
|
|
27
|
+
export { useGlobalStoreSync } from './globalStoreSync'
|
|
28
|
+
export { useQuery } from './useQuery'
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2022 Looker Data Sciences, Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
24
|
+
|
|
25
|
+
*/
|
|
26
|
+
import { useHistory } from 'react-router-dom'
|
|
27
|
+
import { useNavigation } from './navigation'
|
|
28
|
+
|
|
29
|
+
const mockHistoryPush = jest.fn()
|
|
30
|
+
jest.mock('react-router-dom', () => {
|
|
31
|
+
const ReactRouterDOM = jest.requireActual('react-router-dom')
|
|
32
|
+
return {
|
|
33
|
+
...ReactRouterDOM,
|
|
34
|
+
useHistory: () => ({
|
|
35
|
+
push: mockHistoryPush,
|
|
36
|
+
location: {
|
|
37
|
+
pathname: '/3.1/methods/Auth',
|
|
38
|
+
search: 's=test&sdk=py&t=get',
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
describe('useNavigation', () => {
|
|
45
|
+
const history = useHistory()
|
|
46
|
+
const { navigate, navigateWithGlobalParams, buildPathWithGlobalParams } =
|
|
47
|
+
useNavigation()
|
|
48
|
+
const curParams = new URLSearchParams(history.location.search)
|
|
49
|
+
const route = `/3.1`
|
|
50
|
+
|
|
51
|
+
describe('navigate', () => {
|
|
52
|
+
test('preserves existing query params when given params are undefined', () => {
|
|
53
|
+
navigate(route)
|
|
54
|
+
expect(curParams.get('s')).toBe('test')
|
|
55
|
+
expect(curParams.get('sdk')).toBe('py')
|
|
56
|
+
expect(curParams.get('t')).toBe('get')
|
|
57
|
+
expect(mockHistoryPush).lastCalledWith({
|
|
58
|
+
pathname: route,
|
|
59
|
+
search: curParams.toString(),
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('clears existing params when given params are null', () => {
|
|
64
|
+
navigate(route, null)
|
|
65
|
+
expect(mockHistoryPush).lastCalledWith({
|
|
66
|
+
pathname: route,
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('removes null query params while persisting undefined params if in URL', () => {
|
|
71
|
+
navigate(route, { s: null, sdk: 'test' })
|
|
72
|
+
expect(mockHistoryPush).lastCalledWith({
|
|
73
|
+
pathname: route,
|
|
74
|
+
search: 'sdk=test&t=get',
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
test('sets query parameters when given a populated query params object', () => {
|
|
79
|
+
const newParams = new URLSearchParams()
|
|
80
|
+
newParams.set('s', 'newTest')
|
|
81
|
+
newParams.set('sdk', 'kt')
|
|
82
|
+
newParams.set('t', 'post')
|
|
83
|
+
navigate(route, {
|
|
84
|
+
s: newParams.get('s'),
|
|
85
|
+
sdk: newParams.get('sdk'),
|
|
86
|
+
t: newParams.get('t'),
|
|
87
|
+
})
|
|
88
|
+
expect(mockHistoryPush).lastCalledWith({
|
|
89
|
+
pathname: route,
|
|
90
|
+
search: newParams.toString(),
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
describe('buildPathWithGlobalParams', () => {
|
|
96
|
+
test('creates path with global parameters excluding scene specific parameters', () => {
|
|
97
|
+
curParams.delete('t')
|
|
98
|
+
expect(buildPathWithGlobalParams(route)).toEqual(
|
|
99
|
+
`${route}?${curParams.toString()}`
|
|
100
|
+
)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
test('adds other parameters if present', () => {
|
|
104
|
+
curParams.delete('t')
|
|
105
|
+
const actual = buildPathWithGlobalParams(route, { e: 400 })
|
|
106
|
+
expect(actual).toEqual(`${route}?${curParams.toString()}&e=400`)
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
describe('navigateWithGlobalParams', () => {
|
|
111
|
+
test('preserves global query params and removes scene specific parameters', () => {
|
|
112
|
+
curParams.delete('t')
|
|
113
|
+
navigateWithGlobalParams(route)
|
|
114
|
+
expect(curParams.get('s')).toEqual('test')
|
|
115
|
+
expect(mockHistoryPush).lastCalledWith(`${route}?${curParams.toString()}`)
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
})
|