debian-mirror-gitlab/spec/javascripts/gpg_badges_spec.js

57 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-03-27 19:54:05 +05:30
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
2017-09-10 17:25:29 +05:30
import GpgBadges from '~/gpg_badges';
describe('GpgBadges', () => {
2018-03-27 19:54:05 +05:30
let mock;
2017-09-10 17:25:29 +05:30
const dummyCommitSha = 'n0m0rec0ffee';
const dummyBadgeHtml = 'dummy html';
const dummyResponse = {
signatures: [{
commit_sha: dummyCommitSha,
html: dummyBadgeHtml,
}],
};
beforeEach(() => {
2018-03-27 19:54:05 +05:30
mock = new MockAdapter(axios);
2017-09-10 17:25:29 +05:30
setFixtures(`
2018-10-15 14:42:47 +05:30
<form
class="commits-search-form js-signature-container" data-signatures-path="/hello" action="/hello"
2018-03-27 19:54:05 +05:30
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>
2017-09-10 17:25:29 +05:30
<div class="parent-container">
<div class="js-loading-gpg-badge" data-commit-sha="${dummyCommitSha}"></div>
</div>
`);
});
2018-03-27 19:54:05 +05:30
afterEach(() => {
mock.restore();
});
2017-09-10 17:25:29 +05:30
2018-03-27 19:54:05 +05:30
it('displays a loading spinner', (done) => {
mock.onGet('/hello').reply(200);
2017-09-10 17:25:29 +05:30
2018-03-27 19:54:05 +05:30
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(done.fail);
2017-09-10 17:25:29 +05:30
});
2018-03-27 19:54:05 +05:30
it('replaces the loading spinner', (done) => {
mock.onGet('/hello').reply(200, dummyResponse);
2017-09-10 17:25:29 +05:30
2018-03-27 19:54:05 +05:30
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(done.fail);
2017-09-10 17:25:29 +05:30
});
});