@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,103 @@
|
|
|
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
|
+
import React, { useEffect, useState } from 'react'
|
|
28
|
+
import { Tabs2, Tab2 } from '@looker/components'
|
|
29
|
+
import type { ApiModel, IMethod } from '@looker/sdk-codegen'
|
|
30
|
+
import { CollapserCard } from '@looker/run-it'
|
|
31
|
+
import { ErrorDoc } from '@looker/sdk-rtl'
|
|
32
|
+
import {
|
|
33
|
+
apiErrorDisplayFetch,
|
|
34
|
+
ExtMarkdown,
|
|
35
|
+
getEnvAdaptor,
|
|
36
|
+
} from '@looker/extension-utils'
|
|
37
|
+
|
|
38
|
+
import { DocResponseTypes } from './DocResponseTypes'
|
|
39
|
+
import { buildResponseTree } from './utils'
|
|
40
|
+
|
|
41
|
+
interface DocResponsesProps {
|
|
42
|
+
api: ApiModel
|
|
43
|
+
method: IMethod
|
|
44
|
+
/** error code to display */
|
|
45
|
+
errorCode?: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Renders a tab list and tab panels for different method response types
|
|
50
|
+
*/
|
|
51
|
+
export const DocResponses = ({ api, method, errorCode }: DocResponsesProps) => {
|
|
52
|
+
const [errorContent, setErrorContent] = useState('')
|
|
53
|
+
const responses = method.responses
|
|
54
|
+
|
|
55
|
+
const responseTree = buildResponseTree(responses)
|
|
56
|
+
const tabNames = Object.keys(responseTree)
|
|
57
|
+
|
|
58
|
+
let defaultTabId = tabNames[0]
|
|
59
|
+
|
|
60
|
+
if (errorCode) {
|
|
61
|
+
const pattern = new RegExp(`${errorCode}: \\w+`)
|
|
62
|
+
tabNames.forEach((el) => {
|
|
63
|
+
if (pattern.test(el)) {
|
|
64
|
+
defaultTabId = el
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!errorCode) return
|
|
71
|
+
|
|
72
|
+
const getErrorContent = async () => {
|
|
73
|
+
const docUrl = `/err/4.0/${errorCode}/${method.httpMethod.toLocaleLowerCase()}${
|
|
74
|
+
method.endpoint
|
|
75
|
+
}`
|
|
76
|
+
const adaptor = getEnvAdaptor()
|
|
77
|
+
const errDoc = new ErrorDoc(adaptor.sdk, apiErrorDisplayFetch)
|
|
78
|
+
const content = await errDoc.content(docUrl)
|
|
79
|
+
setErrorContent(content)
|
|
80
|
+
}
|
|
81
|
+
getErrorContent()
|
|
82
|
+
}, [errorCode])
|
|
83
|
+
|
|
84
|
+
if (responses.length === 0) return <></>
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<CollapserCard heading="Response Models" id="response models">
|
|
88
|
+
<Tabs2 defaultTabId={defaultTabId}>
|
|
89
|
+
{Object.entries(responseTree).map(([statusCode, response]) => {
|
|
90
|
+
const errorTab = errorCode && statusCode === defaultTabId
|
|
91
|
+
return (
|
|
92
|
+
<Tab2 key={statusCode} id={statusCode} label={statusCode}>
|
|
93
|
+
<DocResponseTypes api={api} responses={response} />
|
|
94
|
+
{errorContent && errorTab && (
|
|
95
|
+
<ExtMarkdown source={errorContent} />
|
|
96
|
+
)}
|
|
97
|
+
</Tab2>
|
|
98
|
+
)
|
|
99
|
+
})}
|
|
100
|
+
</Tabs2>
|
|
101
|
+
</CollapserCard>
|
|
102
|
+
)
|
|
103
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -29,16 +29,28 @@ import { screen, waitFor } from '@testing-library/react'
|
|
|
29
29
|
import userEvent from '@testing-library/user-event'
|
|
30
30
|
|
|
31
31
|
import { api } from '../../test-data'
|
|
32
|
-
import {
|
|
32
|
+
import { renderWithRouterAndReduxProvider } from '../../test-utils'
|
|
33
33
|
import { MethodTagScene } from './MethodTagScene'
|
|
34
34
|
|
|
35
35
|
const opBtnNames = /ALL|GET|POST|PUT|PATCH|DELETE/
|
|
36
36
|
|
|
37
|
+
const mockHistoryPush = jest.fn()
|
|
38
|
+
jest.mock('react-router-dom', () => {
|
|
39
|
+
const ReactRouterDOM = jest.requireActual('react-router-dom')
|
|
40
|
+
return {
|
|
41
|
+
...ReactRouterDOM,
|
|
42
|
+
useHistory: () => ({
|
|
43
|
+
push: mockHistoryPush,
|
|
44
|
+
location,
|
|
45
|
+
}),
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
37
49
|
describe('MethodTagScene', () => {
|
|
38
50
|
Element.prototype.scrollTo = jest.fn()
|
|
39
51
|
|
|
40
52
|
test('it renders operation buttons and all methods for a given method tag', () => {
|
|
41
|
-
|
|
53
|
+
renderWithRouterAndReduxProvider(
|
|
42
54
|
<Route path="/:specKey/methods/:methodTag">
|
|
43
55
|
<MethodTagScene api={api} />
|
|
44
56
|
</Route>,
|
|
@@ -62,7 +74,7 @@ describe('MethodTagScene', () => {
|
|
|
62
74
|
|
|
63
75
|
test('it only renders operation buttons for operations that exist under that tag', () => {
|
|
64
76
|
/** ApiAuth contains two POST methods and a DELETE method */
|
|
65
|
-
|
|
77
|
+
renderWithRouterAndReduxProvider(
|
|
66
78
|
<Route path="/:specKey/methods/:methodTag">
|
|
67
79
|
<MethodTagScene api={api} />
|
|
68
80
|
</Route>,
|
|
@@ -75,30 +87,29 @@ describe('MethodTagScene', () => {
|
|
|
75
87
|
).toHaveLength(3)
|
|
76
88
|
})
|
|
77
89
|
|
|
78
|
-
test('it
|
|
79
|
-
|
|
90
|
+
test('it pushes filter to URL on toggle', async () => {
|
|
91
|
+
renderWithRouterAndReduxProvider(
|
|
80
92
|
<Route path="/:specKey/methods/:methodTag">
|
|
81
93
|
<MethodTagScene api={api} />
|
|
82
94
|
</Route>,
|
|
83
95
|
['/3.1/methods/Look']
|
|
84
96
|
)
|
|
85
|
-
const allLookMethods = /^\/look.*/
|
|
86
|
-
expect(screen.getAllByText(allLookMethods)).toHaveLength(7)
|
|
87
97
|
/** Filter by GET operation */
|
|
88
98
|
userEvent.click(screen.getByRole('button', { name: 'GET' }))
|
|
89
99
|
await waitFor(() => {
|
|
90
|
-
expect(
|
|
100
|
+
expect(mockHistoryPush).toHaveBeenCalledWith({
|
|
101
|
+
pathname: location.pathname,
|
|
102
|
+
search: 't=get',
|
|
103
|
+
})
|
|
91
104
|
})
|
|
92
105
|
/** Filter by DELETE operation */
|
|
93
106
|
userEvent.click(screen.getByRole('button', { name: 'DELETE' }))
|
|
94
107
|
await waitFor(() => {
|
|
95
108
|
// eslint-disable-next-line jest-dom/prefer-in-document
|
|
96
|
-
expect(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
await waitFor(() => {
|
|
101
|
-
expect(screen.getAllByText(allLookMethods)).toHaveLength(7)
|
|
109
|
+
expect(mockHistoryPush).toHaveBeenCalledWith({
|
|
110
|
+
pathname: location.pathname,
|
|
111
|
+
search: 't=delete',
|
|
112
|
+
})
|
|
102
113
|
})
|
|
103
114
|
})
|
|
104
115
|
})
|
|
@@ -28,8 +28,11 @@ import React, { useEffect, useState } from 'react'
|
|
|
28
28
|
import { useHistory, useParams } from 'react-router-dom'
|
|
29
29
|
import { Grid, ButtonToggle, ButtonItem } from '@looker/components'
|
|
30
30
|
import type { ApiModel } from '@looker/sdk-codegen'
|
|
31
|
+
import { useSelector } from 'react-redux'
|
|
31
32
|
import { ApixSection, DocTitle, DocMethodSummary, Link } from '../../components'
|
|
32
|
-
import { buildMethodPath } from '../../utils'
|
|
33
|
+
import { buildMethodPath, isValidFilter, useNavigation } from '../../utils'
|
|
34
|
+
import { selectTagFilter, useSettingActions } from '../../state'
|
|
35
|
+
import { useTagStoreSync } from '../utils'
|
|
33
36
|
import { getOperations } from './utils'
|
|
34
37
|
|
|
35
38
|
interface MethodTagSceneProps {
|
|
@@ -44,17 +47,38 @@ interface MethodTagSceneParams {
|
|
|
44
47
|
export const MethodTagScene: FC<MethodTagSceneProps> = ({ api }) => {
|
|
45
48
|
const { specKey, methodTag } = useParams<MethodTagSceneParams>()
|
|
46
49
|
const history = useHistory()
|
|
47
|
-
const
|
|
50
|
+
const methods = api.tags[methodTag]
|
|
51
|
+
const { navigate, buildPathWithGlobalParams, navigateWithGlobalParams } =
|
|
52
|
+
useNavigation()
|
|
53
|
+
const selectedTagFilter = useSelector(selectTagFilter)
|
|
54
|
+
const { setTagFilterAction } = useSettingActions()
|
|
55
|
+
const [tagFilter, setTagFilter] = useState(selectedTagFilter)
|
|
56
|
+
useTagStoreSync()
|
|
57
|
+
|
|
58
|
+
const handleChange = (filter: string) => {
|
|
59
|
+
navigate(location.pathname, {
|
|
60
|
+
t: filter === 'ALL' ? null : filter.toLowerCase(),
|
|
61
|
+
})
|
|
62
|
+
}
|
|
48
63
|
|
|
49
64
|
useEffect(() => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
65
|
+
const searchParams = new URLSearchParams(location.search)
|
|
66
|
+
let verbParam = searchParams.get('t') || 'ALL'
|
|
67
|
+
verbParam = isValidFilter(location.pathname, verbParam)
|
|
68
|
+
? verbParam.toUpperCase()
|
|
69
|
+
: 'ALL'
|
|
70
|
+
setTagFilterAction({
|
|
71
|
+
tagFilter: verbParam,
|
|
72
|
+
})
|
|
73
|
+
}, [location.search])
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
setTagFilter(selectedTagFilter)
|
|
77
|
+
}, [selectedTagFilter])
|
|
53
78
|
|
|
54
|
-
const methods = api.tags[methodTag]
|
|
55
79
|
useEffect(() => {
|
|
56
80
|
if (!methods) {
|
|
57
|
-
|
|
81
|
+
navigateWithGlobalParams(`/${specKey}/methods`)
|
|
58
82
|
}
|
|
59
83
|
}, [history, methods])
|
|
60
84
|
if (!methods) {
|
|
@@ -68,7 +92,12 @@ export const MethodTagScene: FC<MethodTagSceneProps> = ({ api }) => {
|
|
|
68
92
|
return (
|
|
69
93
|
<ApixSection>
|
|
70
94
|
<DocTitle>{`${tag.name}: ${tag.description}`}</DocTitle>
|
|
71
|
-
<ButtonToggle
|
|
95
|
+
<ButtonToggle
|
|
96
|
+
mb="small"
|
|
97
|
+
mt="xlarge"
|
|
98
|
+
value={tagFilter}
|
|
99
|
+
onChange={handleChange}
|
|
100
|
+
>
|
|
72
101
|
<ButtonItem key="ALL" px="large" py="xsmall">
|
|
73
102
|
ALL
|
|
74
103
|
</ButtonItem>
|
|
@@ -80,10 +109,13 @@ export const MethodTagScene: FC<MethodTagSceneProps> = ({ api }) => {
|
|
|
80
109
|
</ButtonToggle>
|
|
81
110
|
{Object.values(methods).map(
|
|
82
111
|
(method, index) =>
|
|
83
|
-
(
|
|
112
|
+
(selectedTagFilter === 'ALL' ||
|
|
113
|
+
selectedTagFilter === method.httpMethod) && (
|
|
84
114
|
<Link
|
|
85
115
|
key={index}
|
|
86
|
-
to={
|
|
116
|
+
to={buildPathWithGlobalParams(
|
|
117
|
+
buildMethodPath(specKey, tag.name, method.name)
|
|
118
|
+
)}
|
|
87
119
|
>
|
|
88
120
|
<Grid columns={1} py="xsmall">
|
|
89
121
|
<DocMethodSummary key={index} method={method} />
|
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
ExploreType,
|
|
41
41
|
DocSchema,
|
|
42
42
|
} from '../../components'
|
|
43
|
+
import { useNavigation } from '../../utils'
|
|
43
44
|
|
|
44
45
|
interface DocTypeProps {
|
|
45
46
|
api: ApiModel
|
|
@@ -47,19 +48,24 @@ interface DocTypeProps {
|
|
|
47
48
|
|
|
48
49
|
interface DocTypeParams {
|
|
49
50
|
specKey: string
|
|
51
|
+
typeTag: string
|
|
50
52
|
typeName: string
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
export const TypeScene: FC<DocTypeProps> = ({ api }) => {
|
|
54
|
-
const { specKey, typeName } = useParams<DocTypeParams>()
|
|
56
|
+
const { specKey, typeTag, typeName } = useParams<DocTypeParams>()
|
|
55
57
|
const type = api.types[typeName]
|
|
56
58
|
const history = useHistory()
|
|
59
|
+
const { navigate } = useNavigation()
|
|
57
60
|
const typesUsed = typeRefs(api, type?.customTypes)
|
|
58
61
|
const methodsUsedBy = methodRefs(api, type?.methodRefs)
|
|
59
62
|
const typesUsedBy = typeRefs(api, type?.parentTypes)
|
|
60
63
|
useEffect(() => {
|
|
61
64
|
if (!type) {
|
|
62
|
-
|
|
65
|
+
const route = api.typeTags[typeTag]
|
|
66
|
+
? `/${specKey}/types/${typeTag}`
|
|
67
|
+
: `/${specKey}/types`
|
|
68
|
+
navigate(route)
|
|
63
69
|
}
|
|
64
70
|
}, [history, specKey, type])
|
|
65
71
|
|
|
@@ -36,6 +36,18 @@ const opBtnNames = /ALL|SPECIFICATION|WRITE|REQUEST|ENUMERATED/
|
|
|
36
36
|
|
|
37
37
|
const path = '/:specKey/types/:typeTag'
|
|
38
38
|
|
|
39
|
+
const mockHistoryPush = jest.fn()
|
|
40
|
+
jest.mock('react-router-dom', () => {
|
|
41
|
+
const ReactRouterDOM = jest.requireActual('react-router-dom')
|
|
42
|
+
return {
|
|
43
|
+
...ReactRouterDOM,
|
|
44
|
+
useHistory: () => ({
|
|
45
|
+
push: mockHistoryPush,
|
|
46
|
+
location,
|
|
47
|
+
}),
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
|
|
39
51
|
describe('TypeTagScene', () => {
|
|
40
52
|
Element.prototype.scrollTo = jest.fn()
|
|
41
53
|
|
|
@@ -74,30 +86,28 @@ describe('TypeTagScene', () => {
|
|
|
74
86
|
).toHaveLength(2)
|
|
75
87
|
})
|
|
76
88
|
|
|
77
|
-
test('it
|
|
89
|
+
test('it pushes filter to URL on toggle', async () => {
|
|
78
90
|
renderWithRouterAndReduxProvider(
|
|
79
91
|
<Route path={path}>
|
|
80
92
|
<TypeTagScene api={api} />
|
|
81
93
|
</Route>,
|
|
82
94
|
['/3.1/types/Look']
|
|
83
95
|
)
|
|
84
|
-
expect(screen.getAllByRole('heading', { level: 3 })).toHaveLength(
|
|
85
|
-
Object.keys(api.typeTags.Look).length
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
expect(screen.getAllByRole('heading', { level: 3 })).toHaveLength(
|
|
89
|
-
Object.keys(api.typeTags.Look).length
|
|
90
|
-
)
|
|
91
|
-
|
|
92
96
|
/** Filter by SPECIFICATION */
|
|
93
97
|
userEvent.click(screen.getByRole('button', { name: 'SPECIFICATION' }))
|
|
94
98
|
await waitFor(() => {
|
|
95
|
-
expect(
|
|
99
|
+
expect(mockHistoryPush).toHaveBeenCalledWith({
|
|
100
|
+
pathname: location.pathname,
|
|
101
|
+
search: 't=specification',
|
|
102
|
+
})
|
|
96
103
|
})
|
|
97
104
|
/** Filter by REQUEST */
|
|
98
105
|
userEvent.click(screen.getByRole('button', { name: 'REQUEST' }))
|
|
99
106
|
await waitFor(() => {
|
|
100
|
-
expect(
|
|
107
|
+
expect(mockHistoryPush).toHaveBeenCalledWith({
|
|
108
|
+
pathname: location.pathname,
|
|
109
|
+
search: 't=request',
|
|
110
|
+
})
|
|
101
111
|
})
|
|
102
112
|
})
|
|
103
113
|
})
|
|
@@ -27,9 +27,12 @@ import type { FC } from 'react'
|
|
|
27
27
|
import React, { useEffect, useState } from 'react'
|
|
28
28
|
import { Grid, ButtonToggle, ButtonItem } from '@looker/components'
|
|
29
29
|
import type { ApiModel } from '@looker/sdk-codegen'
|
|
30
|
-
import { useParams
|
|
30
|
+
import { useParams } from 'react-router-dom'
|
|
31
|
+
import { useSelector } from 'react-redux'
|
|
31
32
|
import { ApixSection, DocTitle, DocTypeSummary, Link } from '../../components'
|
|
32
|
-
import { buildTypePath } from '../../utils'
|
|
33
|
+
import { buildTypePath, isValidFilter, useNavigation } from '../../utils'
|
|
34
|
+
import { selectTagFilter, useSettingActions } from '../../state'
|
|
35
|
+
import { useTagStoreSync } from '../utils'
|
|
33
36
|
import { getMetaTypes } from './utils'
|
|
34
37
|
|
|
35
38
|
interface TypeTagSceneProps {
|
|
@@ -43,20 +46,40 @@ interface TypeTagSceneParams {
|
|
|
43
46
|
|
|
44
47
|
export const TypeTagScene: FC<TypeTagSceneProps> = ({ api }) => {
|
|
45
48
|
const { specKey, typeTag } = useParams<TypeTagSceneParams>()
|
|
46
|
-
const
|
|
47
|
-
|
|
49
|
+
const { navigate, buildPathWithGlobalParams, navigateWithGlobalParams } =
|
|
50
|
+
useNavigation()
|
|
51
|
+
const selectedTagFilter = useSelector(selectTagFilter)
|
|
52
|
+
const { setTagFilterAction } = useSettingActions()
|
|
53
|
+
const [tagFilter, setTagFilter] = useState(selectedTagFilter)
|
|
54
|
+
useTagStoreSync()
|
|
55
|
+
|
|
56
|
+
const handleChange = (filter: string) => {
|
|
57
|
+
navigate(location.pathname, {
|
|
58
|
+
t: filter === 'ALL' ? null : filter.toLowerCase(),
|
|
59
|
+
})
|
|
60
|
+
}
|
|
48
61
|
|
|
49
62
|
useEffect(() => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
63
|
+
const searchParams = new URLSearchParams(location.search)
|
|
64
|
+
let verbParam = searchParams.get('t') || 'ALL'
|
|
65
|
+
verbParam = isValidFilter(location.pathname, verbParam)
|
|
66
|
+
? verbParam.toUpperCase()
|
|
67
|
+
: 'ALL'
|
|
68
|
+
setTagFilterAction({
|
|
69
|
+
tagFilter: verbParam,
|
|
70
|
+
})
|
|
71
|
+
}, [location.search])
|
|
53
72
|
|
|
54
73
|
const types = api.typeTags[typeTag]
|
|
55
74
|
useEffect(() => {
|
|
56
75
|
if (!types) {
|
|
57
|
-
|
|
76
|
+
navigateWithGlobalParams(`/${specKey}/types`)
|
|
58
77
|
}
|
|
59
|
-
}, [
|
|
78
|
+
}, [types])
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
setTagFilter(selectedTagFilter)
|
|
82
|
+
}, [selectedTagFilter])
|
|
60
83
|
|
|
61
84
|
if (!types) {
|
|
62
85
|
return <></>
|
|
@@ -67,7 +90,12 @@ export const TypeTagScene: FC<TypeTagSceneProps> = ({ api }) => {
|
|
|
67
90
|
return (
|
|
68
91
|
<ApixSection>
|
|
69
92
|
<DocTitle>{`${tag.name}: ${tag.description}`}</DocTitle>
|
|
70
|
-
<ButtonToggle
|
|
93
|
+
<ButtonToggle
|
|
94
|
+
mb="small"
|
|
95
|
+
mt="xlarge"
|
|
96
|
+
value={tagFilter}
|
|
97
|
+
onChange={handleChange}
|
|
98
|
+
>
|
|
71
99
|
<ButtonItem key="ALL" px="large" py="xsmall">
|
|
72
100
|
ALL
|
|
73
101
|
</ButtonItem>
|
|
@@ -79,9 +107,14 @@ export const TypeTagScene: FC<TypeTagSceneProps> = ({ api }) => {
|
|
|
79
107
|
</ButtonToggle>
|
|
80
108
|
{Object.values(types).map(
|
|
81
109
|
(type, index) =>
|
|
82
|
-
(
|
|
83
|
-
|
|
84
|
-
<Link
|
|
110
|
+
(selectedTagFilter === 'ALL' ||
|
|
111
|
+
selectedTagFilter === type.metaType.toString().toUpperCase()) && (
|
|
112
|
+
<Link
|
|
113
|
+
key={index}
|
|
114
|
+
to={buildPathWithGlobalParams(
|
|
115
|
+
buildTypePath(specKey, tag.name, type.name)
|
|
116
|
+
)}
|
|
117
|
+
>
|
|
85
118
|
<Grid columns={1} py="xsmall">
|
|
86
119
|
<DocTypeSummary key={index} type={type} />
|
|
87
120
|
</Grid>
|
package/src/scenes/index.ts
CHANGED
|
@@ -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 './tagStoreSync'
|
|
@@ -0,0 +1,102 @@
|
|
|
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 { useTagStoreSync } from './tagStoreSync'
|
|
33
|
+
|
|
34
|
+
jest.mock('react-router', () => {
|
|
35
|
+
const ReactRouter = jest.requireActual('react-router')
|
|
36
|
+
return {
|
|
37
|
+
...ReactRouter,
|
|
38
|
+
useHistory: jest.fn().mockReturnValue({ push: jest.fn(), location }),
|
|
39
|
+
useLocation: jest.fn().mockReturnValue({ pathname: '/', search: '' }),
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
describe('useTagStoreSync', () => {
|
|
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(() => useTagStoreSync(), { wrapper })
|
|
54
|
+
expect(push).not.toHaveBeenCalled()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
describe.each([
|
|
58
|
+
['methods', 'get'],
|
|
59
|
+
['types', 'specification'],
|
|
60
|
+
])('tag filter verb for sidenav %s tab', (tagType, verb) => {
|
|
61
|
+
test('overrides store tag filter given valid url tag filter param', () => {
|
|
62
|
+
const { push } = useHistory()
|
|
63
|
+
const store = createTestStore({
|
|
64
|
+
settings: {
|
|
65
|
+
initialized: true,
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
jest.spyOn(routerLocation, 'useLocation').mockReturnValue({
|
|
69
|
+
pathname: `/4.0/${tagType}/ApiAuth`,
|
|
70
|
+
search: `t=${verb}`,
|
|
71
|
+
} as unknown as Location)
|
|
72
|
+
jest.spyOn(reactRedux, 'useDispatch').mockReturnValue(mockDispatch)
|
|
73
|
+
const wrapper = ({ children }: any) => withReduxProvider(children, store)
|
|
74
|
+
renderHook(() => useTagStoreSync(), { wrapper })
|
|
75
|
+
expect(push).not.toHaveBeenCalled()
|
|
76
|
+
expect(mockDispatch).toHaveBeenLastCalledWith({
|
|
77
|
+
payload: { tagFilter: verb.toUpperCase() },
|
|
78
|
+
type: 'settings/setTagFilterAction',
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test('updates url with store tag filter given invalid url tag filter param', () => {
|
|
83
|
+
const { push } = useHistory()
|
|
84
|
+
const store = createTestStore({
|
|
85
|
+
settings: {
|
|
86
|
+
initialized: true,
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
jest.spyOn(routerLocation, 'useLocation').mockReturnValue({
|
|
90
|
+
pathname: `/4.0/${tagType}/ApiAuth`,
|
|
91
|
+
search: 't=invalid',
|
|
92
|
+
} as unknown as Location)
|
|
93
|
+
jest.spyOn(reactRedux, 'useDispatch').mockReturnValue(mockDispatch)
|
|
94
|
+
const wrapper = ({ children }: any) => withReduxProvider(children, store)
|
|
95
|
+
renderHook(() => useTagStoreSync(), { wrapper })
|
|
96
|
+
expect(push).toHaveBeenCalledWith({
|
|
97
|
+
pathname: `/4.0/${tagType}/ApiAuth`,
|
|
98
|
+
search: '',
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
})
|
|
102
|
+
})
|