summaryrefslogtreecommitdiff
path: root/spec/frontend/pipelines/pipeline_tabs_spec.js
blob: b184ce31d20dd70962ffc3efb580b4c8c84a861e (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
import { createAppOptions, createPipelineTabs } from '~/pipelines/pipeline_tabs';
import { updateHistory } from '~/lib/utils/url_utility';

jest.mock('~/lib/utils/url_utility', () => ({
  removeParams: () => 'gitlab.com',
  updateHistory: jest.fn(),
  joinPaths: () => {},
  setUrlFragment: () => {},
}));

jest.mock('~/pipelines/utils', () => ({
  getPipelineDefaultTab: () => '',
}));

describe('~/pipelines/pipeline_tabs.js', () => {
  describe('createAppOptions', () => {
    const SELECTOR = 'SELECTOR';

    let el;

    const createElement = () => {
      el = document.createElement('div');
      el.id = SELECTOR;
      el.dataset.canGenerateCodequalityReports = 'true';
      el.dataset.codequalityReportDownloadPath = 'codequalityReportDownloadPath';
      el.dataset.downloadablePathForReportType = 'downloadablePathForReportType';
      el.dataset.exposeSecurityDashboard = 'true';
      el.dataset.exposeLicenseScanningData = 'true';
      el.dataset.failedJobsCount = 1;
      el.dataset.failedJobsSummary = '[]';
      el.dataset.graphqlResourceEtag = 'graphqlResourceEtag';
      el.dataset.pipelineIid = '123';
      el.dataset.pipelineProjectPath = 'pipelineProjectPath';

      document.body.appendChild(el);
    };

    afterEach(() => {
      el = null;
    });

    it("extracts the properties from the element's dataset", () => {
      createElement();
      const options = createAppOptions(`#${SELECTOR}`, null);

      expect(options).toMatchObject({
        el,
        provide: {
          canGenerateCodequalityReports: true,
          codequalityReportDownloadPath: 'codequalityReportDownloadPath',
          downloadablePathForReportType: 'downloadablePathForReportType',
          exposeSecurityDashboard: true,
          exposeLicenseScanningData: true,
          failedJobsCount: '1',
          failedJobsSummary: [],
          graphqlResourceEtag: 'graphqlResourceEtag',
          pipelineIid: '123',
          pipelineProjectPath: 'pipelineProjectPath',
        },
      });
    });

    it('returns `null` if el does not exist', () => {
      expect(createAppOptions('foo', null)).toBe(null);
    });
  });

  describe('createPipelineTabs', () => {
    const title = 'Pipeline Tabs';

    beforeAll(() => {
      document.title = title;
    });

    afterAll(() => {
      document.title = '';
    });

    it('calls `updateHistory` with correct params', () => {
      createPipelineTabs({});

      expect(updateHistory).toHaveBeenCalledWith({
        title,
        url: 'gitlab.com',
        replace: true,
      });
    });

    it("returns early if options aren't provided", () => {
      createPipelineTabs();

      expect(updateHistory).not.toHaveBeenCalled();
    });
  });
});