summaryrefslogtreecommitdiff
path: root/spec/frontend/admin/statistics_panel/store/getters_spec.js
blob: 152d82531edf75b9121e2ccc4e6c7870d5e3d0f3 (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
import createState from '~/admin/statistics_panel/store/state';
import * as getters from '~/admin/statistics_panel/store/getters';

describe('Admin statistics panel getters', () => {
  let state;

  beforeEach(() => {
    state = createState();
  });

  describe('getStatistics', () => {
    describe('when statistics data exists', () => {
      it('returns an array of statistics objects with key, label and value', () => {
        state.statistics = { forks: 10, issues: 20 };

        const statisticsLabels = {
          forks: 'Forks',
          issues: 'Issues',
        };

        const statisticsData = [
          { key: 'forks', label: 'Forks', value: 10 },
          { key: 'issues', label: 'Issues', value: 20 },
        ];

        expect(getters.getStatistics(state)(statisticsLabels)).toEqual(statisticsData);
      });
    });

    describe('when no statistics data exists', () => {
      it('returns an array of statistics objects with key, label and sets value to null', () => {
        state.statistics = null;

        const statisticsLabels = {
          forks: 'Forks',
          issues: 'Issues',
        };

        const statisticsData = [
          { key: 'forks', label: 'Forks', value: null },
          { key: 'issues', label: 'Issues', value: null },
        ];

        expect(getters.getStatistics(state)(statisticsLabels)).toEqual(statisticsData);
      });
    });
  });
});