aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/__tests__/urlStateSpec.js
diff options
context:
space:
mode:
authorMatthew Shao <me@matshao.com>2017-04-30 22:40:58 +0800
committerMatthew Shao <me@matshao.com>2017-04-30 22:40:58 +0800
commit365677006cc9f749a59ce5b5cf9b13d50dca8c0f (patch)
tree7ec58566b4eb219661283b9f2efaf17b7fdcc9ba /web/src/js/__tests__/urlStateSpec.js
parenta7feced5deb2e9b8a874260e59c8badc0153c2be (diff)
downloadmitmproxy-365677006cc9f749a59ce5b5cf9b13d50dca8c0f.tar.gz
mitmproxy-365677006cc9f749a59ce5b5cf9b13d50dca8c0f.tar.bz2
mitmproxy-365677006cc9f749a59ce5b5cf9b13d50dca8c0f.zip
[web] Export updateUrlFromStore and updateStoreFromUrl
Diffstat (limited to 'web/src/js/__tests__/urlStateSpec.js')
-rw-r--r--web/src/js/__tests__/urlStateSpec.js65
1 files changed, 43 insertions, 22 deletions
diff --git a/web/src/js/__tests__/urlStateSpec.js b/web/src/js/__tests__/urlStateSpec.js
index 0b173d46..c57c0a00 100644
--- a/web/src/js/__tests__/urlStateSpec.js
+++ b/web/src/js/__tests__/urlStateSpec.js
@@ -1,4 +1,5 @@
import initialize from '../urlState'
+import { updateStoreFromUrl, updateUrlFromStore } from '../urlState'
import reduceFlows from '../ducks/flows'
import reduceUI from '../ducks/ui/index'
@@ -8,47 +9,44 @@ import * as flowsActions from '../ducks/flows'
import configureStore from 'redux-mock-store'
const mockStore = configureStore()
+history.replaceState = jest.fn()
describe('updateStoreFromUrl', () => {
- history.replaceState = jest.fn()
- let initialState = {
- flows: reduceFlows(undefined, {}),
- ui: reduceUI(undefined, {}),
- eventLog: reduceEventLog(undefined, {})
- }
it('should handle search query', () => {
window.location.hash = "#/flows?s=foo"
- let store = mockStore(initialState)
- initialize(store)
+ let store = mockStore()
+ updateStoreFromUrl(store)
expect(store.getActions()).toEqual([{ filter: "foo", type: "FLOWS_SET_FILTER" }])
})
it('should handle highlight query', () => {
window.location.hash = "#/flows?h=foo"
- let store = mockStore(initialState)
- initialize(store)
+ let store = mockStore()
+ updateStoreFromUrl(store)
expect(store.getActions()).toEqual([{ highlight: "foo", type: "FLOWS_SET_HIGHLIGHT" }])
})
it('should handle show event log', () => {
window.location.hash = "#/flows?e=true"
- let store = mockStore(initialState)
- initialize(store)
- expect(store.getActions()).toEqual([{ type: "EVENTS_TOGGLE_VISIBILITY" }]) })
+ let initialState = { eventLog: reduceEventLog(undefined, {}) },
+ store = mockStore(initialState)
+ updateStoreFromUrl(store)
+ expect(store.getActions()).toEqual([{ type: "EVENTS_TOGGLE_VISIBILITY" }])
+ })
it('should handle unimplemented query argument', () => {
window.location.hash = "#/flows?foo=bar"
console.error = jest.fn()
- let store = mockStore(initialState)
- initialize(store)
+ let store = mockStore()
+ updateStoreFromUrl(store)
expect(console.error).toBeCalledWith("unimplemented query arg: foo=bar")
})
it('should select flow and tab', () => {
window.location.hash = "#/flows/123/request"
- let store = mockStore(initialState)
- initialize(store)
+ let store = mockStore()
+ updateStoreFromUrl(store)
expect(store.getActions()).toEqual([
{
flowIds: ["123"],
@@ -63,17 +61,40 @@ describe('updateStoreFromUrl', () => {
})
describe('updateUrlFromStore', () => {
- history.replaceState = jest.fn()
- let flows = reduceFlows(undefined, flowsActions.select(123)),
- initialState = {
- flows: reduceFlows(flows, flowsActions.setFilter('~u foo')),
+ let initialState = {
+ flows: reduceFlows(undefined, {}),
ui: reduceUI(undefined, {}),
eventLog: reduceEventLog(undefined, {})
}
+ it('should update initial url', () => {
+ let store = mockStore(initialState)
+ updateUrlFromStore(store)
+ expect(history.replaceState).toBeCalledWith(undefined, '', '/#/flows')
+ })
+
it('should update url', () => {
+ let flows = reduceFlows(undefined, flowsActions.select(123)),
+ state = {
+ ...initialState,
+ flows: reduceFlows(flows, flowsActions.setFilter('~u foo'))
+ },
+ store = mockStore(state)
+ updateUrlFromStore(store)
+ expect(history.replaceState).toBeCalledWith(undefined, '', '/#/flows/123/request?s=~u foo')
+ })
+})
+
+describe('initialize', () => {
+ let initialState = {
+ flows: reduceFlows(undefined, {}),
+ ui: reduceUI(undefined, {}),
+ eventLog: reduceEventLog(undefined, {})
+ }
+
+ it('should handle initial state', () => {
let store = mockStore(initialState)
initialize(store)
- expect(history.replaceState).toBeCalledWith(undefined, '', '/#/flows/123/request?s=~u foo')
+ store.dispatch({ type: "foo" })
})
})