Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AmendsenProject
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
Shaik Janipasha
AmendsenProject
Commits
3eaaf377
Unverified
Commit
3eaaf377
authored
Sep 05, 2019
by
Daniel
Committed by
GitHub
Sep 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TagInfo now fires 'submitSearch' instead of using navigation (#285)
parent
2fc3f8b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
137 additions
and
9 deletions
+137
-9
index.tsx
...n_application/static/js/components/Tags/TagInfo/index.tsx
+23
-9
index.spec.tsx
...on/static/js/components/Tags/TagInfo/tests/index.spec.tsx
+114
-0
No files found.
amundsen_application/static/js/components/Tags/TagInfo/index.tsx
View file @
3eaaf377
import
*
as
React
from
'react'
;
import
{
Link
}
from
'react-router-dom'
;
import
{
bindActionCreators
}
from
'redux'
import
{
connect
}
from
'react-redux'
;
import
{
Tag
}
from
'interfaces'
;
import
{
logClick
}
from
'ducks/utilMethods'
;
import
'./styles.scss'
;
import
{
SubmitSearchRequest
}
from
'ducks/search/types'
;
import
{
submitSearch
}
from
'ducks/search/reducer'
;
interface
TagInfo
Props
{
interface
Own
Props
{
data
:
Tag
;
compact
?:
boolean
;
}
class
TagInfo
extends
React
.
Component
<
TagInfoProps
,
{}
>
{
export
interface
DispatchFromProps
{
submitSearch
:
(
searchTerm
:
string
)
=>
SubmitSearchRequest
;
}
export
type
TagInfoProps
=
OwnProps
&
DispatchFromProps
;
export
class
TagInfo
extends
React
.
Component
<
TagInfoProps
>
{
static
defaultProps
=
{
compact
:
true
};
...
...
@@ -20,21 +30,21 @@ class TagInfo extends React.Component<TagInfoProps, {}> {
}
onClick
=
(
e
)
=>
{
const
name
=
this
.
props
.
data
.
tag_name
;
logClick
(
e
,
{
target_type
:
'tag'
,
label
:
this
.
props
.
data
.
tag_
name
,
label
:
name
,
});
this
.
props
.
submitSearch
(
`tag:
${
name
}
`
);
};
render
()
{
const
name
=
this
.
props
.
data
.
tag_name
;
const
searchUrl
=
`/search?searchTerm=tag:
${
name
}
`
;
return
(
<
Link
<
button
id=
{
`tag::${name}`
}
role=
"button"
to=
{
searchUrl
}
className=
{
"btn tag-button"
+
(
this
.
props
.
compact
?
" compact"
:
""
)
}
onClick=
{
this
.
onClick
}
>
...
...
@@ -43,9 +53,13 @@ class TagInfo extends React.Component<TagInfoProps, {}> {
!
this
.
props
.
compact
&&
<
span
className=
"tag-count"
>
{
this
.
props
.
data
.
tag_count
}
</
span
>
}
</
Link
>
</
button
>
);
}
}
export
default
TagInfo
;
export
const
mapDispatchToProps
=
(
dispatch
:
any
)
=>
{
return
bindActionCreators
({
submitSearch
},
dispatch
);
};
export
default
connect
<
null
,
DispatchFromProps
,
OwnProps
>
(
null
,
mapDispatchToProps
)(
TagInfo
);
amundsen_application/static/js/components/Tags/TagInfo/tests/index.spec.tsx
0 → 100644
View file @
3eaaf377
import
*
as
React
from
'react'
;
import
{
shallow
}
from
'enzyme'
;
import
{
mapDispatchToProps
,
TagInfo
,
TagInfoProps
}
from
'../'
;
import
*
as
UtilMethods
from
'ducks/utilMethods'
;
const
logClickSpy
=
jest
.
spyOn
(
UtilMethods
,
'logClick'
);
logClickSpy
.
mockImplementation
(()
=>
null
);
describe
(
'TagInfo'
,
()
=>
{
const
setup
=
(
propOverrides
?:
Partial
<
TagInfoProps
>
)
=>
{
const
props
=
{
data
:
{
tag_name
:
'testTag'
,
tag_count
:
45
,
},
compact
:
false
,
submitSearch
:
jest
.
fn
(),
...
propOverrides
,
};
const
wrapper
=
shallow
<
TagInfo
>
(<
TagInfo
{
...
props
}
/>);
return
{
props
,
wrapper
};
};
describe
(
'onClick'
,
()
=>
{
let
props
;
let
wrapper
;
const
mockEvent
=
{};
beforeAll
(()
=>
{
const
setupResult
=
setup
();
props
=
setupResult
.
props
;
wrapper
=
setupResult
.
wrapper
;
});
it
(
'Calls the logClick utility function'
,
()
=>
{
logClickSpy
.
mockClear
();
const
expectedData
=
{
target_type
:
'tag'
,
label
:
props
.
data
.
tag_name
,
};
wrapper
.
instance
().
onClick
(
mockEvent
);
expect
(
logClickSpy
).
toHaveBeenCalledWith
(
mockEvent
,
expectedData
)
});
it
(
'it calls submitSearch'
,
()
=>
{
wrapper
.
instance
().
onClick
(
mockEvent
);
expect
(
props
.
submitSearch
).
toHaveBeenCalledWith
(
`tag:
${
props
.
data
.
tag_name
}
`
);
});
});
describe
(
'render'
,
()
=>
{
describe
(
'renders a normal sized tag'
,
()
=>
{
let
props
;
let
wrapper
;
beforeAll
(()
=>
{
const
setupResult
=
setup
();
wrapper
=
setupResult
.
wrapper
;
props
=
setupResult
.
props
;
});
it
(
'renders a button with correct props'
,
()
=>
{
expect
(
wrapper
.
find
(
'button'
).
props
()).
toMatchObject
({
id
:
`tag::
${
props
.
data
.
tag_name
}
`
,
role
:
'button'
,
onClick
:
wrapper
.
instance
().
onClick
,
className
:
'btn tag-button'
});
});
it
(
'renders with correct text'
,
()
=>
{
expect
(
wrapper
.
text
()).
toEqual
(
props
.
data
.
tag_name
+
props
.
data
.
tag_count
)
});
});
describe
(
'renders a compact sized tag'
,
()
=>
{
let
props
;
let
wrapper
;
beforeAll
(()
=>
{
const
setupResult
=
setup
({
compact
:
true
});
wrapper
=
setupResult
.
wrapper
;
props
=
setupResult
.
props
;
});
it
(
'renders with correct text'
,
()
=>
{
expect
(
wrapper
.
text
()).
toEqual
(
props
.
data
.
tag_name
)
});
it
(
'renders with the correct classes'
,
()
=>
{
expect
(
wrapper
.
find
(
'button'
).
props
().
className
).
toEqual
(
'btn tag-button compact'
)
});
});
});
});
describe
(
'mapDispatchToProps'
,
()
=>
{
let
dispatch
;
let
result
;
beforeAll
(()
=>
{
dispatch
=
jest
.
fn
(()
=>
Promise
.
resolve
());
result
=
mapDispatchToProps
(
dispatch
);
});
it
(
'sets submitSearch on the props'
,
()
=>
{
expect
(
result
.
submitSearch
).
toBeInstanceOf
(
Function
);
});
});
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