Commit ae06b5db authored by Phil Hughes's avatar Phil Hughes

Merge branch 'winh-gpg-status-spinners' into 'master'

Display GPG status loading spinner only when Ajax request is made

Closes #35699

See merge request !13526
parents 155de419 d2b4109b
export default class GpgBadges {
static fetch() {
const badges = $('.js-loading-gpg-badge');
const form = $('.commits-search-form');
badges.html('<i class="fa fa-spinner fa-spin"></i>');
$.get({
url: form.data('signatures-path'),
data: form.serialize(),
}).done((response) => {
const badges = $('.js-loading-gpg-badge');
response.signatures.forEach((signature) => {
badges.filter(`[data-commit-sha="${signature.commit_sha}"]`).replaceWith(signature.html);
});
......
......@@ -286,6 +286,10 @@
.gpg-status-box {
&:empty {
display: none;
}
&.valid {
@include green-status-color;
}
......
- if commit.has_signature?
%button{ class: commit_signature_badge_classes('js-loading-gpg-badge'), data: { toggle: 'tooltip', placement: 'auto top', title: 'GPG signature (loading...)', 'commit-sha' => commit.sha } }
%i.fa.fa-spinner.fa-spin
import GpgBadges from '~/gpg_badges';
describe('GpgBadges', () => {
const dummyCommitSha = 'n0m0rec0ffee';
const dummyBadgeHtml = 'dummy html';
const dummyResponse = {
signatures: [{
commit_sha: dummyCommitSha,
html: dummyBadgeHtml,
}],
};
beforeEach(() => {
setFixtures(`
<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);
});
it('replaces the loading spinner', () => {
spyOn($, 'get').and.returnValue({
done(callback) {
callback(dummyResponse);
},
});
GpgBadges.fetch();
expect(document.querySelector('.js-loading-gpg-badge')).toBe(null);
const parentContainer = document.querySelector('.parent-container');
expect(parentContainer.innerHTML.trim()).toEqual(dummyBadgeHtml);
});
});
module GpgHelpers
SIGNED_COMMIT_SHA = '8a852d50dda17cc8fd1408d2fd0c5b0f24c76ca4'.freeze
module User1
extend self
......
require 'spec_helper'
describe 'projects/commits/_commit.html.haml' do
context 'with a singed commit' do
let(:project) { create(:project, :repository) }
let(:repository) { project.repository }
let(:ref) { GpgHelpers::SIGNED_COMMIT_SHA }
let(:commit) { repository.commit(ref) }
it 'does not display a loading spinner for GPG status' do
render partial: 'projects/commits/commit', locals: {
project: project,
ref: ref,
commit: commit
}
within '.gpg-status-box' do
expect(page).not_to have_css('i.fa.fa-spinner.fa-spin')
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment