From 97a00728a85a32ca6a8e98a991f6dcf28809e73b Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sat, 29 Apr 2017 19:43:59 +0200 Subject: [PATCH] [web] add connection tests --- mitmproxy/tools/web/static/app.js | Bin 341685 -> 341882 bytes web/src/js/__tests__/ducks/connectionSpec.js | 41 ++++++++++++++++++ .../components/Header/ConnectionIndicator.jsx | 11 ++--- web/src/js/components/common/DocsLink.jsx | 2 +- 4 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 web/src/js/__tests__/ducks/connectionSpec.js diff --git a/mitmproxy/tools/web/static/app.js b/mitmproxy/tools/web/static/app.js index 864f0a49c978cde64f9054e9d24a470d59415071..8ee4d97d50779bd949abc4b285a9ef6bc0640aec 100644 GIT binary patch delta 146 zcmdn`R^-<^k%lddtDj9@u%A(6x}QH&`E<+Yj0Yx{{1suX%uUMAncVNBH+{hdMz-w^ zFBrcwPgk~J5}kfNjfs7`{Ts%8jMERVW%StY`i`;i(e#~yOkgA2C;LoDo__fPlM2un y$>{e|^aGXXL4cJ|9G>yiQceLGhG delta 170 zcmezMPGsv_k%lddtDjBZz{AWsIp0oTy25it@#)%Um|~|JK4&~CR+O5UT%s3HlwS~1 zS&&++S6rE!l%F%X-$|MuO=`Q%3&wxU+x^}!9%G#TNt{t?x-T=c*rem)+oRtx7CoB$ xQcPf)I}`Wx&WlWH7 { + 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, + }) + }) + +}) diff --git a/web/src/js/components/Header/ConnectionIndicator.jsx b/web/src/js/components/Header/ConnectionIndicator.jsx index e8feb20eb..1ee42e259 100644 --- a/web/src/js/components/Header/ConnectionIndicator.jsx +++ b/web/src/js/components/Header/ConnectionIndicator.jsx @@ -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 connecting…; case ConnectionState.FETCHING: @@ -18,7 +18,8 @@ function ConnectionIndicator({ state, message }) { case ConnectionState.ESTABLISHED: return connected; case ConnectionState.ERROR: - return connection lost; + return connection lost; case ConnectionState.OFFLINE: return offline; } diff --git a/web/src/js/components/common/DocsLink.jsx b/web/src/js/components/common/DocsLink.jsx index 182811a30..53c7aca84 100644 --- a/web/src/js/components/common/DocsLink.jsx +++ b/web/src/js/components/common/DocsLink.jsx @@ -1,4 +1,4 @@ -import { PropTypes } from 'react' +import PropTypes from "prop-types" DocsLink.propTypes = { resource: PropTypes.string.isRequired,