debian-mirror-gitlab/spec/frontend/ide/components/ide_status_bar_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

140 lines
3.8 KiB
JavaScript
Raw Normal View History

2022-08-27 11:52:29 +05:30
import { mount } from '@vue/test-utils';
2020-03-13 15:44:24 +05:30
import _ from 'lodash';
2021-03-08 18:12:59 +05:30
import { TEST_HOST } from 'helpers/test_constants';
2020-03-13 15:44:24 +05:30
import IdeStatusBar from '~/ide/components/ide_status_bar.vue';
2022-08-27 11:52:29 +05:30
import IdeStatusMR from '~/ide/components/ide_status_mr.vue';
2018-12-05 23:21:45 +05:30
import { rightSidebarViews } from '~/ide/constants';
2021-03-11 19:13:27 +05:30
import { createStore } from '~/ide/stores';
2018-10-15 14:42:47 +05:30
import { projectData } from '../mock_data';
2020-03-13 15:44:24 +05:30
const TEST_PROJECT_ID = 'abcproject';
const TEST_MERGE_REQUEST_ID = '9001';
const TEST_MERGE_REQUEST_URL = `${TEST_HOST}merge-requests/${TEST_MERGE_REQUEST_ID}`;
2022-07-23 23:45:48 +05:30
jest.mock('~/lib/utils/poll');
2022-08-27 11:52:29 +05:30
describe('IdeStatusBar component', () => {
let wrapper;
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,
});
2018-10-15 14:42:47 +05:30
2022-08-27 11:52:29 +05:30
wrapper = mount(IdeStatusBar, { store });
2020-03-13 15:44:24 +05:30
};
2018-10-15 14:42:47 +05:30
2020-03-13 15:44:24 +05:30
describe('default', () => {
2018-10-15 14:42:47 +05:30
it('triggers a setInterval', () => {
2022-08-27 11:52:29 +05:30
mountComponent();
expect(wrapper.vm.intervalId).not.toBe(null);
2018-10-15 14:42:47 +05:30
});
2020-03-13 15:44:24 +05:30
it('renders the statusbar', () => {
2022-08-27 11:52:29 +05:30
mountComponent();
expect(wrapper.classes()).toEqual(['ide-status-bar']);
2018-10-15 14:42:47 +05:30
});
2020-03-13 15:44:24 +05:30
describe('commitAgeUpdate', () => {
2020-05-24 23:13:21 +05:30
beforeEach(() => {
2022-08-27 11:52:29 +05:30
mountComponent();
jest.spyOn(wrapper.vm, 'commitAgeUpdate').mockImplementation(() => {});
2020-03-13 15:44:24 +05:30
});
2018-10-15 14:42:47 +05:30
2020-05-24 23:13:21 +05:30
afterEach(() => {
jest.clearAllTimers();
2020-03-13 15:44:24 +05:30
});
2018-10-15 14:42:47 +05:30
2020-03-13 15:44:24 +05:30
it('gets called every second', () => {
2022-08-27 11:52:29 +05:30
expect(wrapper.vm.commitAgeUpdate).not.toHaveBeenCalled();
2018-12-13 13:39:08 +05:30
2020-05-24 23:13:21 +05:30
jest.advanceTimersByTime(1000);
2018-10-15 14:42:47 +05:30
2022-08-27 11:52:29 +05:30
expect(wrapper.vm.commitAgeUpdate.mock.calls).toHaveLength(1);
2018-12-13 13:39:08 +05:30
2020-05-24 23:13:21 +05:30
jest.advanceTimersByTime(1000);
2020-03-13 15:44:24 +05:30
2022-08-27 11:52:29 +05:30
expect(wrapper.vm.commitAgeUpdate.mock.calls).toHaveLength(2);
2020-03-13 15:44:24 +05:30
});
2018-10-15 14:42:47 +05:30
});
2020-03-13 15:44:24 +05:30
describe('getCommitPath', () => {
it('returns the path to the commit details', () => {
2022-08-27 11:52:29 +05:30
mountComponent();
expect(wrapper.vm.getCommitPath('abc123de')).toBe('/commit/abc123de');
2020-03-13 15:44:24 +05:30
});
});
describe('pipeline status', () => {
2022-08-27 11:52:29 +05:30
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',
2020-03-13 15:44:24 +05:30
},
},
2022-08-27 11:52:29 +05:30
};
mountComponent({ pipelines });
jest.spyOn(wrapper.vm, 'openRightPane').mockImplementation(() => {});
2020-03-13 15:44:24 +05:30
2022-08-27 11:52:29 +05:30
wrapper.find('button').trigger('click');
2020-03-13 15:44:24 +05:30
2022-08-27 11:52:29 +05:30
expect(wrapper.vm.openRightPane).toHaveBeenCalledWith(rightSidebarViews.pipelines);
2020-03-13 15:44:24 +05:30
});
});
it('does not show merge request status', () => {
2022-08-27 11:52:29 +05:30
mountComponent();
expect(findMRStatus().exists()).toBe(false);
2018-10-15 14:42:47 +05:30
});
});
2018-11-18 11:00:15 +05:30
2020-03-13 15:44:24 +05:30
describe('with merge request in store', () => {
beforeEach(() => {
2022-08-27 11:52:29 +05:30
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}`,
},
},
},
2018-11-18 11:00:15 +05:30
},
},
2020-03-13 15:44:24 +05:30
};
2022-08-27 11:52:29 +05:30
mountComponent(state);
2020-03-13 15:44:24 +05:30
});
2018-11-18 11:00:15 +05:30
2020-03-13 15:44:24 +05:30
it('shows merge request status', () => {
2022-08-27 11:52:29 +05:30
expect(findMRStatus().text()).toBe(`Merge request !${TEST_MERGE_REQUEST_ID}`);
expect(findMRStatus().find('a').attributes('href')).toBe(TEST_MERGE_REQUEST_URL);
2018-11-18 11:00:15 +05:30
});
});
2018-10-15 14:42:47 +05:30
});