summaryrefslogtreecommitdiff
path: root/spec/frontend/user_lists/store/new/mutations_spec.js
blob: a928849e9415cfe9c66bdc67e82c1a7eb9927bae (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
import * as types from '~/user_lists/store/new/mutation_types';
import mutations from '~/user_lists/store/new/mutations';
import createState from '~/user_lists/store/new/state';

describe('User List Edit Mutations', () => {
  let state;

  beforeEach(() => {
    state = createState({ projectId: '1' });
  });

  describe(types.RECIEVE_USER_LIST_ERROR, () => {
    beforeEach(() => {
      mutations[types.RECEIVE_CREATE_USER_LIST_ERROR](state, ['network error']);
    });

    it('sets the error message to the recieved one', () => {
      expect(state.errorMessage).toEqual(['network error']);
    });

    it('sets the error message to the recevied API message if present', () => {
      const message = ['name is blank', 'name is too short'];

      mutations[types.RECEIVE_CREATE_USER_LIST_ERROR](state, message);
      expect(state.errorMessage).toEqual(message);
    });
  });

  describe(types.DISMISS_ERROR_ALERT, () => {
    beforeEach(() => {
      mutations[types.DISMISS_ERROR_ALERT](state);
    });

    it('clears the error message', () => {
      expect(state.errorMessage).toBe('');
    });
  });
});