mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-29 02:57:19 +00:00
[web] Add tests for js/components/FlowView/Nav.jsx
This commit is contained in:
parent
248dde2604
commit
f840d018e5
38
web/src/js/__tests__/components/FlowView/NavSpec.js
Normal file
38
web/src/js/__tests__/components/FlowView/NavSpec.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import renderer from 'react-test-renderer'
|
||||||
|
import Nav, { NavAction } from '../../../components/FlowView/Nav'
|
||||||
|
|
||||||
|
describe('Nav Component', () => {
|
||||||
|
let tabs = ['foo', 'bar'],
|
||||||
|
onSelectTab = jest.fn(),
|
||||||
|
nav = renderer.create(<Nav active='foo' tabs={tabs} onSelectTab={onSelectTab}/>),
|
||||||
|
tree = nav.toJSON()
|
||||||
|
|
||||||
|
it('should render correctly', () => {
|
||||||
|
expect(tree).toMatchSnapshot()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should handle click', () => {
|
||||||
|
let mockEvent = { preventDefault: jest.fn() }
|
||||||
|
tree.children[0].props.onClick(mockEvent)
|
||||||
|
expect(mockEvent.preventDefault).toBeCalled()
|
||||||
|
expect(onSelectTab).toBeCalledWith('foo')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('NavAction Component', () => {
|
||||||
|
let clickFn = jest.fn(),
|
||||||
|
navAction = renderer.create(<NavAction icon="foo" title="bar" onClick={clickFn}/>),
|
||||||
|
tree = navAction.toJSON()
|
||||||
|
|
||||||
|
it('should render correctly', () => {
|
||||||
|
expect(tree).toMatchSnapshot()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should handle click', () => {
|
||||||
|
let mockEvent = { preventDefault: jest.fn() }
|
||||||
|
tree.props.onClick(mockEvent)
|
||||||
|
expect(mockEvent.preventDefault).toBeCalled()
|
||||||
|
expect(clickFn).toBeCalledWith(mockEvent)
|
||||||
|
})
|
||||||
|
})
|
@ -0,0 +1,35 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`Nav Component should render correctly 1`] = `
|
||||||
|
<nav
|
||||||
|
className="nav-tabs nav-tabs-sm"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
className="active"
|
||||||
|
href="#"
|
||||||
|
onClick={[Function]}
|
||||||
|
>
|
||||||
|
Foo
|
||||||
|
</a>
|
||||||
|
<a
|
||||||
|
className=""
|
||||||
|
href="#"
|
||||||
|
onClick={[Function]}
|
||||||
|
>
|
||||||
|
Bar
|
||||||
|
</a>
|
||||||
|
</nav>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`NavAction Component should render correctly 1`] = `
|
||||||
|
<a
|
||||||
|
className="nav-action"
|
||||||
|
href="#"
|
||||||
|
onClick={[Function]}
|
||||||
|
title="bar"
|
||||||
|
>
|
||||||
|
<i
|
||||||
|
className="fa fa-fw foo"
|
||||||
|
/>
|
||||||
|
</a>
|
||||||
|
`;
|
@ -2,6 +2,7 @@ import React from 'react'
|
|||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
|
import _ from 'lodash'
|
||||||
|
|
||||||
NavAction.propTypes = {
|
NavAction.propTypes = {
|
||||||
icon: PropTypes.string.isRequired,
|
icon: PropTypes.string.isRequired,
|
||||||
@ -9,7 +10,7 @@ NavAction.propTypes = {
|
|||||||
onClick: PropTypes.func.isRequired,
|
onClick: PropTypes.func.isRequired,
|
||||||
}
|
}
|
||||||
|
|
||||||
function NavAction({ icon, title, onClick }) {
|
export function NavAction({ icon, title, onClick }) {
|
||||||
return (
|
return (
|
||||||
<a title={title}
|
<a title={title}
|
||||||
href="#"
|
href="#"
|
||||||
|
Loading…
Reference in New Issue
Block a user