Replaced use of $.get with axios.get and updated tests
This commit is contained in:
parent
6441612614
commit
36a301a3c9
|
|
@ -1,3 +1,6 @@
|
|||
import axios from '~/lib/utils/axios_utils';
|
||||
import flash from '~/flash';
|
||||
import { __ } from '~/locale';
|
||||
import { getLocationHash } from './lib/utils/url_utility';
|
||||
import FilesCommentButton from './files_comment_button';
|
||||
import SingleFileDiff from './single_file_diff';
|
||||
|
|
@ -69,7 +72,10 @@ export default class Diff {
|
|||
const view = file.data('view');
|
||||
|
||||
const params = { since, to, bottom, offset, unfold, view };
|
||||
$.get(link, params, response => $target.parent().replaceWith(response));
|
||||
// $.get(link, params, response => $target.parent().replaceWith(response));
|
||||
axios.get(link, { params })
|
||||
.then(({ data }) => $target.parent().replaceWith(data))
|
||||
.catch(() => flash(__('An error occurred while loading diff')));
|
||||
}
|
||||
|
||||
openAnchoredDiff(cb) {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
import axios from '~/lib/utils/axios_utils';
|
||||
import flash from '~/flash';
|
||||
import { __ } from '~/locale';
|
||||
|
||||
export default class GpgBadges {
|
||||
static fetch() {
|
||||
const badges = $('.js-loading-gpg-badge');
|
||||
|
|
@ -5,13 +9,13 @@ export default class GpgBadges {
|
|||
|
||||
badges.html('<i class="fa fa-spinner fa-spin"></i>');
|
||||
|
||||
$.get({
|
||||
url: form.data('signatures-path'),
|
||||
data: form.serialize(),
|
||||
}).done((response) => {
|
||||
response.signatures.forEach((signature) => {
|
||||
const params = form.serialize();
|
||||
return axios.get(form.data('signatures-path'), { params })
|
||||
.then(({ data }) => {
|
||||
data.signatures.forEach((signature) => {
|
||||
badges.filter(`[data-commit-sha="${signature.commit_sha}"]`).replaceWith(signature.html);
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(() => flash(__('An error occurred while loading comm')));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import MockAdapter from 'axios-mock-adapter';
|
||||
import axios from '~/lib/utils/axios_utils';
|
||||
import GpgBadges from '~/gpg_badges';
|
||||
|
||||
describe('GpgBadges', () => {
|
||||
let mock;
|
||||
const dummyCommitSha = 'n0m0rec0ffee';
|
||||
const dummyBadgeHtml = 'dummy html';
|
||||
const dummyResponse = {
|
||||
|
|
@ -11,38 +14,43 @@ describe('GpgBadges', () => {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
mock = new MockAdapter(axios);
|
||||
setFixtures(`
|
||||
<form
|
||||
class="commits-search-form" data-signatures-path="/hello" action="/hello"
|
||||
method="get">
|
||||
<input name="utf8" type="hidden" value="✓">
|
||||
<input type="search" name="search" id="commits-search"class="form-control search-text-input input-short">
|
||||
</form>
|
||||
<div class="parent-container">
|
||||
<div class="js-loading-gpg-badge" data-commit-sha="${dummyCommitSha}"></div>
|
||||
</div>
|
||||
`);
|
||||
});
|
||||
|
||||
it('displays a loading spinner', () => {
|
||||
spyOn($, 'get').and.returnValue({
|
||||
done() {
|
||||
// intentionally left blank
|
||||
},
|
||||
});
|
||||
|
||||
GpgBadges.fetch();
|
||||
|
||||
expect(document.querySelector('.js-loading-gpg-badge:empty')).toBe(null);
|
||||
const spinners = document.querySelectorAll('.js-loading-gpg-badge i.fa.fa-spinner.fa-spin');
|
||||
expect(spinners.length).toBe(1);
|
||||
afterEach(() => {
|
||||
mock.restore();
|
||||
});
|
||||
|
||||
it('replaces the loading spinner', () => {
|
||||
spyOn($, 'get').and.returnValue({
|
||||
done(callback) {
|
||||
callback(dummyResponse);
|
||||
},
|
||||
});
|
||||
it('displays a loading spinner', (done) => {
|
||||
mock.onGet('/hello').reply(200);
|
||||
|
||||
GpgBadges.fetch();
|
||||
GpgBadges.fetch().then(() => {
|
||||
expect(document.querySelector('.js-loading-gpg-badge:empty')).toBe(null);
|
||||
const spinners = document.querySelectorAll('.js-loading-gpg-badge i.fa.fa-spinner.fa-spin');
|
||||
expect(spinners.length).toBe(1);
|
||||
done();
|
||||
}).catch(err => done(err));
|
||||
});
|
||||
|
||||
expect(document.querySelector('.js-loading-gpg-badge')).toBe(null);
|
||||
const parentContainer = document.querySelector('.parent-container');
|
||||
expect(parentContainer.innerHTML.trim()).toEqual(dummyBadgeHtml);
|
||||
it('replaces the loading spinner', (done) => {
|
||||
mock.onGet('/hello').reply(200, dummyResponse);
|
||||
|
||||
GpgBadges.fetch().then(() => {
|
||||
expect(document.querySelector('.js-loading-gpg-badge')).toBe(null);
|
||||
const parentContainer = document.querySelector('.parent-container');
|
||||
expect(parentContainer.innerHTML.trim()).toEqual(dummyBadgeHtml);
|
||||
done();
|
||||
}).catch(err => done(err));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue