mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 15:37:45 +00:00
added tests
This commit is contained in:
parent
cacee3871c
commit
bbe6556bfc
76
web/src/js/__tests__/ducks/ui/flowSpec.js
Normal file
76
web/src/js/__tests__/ducks/ui/flowSpec.js
Normal file
@ -0,0 +1,76 @@
|
||||
jest.unmock('../../../ducks/ui/flow')
|
||||
jest.unmock('../../../ducks/flows')
|
||||
jest.unmock('lodash')
|
||||
|
||||
import _ from 'lodash'
|
||||
import reducer, {
|
||||
startEdit,
|
||||
setContentViewDescription,
|
||||
setShowFullContent,
|
||||
setContent,
|
||||
updateEdit
|
||||
} from '../../../ducks/ui/flow'
|
||||
|
||||
import { select, updateFlow } from '../../../ducks/flows'
|
||||
|
||||
describe('flow reducer', () => {
|
||||
it('should change to edit mode', () => {
|
||||
let testFlow = {flow : 'foo'}
|
||||
const newState = reducer(undefined, startEdit({ flow: 'foo' }))
|
||||
expect(newState.contentView).toEqual('Edit')
|
||||
expect(newState.modifiedFlow).toEqual(testFlow)
|
||||
expect(newState.showFullContent).toEqual(true)
|
||||
})
|
||||
it('should set the view description', () => {
|
||||
expect(reducer(undefined, setContentViewDescription('description')).viewDescription)
|
||||
.toEqual('description')
|
||||
})
|
||||
|
||||
it('should set show full content', () => {
|
||||
expect(reducer({showFullContent: false}, setShowFullContent()).showFullContent)
|
||||
.toBeTruthy()
|
||||
})
|
||||
|
||||
it('should set showFullContent to true', () => {
|
||||
let maxLines = 10
|
||||
let content = _.range(maxLines)
|
||||
const newState = reducer({maxContentLines: maxLines}, setContent(content) )
|
||||
expect(newState.showFullContent).toBeTruthy()
|
||||
expect(newState.content).toEqual(content)
|
||||
})
|
||||
|
||||
it('should set showFullContent to false', () => {
|
||||
let maxLines = 5
|
||||
let content = _.range(maxLines+1);
|
||||
const newState = reducer({maxContentLines: maxLines}, setContent(_.range(maxLines+1)))
|
||||
expect(newState.showFullContent).toBeFalsy()
|
||||
expect(newState.content).toEqual(content)
|
||||
})
|
||||
|
||||
it('should not change the contentview mode', () => {
|
||||
expect(reducer({contentView: 'foo'}, select(1)).contentView).toEqual('foo')
|
||||
})
|
||||
|
||||
it('should change the contentview mode to auto after editing when a new flow will be selected', () => {
|
||||
expect(reducer({contentView: 'foo', modifiedFlow : 'test_flow'}, select(1)).contentView).toEqual('Auto')
|
||||
})
|
||||
|
||||
it('should set update and merge the modifiedflow with the update values', () => {
|
||||
let modifiedFlow = {headers: []}
|
||||
let updateValues = {content: 'bar'}
|
||||
let result = {headers: [], content: 'bar'}
|
||||
expect(reducer({modifiedFlow}, updateEdit(updateValues)).modifiedFlow).toEqual(result)
|
||||
})
|
||||
|
||||
it('should not change the state when a flow is updated which is not selected', () => {
|
||||
let modifiedFlow = {id: 1}
|
||||
let updatedFlow = {id: 0}
|
||||
expect(reducer({modifiedFlow}, updateFlow(updatedFlow)).modifiedFlow).toEqual(modifiedFlow)
|
||||
})
|
||||
|
||||
it('should stop editing when the selected flow is updated', () => {
|
||||
let modifiedFlow = {id: 1}
|
||||
let updatedFlow = {id: 1}
|
||||
expect(reducer({modifiedFlow}, updateFlow(updatedFlow)).modifiedFlow).toBeFalsy()
|
||||
})
|
||||
})
|
@ -2,6 +2,7 @@ jest.unmock('lodash')
|
||||
jest.unmock('../../../ducks/utils/list')
|
||||
|
||||
import reduce, * as list from '../../../ducks/utils/list'
|
||||
import _ from 'lodash'
|
||||
|
||||
describe('list reduce', () => {
|
||||
|
||||
|
@ -16,7 +16,7 @@ function ShowFullContentButton ( {setShowFullContent, showFullContent, visibleLi
|
||||
return (
|
||||
!showFullContent &&
|
||||
<div>
|
||||
<Button className="view-all-content-btn btn-xs" onClick={() => setShowFullContent(true)} text="Show full content"/>
|
||||
<Button className="view-all-content-btn btn-xs" onClick={() => setShowFullContent()} text="Show full content"/>
|
||||
<span className="pull-right"> {visibleLines}/{contentLines} are visible </span>
|
||||
</div>
|
||||
)
|
||||
|
@ -16,7 +16,7 @@ export const SET_CONTENT_VIEW = 'UI_FLOWVIEW_SET_CONTENT_VIEW',
|
||||
|
||||
const defaultState = {
|
||||
displayLarge: false,
|
||||
contentViewDescription: '',
|
||||
viewDescription: '',
|
||||
showFullContent: false,
|
||||
modifiedFlow: false,
|
||||
contentView: 'Auto',
|
||||
@ -27,6 +27,10 @@ const defaultState = {
|
||||
|
||||
export default function reducer(state = defaultState, action) {
|
||||
let wasInEditMode = !!(state.modifiedFlow)
|
||||
|
||||
let content = action.content || state.content
|
||||
let isFullContentShown = content && content.length <= state.maxContentLines
|
||||
|
||||
switch (action.type) {
|
||||
|
||||
case START_EDIT:
|
||||
@ -49,8 +53,7 @@ export default function reducer(state = defaultState, action) {
|
||||
modifiedFlow: false,
|
||||
displayLarge: false,
|
||||
contentView: (wasInEditMode ? 'Auto' : state.contentView),
|
||||
viewDescription: '',
|
||||
showFullContent: false,
|
||||
showFullContent: isFullContentShown,
|
||||
}
|
||||
|
||||
case flowsActions.UPDATE:
|
||||
@ -63,7 +66,6 @@ export default function reducer(state = defaultState, action) {
|
||||
modifiedFlow: false,
|
||||
displayLarge: false,
|
||||
contentView: (wasInEditMode ? 'Auto' : state.contentView),
|
||||
viewDescription: '',
|
||||
showFullContent: false
|
||||
}
|
||||
} else {
|
||||
@ -79,7 +81,7 @@ export default function reducer(state = defaultState, action) {
|
||||
case SET_SHOW_FULL_CONTENT:
|
||||
return {
|
||||
...state,
|
||||
showFullContent: action.show
|
||||
showFullContent: true
|
||||
}
|
||||
|
||||
case SET_TAB:
|
||||
@ -98,7 +100,6 @@ export default function reducer(state = defaultState, action) {
|
||||
}
|
||||
|
||||
case SET_CONTENT:
|
||||
let isFullContentShown = action.content.length < state.maxContentLines
|
||||
return {
|
||||
...state,
|
||||
content: action.content,
|
||||
@ -139,12 +140,8 @@ export function setContentViewDescription(description) {
|
||||
return { type: SET_CONTENT_VIEW_DESCRIPTION, description }
|
||||
}
|
||||
|
||||
export function setShowFullContent(show) {
|
||||
return { type: SET_SHOW_FULL_CONTENT, show }
|
||||
}
|
||||
|
||||
export function updateEdit(update) {
|
||||
return { type: UPDATE_EDIT, update }
|
||||
export function setShowFullContent() {
|
||||
return { type: SET_SHOW_FULL_CONTENT }
|
||||
}
|
||||
|
||||
export function setContent(content){
|
||||
|
Loading…
Reference in New Issue
Block a user