debian-mirror-gitlab/spec/javascripts/jobs/job_details_mediator_spec.js

40 lines
993 B
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
2017-09-10 17:25:29 +05:30
import JobMediator from '~/jobs/job_details_mediator';
import job from './mock_data';
describe('JobMediator', () => {
let mediator;
2018-03-17 18:26:18 +05:30
let mock;
2017-09-10 17:25:29 +05:30
beforeEach(() => {
2018-03-17 18:26:18 +05:30
mediator = new JobMediator({ endpoint: 'jobs/40291672.json' });
mock = new MockAdapter(axios);
});
afterEach(() => {
mock.restore();
2017-09-10 17:25:29 +05:30
});
it('should set defaults', () => {
expect(mediator.store).toBeDefined();
expect(mediator.service).toBeDefined();
2018-03-17 18:26:18 +05:30
expect(mediator.options).toEqual({ endpoint: 'jobs/40291672.json' });
2017-09-10 17:25:29 +05:30
expect(mediator.state.isLoading).toEqual(false);
});
describe('request and store data', () => {
beforeEach(() => {
2018-03-17 18:26:18 +05:30
mock.onGet().reply(200, job, {});
2017-09-10 17:25:29 +05:30
});
it('should store received data', (done) => {
mediator.fetchJob();
setTimeout(() => {
expect(mediator.store.state.job).toEqual(job);
done();
}, 0);
});
});
});