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
This commit is contained in:
commit
ae06b5dbc6
6 changed files with 79 additions and 2 deletions
|
@ -1,12 +1,14 @@
|
||||||
export default class GpgBadges {
|
export default class GpgBadges {
|
||||||
static fetch() {
|
static fetch() {
|
||||||
|
const badges = $('.js-loading-gpg-badge');
|
||||||
const form = $('.commits-search-form');
|
const form = $('.commits-search-form');
|
||||||
|
|
||||||
|
badges.html('<i class="fa fa-spinner fa-spin"></i>');
|
||||||
|
|
||||||
$.get({
|
$.get({
|
||||||
url: form.data('signatures-path'),
|
url: form.data('signatures-path'),
|
||||||
data: form.serialize(),
|
data: form.serialize(),
|
||||||
}).done((response) => {
|
}).done((response) => {
|
||||||
const badges = $('.js-loading-gpg-badge');
|
|
||||||
response.signatures.forEach((signature) => {
|
response.signatures.forEach((signature) => {
|
||||||
badges.filter(`[data-commit-sha="${signature.commit_sha}"]`).replaceWith(signature.html);
|
badges.filter(`[data-commit-sha="${signature.commit_sha}"]`).replaceWith(signature.html);
|
||||||
});
|
});
|
||||||
|
|
|
@ -286,6 +286,10 @@
|
||||||
|
|
||||||
|
|
||||||
.gpg-status-box {
|
.gpg-status-box {
|
||||||
|
&:empty {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
&.valid {
|
&.valid {
|
||||||
@include green-status-color;
|
@include green-status-color;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
- if commit.has_signature?
|
- 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 } }
|
%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
|
|
||||||
|
|
48
spec/javascripts/gpg_badges_spec.js
Normal file
48
spec/javascripts/gpg_badges_spec.js
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,4 +1,6 @@
|
||||||
module GpgHelpers
|
module GpgHelpers
|
||||||
|
SIGNED_COMMIT_SHA = '8a852d50dda17cc8fd1408d2fd0c5b0f24c76ca4'.freeze
|
||||||
|
|
||||||
module User1
|
module User1
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
|
|
22
spec/views/projects/commits/_commit.html.haml_spec.rb
Normal file
22
spec/views/projects/commits/_commit.html.haml_spec.rb
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
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
|
Loading…
Reference in a new issue