2018-02-09 11:14:48 +00:00
|
|
|
import { ImporterStatus } from '~/importer_status';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
|
|
|
|
describe('Importer Status', () => {
|
2018-02-15 21:51:41 +00:00
|
|
|
let instance;
|
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
2018-02-09 11:14:48 +00:00
|
|
|
describe('addToImport', () => {
|
|
|
|
const importUrl = '/import_url';
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
setFixtures(`
|
|
|
|
<tr id="repo_123">
|
|
|
|
<td class="import-target"></td>
|
|
|
|
<td class="import-actions job-status">
|
|
|
|
<button name="button" type="submit" class="btn btn-import js-add-to-import">
|
|
|
|
</button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
`);
|
|
|
|
spyOn(ImporterStatus.prototype, 'initStatusPage').and.callFake(() => {});
|
|
|
|
spyOn(ImporterStatus.prototype, 'setAutoUpdate').and.callFake(() => {});
|
2018-03-07 15:58:50 +00:00
|
|
|
instance = new ImporterStatus({
|
|
|
|
jobsUrl: '',
|
|
|
|
importUrl,
|
|
|
|
});
|
2018-02-09 11:14:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('sets table row to active after post request', (done) => {
|
|
|
|
mock.onPost(importUrl).reply(200, {
|
|
|
|
id: 1,
|
|
|
|
full_path: '/full_path',
|
|
|
|
});
|
|
|
|
|
|
|
|
instance.addToImport({
|
|
|
|
currentTarget: document.querySelector('.js-add-to-import'),
|
|
|
|
})
|
|
|
|
.then(() => {
|
2018-06-06 01:09:58 +00:00
|
|
|
expect(document.querySelector('tr').classList.contains('table-active')).toEqual(true);
|
2018-02-09 11:14:48 +00:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
2018-02-15 21:51:41 +00:00
|
|
|
|
|
|
|
describe('autoUpdate', () => {
|
|
|
|
const jobsUrl = '/jobs_url';
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const div = document.createElement('div');
|
|
|
|
div.innerHTML = `
|
|
|
|
<div id="project_1">
|
|
|
|
<div class="job-status">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
|
|
|
document.body.appendChild(div);
|
|
|
|
|
|
|
|
spyOn(ImporterStatus.prototype, 'initStatusPage').and.callFake(() => {});
|
|
|
|
spyOn(ImporterStatus.prototype, 'setAutoUpdate').and.callFake(() => {});
|
2018-03-07 15:58:50 +00:00
|
|
|
instance = new ImporterStatus({
|
|
|
|
jobsUrl,
|
|
|
|
});
|
2018-02-15 21:51:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function setupMock(importStatus) {
|
|
|
|
mock.onGet(jobsUrl).reply(200, [{
|
|
|
|
id: 1,
|
|
|
|
import_status: importStatus,
|
|
|
|
}]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function expectJobStatus(done, status) {
|
|
|
|
instance.autoUpdate()
|
|
|
|
.then(() => {
|
|
|
|
expect(document.querySelector('#project_1').innerText.trim()).toEqual(status);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
}
|
|
|
|
|
|
|
|
it('sets the job status to done', (done) => {
|
|
|
|
setupMock('finished');
|
2018-03-07 15:58:50 +00:00
|
|
|
expectJobStatus(done, 'Done');
|
2018-02-15 21:51:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the job status to scheduled', (done) => {
|
|
|
|
setupMock('scheduled');
|
2018-03-07 15:58:50 +00:00
|
|
|
expectJobStatus(done, 'Scheduled');
|
2018-02-15 21:51:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the job status to started', (done) => {
|
|
|
|
setupMock('started');
|
2018-03-07 15:58:50 +00:00
|
|
|
expectJobStatus(done, 'Started');
|
2018-02-15 21:51:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the job status to custom status', (done) => {
|
|
|
|
setupMock('custom status');
|
|
|
|
expectJobStatus(done, 'custom status');
|
|
|
|
});
|
|
|
|
});
|
2018-02-09 11:14:48 +00:00
|
|
|
});
|