1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
import reduceOptions, * as OptionsActions from '../../ducks/options'
import configureStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import * as OptionsEditorActions from '../../ducks/ui/optionsEditor'
const mockStore = configureStore([ thunk ])
describe('option reducer', () => {
it('should return initial state', () => {
expect(reduceOptions(undefined, {})).toEqual({})
})
it('should handle receive action', () => {
let action = { type: OptionsActions.RECEIVE, data: 'foo' }
expect(reduceOptions(undefined, action)).toEqual('foo')
})
it('should handle update action', () => {
let action = {type: OptionsActions.UPDATE, data: {id: 1} }
expect(reduceOptions(undefined, action)).toEqual({id: 1})
})
})
let store = mockStore()
describe('option actions', () => {
it('should be possible to update option', () => {
let mockResponse = { status: 200 },
promise = Promise.resolve(mockResponse)
global.fetch = r => { return promise }
store.dispatch(OptionsActions.update('foo', 'bar'))
expect(store.getActions()).toEqual([
{ type: OptionsEditorActions.OPTION_UPDATE_START, option: 'foo', value: 'bar'}
])
store.clearActions()
})
})
describe('sendUpdate', () => {
it('should handle error', () => {
let mockResponse = { status: 400, text: p => Promise.resolve('error') },
promise = Promise.resolve(mockResponse)
global.fetch = r => { return promise }
OptionsActions.pureSendUpdate('bar', 'error')
expect(store.getActions()).toEqual([
{ type: OptionsEditorActions.OPTION_UPDATE_SUCCESS, option: 'foo'}
])
})
})
describe('save', () => {
it('should dump options', () => {
global.fetch = jest.fn()
store.dispatch(OptionsActions.save())
expect(fetch).toBeCalledWith(
'./options/save?_xsrf=undefined',
{
credentials: "same-origin",
method: "POST"
}
)
})
})
|