mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 15:37:45 +00:00
[web] Add tests for js/components/Header/ConnectionIndicator.jsx
This commit is contained in:
parent
05d78a8353
commit
1d7e554487
@ -0,0 +1,57 @@
|
||||
import React from 'react'
|
||||
import renderer from 'react-test-renderer'
|
||||
import ConnectedIndicator, { ConnectionIndicator } from '../../../components/Header/ConnectionIndicator'
|
||||
import { ConnectionState } from '../../../ducks/connection'
|
||||
import { Provider } from 'react-redux'
|
||||
import configureStore from 'redux-mock-store'
|
||||
|
||||
const mockStore = configureStore()
|
||||
|
||||
describe('ConnectionIndicator Component', () => {
|
||||
|
||||
it('should render INIT', () => {
|
||||
let connectionIndicator = renderer.create(
|
||||
<ConnectionIndicator state={ConnectionState.INIT}/>),
|
||||
tree = connectionIndicator.toJSON()
|
||||
expect(tree).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should render FETCHING', () => {
|
||||
let connectionIndicator = renderer.create(
|
||||
<ConnectionIndicator state={ConnectionState.FETCHING}/>),
|
||||
tree = connectionIndicator.toJSON()
|
||||
expect(tree).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should render ESTABLISHED', () => {
|
||||
let connectionIndicator = renderer.create(
|
||||
<ConnectionIndicator state={ConnectionState.ESTABLISHED}/>),
|
||||
tree = connectionIndicator.toJSON()
|
||||
expect(tree).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should render ERROR', () => {
|
||||
let connectionIndicator = renderer.create(
|
||||
<ConnectionIndicator state={ConnectionState.ERROR} message="foo"/>),
|
||||
tree = connectionIndicator.toJSON()
|
||||
expect(tree).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should render OFFLINE', () => {
|
||||
let connectionIndicator = renderer.create(
|
||||
<ConnectionIndicator state={ConnectionState.OFFLINE} />),
|
||||
tree = connectionIndicator.toJSON()
|
||||
expect(tree).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should connect to state', () => {
|
||||
let store = mockStore({ connection: {state: ConnectionState.INIT} }),
|
||||
provider = renderer.create(
|
||||
<Provider store={store}>
|
||||
<ConnectedIndicator/>
|
||||
</Provider>),
|
||||
tree = provider.toJSON()
|
||||
expect(tree).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
|
@ -9,7 +9,7 @@ ConnectionIndicator.propTypes = {
|
||||
message: PropTypes.string,
|
||||
|
||||
}
|
||||
function ConnectionIndicator({ state, message }) {
|
||||
export function ConnectionIndicator({ state, message }) {
|
||||
switch (state) {
|
||||
case ConnectionState.INIT:
|
||||
return <span className="connection-indicator init">connecting…</span>;
|
||||
|
Loading…
Reference in New Issue
Block a user