2017-12-19 05:12:32 -05:00
|
|
|
import _ from 'underscore';
|
2017-03-20 11:36:02 -04:00
|
|
|
import Vue from 'vue';
|
2017-06-14 09:04:50 -04:00
|
|
|
import pipelinesComp from '~/pipelines/components/pipelines.vue';
|
2017-04-19 07:44:37 -04:00
|
|
|
import Store from '~/pipelines/stores/pipelines_store';
|
2018-02-26 14:43:34 -05:00
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
2017-03-20 11:36:02 -04:00
|
|
|
|
|
|
|
describe('Pipelines', () => {
|
2017-05-05 06:34:42 -04:00
|
|
|
const jsonFixtureName = 'pipelines/pipelines.json';
|
|
|
|
|
|
|
|
preloadFixtures(jsonFixtureName);
|
2017-03-20 11:36:02 -04:00
|
|
|
|
|
|
|
let PipelinesComponent;
|
2017-11-14 10:35:29 -05:00
|
|
|
let pipelines;
|
2018-03-01 12:40:00 -05:00
|
|
|
let vm;
|
|
|
|
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-03-20 11:36:02 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-11-14 10:35:29 -05:00
|
|
|
pipelines = getJSONFixture(jsonFixtureName);
|
2017-03-20 11:36:02 -04:00
|
|
|
|
|
|
|
PipelinesComponent = Vue.extend(pipelinesComp);
|
|
|
|
});
|
|
|
|
|
2017-11-14 10:35:29 -05:00
|
|
|
afterEach(() => {
|
2018-03-01 12:40:00 -05:00
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
const pipelinesInterceptor = (request, next) => {
|
|
|
|
next(request.respondWith(JSON.stringify(pipelines), {
|
|
|
|
status: 200,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
const emptyStateInterceptor = (request, next) => {
|
|
|
|
next(request.respondWith(JSON.stringify({
|
|
|
|
pipelines: [],
|
|
|
|
count: {
|
|
|
|
all: 0,
|
|
|
|
pending: 0,
|
|
|
|
running: 0,
|
|
|
|
finished: 0,
|
|
|
|
},
|
|
|
|
}), {
|
|
|
|
status: 200,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
const errorInterceptor = (request, next) => {
|
|
|
|
next(request.respondWith(JSON.stringify({}), {
|
|
|
|
status: 500,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('With permission', () => {
|
|
|
|
describe('With pipelines in main tab', () => {
|
|
|
|
beforeEach((done) => {
|
|
|
|
Vue.http.interceptors.push(pipelinesInterceptor);
|
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: true,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...paths,
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(
|
|
|
|
Vue.http.interceptors, pipelinesInterceptor,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders tabs', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-all').textContent.trim()).toContain('All');
|
|
|
|
});
|
|
|
|
|
2018-03-07 14:45:46 -05:00
|
|
|
it('renders Run Pipeline link', () => {
|
2018-03-01 12:40:00 -05:00
|
|
|
expect(vm.$el.querySelector('.js-run-pipeline').getAttribute('href')).toEqual(paths.newPipelinePath);
|
|
|
|
});
|
|
|
|
|
2018-03-07 14:45:46 -05:00
|
|
|
it('renders CI Lint link', () => {
|
2018-03-01 12:40:00 -05:00
|
|
|
expect(vm.$el.querySelector('.js-ci-lint').getAttribute('href')).toEqual(paths.ciLintPath);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders Clear Runner Cache button', () => {
|
2018-03-07 14:45:46 -05:00
|
|
|
expect(vm.$el.querySelector('.js-clear-cache').textContent.trim()).toEqual('Clear Runner Caches');
|
2018-03-01 12:40:00 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders pipelines table', () => {
|
|
|
|
expect(
|
|
|
|
vm.$el.querySelectorAll('.gl-responsive-table-row').length,
|
|
|
|
).toEqual(pipelines.pipelines.length + 1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Without pipelines on main tab with CI', () => {
|
|
|
|
beforeEach((done) => {
|
|
|
|
Vue.http.interceptors.push(emptyStateInterceptor);
|
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: true,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...paths,
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(
|
|
|
|
Vue.http.interceptors, emptyStateInterceptor,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders tabs', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-all').textContent.trim()).toContain('All');
|
|
|
|
});
|
|
|
|
|
2018-03-07 14:45:46 -05:00
|
|
|
it('renders Run Pipeline link', () => {
|
2018-03-01 12:40:00 -05:00
|
|
|
expect(vm.$el.querySelector('.js-run-pipeline').getAttribute('href')).toEqual(paths.newPipelinePath);
|
|
|
|
});
|
|
|
|
|
2018-03-07 14:45:46 -05:00
|
|
|
it('renders CI Lint link', () => {
|
2018-03-01 12:40:00 -05:00
|
|
|
expect(vm.$el.querySelector('.js-ci-lint').getAttribute('href')).toEqual(paths.ciLintPath);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders Clear Runner Cache button', () => {
|
2018-03-07 14:45:46 -05:00
|
|
|
expect(vm.$el.querySelector('.js-clear-cache').textContent.trim()).toEqual('Clear Runner Caches');
|
2018-03-01 12:40:00 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders tab empty state', () => {
|
|
|
|
expect(vm.$el.querySelector('.empty-state h4').textContent.trim()).toEqual('There are currently no pipelines.');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Without pipelines nor CI', () => {
|
|
|
|
beforeEach((done) => {
|
|
|
|
Vue.http.interceptors.push(emptyStateInterceptor);
|
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: false,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...paths,
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(
|
|
|
|
Vue.http.interceptors, emptyStateInterceptor,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders empty state', () => {
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render tabs nor buttons', () => {
|
2018-03-05 13:40:04 -05:00
|
|
|
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();
|
2018-03-01 12:40:00 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('When API returns error', () => {
|
|
|
|
beforeEach((done) => {
|
|
|
|
Vue.http.interceptors.push(errorInterceptor);
|
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: false,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...paths,
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(
|
|
|
|
Vue.http.interceptors, errorInterceptor,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders tabs', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-all').textContent.trim()).toContain('All');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders buttons', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-run-pipeline').getAttribute('href')).toEqual(paths.newPipelinePath);
|
|
|
|
expect(vm.$el.querySelector('.js-ci-lint').getAttribute('href')).toEqual(paths.ciLintPath);
|
2018-03-07 14:45:46 -05:00
|
|
|
expect(vm.$el.querySelector('.js-clear-cache').textContent.trim()).toEqual('Clear Runner Caches');
|
2018-03-01 12:40:00 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders error state', () => {
|
2018-03-05 13:40:04 -05:00
|
|
|
expect(vm.$el.querySelector('.empty-state').textContent.trim()).toContain('There was an error fetching the pipelines.');
|
2018-03-01 12:40:00 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Without permission', () => {
|
|
|
|
describe('With pipelines in main tab', () => {
|
|
|
|
beforeEach((done) => {
|
|
|
|
Vue.http.interceptors.push(pipelinesInterceptor);
|
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: false,
|
|
|
|
canCreatePipeline: false,
|
|
|
|
...noPermissions,
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(
|
|
|
|
Vue.http.interceptors, pipelinesInterceptor,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders tabs', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-all').textContent.trim()).toContain('All');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render buttons', () => {
|
2018-03-05 13:40:04 -05:00
|
|
|
expect(vm.$el.querySelector('.js-run-pipeline')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-ci-lint')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-clear-cache')).toBeNull();
|
2018-03-01 12:40:00 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders pipelines table', () => {
|
|
|
|
expect(
|
|
|
|
vm.$el.querySelectorAll('.gl-responsive-table-row').length,
|
|
|
|
).toEqual(pipelines.pipelines.length + 1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Without pipelines on main tab with CI', () => {
|
|
|
|
beforeEach((done) => {
|
|
|
|
Vue.http.interceptors.push(emptyStateInterceptor);
|
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: true,
|
|
|
|
canCreatePipeline: false,
|
|
|
|
...noPermissions,
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(
|
|
|
|
Vue.http.interceptors, emptyStateInterceptor,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
it('renders tabs', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-all').textContent.trim()).toContain('All');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render buttons', () => {
|
2018-03-05 13:40:04 -05:00
|
|
|
expect(vm.$el.querySelector('.js-run-pipeline')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-ci-lint')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-clear-cache')).toBeNull();
|
2018-03-01 12:40:00 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders tab empty state', () => {
|
|
|
|
expect(vm.$el.querySelector('.empty-state h4').textContent.trim()).toEqual('There are currently no pipelines.');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Without pipelines nor CI', () => {
|
|
|
|
beforeEach((done) => {
|
|
|
|
Vue.http.interceptors.push(emptyStateInterceptor);
|
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: false,
|
|
|
|
canCreatePipeline: false,
|
|
|
|
...noPermissions,
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(
|
|
|
|
Vue.http.interceptors, emptyStateInterceptor,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders empty state without button to set CI', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-empty-state').textContent.trim()).toEqual('This project is not currently set up to run pipelines.');
|
2018-03-05 13:40:04 -05:00
|
|
|
expect(vm.$el.querySelector('.js-get-started-pipelines')).toBeNull();
|
2018-03-01 12:40:00 -05:00
|
|
|
});
|
|
|
|
|
2018-03-05 13:40:04 -05:00
|
|
|
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();
|
2018-03-01 12:40:00 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('When API returns error', () => {
|
|
|
|
beforeEach((done) => {
|
|
|
|
Vue.http.interceptors.push(errorInterceptor);
|
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: false,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...noPermissions,
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(
|
|
|
|
Vue.http.interceptors, errorInterceptor,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders tabs', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-all').textContent.trim()).toContain('All');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not renders buttons', () => {
|
2018-03-05 13:40:04 -05:00
|
|
|
expect(vm.$el.querySelector('.js-run-pipeline')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-ci-lint')).toBeNull();
|
|
|
|
expect(vm.$el.querySelector('.js-clear-cache')).toBeNull();
|
2018-03-01 12:40:00 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders error state', () => {
|
2018-03-05 13:40:04 -05:00
|
|
|
expect(vm.$el.querySelector('.empty-state').textContent.trim()).toContain('There was an error fetching the pipelines.');
|
2018-03-01 12:40:00 -05:00
|
|
|
});
|
|
|
|
});
|
2017-11-14 10:35:29 -05:00
|
|
|
});
|
|
|
|
|
2017-03-20 11:36:02 -04:00
|
|
|
describe('successfull request', () => {
|
|
|
|
describe('with pipelines', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
Vue.http.interceptors.push(pipelinesInterceptor);
|
2018-03-01 12:40:00 -05:00
|
|
|
vm = mountComponent(PipelinesComponent, {
|
2017-11-14 10:35:29 -05:00
|
|
|
store: new Store(),
|
2018-03-01 12:40:00 -05:00
|
|
|
hasGitlabCi: true,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...paths,
|
2017-11-14 10:35:29 -05:00
|
|
|
});
|
2017-03-20 11:36:02 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(
|
|
|
|
Vue.http.interceptors, pipelinesInterceptor,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render table', (done) => {
|
|
|
|
setTimeout(() => {
|
2018-03-01 12:40:00 -05:00
|
|
|
expect(vm.$el.querySelector('.table-holder')).toBeDefined();
|
2017-11-14 10:35:29 -05:00
|
|
|
expect(
|
2018-03-01 12:40:00 -05:00
|
|
|
vm.$el.querySelectorAll('.gl-responsive-table-row').length,
|
2017-11-14 10:35:29 -05:00
|
|
|
).toEqual(pipelines.pipelines.length + 1);
|
2017-03-20 11:36:02 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-11-14 10:35:29 -05:00
|
|
|
|
|
|
|
it('should render navigation tabs', (done) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(
|
2018-03-01 12:40:00 -05:00
|
|
|
vm.$el.querySelector('.js-pipelines-tab-pending').textContent.trim(),
|
2017-11-14 10:35:29 -05:00
|
|
|
).toContain('Pending');
|
|
|
|
expect(
|
2018-03-01 12:40:00 -05:00
|
|
|
vm.$el.querySelector('.js-pipelines-tab-all').textContent.trim(),
|
2017-11-14 10:35:29 -05:00
|
|
|
).toContain('All');
|
|
|
|
expect(
|
2018-03-01 12:40:00 -05:00
|
|
|
vm.$el.querySelector('.js-pipelines-tab-running').textContent.trim(),
|
2017-11-14 10:35:29 -05:00
|
|
|
).toContain('Running');
|
|
|
|
expect(
|
2018-03-01 12:40:00 -05:00
|
|
|
vm.$el.querySelector('.js-pipelines-tab-finished').textContent.trim(),
|
2017-11-14 10:35:29 -05:00
|
|
|
).toContain('Finished');
|
|
|
|
expect(
|
2018-03-01 12:40:00 -05:00
|
|
|
vm.$el.querySelector('.js-pipelines-tab-branches').textContent.trim(),
|
2017-11-14 10:35:29 -05:00
|
|
|
).toContain('Branches');
|
|
|
|
expect(
|
2018-03-01 12:40:00 -05:00
|
|
|
vm.$el.querySelector('.js-pipelines-tab-tags').textContent.trim(),
|
2017-11-14 10:35:29 -05:00
|
|
|
).toContain('Tags');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should make an API request when using tabs', (done) => {
|
|
|
|
setTimeout(() => {
|
2018-03-01 12:40:00 -05:00
|
|
|
spyOn(vm, 'updateContent');
|
|
|
|
vm.$el.querySelector('.js-pipelines-tab-finished').click();
|
2017-11-14 10:35:29 -05:00
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
expect(vm.updateContent).toHaveBeenCalledWith({ scope: 'finished', page: '1' });
|
2017-11-14 10:35:29 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with pagination', () => {
|
|
|
|
it('should make an API request when using pagination', (done) => {
|
|
|
|
setTimeout(() => {
|
2018-03-01 12:40:00 -05:00
|
|
|
spyOn(vm, 'updateContent');
|
2017-11-14 10:35:29 -05:00
|
|
|
// Mock pagination
|
2018-03-01 12:40:00 -05:00
|
|
|
vm.store.state.pageInfo = {
|
2017-11-14 10:35:29 -05:00
|
|
|
page: 1,
|
|
|
|
total: 10,
|
|
|
|
perPage: 2,
|
|
|
|
nextPage: 2,
|
|
|
|
totalPages: 5,
|
|
|
|
};
|
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
vm.$nextTick(() => {
|
|
|
|
vm.$el.querySelector('.js-next-button a').click();
|
|
|
|
expect(vm.updateContent).toHaveBeenCalledWith({ scope: 'all', page: '2' });
|
2017-11-14 10:35:29 -05:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-03-20 11:36:02 -04:00
|
|
|
});
|
2018-03-01 12:40:00 -05:00
|
|
|
});
|
2017-03-20 11:36:02 -04:00
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
describe('methods', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(history, 'pushState').and.stub();
|
|
|
|
});
|
2017-03-20 11:36:02 -04:00
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
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-03-20 11:36:02 -04:00
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
expect(vm.page).toEqual('4');
|
|
|
|
expect(vm.scope).toEqual('finished');
|
|
|
|
expect(vm.requestData.scope).toEqual('finished');
|
|
|
|
expect(vm.requestData.page).toEqual('4');
|
2017-03-20 11:36:02 -04:00
|
|
|
});
|
2018-03-01 12:40:00 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('onChangeTab', () => {
|
|
|
|
it('should set page to 1', () => {
|
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: true,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...paths,
|
|
|
|
});
|
|
|
|
spyOn(vm, 'updateContent');
|
2017-03-20 11:36:02 -04:00
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
vm.onChangeTab('running');
|
2017-03-20 11:36:02 -04:00
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
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-03-20 11:36:02 -04:00
|
|
|
});
|
2018-03-01 12:40:00 -05:00
|
|
|
spyOn(vm, 'updateContent');
|
|
|
|
|
|
|
|
vm.onChangePage(4);
|
|
|
|
|
|
|
|
expect(vm.updateContent).toHaveBeenCalledWith({ scope: vm.scope, page: '4' });
|
2017-03-20 11:36:02 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
describe('computed properties', () => {
|
2017-03-20 11:36:02 -04:00
|
|
|
beforeEach(() => {
|
2018-03-01 12:40:00 -05:00
|
|
|
vm = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
hasGitlabCi: true,
|
|
|
|
canCreatePipeline: true,
|
|
|
|
...paths,
|
|
|
|
});
|
2017-03-20 11:36:02 -04:00
|
|
|
});
|
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
describe('tabs', () => {
|
|
|
|
it('returns default tabs', () => {
|
|
|
|
expect(vm.tabs).toEqual([
|
2018-03-05 13:40:04 -05:00
|
|
|
{ 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 },
|
2018-03-01 12:40:00 -05:00
|
|
|
{ name: 'Branches', scope: 'branches', isActive: false },
|
|
|
|
{ name: 'Tags', scope: 'tags', isActive: false },
|
|
|
|
]);
|
|
|
|
});
|
2017-03-20 11:36:02 -04:00
|
|
|
});
|
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
describe('emptyTabMessage', () => {
|
|
|
|
it('returns message with scope', (done) => {
|
|
|
|
vm.scope = 'pending';
|
2017-03-20 11:36:02 -04:00
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.emptyTabMessage).toEqual('There are currently no pending pipelines.');
|
|
|
|
done();
|
|
|
|
});
|
2017-03-20 11:36:02 -04:00
|
|
|
});
|
2017-11-14 10:35:29 -05:00
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
it('returns message without scope when scope is `all`', () => {
|
|
|
|
expect(vm.emptyTabMessage).toEqual('There are currently no pipelines.');
|
|
|
|
});
|
2017-11-14 10:35:29 -05:00
|
|
|
});
|
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
describe('stateToRender', () => {
|
|
|
|
it('returns loading state when the app is loading', () => {
|
|
|
|
expect(vm.stateToRender).toEqual('loading');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns error state when app has error', (done) => {
|
|
|
|
vm.hasError = true;
|
|
|
|
vm.isLoading = false;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.stateToRender).toEqual('error');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns table list when app has pipelines', (done) => {
|
|
|
|
vm.isLoading = false;
|
|
|
|
vm.hasError = false;
|
|
|
|
vm.state.pipelines = pipelines.pipelines;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.stateToRender).toEqual('tableList');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns empty tab when app does not have pipelines but project has pipelines', (done) => {
|
|
|
|
vm.state.count.all = 10;
|
|
|
|
vm.isLoading = false;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.stateToRender).toEqual('emptyTab');
|
|
|
|
|
|
|
|
done();
|
2017-11-23 07:04:03 -05:00
|
|
|
});
|
2018-03-01 12:40:00 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns empty tab when project has CI', (done) => {
|
|
|
|
vm.isLoading = false;
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.stateToRender).toEqual('emptyTab');
|
2017-11-14 10:35:29 -05:00
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns empty state when project does not have pipelines nor CI', (done) => {
|
|
|
|
vm.isLoading = false;
|
|
|
|
vm.hasGitlabCi = false;
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.stateToRender).toEqual('emptyState');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2017-11-23 07:04:03 -05:00
|
|
|
});
|
|
|
|
});
|
2017-11-14 10:35:29 -05:00
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
describe('shouldRenderTabs', () => {
|
|
|
|
it('returns true when state is loading & has already made the first request', (done) => {
|
|
|
|
vm.isLoading = true;
|
|
|
|
vm.hasMadeRequest = true;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.shouldRenderTabs).toEqual(true);
|
|
|
|
|
|
|
|
done();
|
2017-11-23 07:04:03 -05:00
|
|
|
});
|
2018-03-01 12:40:00 -05:00
|
|
|
});
|
2017-11-14 10:35:29 -05:00
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
it('returns true when state is tableList & has already made the first request', (done) => {
|
|
|
|
vm.isLoading = false;
|
|
|
|
vm.state.pipelines = pipelines.pipelines;
|
|
|
|
vm.hasMadeRequest = true;
|
2017-11-14 10:35:29 -05:00
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.shouldRenderTabs).toEqual(true);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true when state is error & has already made the first request', (done) => {
|
|
|
|
vm.isLoading = false;
|
|
|
|
vm.hasError = true;
|
|
|
|
vm.hasMadeRequest = true;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.shouldRenderTabs).toEqual(true);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-05 13:40:04 -05:00
|
|
|
it('returns true when state is empty tab & has already made the first request', (done) => {
|
2018-03-01 12:40:00 -05:00
|
|
|
vm.isLoading = false;
|
|
|
|
vm.state.count.all = 10;
|
|
|
|
vm.hasMadeRequest = true;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.shouldRenderTabs).toEqual(true);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false when has not made first request', (done) => {
|
|
|
|
vm.hasMadeRequest = false;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.shouldRenderTabs).toEqual(false);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false when state is emtpy state', (done) => {
|
|
|
|
vm.isLoading = false;
|
|
|
|
vm.hasMadeRequest = true;
|
|
|
|
vm.hasGitlabCi = false;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.shouldRenderTabs).toEqual(false);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2017-11-14 10:35:29 -05:00
|
|
|
});
|
2017-11-23 07:04:03 -05:00
|
|
|
});
|
2017-11-14 10:35:29 -05:00
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
describe('shouldRenderButtons', () => {
|
|
|
|
it('returns true when it has paths & has made the first request', (done) => {
|
|
|
|
vm.hasMadeRequest = true;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.shouldRenderButtons).toEqual(true);
|
|
|
|
|
|
|
|
done();
|
2017-11-23 07:04:03 -05:00
|
|
|
});
|
2018-03-01 12:40:00 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false when it has not made the first request', (done) => {
|
|
|
|
vm.hasMadeRequest = false;
|
2017-11-14 10:35:29 -05:00
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.shouldRenderButtons).toEqual(false);
|
2017-11-14 10:35:29 -05:00
|
|
|
|
2018-03-01 12:40:00 -05:00
|
|
|
done();
|
|
|
|
});
|
2017-11-23 07:04:03 -05:00
|
|
|
});
|
2017-11-14 10:35:29 -05:00
|
|
|
});
|
|
|
|
});
|
2017-03-20 11:36:02 -04:00
|
|
|
});
|