2017-12-19 05:12:32 -05:00
|
|
|
import _ from 'underscore';
|
2017-06-02 09:24:42 -04:00
|
|
|
import Vue from 'vue';
|
2018-02-16 07:07:04 -05:00
|
|
|
import PipelineMediator from '~/pipelines/pipeline_details_mediator';
|
2017-06-02 09:24:42 -04:00
|
|
|
|
|
|
|
describe('PipelineMdediator', () => {
|
|
|
|
let mediator;
|
|
|
|
beforeEach(() => {
|
|
|
|
mediator = new PipelineMediator({ endpoint: 'foo' });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set defaults', () => {
|
|
|
|
expect(mediator.options).toEqual({ endpoint: 'foo' });
|
|
|
|
expect(mediator.state.isLoading).toEqual(false);
|
|
|
|
expect(mediator.store).toBeDefined();
|
|
|
|
expect(mediator.service).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('request and store data', () => {
|
|
|
|
const interceptor = (request, next) => {
|
|
|
|
next(request.respondWith(JSON.stringify({ foo: 'bar' }), {
|
|
|
|
status: 200,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
Vue.http.interceptors.push(interceptor);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(Vue.http.interceptor, interceptor);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should store received data', (done) => {
|
|
|
|
mediator.fetchPipeline();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(mediator.store.state.pipeline).toEqual({ foo: 'bar' });
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|