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

utils_spec.js « cycle_analytics « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 73e26e1cdcc91822e1c12cd251d839e55170fd62 (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
import { decorateEvents, decorateData } from '~/cycle_analytics/utils';
import { selectedStage, rawData, convertedData, rawEvents } from './mock_data';

describe('Value stream analytics utils', () => {
  describe('decorateEvents', () => {
    const [result] = decorateEvents(rawEvents, selectedStage);
    const eventKeys = Object.keys(result);
    const authorKeys = Object.keys(result.author);
    it('will return the same number of events', () => {
      expect(decorateEvents(rawEvents, selectedStage).length).toBe(rawEvents.length);
    });

    it('will set all the required event fields', () => {
      ['totalTime', 'author', 'createdAt', 'shortSha', 'commitUrl'].forEach((key) => {
        expect(eventKeys).toContain(key);
      });
      ['webUrl', 'avatarUrl'].forEach((key) => {
        expect(authorKeys).toContain(key);
      });
    });

    it('will remove unused fields', () => {
      ['total_time', 'created_at', 'short_sha', 'commit_url'].forEach((key) => {
        expect(eventKeys).not.toContain(key);
      });

      ['web_url', 'avatar_url'].forEach((key) => {
        expect(authorKeys).not.toContain(key);
      });
    });
  });

  describe('decorateData', () => {
    const result = decorateData(rawData);
    it('returns the summary data', () => {
      expect(result.summary).toEqual(convertedData.summary);
    });

    it('returns the stages data', () => {
      expect(result.stages).toEqual(convertedData.stages);
    });

    it('returns each of the default value stream stages', () => {
      const stages = result.stages.map(({ name }) => name);
      ['issue', 'plan', 'code', 'test', 'review', 'staging'].forEach((stageName) => {
        expect(stages).toContain(stageName);
      });
    });

    it('returns `-` for summary data that has no value', () => {
      const singleSummaryResult = decorateData({
        stats: [],
        permissions: { issue: true },
        summary: [{ value: null, title: 'Commits' }],
      });
      expect(singleSummaryResult.summary).toEqual([{ value: '-', title: 'Commits' }]);
    });

    it('returns additional fields for each stage', () => {
      const singleStageResult = decorateData({
        stats: [{ name: 'issue', value: null }],
        permissions: { issue: false },
      });
      const stage = singleStageResult.stages[0];
      const txt =
        'The issue stage shows the time it takes from creating an issue to assigning the issue to a milestone, or add the issue to a list on your Issue Board. Begin creating issues to see data for this stage.';

      expect(stage).toMatchObject({
        active: false,
        isUserAllowed: false,
        emptyStageText: txt,
        slug: 'issue',
        component: 'stage-issue-component',
      });
    });
  });
});