Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mutations_spec.js « store « awards_app « emoji « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dd32c3a444500e42d3596b4a98939f1f898b2999 (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
import {
  SET_INITIAL_DATA,
  FETCH_AWARDS_SUCCESS,
  ADD_NEW_AWARD,
  REMOVE_AWARD,
} from '~/emoji/awards_app/store/mutation_types';
import mutations from '~/emoji/awards_app/store/mutations';

describe('Awards app mutations', () => {
  describe('SET_INITIAL_DATA', () => {
    it('sets initial data', () => {
      const state = {};

      mutations[SET_INITIAL_DATA](state, {
        path: 'https://gitlab.com',
        currentUserId: 1,
        canAwardEmoji: true,
      });

      expect(state).toEqual({
        path: 'https://gitlab.com',
        currentUserId: 1,
        canAwardEmoji: true,
      });
    });
  });

  describe('FETCH_AWARDS_SUCCESS', () => {
    it('sets awards', () => {
      const state = { awards: [] };

      mutations[FETCH_AWARDS_SUCCESS](state, ['thumbsup']);

      expect(state.awards).toEqual(['thumbsup']);
    });

    it('does not overwrite previously set awards', () => {
      const state = { awards: ['thumbsup'] };

      mutations[FETCH_AWARDS_SUCCESS](state, ['thumbsdown']);

      expect(state.awards).toEqual(['thumbsup', 'thumbsdown']);
    });
  });

  describe('ADD_NEW_AWARD', () => {
    it('adds new award to array', () => {
      const state = { awards: ['thumbsup'] };

      mutations[ADD_NEW_AWARD](state, 'thumbsdown');

      expect(state.awards).toEqual(['thumbsup', 'thumbsdown']);
    });
  });

  describe('REMOVE_AWARD', () => {
    it('removes award from array', () => {
      const state = { awards: [{ id: 1 }, { id: 2 }] };

      mutations[REMOVE_AWARD](state, 1);

      expect(state.awards).toEqual([{ id: 2 }]);
    });
  });
});