summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2017-05-18 20:53:16 +0000
committerPhil Hughes <me@iamphill.com>2017-05-18 20:53:16 +0000
commit6b092d96e0eeacb50781610071ce3998493127f2 (patch)
tree2279dbb81976d9fd6674823a8f4d3c6ce2b128c9
parenta3eabcc20c422db7032e31397c21dbc6ca3166de (diff)
parent1f9a9629dbd954520e15e436352316cfdc24d362 (diff)
downloadgitlab-ce-6b092d96e0eeacb50781610071ce3998493127f2.tar.gz
Merge branch 'disable-clicking-disabled-clipboard-button' into 'master'
Fix clicking disabled clipboard button toolip Closes #32518 See merge request !11493
-rw-r--r--app/assets/javascripts/blob/viewer/index.js4
-rw-r--r--spec/javascripts/blob/viewer/index_spec.js31
2 files changed, 29 insertions, 6 deletions
diff --git a/app/assets/javascripts/blob/viewer/index.js b/app/assets/javascripts/blob/viewer/index.js
index 54b85e47358..d7c62889dde 100644
--- a/app/assets/javascripts/blob/viewer/index.js
+++ b/app/assets/javascripts/blob/viewer/index.js
@@ -50,9 +50,9 @@ export default class BlobViewer {
if (this.copySourceBtn) {
this.copySourceBtn.addEventListener('click', () => {
- if (this.copySourceBtn.classList.contains('disabled')) return;
+ if (this.copySourceBtn.classList.contains('disabled')) return this.copySourceBtn.blur();
- this.switchToViewer('simple');
+ return this.switchToViewer('simple');
});
}
}
diff --git a/spec/javascripts/blob/viewer/index_spec.js b/spec/javascripts/blob/viewer/index_spec.js
index 13f122b68b2..af04e7c1e72 100644
--- a/spec/javascripts/blob/viewer/index_spec.js
+++ b/spec/javascripts/blob/viewer/index_spec.js
@@ -83,25 +83,48 @@ describe('Blob viewer', () => {
});
describe('copy blob button', () => {
+ let copyButton;
+
+ beforeEach(() => {
+ copyButton = document.querySelector('.js-copy-blob-source-btn');
+ });
+
it('disabled on load', () => {
expect(
- document.querySelector('.js-copy-blob-source-btn').classList.contains('disabled'),
+ copyButton.classList.contains('disabled'),
).toBeTruthy();
});
it('has tooltip when disabled', () => {
expect(
- document.querySelector('.js-copy-blob-source-btn').getAttribute('data-original-title'),
+ copyButton.getAttribute('data-original-title'),
).toBe('Switch to the source to copy it to the clipboard');
});
+ it('is blurred when clicked and disabled', () => {
+ spyOn(copyButton, 'blur');
+
+ copyButton.click();
+
+ expect(copyButton.blur).toHaveBeenCalled();
+ });
+
+ it('is not blurred when clicked and not disabled', () => {
+ spyOn(copyButton, 'blur');
+
+ copyButton.classList.remove('disabled');
+ copyButton.click();
+
+ expect(copyButton.blur).not.toHaveBeenCalled();
+ });
+
it('enables after switching to simple view', (done) => {
document.querySelector('.js-blob-viewer-switch-btn[data-viewer="simple"]').click();
setTimeout(() => {
expect($.ajax).toHaveBeenCalled();
expect(
- document.querySelector('.js-copy-blob-source-btn').classList.contains('disabled'),
+ copyButton.classList.contains('disabled'),
).toBeFalsy();
done();
@@ -115,7 +138,7 @@ describe('Blob viewer', () => {
expect($.ajax).toHaveBeenCalled();
expect(
- document.querySelector('.js-copy-blob-source-btn').getAttribute('data-original-title'),
+ copyButton.getAttribute('data-original-title'),
).toBe('Copy source to clipboard');
done();