aboutsummaryrefslogtreecommitdiff
path: root/test/settings/reducers/setting.test.js
blob: c1a164877be34f6e2bc0520bdab2b488e0cf3a35 (plain) (blame)
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
import actions from 'settings/actions';
import settingReducer from 'settings/reducers/setting';

describe("settings setting reducer", () => {
  it('return the initial state', () => {
    let state = settingReducer(undefined, {});
    expect(state).to.have.deep.property('json', '');
    expect(state).to.have.deep.property('form', null);
    expect(state).to.have.deep.property('error', '');
  });

  it('return next state for SETTING_SET_SETTINGS', () => {
    let action = {
      type: actions.SETTING_SET_SETTINGS,
      source: 'json',
      json: '{ "key": "value" }',
      form: {},
    };
    let state = settingReducer(undefined, action);
    expect(state).to.have.deep.property('source', 'json');
    expect(state).to.have.deep.property('json', '{ "key": "value" }');
    expect(state).to.have.deep.property('form', {});
  });

  it('return next state for SETTING_SHOW_ERROR', () => {
    let action = {
      type: actions.SETTING_SHOW_ERROR,
      error: 'bad value',
      json: '{}',
    };
    let state = settingReducer(undefined, action);
    expect(state).to.have.deep.property('error', 'bad value');
    expect(state).to.have.deep.property('json', '{}');
  });

  it('return next state for SETTING_SWITCH_TO_FORM', () => {
    let action = {
      type: actions.SETTING_SWITCH_TO_FORM,
      form: {},
    };
    let state = settingReducer(undefined, action);
    expect(state).to.have.deep.property('form', {});
    expect(state).to.have.deep.property('source', 'form');
  });

  it('return next state for SETTING_SWITCH_TO_JSON', () => {
    let action = {
      type: actions.SETTING_SWITCH_TO_JSON,
      json: '{}',
    };
    let state = settingReducer(undefined, action);
    expect(state).to.have.deep.property('json', '{}');
    expect(state).to.have.deep.property('source', 'json');
  });
});