@urbanos/react-discovery-ui 2.1.43
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/LICENSE +201 -0
- package/README.md +118 -0
- package/lib/ReactDiscoveryUI.js +103 -0
- package/lib/ReactDiscoveryUI.scss +13 -0
- package/lib/assets/arrow.svg +6 -0
- package/lib/assets/blk-database.svg +48 -0
- package/lib/assets/chart.svg +1 -0
- package/lib/assets/down.png +0 -0
- package/lib/assets/down.svg +1 -0
- package/lib/assets/folder_icon.png +0 -0
- package/lib/assets/folder_icon.svg +1 -0
- package/lib/assets/ic_arrow.svg +15 -0
- package/lib/assets/loadingicon.svg +57 -0
- package/lib/assets/no_image.png +0 -0
- package/lib/assets/plus.png +0 -0
- package/lib/assets/plus.svg +1 -0
- package/lib/assets/user.svg +1 -0
- package/lib/auth/auth0-client-provider.js +37 -0
- package/lib/auth/auth0-client-provider.test.js +33 -0
- package/lib/auth/auth0-wrapper.js +155 -0
- package/lib/auth/auth0-wrapper.test.js +100 -0
- package/lib/components/auth0-login-zone/auth0-login-zone.js +147 -0
- package/lib/components/auth0-login-zone/auth0-login-zone.test.js +177 -0
- package/lib/components/auth0-login-zone/index.js +9 -0
- package/lib/components/code-editor/code-editor.css +173 -0
- package/lib/components/code-editor/code-editor.js +64 -0
- package/lib/components/code-editor/index.js +9 -0
- package/lib/components/collapsable-box/collapsable-box.js +81 -0
- package/lib/components/collapsable-box/collapsable-box.scss +39 -0
- package/lib/components/collapsable-box/collapsable-box.test.js +87 -0
- package/lib/components/collapsable-box/index.js +9 -0
- package/lib/components/data-card/data-card.js +63 -0
- package/lib/components/data-card/data-card.scss +93 -0
- package/lib/components/data-card/data-card.test.js +74 -0
- package/lib/components/data-card/index.js +9 -0
- package/lib/components/data-view/data-view.js +194 -0
- package/lib/components/data-view/data-view.scss +39 -0
- package/lib/components/data-view/data-view.test.js +155 -0
- package/lib/components/data-view/index.js +9 -0
- package/lib/components/dataset-api-doc/api-example.js +120 -0
- package/lib/components/dataset-api-doc/api-example.scss +84 -0
- package/lib/components/dataset-api-doc/api-example.test.js +88 -0
- package/lib/components/dataset-api-doc/dataset-api-doc.js +117 -0
- package/lib/components/dataset-api-doc/dataset-api-doc.scss +8 -0
- package/lib/components/dataset-api-doc/dataset-api-doc.test.js +42 -0
- package/lib/components/dataset-api-doc/index.js +9 -0
- package/lib/components/dataset-details/dataset-details.js +64 -0
- package/lib/components/dataset-details/dataset-details.scss +58 -0
- package/lib/components/dataset-details/dataset-details.test.js +38 -0
- package/lib/components/dataset-details/index.js +9 -0
- package/lib/components/dataset-dictionary/dataset-dictionary.js +127 -0
- package/lib/components/dataset-dictionary/dataset-dictionary.scss +42 -0
- package/lib/components/dataset-dictionary/dataset-dictionary.test.js +286 -0
- package/lib/components/dataset-dictionary/index.js +9 -0
- package/lib/components/dataset-list/dataset-list.js +22 -0
- package/lib/components/dataset-list/dataset-list.scss +9 -0
- package/lib/components/dataset-list/dataset-list.test.js +16 -0
- package/lib/components/dataset-list/index.js +9 -0
- package/lib/components/dataset-metadata/dataset-metadata.js +169 -0
- package/lib/components/dataset-metadata/dataset-metadata.scss +34 -0
- package/lib/components/dataset-metadata/dataset-metadata.test.js +24 -0
- package/lib/components/dataset-metadata/index.js +9 -0
- package/lib/components/dataset-preview/connector.js +26 -0
- package/lib/components/dataset-preview/dataset-preview.js +58 -0
- package/lib/components/dataset-preview/dataset-preview.scss +24 -0
- package/lib/components/dataset-preview/dataset-preview.test.js +34 -0
- package/lib/components/dataset-preview/index.js +9 -0
- package/lib/components/dataset-quality/dataset-quality.js +56 -0
- package/lib/components/dataset-quality/dataset-quality.scss +24 -0
- package/lib/components/dataset-quality/dataset-quality.test.js +34 -0
- package/lib/components/dataset-quality/index.js +9 -0
- package/lib/components/dataset-recommendations/connector.js +24 -0
- package/lib/components/dataset-recommendations/dataset-recommendations.js +47 -0
- package/lib/components/dataset-recommendations/dataset-recommendations.scss +17 -0
- package/lib/components/dataset-recommendations/dataset-recommendations.test.js +37 -0
- package/lib/components/dataset-recommendations/index.js +9 -0
- package/lib/components/detail-toggle-icon/detail-toggle-icon.js +41 -0
- package/lib/components/detail-toggle-icon/detail-toggle-icon.scss +13 -0
- package/lib/components/detail-toggle-icon/detail-toggle-icon.test.js +20 -0
- package/lib/components/detail-toggle-icon/index.js +9 -0
- package/lib/components/facet-list/facet-list.js +47 -0
- package/lib/components/facet-list/facet-list.scss +19 -0
- package/lib/components/facet-list/facet-list.test.js +94 -0
- package/lib/components/facet-list/index.js +9 -0
- package/lib/components/facet-sidebar/facet-sidebar.js +101 -0
- package/lib/components/facet-sidebar/facet-sidebar.scss +129 -0
- package/lib/components/facet-sidebar/facet-sidebar.test.js +93 -0
- package/lib/components/facet-sidebar/index.js +9 -0
- package/lib/components/generic-elements/alert-component/alert-component.js +51 -0
- package/lib/components/generic-elements/alert-component/alert-component.scss +26 -0
- package/lib/components/generic-elements/alert-component/alert-component.test.js +26 -0
- package/lib/components/generic-elements/alert-component/index.js +9 -0
- package/lib/components/generic-elements/arrow-button/arrow-button.js +30 -0
- package/lib/components/generic-elements/arrow-button/index.js +9 -0
- package/lib/components/generic-elements/auto-anchoring-popover/index.js +61 -0
- package/lib/components/generic-elements/back-button/back-button.js +14 -0
- package/lib/components/generic-elements/back-button/back-button.scss +14 -0
- package/lib/components/generic-elements/back-button/index.js +9 -0
- package/lib/components/generic-elements/call-to-action-button/call-to-action-button.js +118 -0
- package/lib/components/generic-elements/call-to-action-button/call-to-action-button.scss +19 -0
- package/lib/components/generic-elements/call-to-action-button/call-to-action-button.test.js +68 -0
- package/lib/components/generic-elements/call-to-action-button/index.js +9 -0
- package/lib/components/generic-elements/chart-icon/index.js +23 -0
- package/lib/components/generic-elements/checkbox/checkbox.js +50 -0
- package/lib/components/generic-elements/checkbox/checkbox.scss +44 -0
- package/lib/components/generic-elements/checkbox/checkbox.test.js +71 -0
- package/lib/components/generic-elements/checkbox/index.js +9 -0
- package/lib/components/generic-elements/error-component/error-component.js +21 -0
- package/lib/components/generic-elements/error-component/error-component.scss +16 -0
- package/lib/components/generic-elements/error-component/error-component.test.js +12 -0
- package/lib/components/generic-elements/error-component/index.js +9 -0
- package/lib/components/generic-elements/folder-icon/index.js +23 -0
- package/lib/components/generic-elements/generated-link/generated-link.js +25 -0
- package/lib/components/generic-elements/generated-link/index.js +13 -0
- package/lib/components/generic-elements/loading-element/index.js +9 -0
- package/lib/components/generic-elements/loading-element/loading-element.js +22 -0
- package/lib/components/generic-elements/loading-element/loading-element.scss +6 -0
- package/lib/components/generic-elements/loading-element/loading-element.test.js +11 -0
- package/lib/components/generic-elements/paginator/index.js +9 -0
- package/lib/components/generic-elements/paginator/paginator.js +84 -0
- package/lib/components/generic-elements/paginator/paginator.scss +38 -0
- package/lib/components/generic-elements/paginator/paginator.test.js +140 -0
- package/lib/components/generic-elements/plus-icon/index.js +21 -0
- package/lib/components/generic-elements/save-indicator/index.js +9 -0
- package/lib/components/generic-elements/save-indicator/save-indicator.js +39 -0
- package/lib/components/generic-elements/save-indicator/save-indicator.scss +31 -0
- package/lib/components/generic-elements/save-indicator/save-indicator.test.js +89 -0
- package/lib/components/generic-elements/search/index.js +9 -0
- package/lib/components/generic-elements/search/search.js +93 -0
- package/lib/components/generic-elements/search/search.scss +90 -0
- package/lib/components/generic-elements/search/search.test.js +41 -0
- package/lib/components/generic-elements/select/index.js +9 -0
- package/lib/components/generic-elements/select/select.js +44 -0
- package/lib/components/generic-elements/select/select.scss +22 -0
- package/lib/components/generic-elements/select/select.test.js +34 -0
- package/lib/components/generic-elements/share-link/index.js +9 -0
- package/lib/components/generic-elements/share-link/share-link.js +23 -0
- package/lib/components/generic-elements/share-link/share-link.scss +17 -0
- package/lib/components/generic-elements/share-link/share-link.test.js +28 -0
- package/lib/components/generic-elements/sql-icon/index.js +20 -0
- package/lib/components/generic-elements/tab-button/index.js +9 -0
- package/lib/components/generic-elements/tab-button/tab-button.js +25 -0
- package/lib/components/generic-elements/tab-button/tab-button.scss +27 -0
- package/lib/components/generic-elements/visualize-button/index.js +9 -0
- package/lib/components/generic-elements/visualize-button/visualize-button.js +37 -0
- package/lib/components/generic-elements/visualize-button/visualize-button.scss +14 -0
- package/lib/components/login-zone/connector.js +25 -0
- package/lib/components/login-zone/index.js +9 -0
- package/lib/components/login-zone/login-svgs-and-text.js +39 -0
- package/lib/components/login-zone/login-zone.js +21 -0
- package/lib/components/login-zone/login-zone.scss +115 -0
- package/lib/components/login-zone/login-zone.test.js +17 -0
- package/lib/components/login-zone/login.js +48 -0
- package/lib/components/login-zone/logout.js +39 -0
- package/lib/components/network-loading-element/connector.js +17 -0
- package/lib/components/network-loading-element/index.js +9 -0
- package/lib/components/network-loading-element/network-loading-element.js +23 -0
- package/lib/components/network-loading-element/network-loading-element.scss +21 -0
- package/lib/components/network-loading-element/network-loading-element.test.js +34 -0
- package/lib/components/organization/index.js +9 -0
- package/lib/components/organization/organization.js +27 -0
- package/lib/components/organization/organization.scss +32 -0
- package/lib/components/protected-route/protected-route.js +101 -0
- package/lib/components/protected-route/protected-route.scss +4 -0
- package/lib/components/protected-route/protected-route.test.js +63 -0
- package/lib/components/query-form/index.js +9 -0
- package/lib/components/query-form/query-form.js +262 -0
- package/lib/components/query-form/query-form.scss +167 -0
- package/lib/components/query-form/query-form.test.js +248 -0
- package/lib/components/recommendation-list/index.js +9 -0
- package/lib/components/recommendation-list/recommendation-list.js +72 -0
- package/lib/components/recommendation-list/recommendation-list.scss +61 -0
- package/lib/components/recommendation-list/recommendation-list.test.js +38 -0
- package/lib/components/remote-toggle/__snapshots__/remote-toggle.test.js.snap +3 -0
- package/lib/components/remote-toggle/index.js +13 -0
- package/lib/components/remote-toggle/remote-toggle.js +35 -0
- package/lib/components/remote-toggle/remote-toggle.scss +0 -0
- package/lib/components/remote-toggle/remote-toggle.test.js +10 -0
- package/lib/components/share/index.js +9 -0
- package/lib/components/share/share.js +109 -0
- package/lib/components/share/share.scss +66 -0
- package/lib/components/streaming-api-doc/index.js +9 -0
- package/lib/components/streaming-api-doc/streaming-api-doc.js +76 -0
- package/lib/components/streaming-api-doc/streaming-api-doc.scss +23 -0
- package/lib/components/streaming-api-doc/streaming-api-doc.test.js +24 -0
- package/lib/components/tooltip/index.js +9 -0
- package/lib/components/tooltip/tooltip.js +17 -0
- package/lib/components/tooltip/tooltip.scss +16 -0
- package/lib/components/tooltip/tooltip.test.js +19 -0
- package/lib/components/visualization-list-menu-item/index.js +9 -0
- package/lib/components/visualization-list-menu-item/visualization-list-menu-item.js +53 -0
- package/lib/components/visualization-list-menu-item/visualization-list-menu-item.scss +21 -0
- package/lib/components/visualization-list-menu-item/visualization-list-menu-item.test.js +42 -0
- package/lib/components/visualization-save-menu-item/index.js +9 -0
- package/lib/components/visualization-save-menu-item/visualization-save-menu-item.js +101 -0
- package/lib/components/visualization-save-menu-item/visualization-save-menu-item.scss +37 -0
- package/lib/components/visualization-save-menu-item/visualization-save-menu-item.test.js +185 -0
- package/lib/components/visualizations/geojson/connector.js +29 -0
- package/lib/components/visualizations/geojson/geojson-visualization.js +151 -0
- package/lib/components/visualizations/geojson/geojson-visualization.scss +24 -0
- package/lib/components/visualizations/geojson/geojson-visualization.test.js +238 -0
- package/lib/components/visualizations/geojson/index.js +9 -0
- package/lib/pages/apikey-view/apiKey-view.test.js +204 -0
- package/lib/pages/apikey-view/apikey-view.js +166 -0
- package/lib/pages/apikey-view/apikey-view.scss +340 -0
- package/lib/pages/apikey-view/connector.js +31 -0
- package/lib/pages/apikey-view/index.js +9 -0
- package/lib/pages/chart-view/chart-view.js +92 -0
- package/lib/pages/chart-view/chart-view.scss +35 -0
- package/lib/pages/chart-view/chart-view.test.js +206 -0
- package/lib/pages/chart-view/connector.js +30 -0
- package/lib/pages/chart-view/index.js +9 -0
- package/lib/pages/dataset-detail-view/connector.js +38 -0
- package/lib/pages/dataset-detail-view/dataset-detail-view-connector.test.js +42 -0
- package/lib/pages/dataset-detail-view/dataset-detail-view.js +99 -0
- package/lib/pages/dataset-detail-view/dataset-detail-view.scss +190 -0
- package/lib/pages/dataset-detail-view/dataset-detail-view.test.js +305 -0
- package/lib/pages/dataset-detail-view/index.js +9 -0
- package/lib/pages/dataset-list-view/connector.js +30 -0
- package/lib/pages/dataset-list-view/dataset-list-view.js +132 -0
- package/lib/pages/dataset-list-view/dataset-list-view.scss +242 -0
- package/lib/pages/dataset-list-view/dataset-list-view.test.js +162 -0
- package/lib/pages/dataset-list-view/index.js +9 -0
- package/lib/pages/dataset-view/connector.js +55 -0
- package/lib/pages/dataset-view/dataset-view-connector.test.js +78 -0
- package/lib/pages/dataset-view/dataset-view.js +175 -0
- package/lib/pages/dataset-view/dataset-view.scss +95 -0
- package/lib/pages/dataset-view/dataset-view.test.js +157 -0
- package/lib/pages/dataset-view/index.js +9 -0
- package/lib/pages/login-view/connector.js +25 -0
- package/lib/pages/login-view/index.js +9 -0
- package/lib/pages/login-view/login-view.js +83 -0
- package/lib/pages/login-view/login-view.scss +62 -0
- package/lib/pages/login-view/login-view.test.js +23 -0
- package/lib/pages/oauth-error-view/index.js +9 -0
- package/lib/pages/oauth-error-view/oauth-error-view.js +25 -0
- package/lib/pages/oauth-error-view/oauth-error-view.scss +13 -0
- package/lib/pages/oauth-error-view/oauth-error-view.test.js +13 -0
- package/lib/pages/oauth-view/connector.js +22 -0
- package/lib/pages/oauth-view/index.js +9 -0
- package/lib/pages/oauth-view/oauth-view.js +124 -0
- package/lib/pages/oauth-view/oauth-view.scss +7 -0
- package/lib/pages/oauth-view/oauth-view.test.js +195 -0
- package/lib/pages/query-view/connector.js +40 -0
- package/lib/pages/query-view/index.js +9 -0
- package/lib/pages/query-view/query-view.js +80 -0
- package/lib/pages/query-view/query-view.scss +39 -0
- package/lib/pages/query-view/query-view.test.js +104 -0
- package/lib/pages/user-profile-view/connector.js +39 -0
- package/lib/pages/user-profile-view/index.js +9 -0
- package/lib/pages/user-profile-view/user-profile-view.js +154 -0
- package/lib/pages/user-profile-view/user-profile-view.scss +81 -0
- package/lib/pages/user-profile-view/user-profile-view.test.js +129 -0
- package/lib/pages/visualization-view/connector.js +52 -0
- package/lib/pages/visualization-view/index.js +9 -0
- package/lib/pages/visualization-view/visualization-view-connector.test.js +62 -0
- package/lib/pages/visualization-view/visualization-view.js +128 -0
- package/lib/pages/visualization-view/visualization-view.scss +115 -0
- package/lib/pages/visualization-view/visualization-view.test.js +188 -0
- package/lib/routes.js +18 -0
- package/lib/search-params/search-params-manager.js +171 -0
- package/lib/search-params/search-params-manager.test.js +490 -0
- package/lib/store/actions.js +428 -0
- package/lib/store/dataset-selectors.js +47 -0
- package/lib/store/dataset-selectors.test.js +154 -0
- package/lib/store/query-selectors.js +53 -0
- package/lib/store/query-selectors.test.js +153 -0
- package/lib/store/reducers/index.js +20 -0
- package/lib/store/reducers/query-reducer.js +52 -0
- package/lib/store/reducers/query-reducer.test.js +89 -0
- package/lib/store/reducers/reducers.js +196 -0
- package/lib/store/reducers/reducers.test.js +309 -0
- package/lib/store/reducers/visualization-reducer.js +167 -0
- package/lib/store/reducers/visualization-reducer.test.js +426 -0
- package/lib/store/sagas/api-invoker.js +79 -0
- package/lib/store/sagas/api-invoker.test.js +139 -0
- package/lib/store/sagas/apiKey-saga.js +81 -0
- package/lib/store/sagas/apiKey-saga.test.js +57 -0
- package/lib/store/sagas/dataset-download-saga.js +43 -0
- package/lib/store/sagas/dataset-list-saga.js +49 -0
- package/lib/store/sagas/dataset-list-saga.test.js +72 -0
- package/lib/store/sagas/dataset-preview-saga.js +44 -0
- package/lib/store/sagas/dataset-query-saga.js +43 -0
- package/lib/store/sagas/dataset-recommendation-saga.js +40 -0
- package/lib/store/sagas/dataset-saga.js +50 -0
- package/lib/store/sagas/freestyle-query-saga.js +127 -0
- package/lib/store/sagas/freestyle-query-saga.test.js +145 -0
- package/lib/store/sagas/index.js +44 -0
- package/lib/store/sagas/login-saga.js +85 -0
- package/lib/store/sagas/login-saga.test.js +84 -0
- package/lib/store/sagas/logout-saga.js +96 -0
- package/lib/store/sagas/oauth-saga.js +78 -0
- package/lib/store/sagas/oauth-saga.test.js +51 -0
- package/lib/store/sagas/process-login-saga.js +62 -0
- package/lib/store/sagas/process-login-saga.test.js +83 -0
- package/lib/store/sagas/visualization-saga.js +371 -0
- package/lib/store/sagas/visualization-saga.test.js +388 -0
- package/lib/store/selectors.js +83 -0
- package/lib/store/visualization-selectors.js +85 -0
- package/lib/store/visualization-selectors.test.js +195 -0
- package/lib/styles/mixins.scss +117 -0
- package/lib/styles/variables.scss +41 -0
- package/lib/utils/file-type-utils.js +18 -0
- package/lib/utils/file-type-utils.test.js +29 -0
- package/lib/utils/geojson-utils.js +70 -0
- package/lib/utils/geojson-utils.test.js +129 -0
- package/lib/utils/http-clients.js +218 -0
- package/lib/utils/http-clients.test.js +88 -0
- package/lib/utils/index.js +34 -0
- package/lib/utils/modified-date-string-builder.js +29 -0
- package/lib/utils/modified-date-string-builder.test.js +93 -0
- package/lib/utils/query-string-builder.js +38 -0
- package/lib/utils/query-string-builder.test.js +33 -0
- package/lib/utils/recommendation-utils.js +12 -0
- package/lib/utils/recommendation-utils.test.js +9 -0
- package/package.json +172 -0
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
import withSearchParamsManager, { SearchParamsManager, defaults } from './search-params-manager'
|
|
2
|
+
import { mount, shallow } from 'enzyme'
|
|
3
|
+
import { createStore, applyMiddleware } from 'redux'
|
|
4
|
+
import { Provider } from 'react-redux'
|
|
5
|
+
import { datasetSearch } from '../store/actions.js'
|
|
6
|
+
import React from 'react'
|
|
7
|
+
|
|
8
|
+
describe('SearchParamsManager', () => {
|
|
9
|
+
describe('property access', () => {
|
|
10
|
+
describe('all query params', () => {
|
|
11
|
+
it('returns all parameters with appropriate deserialization', () => {
|
|
12
|
+
const params = '?apiAccessible=false&page=9000'
|
|
13
|
+
const history = {
|
|
14
|
+
location: {
|
|
15
|
+
search: params
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const subject = new SearchParamsManager(history)
|
|
19
|
+
expect(subject.getParams()).toMatchObject({ apiAccessible: false, page: 9000 })
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('returns all the defaults if the query params are empty', () => {
|
|
23
|
+
const params = ''
|
|
24
|
+
const history = {
|
|
25
|
+
location: {
|
|
26
|
+
search: params
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const subject = new SearchParamsManager(history)
|
|
30
|
+
expect(subject.getParams()).toEqual({
|
|
31
|
+
apiAccessible: defaults.apiAccessible,
|
|
32
|
+
page: defaults.page,
|
|
33
|
+
sortOrder: defaults.sortOrder,
|
|
34
|
+
searchText: defaults.searchText,
|
|
35
|
+
facets: defaults.facets
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
describe('apiAccessible', () => {
|
|
41
|
+
it('returns apiAccessible', () => {
|
|
42
|
+
const params = '?apiAccessible=false'
|
|
43
|
+
const history = {
|
|
44
|
+
location: {
|
|
45
|
+
search: params
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const subject = new SearchParamsManager(history)
|
|
49
|
+
expect(subject.apiAccessible).toEqual(false)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('returns default apiAccessible if missing', () => {
|
|
53
|
+
const params = ''
|
|
54
|
+
const history = {
|
|
55
|
+
location: {
|
|
56
|
+
search: params
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const subject = new SearchParamsManager(history)
|
|
60
|
+
expect(subject.apiAccessible).toEqual(true)
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
describe('sortOrder', () => {
|
|
65
|
+
it('returns sort order', () => {
|
|
66
|
+
const params = '?sort=last_mod'
|
|
67
|
+
const history = {
|
|
68
|
+
location: {
|
|
69
|
+
search: params
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const subject = new SearchParamsManager(history)
|
|
73
|
+
expect(subject.sortOrder).toEqual('last_mod')
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('returns default sort order if missing', () => {
|
|
77
|
+
const params = ''
|
|
78
|
+
const history = {
|
|
79
|
+
location: {
|
|
80
|
+
search: params
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const subject = new SearchParamsManager(history)
|
|
84
|
+
expect(subject.sortOrder).toEqual('start')
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
describe('page', () => {
|
|
89
|
+
it('returns current page if integer', () => {
|
|
90
|
+
const params = '?page=9000'
|
|
91
|
+
const history = {
|
|
92
|
+
location: {
|
|
93
|
+
search: params
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const subject = new SearchParamsManager(history)
|
|
97
|
+
expect(subject.page).toEqual(9000)
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('returns first page if non-integer', () => {
|
|
101
|
+
const params = '?page=nine_thousand'
|
|
102
|
+
const history = {
|
|
103
|
+
location: {
|
|
104
|
+
search: params
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const subject = new SearchParamsManager(history)
|
|
108
|
+
expect(subject.page).toEqual(1)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('returns first page if missing', () => {
|
|
112
|
+
const params = '?other-stuff=things'
|
|
113
|
+
const history = {
|
|
114
|
+
location: {
|
|
115
|
+
search: params
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const subject = new SearchParamsManager(history)
|
|
119
|
+
expect(subject.page).toEqual(1)
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
describe('searchText', () => {
|
|
124
|
+
it('returns search text', () => {
|
|
125
|
+
const params = '?q=power%20level'
|
|
126
|
+
const history = {
|
|
127
|
+
location: {
|
|
128
|
+
search: params
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const subject = new SearchParamsManager(history)
|
|
132
|
+
expect(subject.searchText).toEqual('power level')
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
it('returns default search text if missing', () => {
|
|
136
|
+
const params = ''
|
|
137
|
+
const history = {
|
|
138
|
+
location: {
|
|
139
|
+
search: params
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const subject = new SearchParamsManager(history)
|
|
143
|
+
expect(subject.searchText).toEqual('')
|
|
144
|
+
})
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
describe('facets', () => {
|
|
148
|
+
it('returns currently applied facets', () => {
|
|
149
|
+
const paramsUnencoded = '?facets[organization][]=Ohio Geographically Referenced Information Program (OGRIP)&facets[organization][]=stuff&facets[keywords][]=Transportation'
|
|
150
|
+
const params = decodeURI(paramsUnencoded)
|
|
151
|
+
const history = {
|
|
152
|
+
location: {
|
|
153
|
+
search: params
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const subject = new SearchParamsManager(history)
|
|
157
|
+
expect(subject.facets).toEqual({
|
|
158
|
+
organization: ['Ohio Geographically Referenced Information Program (OGRIP)', 'stuff'],
|
|
159
|
+
keywords: ['Transportation']
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
it('returns empty facets if missing', () => {
|
|
164
|
+
const paramsUnencoded = '?other=stuff'
|
|
165
|
+
const params = decodeURI(paramsUnencoded)
|
|
166
|
+
const history = {
|
|
167
|
+
location: {
|
|
168
|
+
search: params
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const subject = new SearchParamsManager(history)
|
|
172
|
+
expect(subject.facets).toEqual({})
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it('returns empty facets if unparseable (a lot of times it will just give weird results instead of failing to parse)', () => {
|
|
176
|
+
const paramsUnencoded = '?facets organization]=Ohio Geographically Referenced Information Program (OGRIP)&facets[keywords=Transportation'
|
|
177
|
+
const params = decodeURI(paramsUnencoded)
|
|
178
|
+
const history = {
|
|
179
|
+
location: {
|
|
180
|
+
search: params
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const subject = new SearchParamsManager(history)
|
|
184
|
+
expect(subject.facets).toEqual({})
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
describe('updates', () => {
|
|
190
|
+
describe('apiAccessible', () => {
|
|
191
|
+
it('with a default flag, updates apiAccessible', () => {
|
|
192
|
+
const { historyPushSpy, history } = createFakeHistory('')
|
|
193
|
+
|
|
194
|
+
const subject = new SearchParamsManager(history)
|
|
195
|
+
subject.toggleApiAccessible()
|
|
196
|
+
|
|
197
|
+
expect(historyPushSpy).toHaveBeenCalledWith({
|
|
198
|
+
search: 'apiAccessible=false&page=1'
|
|
199
|
+
})
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
it('with a true flag, updates apiAccessible', () => {
|
|
203
|
+
const { historyPushSpy, history } = createFakeHistory('?apiAccessible=true')
|
|
204
|
+
|
|
205
|
+
const subject = new SearchParamsManager(history)
|
|
206
|
+
subject.toggleApiAccessible()
|
|
207
|
+
|
|
208
|
+
expect(historyPushSpy).toHaveBeenCalledWith({
|
|
209
|
+
search: 'apiAccessible=false&page=1'
|
|
210
|
+
})
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
it('with a false flag updates apiAccessible', () => {
|
|
214
|
+
const { historyPushSpy, history } = createFakeHistory('?apiAccessible=false&knuckles=true')
|
|
215
|
+
|
|
216
|
+
const subject = new SearchParamsManager(history)
|
|
217
|
+
subject.toggleApiAccessible()
|
|
218
|
+
|
|
219
|
+
expect(historyPushSpy).toHaveBeenCalledWith({
|
|
220
|
+
search: 'apiAccessible=true&knuckles=true&page=1'
|
|
221
|
+
})
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
it('resets the page number to 1', () => {
|
|
225
|
+
const { historyPushSpy, history } = createFakeHistory('?apiAccessible=true&page=5')
|
|
226
|
+
|
|
227
|
+
const subject = new SearchParamsManager(history)
|
|
228
|
+
subject.toggleApiAccessible()
|
|
229
|
+
|
|
230
|
+
expect(historyPushSpy).toHaveBeenCalledWith({
|
|
231
|
+
search: 'apiAccessible=false&page=1'
|
|
232
|
+
})
|
|
233
|
+
})
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
describe('sortOrder', () => {
|
|
237
|
+
it('with a default sort order, updates sort order', () => {
|
|
238
|
+
const { historyPushSpy, history } = createFakeHistory('')
|
|
239
|
+
|
|
240
|
+
const subject = new SearchParamsManager(history)
|
|
241
|
+
subject.updateSortOrder('last_mod')
|
|
242
|
+
|
|
243
|
+
expect(historyPushSpy).toHaveBeenCalledWith({
|
|
244
|
+
search: 'sort=last_mod'
|
|
245
|
+
})
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
it('with an existing sort order, updates sort order', () => {
|
|
249
|
+
const { historyPushSpy, history } = createFakeHistory('?sort=last_mod&knuckles=true')
|
|
250
|
+
|
|
251
|
+
const subject = new SearchParamsManager(history)
|
|
252
|
+
subject.updateSortOrder('name_asc')
|
|
253
|
+
|
|
254
|
+
expect(historyPushSpy).toHaveBeenCalledWith({
|
|
255
|
+
search: 'sort=name_asc&knuckles=true'
|
|
256
|
+
})
|
|
257
|
+
})
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
describe('page', () => {
|
|
261
|
+
it('with a default page number, updates page number', () => {
|
|
262
|
+
const { historyPushSpy, history } = createFakeHistory('')
|
|
263
|
+
|
|
264
|
+
const subject = new SearchParamsManager(history)
|
|
265
|
+
subject.updatePage(5)
|
|
266
|
+
|
|
267
|
+
expect(historyPushSpy).toHaveBeenCalledWith({
|
|
268
|
+
search: 'page=5'
|
|
269
|
+
})
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
it('with an existing search text, updates page number', () => {
|
|
273
|
+
const { historyPushSpy, history } = createFakeHistory('?page=1&knuckles=true')
|
|
274
|
+
|
|
275
|
+
const subject = new SearchParamsManager(history)
|
|
276
|
+
subject.updatePage(5)
|
|
277
|
+
|
|
278
|
+
expect(historyPushSpy).toHaveBeenCalledWith({
|
|
279
|
+
search: 'page=5&knuckles=true'
|
|
280
|
+
})
|
|
281
|
+
})
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
describe('searchText', () => {
|
|
285
|
+
it('with a default search text and existing sort value, updates search text but keeps sort value', () => {
|
|
286
|
+
const { historyPushSpy, history } = createFakeHistory('?sort=name_asc')
|
|
287
|
+
|
|
288
|
+
const subject = new SearchParamsManager(history)
|
|
289
|
+
subject.updateSearchText('sweet_query')
|
|
290
|
+
|
|
291
|
+
expect(historyPushSpy).toHaveBeenCalledWith({
|
|
292
|
+
search: 'sort=name_asc&q=sweet_query&page=1'
|
|
293
|
+
})
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
it('with a default search text and default sort, updates search text and sorts by relevance', () => {
|
|
297
|
+
const { historyPushSpy, history } = createFakeHistory('')
|
|
298
|
+
|
|
299
|
+
const subject = new SearchParamsManager(history)
|
|
300
|
+
subject.updateSearchText('sweet_query')
|
|
301
|
+
|
|
302
|
+
expect(historyPushSpy).toHaveBeenCalledWith({
|
|
303
|
+
search: 'q=sweet_query&page=1&sort=relevance'
|
|
304
|
+
})
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
it('with and existing search text and existing sort value, updates search text, but keeps sort value', () => {
|
|
308
|
+
const { historyPushSpy, history } = createFakeHistory('?q=the_world&knuckles=true&sort=name_asc')
|
|
309
|
+
|
|
310
|
+
const subject = new SearchParamsManager(history)
|
|
311
|
+
subject.updateSearchText('sweet_query')
|
|
312
|
+
|
|
313
|
+
expect(historyPushSpy).toHaveBeenCalledWith({
|
|
314
|
+
search: 'q=sweet_query&knuckles=true&sort=name_asc&page=1'
|
|
315
|
+
})
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
it('with an existing search text and default sort, updates search text and sorts by relevance', () => {
|
|
319
|
+
const { historyPushSpy, history } = createFakeHistory('?q=the_world&knuckles=true')
|
|
320
|
+
|
|
321
|
+
const subject = new SearchParamsManager(history)
|
|
322
|
+
subject.updateSearchText('sweet_query')
|
|
323
|
+
|
|
324
|
+
expect(historyPushSpy).toHaveBeenCalledWith({
|
|
325
|
+
search: 'q=sweet_query&knuckles=true&page=1&sort=relevance'
|
|
326
|
+
})
|
|
327
|
+
})
|
|
328
|
+
|
|
329
|
+
it('resets the page number to 1', () => {
|
|
330
|
+
const { historyPushSpy, history } = createFakeHistory('?q=the_world&page=5')
|
|
331
|
+
|
|
332
|
+
const subject = new SearchParamsManager(history)
|
|
333
|
+
subject.updateSearchText('sweet_query')
|
|
334
|
+
|
|
335
|
+
expect(historyPushSpy).toHaveBeenCalledWith({
|
|
336
|
+
search: 'q=sweet_query&page=1&sort=relevance'
|
|
337
|
+
})
|
|
338
|
+
})
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
describe('facets', () => {
|
|
342
|
+
it('with default facets (none), updates facets', () => {
|
|
343
|
+
const { historyPushSpy, history } = createFakeHistory('')
|
|
344
|
+
|
|
345
|
+
const subject = new SearchParamsManager(history)
|
|
346
|
+
subject.toggleFacet('organization', 'SCOS')
|
|
347
|
+
|
|
348
|
+
expect(historyPushSpy).toHaveBeenCalledWith({
|
|
349
|
+
search: encodeURI('facets[organization][]=SCOS&page=1')
|
|
350
|
+
})
|
|
351
|
+
})
|
|
352
|
+
|
|
353
|
+
it('with existing facets for the name (organization), toggles facet', () => {
|
|
354
|
+
const { historyPushSpy, history } = createFakeHistory('?facets%5Borganization%5D%5B%5D=SCOS')
|
|
355
|
+
|
|
356
|
+
const subject = new SearchParamsManager(history)
|
|
357
|
+
subject.toggleFacet('organization', 'SCOS')
|
|
358
|
+
|
|
359
|
+
expect(historyPushSpy).toHaveBeenCalledWith({ search: 'page=1' })
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
it('with existing facets for the name (keywords), add new facets', () => {
|
|
363
|
+
const { historyPushSpy, history } = createFakeHistory('?facets%5Bkeywords%5D%5B%5D=Ohio')
|
|
364
|
+
|
|
365
|
+
const subject = new SearchParamsManager(history)
|
|
366
|
+
subject.toggleFacet('keywords', 'Transportation')
|
|
367
|
+
|
|
368
|
+
expect(historyPushSpy).toHaveBeenCalledWith({
|
|
369
|
+
search: encodeURI('facets[keywords][]=Ohio&facets[keywords][]=Transportation&page=1')
|
|
370
|
+
})
|
|
371
|
+
})
|
|
372
|
+
|
|
373
|
+
it('with existing facets for the other names (organization), add new facets and keeps others', () => {
|
|
374
|
+
const { historyPushSpy, history } = createFakeHistory('?facets%5Bkeywords%5D%5B%5D=Ohio&facets%5Borganization%5D%5B%5D=SCOS')
|
|
375
|
+
|
|
376
|
+
const subject = new SearchParamsManager(history)
|
|
377
|
+
subject.toggleFacet('keywords', 'Ohio')
|
|
378
|
+
|
|
379
|
+
expect(historyPushSpy).toHaveBeenCalledWith({
|
|
380
|
+
search: encodeURI('facets[organization][]=SCOS&page=1')
|
|
381
|
+
})
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
it('resets the page number to 1', () => {
|
|
385
|
+
const { historyPushSpy, history } = createFakeHistory('?facets%5Bkeywords%5D%5B%5D=Ohio&facets%5Borganization%5D%5B%5D=SCOS&page=5')
|
|
386
|
+
|
|
387
|
+
const subject = new SearchParamsManager(history)
|
|
388
|
+
subject.toggleFacet('keywords', 'Ohio')
|
|
389
|
+
|
|
390
|
+
expect(historyPushSpy).toHaveBeenCalledWith({
|
|
391
|
+
search: encodeURI('facets[organization][]=SCOS&page=1')
|
|
392
|
+
})
|
|
393
|
+
})
|
|
394
|
+
})
|
|
395
|
+
})
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
describe('withSearchParamsManager', () => {
|
|
399
|
+
const reducer = (state = [], action) => {
|
|
400
|
+
return [...state, action]
|
|
401
|
+
}
|
|
402
|
+
let store, Rapper
|
|
403
|
+
|
|
404
|
+
beforeEach(() => {
|
|
405
|
+
const wrappedComponent = (props) => {
|
|
406
|
+
return <wrapped-component {...props} />
|
|
407
|
+
}
|
|
408
|
+
store = createStore(reducer)
|
|
409
|
+
Rapper = withSearchParamsManager(wrappedComponent)
|
|
410
|
+
})
|
|
411
|
+
|
|
412
|
+
it('injects an instance of the query params manager into the wrapped component', () => {
|
|
413
|
+
const subject = mount(
|
|
414
|
+
<TestableProvider store={store}>
|
|
415
|
+
<Rapper history={{ location: {} }} />
|
|
416
|
+
</TestableProvider>
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
expect(subject.find('wrapped-component').prop('searchParamsManager')).toBeInstanceOf(SearchParamsManager)
|
|
420
|
+
})
|
|
421
|
+
|
|
422
|
+
it('dispatches search on the initial render', () => {
|
|
423
|
+
const subject = mount(
|
|
424
|
+
<TestableProvider store={store}>
|
|
425
|
+
<Rapper history={{ location: { search: '?apiAccessible=false' } }} />
|
|
426
|
+
</TestableProvider>
|
|
427
|
+
)
|
|
428
|
+
|
|
429
|
+
expect(store.getState()).toContainEqual(datasetSearch(expect.objectContaining({ apiAccessible: false })))
|
|
430
|
+
})
|
|
431
|
+
|
|
432
|
+
it('dispatches search on string updates', () => {
|
|
433
|
+
const subject = mount(
|
|
434
|
+
<TestableProvider store={store}>
|
|
435
|
+
<Rapper history={{ location: { search: '?apiAccessible=false' } }} />
|
|
436
|
+
</TestableProvider>
|
|
437
|
+
)
|
|
438
|
+
|
|
439
|
+
expect(store.getState()).toContainEqual(datasetSearch(expect.objectContaining({ apiAccessible: false })))
|
|
440
|
+
|
|
441
|
+
subject.setProps({ history: { location: { search: '?apiAccessible=true' } } })
|
|
442
|
+
|
|
443
|
+
expect(store.getState()).toContainEqual(datasetSearch(expect.objectContaining({ apiAccessible: true })))
|
|
444
|
+
})
|
|
445
|
+
|
|
446
|
+
it('refocuses any cached element after the search', () => {
|
|
447
|
+
let fakeElementId = 'fakeElement'
|
|
448
|
+
let fakeElement = {focus: jest.fn()}
|
|
449
|
+
sessionStorage.setItem('cachedFocusedElement', fakeElementId)
|
|
450
|
+
document.getElementById = jest.fn(() => fakeElement)
|
|
451
|
+
|
|
452
|
+
const subject = mount(
|
|
453
|
+
<TestableProvider store={store}>
|
|
454
|
+
<Rapper history={{ location: { search: '?apiAccessible=false' } }} />
|
|
455
|
+
</TestableProvider>)
|
|
456
|
+
|
|
457
|
+
expect(fakeElement.focus).toHaveBeenCalledTimes(1)
|
|
458
|
+
})
|
|
459
|
+
|
|
460
|
+
it('does not dispatch search on other updates', () => {
|
|
461
|
+
const subject = mount(
|
|
462
|
+
<TestableProvider store={store}>
|
|
463
|
+
<Rapper history={{ location: { search: '?apiAccessible=false' } }} />
|
|
464
|
+
</TestableProvider>
|
|
465
|
+
)
|
|
466
|
+
|
|
467
|
+
expect(store.getState()).toContainEqual(datasetSearch(expect.objectContaining({ apiAccessible: false })))
|
|
468
|
+
|
|
469
|
+
subject.setProps({ otherThing: 'stuff' })
|
|
470
|
+
|
|
471
|
+
expect(store.getState().pop()).toEqual(datasetSearch(expect.objectContaining({ apiAccessible: false })))
|
|
472
|
+
})
|
|
473
|
+
})
|
|
474
|
+
|
|
475
|
+
function createFakeHistory (search) {
|
|
476
|
+
const historyPushSpy = jest.fn()
|
|
477
|
+
const history = {
|
|
478
|
+
push: historyPushSpy,
|
|
479
|
+
location: { search }
|
|
480
|
+
}
|
|
481
|
+
return { historyPushSpy, history }
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function TestableProvider ({ children, store, ...props }) {
|
|
485
|
+
return (
|
|
486
|
+
<Provider store={store}>
|
|
487
|
+
{React.cloneElement(children, { ...props })}
|
|
488
|
+
</Provider>
|
|
489
|
+
)
|
|
490
|
+
}
|