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

timelog_source_cell_spec.js « components « time_tracking « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 14015ee4e751c43666a0094592376f93cad5c389 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import TimelogSourceCell from '~/time_tracking/components/timelog_source_cell.vue';
import {
  issuableStatusText,
  STATUS_CLOSED,
  STATUS_MERGED,
  STATUS_OPEN,
  STATUS_LOCKED,
  STATUS_REOPENED,
} from '~/issues/constants';

const createIssuableTimelogMock = (
  type,
  { title, state, webUrl, reference } = {
    title: 'Issuable title',
    state: STATUS_OPEN,
    webUrl: 'https://example.com/issuable_url',
    reference: '#111',
  },
) => {
  return {
    timelog: {
      project: {
        fullPath: 'group/project',
      },
      [type]: {
        title,
        state,
        webUrl,
        reference,
      },
    },
  };
};

describe('TimelogSourceCell component', () => {
  Vue.use(VueApollo);

  let wrapper;

  const findTitleContainer = () => wrapper.findByTestId('title-container');
  const findReferenceContainer = () => wrapper.findByTestId('reference-container');
  const findStateContainer = () => wrapper.findByTestId('state-container');

  const mountComponent = ({ timelog } = {}) => {
    wrapper = shallowMountExtended(TimelogSourceCell, {
      propsData: {
        timelog,
      },
    });
  };

  describe('when the timelog is associated to an issue', () => {
    it('shows the issue title as link to the issue', () => {
      mountComponent(
        createIssuableTimelogMock('issue', {
          title: 'Issue title',
          webUrl: 'https://example.com/issue_url',
        }),
      );

      const titleContainer = findTitleContainer();

      expect(titleContainer.text()).toBe('Issue title');
      expect(titleContainer.attributes('href')).toBe('https://example.com/issue_url');
    });

    it('shows the issue full reference as link to the issue', () => {
      mountComponent(
        createIssuableTimelogMock('issue', {
          reference: '#111',
          webUrl: 'https://example.com/issue_url',
        }),
      );

      const referenceContainer = findReferenceContainer();

      expect(referenceContainer.text()).toBe('group/project#111');
      expect(referenceContainer.attributes('href')).toBe('https://example.com/issue_url');
    });

    it.each`
      state              | stateDescription
      ${STATUS_OPEN}     | ${issuableStatusText[STATUS_OPEN]}
      ${STATUS_REOPENED} | ${issuableStatusText[STATUS_REOPENED]}
      ${STATUS_LOCKED}   | ${issuableStatusText[STATUS_LOCKED]}
      ${STATUS_CLOSED}   | ${issuableStatusText[STATUS_CLOSED]}
    `('shows $stateDescription when the state is $state', ({ state, stateDescription }) => {
      mountComponent(createIssuableTimelogMock('issue', { state }));

      expect(findStateContainer().text()).toBe(stateDescription);
    });
  });

  describe('when the timelog is associated to a merge request', () => {
    it('shows the merge request title as link to the merge request', () => {
      mountComponent(
        createIssuableTimelogMock('mergeRequest', {
          title: 'MR title',
          webUrl: 'https://example.com/mr_url',
        }),
      );

      const titleContainer = findTitleContainer();

      expect(titleContainer.text()).toBe('MR title');
      expect(titleContainer.attributes('href')).toBe('https://example.com/mr_url');
    });

    it('shows the merge request full reference as link to the merge request', () => {
      mountComponent(
        createIssuableTimelogMock('mergeRequest', {
          reference: '!111',
          webUrl: 'https://example.com/mr_url',
        }),
      );

      const referenceContainer = findReferenceContainer();

      expect(referenceContainer.text()).toBe('group/project!111');
      expect(referenceContainer.attributes('href')).toBe('https://example.com/mr_url');
    });
    it.each`
      state            | stateDescription
      ${STATUS_OPEN}   | ${issuableStatusText[STATUS_OPEN]}
      ${STATUS_CLOSED} | ${issuableStatusText[STATUS_CLOSED]}
      ${STATUS_MERGED} | ${issuableStatusText[STATUS_MERGED]}
    `('shows $stateDescription when the state is $state', ({ state, stateDescription }) => {
      mountComponent(createIssuableTimelogMock('mergeRequest', { state }));

      expect(findStateContainer().text()).toBe(stateDescription);
    });
  });
});