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

130 lines
3.6 KiB
JavaScript
Raw Normal View History

2018-10-15 14:42:47 +05:30
import Vue from 'vue';
2020-03-13 15:44:24 +05:30
import _ from 'lodash';
2020-01-01 13:55:28 +05:30
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
2020-03-13 15:44:24 +05:30
import { TEST_HOST } from 'spec/test_constants';
import { createStore } from '~/ide/stores';
import IdeStatusBar from '~/ide/components/ide_status_bar.vue';
2018-12-05 23:21:45 +05:30
import { rightSidebarViews } from '~/ide/constants';
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}`;
2018-10-15 14:42:47 +05:30
describe('ideStatusBar', () => {
2020-03-13 15:44:24 +05:30
let store;
2018-10-15 14:42:47 +05:30
let vm;
2020-03-13 15:44:24 +05:30
const createComponent = () => {
vm = createComponentWithStore(Vue.extend(IdeStatusBar), store).$mount();
};
const findMRStatus = () => vm.$el.querySelector('.js-ide-status-mr');
2018-10-15 14:42:47 +05:30
2020-03-13 15:44:24 +05:30
beforeEach(() => {
store = createStore();
store.state.currentProjectId = TEST_PROJECT_ID;
store.state.projects[TEST_PROJECT_ID] = _.clone(projectData);
2018-11-18 11:00:15 +05:30
store.state.currentBranchId = 'master';
2018-10-15 14:42:47 +05:30
});
afterEach(() => {
vm.$destroy();
});
2020-03-13 15:44:24 +05:30
describe('default', () => {
beforeEach(() => {
createComponent();
});
2018-10-15 14:42:47 +05:30
it('triggers a setInterval', () => {
expect(vm.intervalId).not.toBe(null);
});
2020-03-13 15:44:24 +05:30
it('renders the statusbar', () => {
expect(vm.$el.className).toBe('ide-status-bar');
2018-10-15 14:42:47 +05:30
});
2020-03-13 15:44:24 +05:30
describe('commitAgeUpdate', () => {
beforeEach(function() {
jasmine.clock().install();
spyOn(vm, 'commitAgeUpdate').and.callFake(() => {});
vm.startTimer();
});
2018-10-15 14:42:47 +05:30
2020-03-13 15:44:24 +05:30
afterEach(function() {
jasmine.clock().uninstall();
});
2018-10-15 14:42:47 +05:30
2020-03-13 15:44:24 +05:30
it('gets called every second', () => {
expect(vm.commitAgeUpdate).not.toHaveBeenCalled();
2018-12-13 13:39:08 +05:30
2020-03-13 15:44:24 +05:30
jasmine.clock().tick(1100);
2018-10-15 14:42:47 +05:30
2020-03-13 15:44:24 +05:30
expect(vm.commitAgeUpdate.calls.count()).toEqual(1);
2018-12-13 13:39:08 +05:30
2020-03-13 15:44:24 +05:30
jasmine.clock().tick(1000);
expect(vm.commitAgeUpdate.calls.count()).toEqual(2);
});
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', () => {
expect(vm.getCommitPath('abc123de')).toBe('/commit/abc123de');
});
});
describe('pipeline status', () => {
it('opens right sidebar on clicking icon', done => {
spyOn(vm, 'openRightPane');
Vue.set(vm.$store.state.pipelines, 'latestPipeline', {
details: {
status: {
text: 'success',
details_path: 'test',
icon: 'status_success',
},
},
commit: {
author_gravatar_url: 'www',
},
});
vm.$nextTick()
.then(() => {
vm.$el.querySelector('.ide-status-pipeline button').click();
expect(vm.openRightPane).toHaveBeenCalledWith(rightSidebarViews.pipelines);
})
.then(done)
.catch(done.fail);
});
});
it('does not show merge request status', () => {
expect(findMRStatus()).toBe(null);
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(() => {
store.state.projects[TEST_PROJECT_ID].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
};
store.state.currentMergeRequestId = TEST_MERGE_REQUEST_ID;
2018-11-18 11:00:15 +05:30
2020-03-13 15:44:24 +05:30
createComponent();
});
2018-11-18 11:00:15 +05:30
2020-03-13 15:44:24 +05:30
it('shows merge request status', () => {
expect(findMRStatus().textContent.trim()).toEqual(`Merge request !${TEST_MERGE_REQUEST_ID}`);
expect(findMRStatus().querySelector('a').href).toEqual(TEST_MERGE_REQUEST_URL);
2018-11-18 11:00:15 +05:30
});
});
2018-10-15 14:42:47 +05:30
});