aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/__tests__/urlStateSpec.js
diff options
context:
space:
mode:
authorMatthew Shao <me@matshao.com>2017-04-28 22:06:17 +0800
committerMatthew Shao <me@matshao.com>2017-04-28 22:06:17 +0800
commitf8b76a62ff685d9aaf7b74155f6fe5d448c80805 (patch)
treecd51d0bbf497bee95c79a50e220a59be6d20ffbe /web/src/js/__tests__/urlStateSpec.js
parentb537997f4f5d7c33562414a414913b6cd89f99c3 (diff)
downloadmitmproxy-f8b76a62ff685d9aaf7b74155f6fe5d448c80805.tar.gz
mitmproxy-f8b76a62ff685d9aaf7b74155f6fe5d448c80805.tar.bz2
mitmproxy-f8b76a62ff685d9aaf7b74155f6fe5d448c80805.zip
[web] Add coverage for js/urlState.js
Diffstat (limited to 'web/src/js/__tests__/urlStateSpec.js')
-rw-r--r--web/src/js/__tests__/urlStateSpec.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/web/src/js/__tests__/urlStateSpec.js b/web/src/js/__tests__/urlStateSpec.js
new file mode 100644
index 00000000..581e79e7
--- /dev/null
+++ b/web/src/js/__tests__/urlStateSpec.js
@@ -0,0 +1,66 @@
+import initialize from '../urlState'
+
+import reduceFlows from '../ducks/flows'
+import reduceUI from '../ducks/ui/index'
+import reduceEventLog from '../ducks/eventLog'
+
+import * as flowsAction from '../ducks/flows'
+import * as uiFlowAction from '../ducks/ui/flow'
+import * as eventLogAction from '../ducks/eventLog'
+
+import {createStore} from './ducks/tutils'
+
+
+describe('test updateStoreFromUrl and updateUrlFromStore', () => {
+
+ let store = createStore({
+ flows: reduceFlows,
+ ui: reduceUI,
+ eventLog: reduceEventLog
+ })
+
+ history.replaceState = jest.fn()
+
+ it('should handle search query', () => {
+ window.location.hash = "#/flows?s=foo"
+ let setFilter = jest.spyOn(flowsAction, 'setFilter')
+
+ initialize(store)
+ expect(setFilter).toBeCalledWith('foo')
+ })
+
+ it('should handle highlight query', () => {
+ window.location.hash = "#/flows?h=foo"
+ let setHighlight = jest.spyOn(flowsAction, 'setHighlight')
+
+ initialize(store)
+ expect(setHighlight).toBeCalledWith('foo')
+ })
+
+ it('should handle show event log', () => {
+ window.location.hash = "#/flows?e=true"
+ let toggleVisibility = jest.spyOn(eventLogAction, 'toggleVisibility')
+
+ initialize(store)
+ expect(toggleVisibility).toHaveBeenCalled()
+ })
+
+ it('should handle unimplemented query argument', () => {
+ window.location.hash = "#/flows?foo=bar"
+ console.error = jest.fn()
+
+ initialize(store)
+ expect(console.error).toBeCalledWith("unimplemented query arg: foo=bar")
+ })
+
+ it('should select flow and tab', () => {
+ window.location.hash = "#/flows/123/request"
+ let select = jest.spyOn(flowsAction, 'select'),
+ selectTab = jest.spyOn(uiFlowAction, 'selectTab')
+
+ initialize(store)
+ expect(select).toBeCalledWith('123')
+ expect(selectTab).toBeCalledWith('request')
+ })
+
+})