aboutsummaryrefslogtreecommitdiffstats
path: root/spec/javascript/journey_patterns/reducers/modal_spec.js
blob: 4031ea2340596ac1d81d77e6243504527d9e213a (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import modalReducer from '../../../../app/javascript/journey_patterns/reducers/modal'

let state = {}

let fakeJourneyPattern = {
  name: 'jp_test 1',
  object_id: 'jp_test:JourneyPattern:1',
  published_name: 'jp_test publishedname 1',
  registration_number: 'jp_test registrationnumber 1',
  stop_points: [],
  deletable: false
}

const cb = function(){}

describe('modal reducer', () => {
  beforeEach(() => {
    state = {
      type: '',
      modalProps: {},
      confirmModal: {}
    }
  })

  it('should return the initial state', () => {
    expect(
      modalReducer(undefined, {})
    ).toEqual({})
  })

  it('should handle OPEN_CONFIRM_MODAL', () => {
    let newState = Object.assign({}, state, {
      type: 'confirm',
      confirmModal: {
        callback: cb
      }
    })
    expect(
      modalReducer(state, {
        type: 'OPEN_CONFIRM_MODAL',
        callback: cb
      })
    ).toEqual(newState)
  })

  it('should handle EDIT_JOURNEYPATTERN_MODAL', () => {
    let newState = Object.assign({}, state, {
      type: 'edit',
      modalProps: {
        index: 0,
        journeyPattern: fakeJourneyPattern
      },
      confirmModal: {}
    })
    expect(
      modalReducer(state, {
        type: 'EDIT_JOURNEYPATTERN_MODAL',
        index: 0,
        journeyPattern : fakeJourneyPattern
      })
    ).toEqual(newState)
  })

  it('should handle CREATE_JOURNEYPATTERN_MODAL', () => {
    expect(
      modalReducer(state, {
        type: 'CREATE_JOURNEYPATTERN_MODAL'
      })
    ).toEqual(Object.assign({}, state, { type: 'create' }))
  })

  it('should handle DELETE_JOURNEYPATTERN', () => {
    expect(
      modalReducer(state, {
        type: 'DELETE_JOURNEYPATTERN',
        index: 0
      })
    ).toEqual(state)
  })

  it('should handle SAVE_MODAL', () => {
    expect(
      modalReducer(state, {
        type: 'SAVE_MODAL',
        index: 0,
        data: {}
      })
    ).toEqual(state)
  })

  it('should handle CLOSE_MODAL', () => {
    expect(
      modalReducer(state, {
        type: 'CLOSE_MODAL'
      })
    ).toEqual(state)
  })
})