2017-08-17 22:00:37 +05:30
|
|
|
import Vue from 'vue';
|
2018-10-15 14:42:47 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-09-10 17:25:29 +05:30
|
|
|
import pipelinesComp from '~/pipelines/components/pipelines.vue';
|
2017-08-17 22:00:37 +05:30
|
|
|
import Store from '~/pipelines/stores/pipelines_store';
|
2018-03-27 19:54:05 +05:30
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
2018-10-15 14:42:47 +05:30
|
|
|
import { pipelineWithStages, stageReply } from './mock_data';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe('Pipelines', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
const jsonFixtureName = 'pipelines/pipelines.json';
|
|
|
|
|
|
|
|
preloadFixtures(jsonFixtureName);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
let PipelinesComponent;
|
2018-03-17 18:26:18 +05:30
|
|
|
let pipelines;
|
2018-03-27 19:54:05 +05:30
|
|
|
let vm;
|
2018-10-15 14:42:47 +05:30
|
|
|
let mock;
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
const paths = {
|
|
|
|
endpoint: 'twitter/flight/pipelines.json',
|
|
|
|
autoDevopsPath: '/help/topics/autodevops/index.md',
|
|
|
|
helpPagePath: '/help/ci/quick_start/README',
|
|
|
|
emptyStateSvgPath: '/assets/illustrations/pipelines_empty.svg',
|
|
|
|
errorStateSvgPath: '/assets/illustrations/pipelines_failed.svg',
|
|
|
|
noPipelinesSvgPath: '/assets/illustrations/pipelines_pending.svg',
|
|
|
|
ciLintPath: '/ci/lint',
|
|
|
|
resetCachePath: '/twitter/flight/settings/ci_cd/reset_cache',
|
|
|
|
newPipelinePath: '/twitter/flight/pipelines/new',
|
|
|
|
};
|
|
|
|
|
|
|
|
const noPermissions = {
|
|
|
|
endpoint: 'twitter/flight/pipelines.json',
|
|
|
|
autoDevopsPath: '/help/topics/autodevops/index.md',
|
|
|
|
helpPagePath: '/help/ci/quick_start/README',
|
|
|
|
emptyStateSvgPath: '/assets/illustrations/pipelines_empty.svg',
|
|
|
|
errorStateSvgPath: '/assets/illustrations/pipelines_failed.svg',
|
|
|
|
noPipelinesSvgPath: '/assets/illustrations/pipelines_pending.svg',
|
|
|
|
};
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-10-15 14:42:47 +05:30
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
pipelines = getJSONFixture(jsonFixtureName);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
PipelinesComponent = Vue.extend(pipelinesComp);
|
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
afterEach(() => {
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.$destroy();
|
2018-10-15 14:42:47 +05:30
|
|
|
mock.restore();
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('With permission', () => {
|
|
|
|
describe('With pipelines in main tab', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
2018-10-15 14:42:47 +05:30
|
|
|
mock.onGet('twitter/flight/pipelines.json').reply(200, pipelines);
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: true,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...paths,
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders tabs', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-all').textContent.trim()).toContain('All');
|
|
|
|
});
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
it('renders Run Pipeline link', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('.js-run-pipeline').getAttribute('href')).toEqual(
|
|
|
|
paths.newPipelinePath,
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
it('renders CI Lint link', () => {
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(vm.$el.querySelector('.js-ci-lint').getAttribute('href')).toEqual(paths.ciLintPath);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders Clear Runner Cache button', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('.js-clear-cache').textContent.trim()).toEqual(
|
|
|
|
'Clear Runner Caches',
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders pipelines table', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelectorAll('.gl-responsive-table-row').length).toEqual(
|
|
|
|
pipelines.pipelines.length + 1,
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Without pipelines on main tab with CI', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
2018-10-15 14:42:47 +05:30
|
|
|
mock.onGet('twitter/flight/pipelines.json').reply(200, {
|
|
|
|
pipelines: [],
|
|
|
|
count: {
|
|
|
|
all: 0,
|
|
|
|
pending: 0,
|
|
|
|
running: 0,
|
|
|
|
finished: 0,
|
|
|
|
},
|
|
|
|
});
|
2018-03-27 19:54:05 +05:30
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: true,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...paths,
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders tabs', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-all').textContent.trim()).toContain('All');
|
|
|
|
});
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
it('renders Run Pipeline link', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('.js-run-pipeline').getAttribute('href')).toEqual(
|
|
|
|
paths.newPipelinePath,
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
it('renders CI Lint link', () => {
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(vm.$el.querySelector('.js-ci-lint').getAttribute('href')).toEqual(paths.ciLintPath);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders Clear Runner Cache button', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('.js-clear-cache').textContent.trim()).toEqual(
|
|
|
|
'Clear Runner Caches',
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders tab empty state', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('.empty-state h4').textContent.trim()).toEqual(
|
|
|
|
'There are currently no pipelines.',
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Without pipelines nor CI', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
2018-10-15 14:42:47 +05:30
|
|
|
mock.onGet('twitter/flight/pipelines.json').reply(200, {
|
|
|
|
pipelines: [],
|
|
|
|
count: {
|
|
|
|
all: 0,
|
|
|
|
pending: 0,
|
|
|
|
running: 0,
|
|
|
|
finished: 0,
|
|
|
|
},
|
|
|
|
});
|
2018-03-27 19:54:05 +05:30
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: false,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...paths,
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders empty state', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('.js-empty-state h4').textContent.trim()).toEqual(
|
|
|
|
'Build with confidence',
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(vm.$el.querySelector('.js-get-started-pipelines').getAttribute('href')).toEqual(
|
|
|
|
paths.helpPagePath,
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render tabs nor buttons', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-all')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-run-pipeline')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-ci-lint')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-clear-cache')).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('When API returns error', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
2018-10-15 14:42:47 +05:30
|
|
|
mock.onGet('twitter/flight/pipelines.json').reply(500, {});
|
2018-03-27 19:54:05 +05:30
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: false,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...paths,
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders tabs', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-all').textContent.trim()).toContain('All');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders buttons', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('.js-run-pipeline').getAttribute('href')).toEqual(
|
|
|
|
paths.newPipelinePath,
|
|
|
|
);
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(vm.$el.querySelector('.js-ci-lint').getAttribute('href')).toEqual(paths.ciLintPath);
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('.js-clear-cache').textContent.trim()).toEqual(
|
|
|
|
'Clear Runner Caches',
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders error state', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('.empty-state').textContent.trim()).toContain(
|
|
|
|
'There was an error fetching the pipelines.',
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Without permission', () => {
|
|
|
|
describe('With pipelines in main tab', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
2018-10-15 14:42:47 +05:30
|
|
|
mock.onGet('twitter/flight/pipelines.json').reply(200, pipelines);
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: false,
|
|
|
|
canCreatePipeline: false,
|
|
|
|
...noPermissions,
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders tabs', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-all').textContent.trim()).toContain('All');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render buttons', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-run-pipeline')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-ci-lint')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-clear-cache')).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders pipelines table', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelectorAll('.gl-responsive-table-row').length).toEqual(
|
|
|
|
pipelines.pipelines.length + 1,
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Without pipelines on main tab with CI', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
2018-10-15 14:42:47 +05:30
|
|
|
mock.onGet('twitter/flight/pipelines.json').reply(200, {
|
|
|
|
pipelines: [],
|
|
|
|
count: {
|
|
|
|
all: 0,
|
|
|
|
pending: 0,
|
|
|
|
running: 0,
|
|
|
|
finished: 0,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: true,
|
|
|
|
canCreatePipeline: false,
|
|
|
|
...noPermissions,
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders tabs', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-all').textContent.trim()).toContain('All');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render buttons', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-run-pipeline')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-ci-lint')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-clear-cache')).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders tab empty state', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('.empty-state h4').textContent.trim()).toEqual(
|
|
|
|
'There are currently no pipelines.',
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Without pipelines nor CI', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
2018-10-15 14:42:47 +05:30
|
|
|
mock.onGet('twitter/flight/pipelines.json').reply(200, {
|
|
|
|
pipelines: [],
|
|
|
|
count: {
|
|
|
|
all: 0,
|
|
|
|
pending: 0,
|
|
|
|
running: 0,
|
|
|
|
finished: 0,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: false,
|
|
|
|
canCreatePipeline: false,
|
|
|
|
...noPermissions,
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders empty state without button to set CI', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('.js-empty-state').textContent.trim()).toEqual(
|
|
|
|
'This project is not currently set up to run pipelines.',
|
|
|
|
);
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(vm.$el.querySelector('.js-get-started-pipelines')).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render tabs or buttons', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-all')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-run-pipeline')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-ci-lint')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-clear-cache')).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('When API returns error', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(done => {
|
2018-10-15 14:42:47 +05:30
|
|
|
mock.onGet('twitter/flight/pipelines.json').reply(500, {});
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: false,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...noPermissions,
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders tabs', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-all').textContent.trim()).toContain('All');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not renders buttons', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-run-pipeline')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-ci-lint')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-clear-cache')).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders error state', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('.empty-state').textContent.trim()).toContain(
|
|
|
|
'There was an error fetching the pipelines.',
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
describe('successful request', () => {
|
2017-08-17 22:00:37 +05:30
|
|
|
describe('with pipelines', () => {
|
|
|
|
beforeEach(() => {
|
2018-10-15 14:42:47 +05:30
|
|
|
mock.onGet('twitter/flight/pipelines.json').reply(200, pipelines);
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
vm = mountComponent(PipelinesComponent, {
|
2018-03-17 18:26:18 +05:30
|
|
|
store: new Store(),
|
2018-03-27 19:54:05 +05:30
|
|
|
hasGitlabCi: true,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...paths,
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('should render table', done => {
|
2017-08-17 22:00:37 +05:30
|
|
|
setTimeout(() => {
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(vm.$el.querySelector('.table-holder')).toBeDefined();
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelectorAll('.gl-responsive-table-row').length).toEqual(
|
|
|
|
pipelines.pipelines.length + 1,
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('should render navigation tabs', done => {
|
2018-03-17 18:26:18 +05:30
|
|
|
setTimeout(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-pending').textContent.trim()).toContain(
|
|
|
|
'Pending',
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-all').textContent.trim()).toContain('All');
|
|
|
|
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-running').textContent.trim()).toContain(
|
|
|
|
'Running',
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-finished').textContent.trim()).toContain(
|
|
|
|
'Finished',
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-branches').textContent.trim()).toContain(
|
|
|
|
'Branches',
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-tags').textContent.trim()).toContain(
|
|
|
|
'Tags',
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('should make an API request when using tabs', done => {
|
2018-03-17 18:26:18 +05:30
|
|
|
setTimeout(() => {
|
2018-03-27 19:54:05 +05:30
|
|
|
spyOn(vm, 'updateContent');
|
|
|
|
vm.$el.querySelector('.js-pipelines-tab-finished').click();
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(vm.updateContent).toHaveBeenCalledWith({ scope: 'finished', page: '1' });
|
2017-08-17 22:00:37 +05:30
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
describe('with pagination', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
it('should make an API request when using pagination', done => {
|
2018-03-17 18:26:18 +05:30
|
|
|
setTimeout(() => {
|
2018-03-27 19:54:05 +05:30
|
|
|
spyOn(vm, 'updateContent');
|
2018-03-17 18:26:18 +05:30
|
|
|
// Mock pagination
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.store.state.pageInfo = {
|
2018-03-17 18:26:18 +05:30
|
|
|
page: 1,
|
|
|
|
total: 10,
|
|
|
|
perPage: 2,
|
|
|
|
nextPage: 2,
|
|
|
|
totalPages: 5,
|
|
|
|
};
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.$nextTick(() => {
|
2019-05-30 16:15:17 +05:30
|
|
|
vm.$el.querySelector('.js-next-button a').click();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(vm.updateContent).toHaveBeenCalledWith({ scope: 'all', page: '2' });
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
describe('methods', () => {
|
|
|
|
beforeEach(() => {
|
2018-11-08 19:23:39 +05:30
|
|
|
spyOn(window.history, 'pushState').and.stub();
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
describe('updateContent', () => {
|
|
|
|
it('should set given parameters', () => {
|
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: true,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...paths,
|
|
|
|
});
|
|
|
|
vm.updateContent({ scope: 'finished', page: '4' });
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(vm.page).toEqual('4');
|
|
|
|
expect(vm.scope).toEqual('finished');
|
|
|
|
expect(vm.requestData.scope).toEqual('finished');
|
|
|
|
expect(vm.requestData.page).toEqual('4');
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('onChangeTab', () => {
|
|
|
|
it('should set page to 1', () => {
|
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: true,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...paths,
|
|
|
|
});
|
|
|
|
spyOn(vm, 'updateContent');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.onChangeTab('running');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(vm.updateContent).toHaveBeenCalledWith({ scope: 'running', page: '1' });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onChangePage', () => {
|
|
|
|
it('should update page and keep scope', () => {
|
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: true,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...paths,
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
2018-03-27 19:54:05 +05:30
|
|
|
spyOn(vm, 'updateContent');
|
|
|
|
|
|
|
|
vm.onChangePage(4);
|
|
|
|
|
|
|
|
expect(vm.updateContent).toHaveBeenCalledWith({ scope: vm.scope, page: '4' });
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
describe('computed properties', () => {
|
2017-08-17 22:00:37 +05:30
|
|
|
beforeEach(() => {
|
2018-03-27 19:54:05 +05:30
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: true,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...paths,
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
describe('tabs', () => {
|
|
|
|
it('returns default tabs', () => {
|
|
|
|
expect(vm.tabs).toEqual([
|
|
|
|
{ name: 'All', scope: 'all', count: undefined, isActive: true },
|
|
|
|
{ name: 'Pending', scope: 'pending', count: undefined, isActive: false },
|
|
|
|
{ name: 'Running', scope: 'running', count: undefined, isActive: false },
|
|
|
|
{ name: 'Finished', scope: 'finished', count: undefined, isActive: false },
|
|
|
|
{ name: 'Branches', scope: 'branches', isActive: false },
|
|
|
|
{ name: 'Tags', scope: 'tags', isActive: false },
|
|
|
|
]);
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
describe('emptyTabMessage', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
it('returns message with scope', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.scope = 'pending';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.emptyTabMessage).toEqual('There are currently no pending pipelines.');
|
|
|
|
done();
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
it('returns message without scope when scope is `all`', () => {
|
|
|
|
expect(vm.emptyTabMessage).toEqual('There are currently no pipelines.');
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
describe('stateToRender', () => {
|
|
|
|
it('returns loading state when the app is loading', () => {
|
|
|
|
expect(vm.stateToRender).toEqual('loading');
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('returns error state when app has error', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.hasError = true;
|
|
|
|
vm.isLoading = false;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.stateToRender).toEqual('error');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('returns table list when app has pipelines', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.isLoading = false;
|
|
|
|
vm.hasError = false;
|
|
|
|
vm.state.pipelines = pipelines.pipelines;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.stateToRender).toEqual('tableList');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('returns empty tab when app does not have pipelines but project has pipelines', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.state.count.all = 10;
|
|
|
|
vm.isLoading = false;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.stateToRender).toEqual('emptyTab');
|
|
|
|
|
|
|
|
done();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('returns empty tab when project has CI', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.isLoading = false;
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.stateToRender).toEqual('emptyTab');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('returns empty state when project does not have pipelines nor CI', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.isLoading = false;
|
|
|
|
vm.hasGitlabCi = false;
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.stateToRender).toEqual('emptyState');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
describe('shouldRenderTabs', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
it('returns true when state is loading & has already made the first request', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.isLoading = true;
|
|
|
|
vm.hasMadeRequest = true;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.shouldRenderTabs).toEqual(true);
|
|
|
|
|
|
|
|
done();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('returns true when state is tableList & has already made the first request', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.isLoading = false;
|
|
|
|
vm.state.pipelines = pipelines.pipelines;
|
|
|
|
vm.hasMadeRequest = true;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.shouldRenderTabs).toEqual(true);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('returns true when state is error & has already made the first request', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.isLoading = false;
|
|
|
|
vm.hasError = true;
|
|
|
|
vm.hasMadeRequest = true;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.shouldRenderTabs).toEqual(true);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('returns true when state is empty tab & has already made the first request', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.isLoading = false;
|
|
|
|
vm.state.count.all = 10;
|
|
|
|
vm.hasMadeRequest = true;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.shouldRenderTabs).toEqual(true);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('returns false when has not made first request', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.hasMadeRequest = false;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.shouldRenderTabs).toEqual(false);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('returns false when state is empty state', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.isLoading = false;
|
|
|
|
vm.hasMadeRequest = true;
|
|
|
|
vm.hasGitlabCi = false;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.shouldRenderTabs).toEqual(false);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
describe('shouldRenderButtons', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
it('returns true when it has paths & has made the first request', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.hasMadeRequest = true;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.shouldRenderButtons).toEqual(true);
|
|
|
|
|
|
|
|
done();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('returns false when it has not made the first request', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.hasMadeRequest = false;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.shouldRenderButtons).toEqual(false);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
done();
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
describe('updates results when a staged is clicked', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const copyPipeline = Object.assign({}, pipelineWithStages);
|
|
|
|
copyPipeline.id += 1;
|
|
|
|
mock
|
2018-12-13 13:39:08 +05:30
|
|
|
.onGet('twitter/flight/pipelines.json')
|
|
|
|
.reply(
|
|
|
|
200,
|
|
|
|
{
|
|
|
|
pipelines: [pipelineWithStages],
|
|
|
|
count: {
|
|
|
|
all: 1,
|
|
|
|
finished: 1,
|
|
|
|
pending: 0,
|
|
|
|
running: 0,
|
|
|
|
},
|
2018-10-15 14:42:47 +05:30
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
{
|
|
|
|
'POLL-INTERVAL': 100,
|
|
|
|
},
|
|
|
|
)
|
2018-10-15 14:42:47 +05:30
|
|
|
.onGet(pipelineWithStages.details.stages[0].dropdown_path)
|
2018-12-13 13:39:08 +05:30
|
|
|
.reply(200, stageReply);
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: true,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...paths,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when a request is being made', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
it('stops polling, cancels the request, fetches pipelines & restarts polling', done => {
|
2018-10-15 14:42:47 +05:30
|
|
|
spyOn(vm.poll, 'stop');
|
|
|
|
spyOn(vm.poll, 'restart');
|
|
|
|
spyOn(vm, 'getPipelines').and.returnValue(Promise.resolve());
|
|
|
|
spyOn(vm.service.cancelationSource, 'cancel').and.callThrough();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
vm.isMakingRequest = true;
|
2018-12-13 13:39:08 +05:30
|
|
|
return vm
|
|
|
|
.$nextTick()
|
2018-10-15 14:42:47 +05:30
|
|
|
.then(() => {
|
|
|
|
vm.$el.querySelector('.js-builds-dropdown-button').click();
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
expect(vm.service.cancelationSource.cancel).toHaveBeenCalled();
|
|
|
|
expect(vm.poll.stop).toHaveBeenCalled();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(vm.getPipelines).toHaveBeenCalled();
|
|
|
|
expect(vm.poll.restart).toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
}, 0);
|
2018-12-13 13:39:08 +05:30
|
|
|
})
|
|
|
|
.catch(done.fail);
|
2018-10-15 14:42:47 +05:30
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when no request is being made', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
it('stops polling, fetches pipelines & restarts polling', done => {
|
2018-10-15 14:42:47 +05:30
|
|
|
spyOn(vm.poll, 'stop');
|
|
|
|
spyOn(vm.poll, 'restart');
|
|
|
|
spyOn(vm, 'getPipelines').and.returnValue(Promise.resolve());
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
vm.$el.querySelector('.js-builds-dropdown-button').click();
|
|
|
|
|
|
|
|
expect(vm.poll.stop).toHaveBeenCalled();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(vm.getPipelines).toHaveBeenCalled();
|
|
|
|
expect(vm.poll.restart).toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|