[web] add connection tests
This commit is contained in:
parent
8f1b763082
commit
97a00728a8
Binary file not shown.
|
@ -0,0 +1,41 @@
|
|||
import reduceConnection from "../../ducks/connection"
|
||||
import * as ConnectionActions from "../../ducks/connection"
|
||||
import { ConnectionState } from "../../ducks/connection"
|
||||
|
||||
describe('connection reducer', () => {
|
||||
it('should return initial state', () => {
|
||||
expect(reduceConnection(undefined, {})).toEqual({
|
||||
state: ConnectionState.INIT,
|
||||
message: null,
|
||||
})
|
||||
})
|
||||
|
||||
it('should handle start fetch', () => {
|
||||
expect(reduceConnection(undefined, ConnectionActions.startFetching())).toEqual({
|
||||
state: ConnectionState.FETCHING,
|
||||
message: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
it('should handle connection established', () => {
|
||||
expect(reduceConnection(undefined, ConnectionActions.connectionEstablished())).toEqual({
|
||||
state: ConnectionState.ESTABLISHED,
|
||||
message: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
it('should handle connection error', () => {
|
||||
expect(reduceConnection(undefined, ConnectionActions.connectionError("no internet"))).toEqual({
|
||||
state: ConnectionState.ERROR,
|
||||
message: "no internet",
|
||||
})
|
||||
})
|
||||
|
||||
it('should handle offline mode', () => {
|
||||
expect(reduceConnection(undefined, ConnectionActions.setOffline())).toEqual({
|
||||
state: ConnectionState.OFFLINE,
|
||||
message: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
})
|
|
@ -1,7 +1,7 @@
|
|||
import React, { PropTypes } from "react"
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
import { connect } from "react-redux"
|
||||
import classnames from "classnames"
|
||||
import {ConnectionState} from "../../ducks/connection"
|
||||
import { ConnectionState } from "../../ducks/connection"
|
||||
|
||||
|
||||
ConnectionIndicator.propTypes = {
|
||||
|
@ -10,7 +10,7 @@ ConnectionIndicator.propTypes = {
|
|||
|
||||
}
|
||||
function ConnectionIndicator({ state, message }) {
|
||||
switch(state){
|
||||
switch (state) {
|
||||
case ConnectionState.INIT:
|
||||
return <span className="connection-indicator init">connecting…</span>;
|
||||
case ConnectionState.FETCHING:
|
||||
|
@ -18,7 +18,8 @@ function ConnectionIndicator({ state, message }) {
|
|||
case ConnectionState.ESTABLISHED:
|
||||
return <span className="connection-indicator established">connected</span>;
|
||||
case ConnectionState.ERROR:
|
||||
return <span className="connection-indicator error" title={message}>connection lost</span>;
|
||||
return <span className="connection-indicator error"
|
||||
title={message}>connection lost</span>;
|
||||
case ConnectionState.OFFLINE:
|
||||
return <span className="connection-indicator offline">offline</span>;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { PropTypes } from 'react'
|
||||
import PropTypes from "prop-types"
|
||||
|
||||
DocsLink.propTypes = {
|
||||
resource: PropTypes.string.isRequired,
|
||||
|
|
Loading…
Reference in New Issue