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

ide_status_bar_spec.js « components « ide « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eb51faaaa164d88581d51ccb11dfed206e81b8ab (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
import { clone } from 'lodash';
import { TEST_HOST } from 'helpers/test_constants';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import IdeStatusBar from '~/ide/components/ide_status_bar.vue';
import IdeStatusMR from '~/ide/components/ide_status_mr.vue';
import { rightSidebarViews } from '~/ide/constants';
import { createStore } from '~/ide/stores';
import { projectData } from '../mock_data';

const TEST_PROJECT_ID = 'abcproject';
const TEST_MERGE_REQUEST_ID = '9001';
const TEST_MERGE_REQUEST_URL = `${TEST_HOST}merge-requests/${TEST_MERGE_REQUEST_ID}`;

jest.mock('~/lib/utils/poll');

describe('IdeStatusBar component', () => {
  let wrapper;
  const dummyIntervalId = 1337;
  let dispatchMock;

  const findMRStatus = () => wrapper.findComponent(IdeStatusMR);

  const mountComponent = (state = {}) => {
    const store = createStore();
    store.replaceState({
      ...store.state,
      currentBranchId: 'main',
      currentProjectId: TEST_PROJECT_ID,
      projects: {
        ...store.state.projects,
        [TEST_PROJECT_ID]: clone(projectData),
      },
      ...state,
    });

    wrapper = mountExtended(IdeStatusBar, { store });
    dispatchMock = jest.spyOn(store, 'dispatch');
  };

  beforeEach(() => {
    jest.spyOn(window, 'setInterval').mockReturnValue(dummyIntervalId);
  });

  const findCommitShaLink = () => wrapper.findByTestId('commit-sha-content');

  describe('default', () => {
    it('triggers a setInterval', () => {
      mountComponent();

      expect(window.setInterval).toHaveBeenCalledTimes(1);
    });

    it('renders the statusbar', () => {
      mountComponent();

      expect(wrapper.classes()).toEqual(['ide-status-bar']);
    });

    describe('getCommitPath', () => {
      it('returns the path to the commit details', () => {
        mountComponent();
        expect(findCommitShaLink().attributes('href')).toBe('/commit/abc123de');
      });
    });

    describe('pipeline status', () => {
      it('opens right sidebar on clicking icon', () => {
        const pipelines = {
          latestPipeline: {
            details: {
              status: {
                text: 'success',
                details_path: 'test',
                icon: 'status_success',
              },
            },
            commit: {
              author_gravatar_url: 'www',
            },
          },
        };
        mountComponent({ pipelines });

        wrapper.find('button').trigger('click');

        expect(dispatchMock).toHaveBeenCalledWith('rightPane/open', rightSidebarViews.pipelines);
      });
    });

    it('does not show merge request status', () => {
      mountComponent();

      expect(findMRStatus().exists()).toBe(false);
    });
  });

  describe('with merge request in store', () => {
    beforeEach(() => {
      const state = {
        currentMergeRequestId: TEST_MERGE_REQUEST_ID,
        projects: {
          [TEST_PROJECT_ID]: {
            ...clone(projectData),
            mergeRequests: {
              [TEST_MERGE_REQUEST_ID]: {
                web_url: TEST_MERGE_REQUEST_URL,
                references: {
                  short: `!${TEST_MERGE_REQUEST_ID}`,
                },
              },
            },
          },
        },
      };
      mountComponent(state);
    });

    it('shows merge request status', () => {
      expect(findMRStatus().text()).toBe(`Merge request !${TEST_MERGE_REQUEST_ID}`);
      expect(findMRStatus().find('a').attributes('href')).toBe(TEST_MERGE_REQUEST_URL);
    });
  });
});