Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
amundsen_dev
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Surendar Reddy Mangannagari
amundsen_dev
Commits
ce5096dd
Unverified
Commit
ce5096dd
authored
May 29, 2019
by
Ryan Lieu
Committed by
GitHub
May 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
url to state fixes (#171)
parent
523e0e71
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
239 additions
and
57 deletions
+239
-57
index.tsx
...sen_application/static/js/components/SearchPage/index.tsx
+28
-13
index.spec.tsx
...tion/static/js/components/SearchPage/tests/index.spec.tsx
+201
-41
reducer.ts
amundsen_application/static/js/ducks/search/reducer.ts
+10
-3
No files found.
amundsen_application/static/js/components/SearchPage/index.tsx
View file @
ce5096dd
...
@@ -4,6 +4,7 @@ import { bindActionCreators } from 'redux';
...
@@ -4,6 +4,7 @@ import { bindActionCreators } from 'redux';
import
*
as
DocumentTitle
from
'react-document-title'
;
import
*
as
DocumentTitle
from
'react-document-title'
;
import
*
as
qs
from
'simple-query-string'
;
import
*
as
qs
from
'simple-query-string'
;
import
Pagination
from
'react-js-pagination'
;
import
Pagination
from
'react-js-pagination'
;
import
{
RouteComponentProps
}
from
'react-router'
;
import
SearchBar
from
'./SearchBar'
;
import
SearchBar
from
'./SearchBar'
;
import
SearchList
from
'./SearchList'
;
import
SearchList
from
'./SearchList'
;
...
@@ -48,7 +49,7 @@ export interface StateFromProps {
...
@@ -48,7 +49,7 @@ export interface StateFromProps {
searchTerm
:
string
;
searchTerm
:
string
;
popularTables
:
TableResource
[];
popularTables
:
TableResource
[];
tables
:
TableSearchResults
;
tables
:
TableSearchResults
;
dashboards
:
DashboardSearchResults
dashboards
:
DashboardSearchResults
;
users
:
UserSearchResults
;
users
:
UserSearchResults
;
}
}
...
@@ -58,7 +59,7 @@ export interface DispatchFromProps {
...
@@ -58,7 +59,7 @@ export interface DispatchFromProps {
getPopularTables
:
()
=>
GetPopularTablesRequest
;
getPopularTables
:
()
=>
GetPopularTablesRequest
;
}
}
export
type
SearchPageProps
=
StateFromProps
&
DispatchFromProps
;
export
type
SearchPageProps
=
StateFromProps
&
DispatchFromProps
&
RouteComponentProps
<
any
>
;
interface
SearchPageState
{
interface
SearchPageState
{
selectedTab
:
ResourceType
;
selectedTab
:
ResourceType
;
...
@@ -77,17 +78,25 @@ export class SearchPage extends React.Component<SearchPageProps, SearchPageState
...
@@ -77,17 +78,25 @@ export class SearchPage extends React.Component<SearchPageProps, SearchPageState
componentDidMount
()
{
componentDidMount
()
{
this
.
props
.
getPopularTables
();
this
.
props
.
getPopularTables
();
const
params
=
qs
.
parse
(
this
.
props
.
location
.
search
);
const
params
=
qs
.
parse
(
window
.
location
.
search
);
const
{
searchTerm
,
pageIndex
,
selectedTab
}
=
params
;
const
{
searchTerm
,
pageIndex
,
selectedTab
}
=
params
;
const
{
term
,
index
,
currentTab
}
=
this
.
getSanitizedUrlParams
(
searchTerm
,
pageIndex
,
selectedTab
);
const
currentTab
=
this
.
getSelectedTabByResourceType
(
selectedTab
);
this
.
setState
({
selectedTab
:
currentTab
});
this
.
setState
({
selectedTab
:
currentTab
});
if
(
searchTerm
&&
searchTerm
.
length
>
0
)
{
if
(
term
!==
""
)
{
const
index
=
pageIndex
||
0
;
this
.
props
.
searchAll
(
term
,
this
.
createSearchOptions
(
index
,
currentTab
));
this
.
props
.
searchAll
(
searchTerm
,
this
.
createSearchOptions
(
index
,
currentTab
));
if
(
currentTab
!==
selectedTab
||
pageIndex
!==
index
)
{
// Update the page URL with validated parameters.
this
.
updatePageUrl
(
term
,
currentTab
,
index
);
this
.
updatePageUrl
(
searchTerm
,
currentTab
,
index
);
}
}
}
componentDidUpdate
(
prevProps
)
{
if
(
this
.
props
.
location
.
search
!==
prevProps
.
location
.
search
)
{
const
params
=
qs
.
parse
(
this
.
props
.
location
.
search
);
const
{
searchTerm
,
pageIndex
,
selectedTab
}
=
params
;
const
{
term
,
index
,
currentTab
}
=
this
.
getSanitizedUrlParams
(
searchTerm
,
pageIndex
,
selectedTab
);
this
.
setState
({
selectedTab
:
currentTab
});
this
.
props
.
searchAll
(
term
,
this
.
createSearchOptions
(
index
,
currentTab
));
}
}
}
}
...
@@ -110,6 +119,13 @@ export class SearchPage extends React.Component<SearchPageProps, SearchPageState
...
@@ -110,6 +119,13 @@ export class SearchPage extends React.Component<SearchPageProps, SearchPageState
};
};
};
};
getSanitizedUrlParams
=
(
searchTerm
:
string
,
pageIndex
:
number
,
selectedTab
:
ResourceType
)
=>
{
const
currentTab
=
this
.
getSelectedTabByResourceType
(
selectedTab
);
const
index
=
pageIndex
||
0
;
const
term
=
searchTerm
?
searchTerm
:
""
;
return
{
term
,
index
,
currentTab
};
};
getPageIndexByResourceType
=
(
tab
:
ResourceType
):
number
=>
{
getPageIndexByResourceType
=
(
tab
:
ResourceType
):
number
=>
{
switch
(
tab
)
{
switch
(
tab
)
{
case
ResourceType
.
table
:
case
ResourceType
.
table
:
...
@@ -123,7 +139,6 @@ export class SearchPage extends React.Component<SearchPageProps, SearchPageState
...
@@ -123,7 +139,6 @@ export class SearchPage extends React.Component<SearchPageProps, SearchPageState
};
};
onSearchBarSubmit
=
(
searchTerm
:
string
):
void
=>
{
onSearchBarSubmit
=
(
searchTerm
:
string
):
void
=>
{
this
.
props
.
searchAll
(
searchTerm
);
this
.
updatePageUrl
(
searchTerm
,
this
.
state
.
selectedTab
,
0
);
this
.
updatePageUrl
(
searchTerm
,
this
.
state
.
selectedTab
,
0
);
};
};
...
@@ -141,7 +156,7 @@ export class SearchPage extends React.Component<SearchPageProps, SearchPageState
...
@@ -141,7 +156,7 @@ export class SearchPage extends React.Component<SearchPageProps, SearchPageState
updatePageUrl
=
(
searchTerm
:
string
,
tab
:
ResourceType
,
pageIndex
:
number
):
void
=>
{
updatePageUrl
=
(
searchTerm
:
string
,
tab
:
ResourceType
,
pageIndex
:
number
):
void
=>
{
const
pathName
=
`/search?searchTerm=
${
searchTerm
}
&selectedTab=
${
tab
}
&pageIndex=
${
pageIndex
}
`
;
const
pathName
=
`/search?searchTerm=
${
searchTerm
}
&selectedTab=
${
tab
}
&pageIndex=
${
pageIndex
}
`
;
window
.
history
.
pushState
({},
''
,
`
${
window
.
location
.
origin
}${
pathName
}
`
);
this
.
props
.
history
.
push
(
pathName
);
};
};
renderPopularTables
=
()
=>
{
renderPopularTables
=
()
=>
{
...
...
amundsen_application/static/js/components/SearchPage/tests/index.spec.tsx
View file @
ce5096dd
...
@@ -32,7 +32,6 @@ import globalState from 'fixtures/globalState';
...
@@ -32,7 +32,6 @@ import globalState from 'fixtures/globalState';
describe
(
'SearchPage'
,
()
=>
{
describe
(
'SearchPage'
,
()
=>
{
const
setStateSpy
=
jest
.
spyOn
(
SearchPage
.
prototype
,
'setState'
);
const
setStateSpy
=
jest
.
spyOn
(
SearchPage
.
prototype
,
'setState'
);
const
setup
=
(
propOverrides
?:
Partial
<
SearchPageProps
>
)
=>
{
const
setup
=
(
propOverrides
?:
Partial
<
SearchPageProps
>
)
=>
{
const
props
:
SearchPageProps
=
{
const
props
:
SearchPageProps
=
{
searchTerm
:
globalState
.
search
.
search_term
,
searchTerm
:
globalState
.
search
.
search_term
,
...
@@ -43,7 +42,28 @@ describe('SearchPage', () => {
...
@@ -43,7 +42,28 @@ describe('SearchPage', () => {
searchAll
:
jest
.
fn
(),
searchAll
:
jest
.
fn
(),
searchResource
:
jest
.
fn
(),
searchResource
:
jest
.
fn
(),
getPopularTables
:
jest
.
fn
(),
getPopularTables
:
jest
.
fn
(),
...
propOverrides
history
:
{
length
:
2
,
action
:
"POP"
,
location
:
jest
.
fn
()
as
any
,
push
:
jest
.
fn
(),
replace
:
jest
.
fn
(),
go
:
jest
.
fn
(),
goBack
:
jest
.
fn
(),
goForward
:
jest
.
fn
(),
block
:
jest
.
fn
(),
createHref
:
jest
.
fn
(),
listen
:
jest
.
fn
(),
},
location
:
{
search
:
'/search?searchTerm=testName&selectedTab=table&pageIndex=1'
,
pathname
:
'mockstr'
,
state
:
jest
.
fn
(),
hash
:
'mockstr'
,
},
match
:
jest
.
fn
()
as
any
,
staticContext
:
jest
.
fn
()
as
any
,
...
propOverrides
,
};
};
const
wrapper
=
shallow
<
SearchPage
>
(<
SearchPage
{
...
props
}
/>)
const
wrapper
=
shallow
<
SearchPage
>
(<
SearchPage
{
...
props
}
/>)
return
{
props
,
wrapper
};
return
{
props
,
wrapper
};
...
@@ -59,26 +79,31 @@ describe('SearchPage', () => {
...
@@ -59,26 +79,31 @@ describe('SearchPage', () => {
describe
(
'componentDidMount'
,
()
=>
{
describe
(
'componentDidMount'
,
()
=>
{
let
props
;
let
props
;
let
wrapper
;
let
wrapper
;
let
mockResourceType
;
let
mockSearchOptions
;
let
mockSearchOptions
;
let
mockSanitizedUrlParams
;
let
createSearchOptionsSpy
;
let
createSearchOptionsSpy
;
let
getS
electedTabByResourceType
Spy
;
let
getS
anitizedUrlParams
Spy
;
let
searchAllSpy
;
let
searchAllSpy
;
let
updatePageUrlSpy
;
let
updatePageUrlSpy
;
beforeAll
(()
=>
{
beforeAll
(()
=>
{
window
.
history
.
pushState
({},
''
,
'/search?searchTerm=testName&selectedTab=table&pageIndex=1'
);
const
setupResult
=
setup
({
location
:
{
const
setupResult
=
setup
();
search
:
'/search?searchTerm=testName&selectedTab=table&pageIndex=1'
,
pathname
:
'mockstr'
,
state
:
jest
.
fn
(),
hash
:
'mockstr'
,
}
});
props
=
setupResult
.
props
;
props
=
setupResult
.
props
;
wrapper
=
setupResult
.
wrapper
;
wrapper
=
setupResult
.
wrapper
;
mock
ResourceType
=
ResourceType
.
user
;
mock
SanitizedUrlParams
=
{
'term'
:
'testName'
,
' index'
:
1
,
'currentTab'
:
'table'
}
;
getS
electedTabByResourceTypeSpy
=
jest
.
spyOn
(
wrapper
.
instance
(),
'getSelectedTabByResourceType
'
).
mockImplementation
(()
=>
{
getS
anitizedUrlParamsSpy
=
jest
.
spyOn
(
wrapper
.
instance
(),
'getSanitizedUrlParams
'
).
mockImplementation
(()
=>
{
return
mock
ResourceType
;
return
mock
SanitizedUrlParams
;
});
});
mockSearchOptions
=
{
'dashboardIndex'
:
0
,
'tableIndex'
:
0
,
'userIndex'
:
1
};
mockSearchOptions
=
{
'dashboardIndex'
:
0
,
'tableIndex'
:
0
,
'userIndex'
:
1
};
createSearchOptionsSpy
=
jest
.
spyOn
(
wrapper
.
instance
(),
'createSearchOptions'
).
mockImplementation
(()
=>
{
createSearchOptionsSpy
=
jest
.
spyOn
(
wrapper
.
instance
(),
'createSearchOptions'
).
mockImplementation
(()
=>
{
return
mockSearchOptions
;
return
mockSearchOptions
;
});
});
...
@@ -93,32 +118,57 @@ describe('SearchPage', () => {
...
@@ -93,32 +118,57 @@ describe('SearchPage', () => {
expect
(
props
.
getPopularTables
).
toHaveBeenCalled
();
expect
(
props
.
getPopularTables
).
toHaveBeenCalled
();
});
});
it
(
'calls getSelectedTabByResourceType with correct value'
,
()
=>
{
it
(
'calls setState'
,
()
=>
{
expect
(
getSelectedTabByResourceTypeSpy
).
toHaveBeenCalledWith
(
'table'
);
expect
(
setStateSpy
).
toHaveBeenCalledWith
({
selectedTab
:
mockSanitizedUrlParams
.
currentTab
});
});
it
(
'calls setState with result of getSelectedTabByResourceType'
,
()
=>
{
expect
(
setStateSpy
).
toHaveBeenCalledWith
({
selectedTab
:
mockResourceType
});
});
});
describe
(
'when searchTerm in params is valid'
,
()
=>
{
describe
(
'when searchTerm in params is valid'
,
()
=>
{
beforeAll
(()
=>
{
updatePageUrlSpy
.
mockClear
();
const
{
props
,
wrapper
}
=
setup
({
location
:
{
search
:
'/search?searchTerm=testName&selectedTab=table&pageIndex=1'
,
pathname
:
'mockstr'
,
state
:
jest
.
fn
(),
hash
:
'mockstr'
,
}
});
updatePageUrlSpy
=
jest
.
spyOn
(
wrapper
.
instance
(),
'updatePageUrl'
);
wrapper
.
instance
().
componentDidMount
();
});
it
(
'calls searchAll'
,
()
=>
{
it
(
'calls searchAll'
,
()
=>
{
expect
(
searchAllSpy
).
toHaveBeenCalledWith
(
'testName'
,
mockSearchOptions
);
expect
(
searchAllSpy
).
toHaveBeenCalledWith
(
mockSanitizedUrlParams
.
term
,
mockSearchOptions
);
});
});
it
(
'
calls updatePageUrl
'
,
()
=>
{
it
(
'
does not call updateURL
'
,
()
=>
{
expect
(
updatePageUrlSpy
).
toHaveBeenCalledWith
(
'testName'
,
mockResourceType
,
'1'
);
expect
(
updatePageUrlSpy
).
not
.
toHaveBeenCalled
(
);
});
});
});
});
describe
(
'when pageIndex in params is undefined'
,
()
=>
{
describe
(
'when pageIndex in params is undefined'
,
()
=>
{
let
mockSanitizedUrlParams
;
let
getSanitizedUrlParamsSpy
;
let
updatePageUrlSpy
;
beforeAll
(()
=>
{
beforeAll
(()
=>
{
updatePageUrlSpy
.
mockClear
();
const
{
props
,
wrapper
}
=
setup
({
window
.
history
.
pushState
({},
''
,
'/search?searchTerm=testName'
);
location
:
{
search
:
'/search?searchTerm=testName'
,
pathname
:
'mockstr'
,
state
:
jest
.
fn
(),
hash
:
'mockstr'
,
}
});
mockSanitizedUrlParams
=
{
'term'
:
'testName'
,
' index'
:
0
,
'currentTab'
:
'table'
};
getSanitizedUrlParamsSpy
=
jest
.
spyOn
(
wrapper
.
instance
(),
'getSanitizedUrlParams'
).
mockImplementation
(()
=>
{
return
mockSanitizedUrlParams
;
});
updatePageUrlSpy
=
jest
.
spyOn
(
wrapper
.
instance
(),
'updatePageUrl'
);
wrapper
.
instance
().
componentDidMount
();
wrapper
.
instance
().
componentDidMount
();
});
});
it
(
'uses 0 as pageIndex'
,
()
=>
{
it
(
'uses 0 as pageIndex'
,
()
=>
{
expect
(
updatePageUrlSpy
).
toHaveBeenCalledWith
(
'testName'
,
mockResourceType
,
0
);
expect
(
updatePageUrlSpy
).
toHaveBeenCalledWith
(
mockSanitizedUrlParams
.
term
,
mockSanitizedUrlParams
.
currentTab
,
mockSanitizedUrlParams
.
index
);
});
});
});
});
...
@@ -126,7 +176,15 @@ describe('SearchPage', () => {
...
@@ -126,7 +176,15 @@ describe('SearchPage', () => {
beforeAll
(()
=>
{
beforeAll
(()
=>
{
searchAllSpy
.
mockClear
();
searchAllSpy
.
mockClear
();
updatePageUrlSpy
.
mockClear
();
updatePageUrlSpy
.
mockClear
();
window
.
history
.
pushState
({},
''
,
'/search?selectedTab=table&pageIndex=1'
);
const
{
props
,
wrapper
}
=
setup
({
location
:
{
search
:
'/search?selectedTab=table&pageIndex=1'
,
pathname
:
'mockstr'
,
state
:
jest
.
fn
(),
hash
:
'mockstr'
,
}
});
updatePageUrlSpy
=
jest
.
spyOn
(
wrapper
.
instance
(),
'updatePageUrl'
);
wrapper
.
instance
().
componentDidMount
();
wrapper
.
instance
().
componentDidMount
();
});
});
it
(
'does not call searchAll'
,
()
=>
{
it
(
'does not call searchAll'
,
()
=>
{
...
@@ -142,7 +200,15 @@ describe('SearchPage', () => {
...
@@ -142,7 +200,15 @@ describe('SearchPage', () => {
beforeAll
(()
=>
{
beforeAll
(()
=>
{
searchAllSpy
.
mockClear
();
searchAllSpy
.
mockClear
();
updatePageUrlSpy
.
mockClear
();
updatePageUrlSpy
.
mockClear
();
window
.
history
.
pushState
({},
''
,
`/search?searchTerm=&selectedTab=table&pageIndex=1`
);
const
{
props
,
wrapper
}
=
setup
({
location
:
{
search
:
'/search?searchTerm=&selectedTab=table&pageIndex=1'
,
pathname
:
'mockstr'
,
state
:
jest
.
fn
(),
hash
:
'mockstr'
,
}
});
updatePageUrlSpy
=
jest
.
spyOn
(
wrapper
.
instance
(),
'updatePageUrl'
);
wrapper
.
instance
().
componentDidMount
();
wrapper
.
instance
().
componentDidMount
();
});
});
it
(
'does not call searchAll'
,
()
=>
{
it
(
'does not call searchAll'
,
()
=>
{
...
@@ -155,14 +221,114 @@ describe('SearchPage', () => {
...
@@ -155,14 +221,114 @@ describe('SearchPage', () => {
});
});
afterAll
(()
=>
{
afterAll
(()
=>
{
getSelectedTabByResourceTypeSpy
.
mockRestore
();
createSearchOptionsSpy
.
mockRestore
();
createSearchOptionsSpy
.
mockRestore
();
});
});
});
});
describe
(
'componentDidUpdate'
,
()
=>
{
let
props
;
let
wrapper
;
let
searchAllSpy
;
let
mockSearchOptions
;
let
mockSanitizedUrlParams
;
let
createSearchOptionsSpy
;
let
getSanitizedUrlParamsSpy
;
beforeAll
(()
=>
{
const
setupResult
=
setup
({
location
:
{
search
:
'/search?searchTerm=current&selectedTab=table&pageIndex=0'
,
pathname
:
'mockstr'
,
state
:
jest
.
fn
(),
hash
:
'mockstr'
,
}
});
props
=
setupResult
.
props
;
wrapper
=
setupResult
.
wrapper
;
mockSanitizedUrlParams
=
{
'term'
:
'current'
,
' index'
:
0
,
'currentTab'
:
'table'
};
getSanitizedUrlParamsSpy
=
jest
.
spyOn
(
wrapper
.
instance
(),
'getSanitizedUrlParams'
).
mockImplementation
(()
=>
{
return
mockSanitizedUrlParams
;
});
mockSearchOptions
=
{
'dashboardIndex'
:
0
,
'tableIndex'
:
1
,
'userIndex'
:
0
};
createSearchOptionsSpy
=
jest
.
spyOn
(
wrapper
.
instance
(),
'createSearchOptions'
).
mockImplementation
(()
=>
{
return
mockSearchOptions
;
});
searchAllSpy
=
jest
.
spyOn
(
props
,
'searchAll'
);
setStateSpy
.
mockClear
();
const
mockPrevProps
=
{
location
:
{
search
:
'/search?searchTerm=previous&selectedTab=table&pageIndex=0'
,
pathname
:
'mockstr'
,
state
:
jest
.
fn
(),
hash
:
'mockstr'
,
}
};
wrapper
.
instance
().
componentDidUpdate
(
mockPrevProps
);
});
it
(
'calls setState'
,
()
=>
{
expect
(
setStateSpy
).
toHaveBeenCalledWith
({
selectedTab
:
ResourceType
.
table
});
});
it
(
'calls searchAll'
,
()
=>
{
expect
(
searchAllSpy
).
toHaveBeenCalledWith
(
mockSanitizedUrlParams
.
term
,
mockSearchOptions
);
});
});
describe
(
'getSanitizedUrlParams'
,
()
=>
{
let
props
;
let
wrapper
;
let
getSelectedTabByResourceTypeSpy
;
let
mockSelectedTab
;
beforeAll
(()
=>
{
const
setupResult
=
setup
({
location
:
{
search
:
'/search?searchTerm=current&selectedTab=table&pageIndex=0'
,
pathname
:
'mockstr'
,
state
:
jest
.
fn
(),
hash
:
'mockstr'
,
}
});
props
=
setupResult
.
props
;
wrapper
=
setupResult
.
wrapper
;
const
mockResourceType
=
ResourceType
.
table
;
getSelectedTabByResourceTypeSpy
=
jest
.
spyOn
(
wrapper
.
instance
(),
'getSelectedTabByResourceType'
).
mockImplementation
(()
=>
{
return
mockResourceType
;
});
mockSelectedTab
=
ResourceType
.
table
;
wrapper
.
instance
().
getSanitizedUrlParams
(
'current'
,
0
,
mockSelectedTab
)
});
it
(
'calls getSelectedTabByResourceType with correct value'
,
()
=>
{
expect
(
getSelectedTabByResourceTypeSpy
).
toHaveBeenCalledWith
(
mockSelectedTab
);
});
it
(
'output of getSanitizedUrlParams is expected'
,
()
=>
{
const
expected
=
{
'term'
:
'current'
,
'index'
:
0
,
'currentTab'
:
ResourceType
.
table
};
expect
(
wrapper
.
instance
().
getSanitizedUrlParams
(
'current'
,
0
,
ResourceType
.
table
)).
toEqual
(
expected
);
});
it
(
'output of getSanitizedUrlParams is expected for undefined vars'
,
()
=>
{
const
expected
=
{
'term'
:
''
,
'index'
:
0
,
'currentTab'
:
ResourceType
.
table
};
expect
(
wrapper
.
instance
().
getSanitizedUrlParams
(
undefined
,
undefined
,
ResourceType
.
table
)).
toEqual
(
expected
);
});
});
describe
(
'getSelectedTabByResourceType'
,
()
=>
{
describe
(
'getSelectedTabByResourceType'
,
()
=>
{
let
props
;
let
props
;
let
wrapper
;
let
wrapper
;
beforeAll
(()
=>
{
beforeAll
(()
=>
{
const
setupResult
=
setup
();
const
setupResult
=
setup
();
props
=
setupResult
.
props
;
props
=
setupResult
.
props
;
...
@@ -228,9 +394,9 @@ describe('SearchPage', () => {
...
@@ -228,9 +394,9 @@ describe('SearchPage', () => {
let
wrapper
;
let
wrapper
;
beforeAll
(()
=>
{
beforeAll
(()
=>
{
const
setupResult
=
setup
({
const
setupResult
=
setup
({
dashboards
:
{
...
globalState
.
search
.
dashboards
,
page_index
:
1
},
dashboards
:
{
...
globalState
.
search
.
dashboards
,
page_index
:
1
},
tables
:
{
...
globalState
.
search
.
tables
,
page_index
:
2
},
tables
:
{
...
globalState
.
search
.
tables
,
page_index
:
2
},
users
:
{
...
globalState
.
search
.
users
,
page_index
:
3
},
users
:
{
...
globalState
.
search
.
users
,
page_index
:
3
},
});
});
props
=
setupResult
.
props
;
props
=
setupResult
.
props
;
wrapper
=
setupResult
.
wrapper
;
wrapper
=
setupResult
.
wrapper
;
...
@@ -258,23 +424,17 @@ describe('SearchPage', () => {
...
@@ -258,23 +424,17 @@ describe('SearchPage', () => {
let
props
;
let
props
;
let
wrapper
;
let
wrapper
;
let
searchAllSpy
;
let
updatePageUrlSpy
;
let
updatePageUrlSpy
;
beforeAll
(()
=>
{
beforeAll
(()
=>
{
const
setupResult
=
setup
();
const
setupResult
=
setup
();
props
=
setupResult
.
props
;
props
=
setupResult
.
props
;
wrapper
=
setupResult
.
wrapper
;
wrapper
=
setupResult
.
wrapper
;
searchAllSpy
=
jest
.
spyOn
(
props
,
'searchAll'
);
updatePageUrlSpy
=
jest
.
spyOn
(
wrapper
.
instance
(),
'updatePageUrl'
);
updatePageUrlSpy
=
jest
.
spyOn
(
wrapper
.
instance
(),
'updatePageUrl'
);
wrapper
.
instance
().
onSearchBarSubmit
(
'searchTerm'
);
wrapper
.
instance
().
onSearchBarSubmit
(
'searchTerm'
);
});
});
it
(
'calls props.searchAll with correct parameters'
,
()
=>
{
expect
(
searchAllSpy
).
toHaveBeenCalledWith
(
'searchTerm'
);
});
it
(
'call updatePageUrl with correct parameters'
,
()
=>
{
it
(
'call updatePageUrl with correct parameters'
,
()
=>
{
expect
(
updatePageUrlSpy
).
toHaveBeenCalledWith
(
'searchTerm'
,
wrapper
.
state
().
selectedTab
,
0
);
expect
(
updatePageUrlSpy
).
toHaveBeenCalledWith
(
'searchTerm'
,
wrapper
.
state
().
selectedTab
,
0
);
});
});
...
@@ -358,9 +518,9 @@ describe('SearchPage', () => {
...
@@ -358,9 +518,9 @@ describe('SearchPage', () => {
const
searchTerm
=
'testing'
;
const
searchTerm
=
'testing'
;
const
tab
=
ResourceType
.
user
;
const
tab
=
ResourceType
.
user
;
const
expectedPath
=
`/search?searchTerm=
${
searchTerm
}
&selectedTab=
${
tab
}
&pageIndex=
${
pageIndex
}
`
;
const
expectedPath
=
`/search?searchTerm=
${
searchTerm
}
&selectedTab=
${
tab
}
&pageIndex=
${
pageIndex
}
`
;
const
pushStateSpy
=
jest
.
spyOn
(
window
.
history
,
'pushState
'
);
const
historyPushSpy
=
jest
.
spyOn
(
props
.
history
,
'push
'
);
wrapper
.
instance
().
updatePageUrl
(
searchTerm
,
tab
,
pageIndex
);
wrapper
.
instance
().
updatePageUrl
(
searchTerm
,
tab
,
pageIndex
);
expect
(
pushStateSpy
).
toHaveBeenCalledWith
({},
''
,
`
${
window
.
location
.
origin
}${
expectedPath
}
`
);
expect
(
historyPushSpy
).
toHaveBeenCalledWith
(
expectedPath
);
});
});
});
});
...
@@ -397,7 +557,7 @@ describe('SearchPage', () => {
...
@@ -397,7 +557,7 @@ describe('SearchPage', () => {
let
props
;
let
props
;
let
wrapper
;
let
wrapper
;
beforeAll
(()
=>
{
beforeAll
(()
=>
{
const
setupResult
=
setup
({
searchTerm
:
''
});
const
setupResult
=
setup
({
searchTerm
:
''
});
props
=
setupResult
.
props
;
props
=
setupResult
.
props
;
wrapper
=
setupResult
.
wrapper
;
wrapper
=
setupResult
.
wrapper
;
content
=
shallow
(
wrapper
.
instance
().
getTabContent
(
props
.
tables
,
TABLE_RESOURCE_TITLE
));
content
=
shallow
(
wrapper
.
instance
().
getTabContent
(
props
.
tables
,
TABLE_RESOURCE_TITLE
));
...
@@ -451,7 +611,7 @@ describe('SearchPage', () => {
...
@@ -451,7 +611,7 @@ describe('SearchPage', () => {
let
props
;
let
props
;
let
wrapper
;
let
wrapper
;
beforeAll
(()
=>
{
beforeAll
(()
=>
{
const
setupResult
=
setup
({
searchTerm
:
''
});
const
setupResult
=
setup
({
searchTerm
:
''
});
props
=
setupResult
.
props
;
props
=
setupResult
.
props
;
wrapper
=
setupResult
.
wrapper
;
wrapper
=
setupResult
.
wrapper
;
content
=
shallow
(
wrapper
.
instance
().
renderPopularTables
());
content
=
shallow
(
wrapper
.
instance
().
renderPopularTables
());
...
@@ -483,7 +643,7 @@ describe('SearchPage', () => {
...
@@ -483,7 +643,7 @@ describe('SearchPage', () => {
const
content
=
shallow
(
wrapper
.
instance
().
renderSearchResults
());
const
content
=
shallow
(
wrapper
.
instance
().
renderSearchResults
());
const
expectedTabConfig
=
[
const
expectedTabConfig
=
[
{
{
title
:
`
${
TABLE_RESOURCE_TITLE
}
(
${
props
.
tables
.
total_results
}
)`
,
title
:
`
${
TABLE_RESOURCE_TITLE
}
(
${
props
.
tables
.
total_results
}
)`
,
key
:
ResourceType
.
table
,
key
:
ResourceType
.
table
,
content
:
wrapper
.
instance
().
getTabContent
(
props
.
tables
,
TABLE_RESOURCE_TITLE
),
content
:
wrapper
.
instance
().
getTabContent
(
props
.
tables
,
TABLE_RESOURCE_TITLE
),
}
}
...
@@ -500,7 +660,7 @@ describe('SearchPage', () => {
...
@@ -500,7 +660,7 @@ describe('SearchPage', () => {
describe
(
'render'
,
()
=>
{
describe
(
'render'
,
()
=>
{
describe
(
'DocumentTitle'
,
()
=>
{
describe
(
'DocumentTitle'
,
()
=>
{
it
(
'renders correct title if there is a search term'
,
()
=>
{
it
(
'renders correct title if there is a search term'
,
()
=>
{
const
{
props
,
wrapper
}
=
setup
({
searchTerm
:
'test search'
});
const
{
props
,
wrapper
}
=
setup
({
searchTerm
:
'test search'
});
expect
(
wrapper
.
find
(
DocumentTitle
).
props
()).
toMatchObject
({
expect
(
wrapper
.
find
(
DocumentTitle
).
props
()).
toMatchObject
({
title
:
`test search
${
DOCUMENT_TITLE_SUFFIX
}
`
title
:
`test search
${
DOCUMENT_TITLE_SUFFIX
}
`
});
});
...
...
amundsen_application/static/js/ducks/search/reducer.ts
View file @
ce5096dd
...
@@ -12,7 +12,7 @@ import {
...
@@ -12,7 +12,7 @@ import {
}
from
'./types'
;
}
from
'./types'
;
import
{
ResourceType
}
from
'components/common/ResourceListItem/types'
;
import
{
ResourceType
}
from
'components/common/ResourceListItem/types'
;
export
type
SearchReducerAction
=
SearchAllResponse
|
SearchResourceResponse
;
export
type
SearchReducerAction
=
SearchAllResponse
|
SearchResourceResponse
|
SearchAllRequest
;
export
interface
SearchReducerState
{
export
interface
SearchReducerState
{
search_term
:
string
;
search_term
:
string
;
...
@@ -58,19 +58,26 @@ const initialState: SearchReducerState = {
...
@@ -58,19 +58,26 @@ const initialState: SearchReducerState = {
};
};
export
default
function
reducer
(
state
:
SearchReducerState
=
initialState
,
action
:
SearchReducerAction
):
SearchReducerState
{
export
default
function
reducer
(
state
:
SearchReducerState
=
initialState
,
action
:
SearchReducerAction
):
SearchReducerState
{
const
newState
=
action
.
payload
;
switch
(
action
.
type
)
{
switch
(
action
.
type
)
{
// Updates search term to reflect action
case
SearchAll
.
ACTION
:
return
{
...
state
,
search_term
:
action
.
term
,
};
// SearchAll will reset all resources with search results or the initial state
// SearchAll will reset all resources with search results or the initial state
case
SearchAll
.
SUCCESS
:
case
SearchAll
.
SUCCESS
:
const
newState
=
action
.
payload
;
return
{
return
{
...
initialState
,
...
initialState
,
...
newState
,
...
newState
,
};
};
// SearchResource will set only a single resource and preserves search state for other resources
// SearchResource will set only a single resource and preserves search state for other resources
case
SearchResource
.
SUCCESS
:
case
SearchResource
.
SUCCESS
:
const
resourceNewState
=
action
.
payload
;
return
{
return
{
...
state
,
...
state
,
...
n
ewState
,
...
resourceN
ewState
,
};
};
case
SearchAll
.
FAILURE
:
case
SearchAll
.
FAILURE
:
case
SearchResource
.
FAILURE
:
case
SearchResource
.
FAILURE
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment