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';
|
2017-11-14 10:35:29 -05:00
|
|
|
import mountComponent from '../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';
|
|
|
|
|
2017-03-20 11:36:02 -04:00
|
|
|
preloadFixtures('static/pipelines.html.raw');
|
2017-05-05 06:34:42 -04:00
|
|
|
preloadFixtures(jsonFixtureName);
|
2017-03-20 11:36:02 -04:00
|
|
|
|
|
|
|
let PipelinesComponent;
|
2017-11-14 10:35:29 -05:00
|
|
|
let pipelines;
|
|
|
|
let component;
|
2017-03-20 11:36:02 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
loadFixtures('static/pipelines.html.raw');
|
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(() => {
|
|
|
|
component.$destroy();
|
|
|
|
});
|
|
|
|
|
2017-03-20 11:36:02 -04:00
|
|
|
describe('successfull request', () => {
|
|
|
|
describe('with pipelines', () => {
|
|
|
|
const pipelinesInterceptor = (request, next) => {
|
2017-11-14 10:35:29 -05:00
|
|
|
next(request.respondWith(JSON.stringify(pipelines), {
|
2017-03-20 11:36:02 -04:00
|
|
|
status: 200,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
Vue.http.interceptors.push(pipelinesInterceptor);
|
2017-11-14 10:35:29 -05:00
|
|
|
component = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
});
|
2017-03-20 11:36:02 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(
|
|
|
|
Vue.http.interceptors, pipelinesInterceptor,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render table', (done) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(component.$el.querySelector('.table-holder')).toBeDefined();
|
2017-11-14 10:35:29 -05:00
|
|
|
expect(
|
|
|
|
component.$el.querySelectorAll('.gl-responsive-table-row').length,
|
|
|
|
).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(
|
|
|
|
component.$el.querySelector('.js-pipelines-tab-pending').textContent.trim(),
|
|
|
|
).toContain('Pending');
|
|
|
|
expect(
|
|
|
|
component.$el.querySelector('.js-pipelines-tab-all').textContent.trim(),
|
|
|
|
).toContain('All');
|
|
|
|
expect(
|
|
|
|
component.$el.querySelector('.js-pipelines-tab-running').textContent.trim(),
|
|
|
|
).toContain('Running');
|
|
|
|
expect(
|
|
|
|
component.$el.querySelector('.js-pipelines-tab-finished').textContent.trim(),
|
|
|
|
).toContain('Finished');
|
|
|
|
expect(
|
|
|
|
component.$el.querySelector('.js-pipelines-tab-branches').textContent.trim(),
|
|
|
|
).toContain('Branches');
|
|
|
|
expect(
|
|
|
|
component.$el.querySelector('.js-pipelines-tab-tags').textContent.trim(),
|
|
|
|
).toContain('Tags');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should make an API request when using tabs', (done) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
spyOn(component, 'updateContent');
|
|
|
|
component.$el.querySelector('.js-pipelines-tab-finished').click();
|
|
|
|
|
|
|
|
expect(component.updateContent).toHaveBeenCalledWith({ scope: 'finished', page: '1' });
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with pagination', () => {
|
|
|
|
it('should make an API request when using pagination', (done) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
spyOn(component, 'updateContent');
|
|
|
|
// Mock pagination
|
|
|
|
component.store.state.pageInfo = {
|
|
|
|
page: 1,
|
|
|
|
total: 10,
|
|
|
|
perPage: 2,
|
|
|
|
nextPage: 2,
|
|
|
|
totalPages: 5,
|
|
|
|
};
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
component.$el.querySelector('.js-next-button a').click();
|
|
|
|
expect(component.updateContent).toHaveBeenCalledWith({ scope: 'all', page: '2' });
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-03-20 11:36:02 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('without pipelines', () => {
|
|
|
|
const emptyInterceptor = (request, next) => {
|
|
|
|
next(request.respondWith(JSON.stringify([]), {
|
|
|
|
status: 200,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
Vue.http.interceptors.push(emptyInterceptor);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(
|
|
|
|
Vue.http.interceptors, emptyInterceptor,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render empty state', (done) => {
|
2017-11-14 10:35:29 -05:00
|
|
|
component = new PipelinesComponent({
|
2017-03-20 11:36:02 -04:00
|
|
|
propsData: {
|
|
|
|
store: new Store(),
|
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2017-11-14 10:35:29 -05:00
|
|
|
expect(component.$el.querySelector('.empty-state')).not.toBe(null);
|
2017-03-20 11:36:02 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('unsuccessfull request', () => {
|
|
|
|
const errorInterceptor = (request, next) => {
|
|
|
|
next(request.respondWith(JSON.stringify([]), {
|
|
|
|
status: 500,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
Vue.http.interceptors.push(errorInterceptor);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(
|
|
|
|
Vue.http.interceptors, errorInterceptor,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render error state', (done) => {
|
2017-11-14 10:35:29 -05:00
|
|
|
component = new PipelinesComponent({
|
2017-03-20 11:36:02 -04:00
|
|
|
propsData: {
|
|
|
|
store: new Store(),
|
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(component.$el.querySelector('.js-pipelines-error-state')).toBeDefined();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-11-14 10:35:29 -05:00
|
|
|
|
2017-11-23 07:04:03 -05:00
|
|
|
describe('methods', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(history, 'pushState').and.stub();
|
2017-11-14 10:35:29 -05:00
|
|
|
});
|
|
|
|
|
2017-11-23 07:04:03 -05:00
|
|
|
describe('updateContent', () => {
|
|
|
|
it('should set given parameters', () => {
|
|
|
|
component = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
});
|
|
|
|
component.updateContent({ scope: 'finished', page: '4' });
|
2017-11-14 10:35:29 -05:00
|
|
|
|
2017-11-23 07:04:03 -05:00
|
|
|
expect(component.page).toEqual('4');
|
|
|
|
expect(component.scope).toEqual('finished');
|
|
|
|
expect(component.requestData.scope).toEqual('finished');
|
|
|
|
expect(component.requestData.page).toEqual('4');
|
|
|
|
});
|
|
|
|
});
|
2017-11-14 10:35:29 -05:00
|
|
|
|
2017-11-23 07:04:03 -05:00
|
|
|
describe('onChangeTab', () => {
|
|
|
|
it('should set page to 1', () => {
|
|
|
|
component = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
});
|
|
|
|
spyOn(component, 'updateContent');
|
2017-11-14 10:35:29 -05:00
|
|
|
|
2017-11-23 07:04:03 -05:00
|
|
|
component.onChangeTab('running');
|
2017-11-14 10:35:29 -05:00
|
|
|
|
2017-11-23 07:04:03 -05:00
|
|
|
expect(component.updateContent).toHaveBeenCalledWith({ scope: 'running', page: '1' });
|
2017-11-14 10:35:29 -05:00
|
|
|
});
|
2017-11-23 07:04:03 -05:00
|
|
|
});
|
2017-11-14 10:35:29 -05:00
|
|
|
|
2017-11-23 07:04:03 -05:00
|
|
|
describe('onChangePage', () => {
|
|
|
|
it('should update page and keep scope', () => {
|
|
|
|
component = mountComponent(PipelinesComponent, {
|
|
|
|
store: new Store(),
|
|
|
|
});
|
|
|
|
spyOn(component, 'updateContent');
|
2017-11-14 10:35:29 -05:00
|
|
|
|
2017-11-23 07:04:03 -05:00
|
|
|
component.onChangePage(4);
|
2017-11-14 10:35:29 -05:00
|
|
|
|
2017-11-23 07:04:03 -05:00
|
|
|
expect(component.updateContent).toHaveBeenCalledWith({ scope: component.scope, page: '4' });
|
|
|
|
});
|
2017-11-14 10:35:29 -05:00
|
|
|
});
|
|
|
|
});
|
2017-03-20 11:36:02 -04:00
|
|
|
});
|