mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 07:08:10 +00:00
Merge pull request #2285 from MatthewShao/jest-dev
[web] Add coverage for js/urlState.js
This commit is contained in:
commit
288448c575
@ -14,23 +14,24 @@
|
||||
"unmockedModulePathPatterns": [
|
||||
"react"
|
||||
],
|
||||
"coverageDirectory":"./coverage",
|
||||
"coverageDirectory": "./coverage",
|
||||
"collectCoverage": true,
|
||||
"coveragePathIgnorePatterns": [
|
||||
"<rootDir>/src/js/filt/filt.js"
|
||||
"<rootDir>/src/js/filt/filt.js"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"bootstrap": "^3.3.7",
|
||||
"classnames": "^2.2.5",
|
||||
"lodash": "^4.17.4",
|
||||
"react": "^15.4.2",
|
||||
"prop-types": "^15.5.0",
|
||||
"react": "^15.4.2",
|
||||
"react-codemirror": "^0.3.0",
|
||||
"react-dom": "^15.4.2",
|
||||
"react-redux": "^5.0.2",
|
||||
"redux": "^3.6.0",
|
||||
"redux-logger": "^2.8.1",
|
||||
"redux-mock-store": "^1.2.3",
|
||||
"redux-thunk": "^2.2.0",
|
||||
"shallowequal": "^0.2.2"
|
||||
},
|
||||
|
100
web/src/js/__tests__/urlStateSpec.js
Normal file
100
web/src/js/__tests__/urlStateSpec.js
Normal file
@ -0,0 +1,100 @@
|
||||
import initialize from '../urlState'
|
||||
import { updateStoreFromUrl, updateUrlFromStore } from '../urlState'
|
||||
|
||||
import reduceFlows from '../ducks/flows'
|
||||
import reduceUI from '../ducks/ui/index'
|
||||
import reduceEventLog from '../ducks/eventLog'
|
||||
import * as flowsActions from '../ducks/flows'
|
||||
|
||||
import configureStore from 'redux-mock-store'
|
||||
|
||||
const mockStore = configureStore()
|
||||
history.replaceState = jest.fn()
|
||||
|
||||
describe('updateStoreFromUrl', () => {
|
||||
|
||||
it('should handle search query', () => {
|
||||
window.location.hash = "#/flows?s=foo"
|
||||
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()
|
||||
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 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()
|
||||
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()
|
||||
updateStoreFromUrl(store)
|
||||
expect(store.getActions()).toEqual([
|
||||
{
|
||||
flowIds: ["123"],
|
||||
type: "FLOWS_SELECT"
|
||||
},
|
||||
{
|
||||
tab: "request",
|
||||
type: "UI_FLOWVIEW_SET_TAB"
|
||||
}
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('updateUrlFromStore', () => {
|
||||
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)
|
||||
store.dispatch({ type: "foo" })
|
||||
})
|
||||
})
|
@ -15,7 +15,7 @@ const Query = {
|
||||
SHOW_EVENTLOG: "e"
|
||||
};
|
||||
|
||||
function updateStoreFromUrl(store) {
|
||||
export function updateStoreFromUrl(store) {
|
||||
const [path, query] = window.location.hash.substr(1).split("?", 2)
|
||||
const path_components = path.substr(1).split("/")
|
||||
|
||||
@ -50,7 +50,7 @@ function updateStoreFromUrl(store) {
|
||||
}
|
||||
}
|
||||
|
||||
function updateUrlFromStore(store) {
|
||||
export function updateUrlFromStore(store) {
|
||||
const state = store.getState()
|
||||
let query = {
|
||||
[Query.SEARCH]: state.flows.filter,
|
||||
|
@ -4291,6 +4291,10 @@ redux-logger@^2.8.1:
|
||||
dependencies:
|
||||
deep-diff "0.3.4"
|
||||
|
||||
redux-mock-store@^1.2.3:
|
||||
version "1.2.3"
|
||||
resolved "https://registry.yarnpkg.com/redux-mock-store/-/redux-mock-store-1.2.3.tgz#1b3ad299da91cb41ba30d68e3b6f024475fb9e1b"
|
||||
|
||||
redux-thunk@^2.2.0:
|
||||
version "2.2.0"
|
||||
resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.2.0.tgz#e615a16e16b47a19a515766133d1e3e99b7852e5"
|
||||
|
Loading…
Reference in New Issue
Block a user