summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke "Jared" Bennett <lbennett@gitlab.com>2017-04-18 15:44:08 +0100
committerLuke "Jared" Bennett <lbennett@gitlab.com>2017-04-18 15:44:08 +0100
commite3f4dc0a01c93caf5697c930d32c8f2b23437643 (patch)
treec0f41e26f03f0d6ed2b6f532e3eb001c8367986c
parent6027dd25a84a44b2057dd4489edab11a347d4a27 (diff)
downloadgitlab-ce-debounce-comment-button-render.tar.gz
-rw-r--r--app/assets/javascripts/files_comment_button.js2
-rw-r--r--spec/javascripts/files_comment_button_spec.js59
2 files changed, 61 insertions, 0 deletions
diff --git a/app/assets/javascripts/files_comment_button.js b/app/assets/javascripts/files_comment_button.js
index 9a4e6e5f46a..77e944f0d10 100644
--- a/app/assets/javascripts/files_comment_button.js
+++ b/app/assets/javascripts/files_comment_button.js
@@ -161,3 +161,5 @@ $.fn.filesCommentButton = function() {
}
});
};
+
+export default FilesCommentButton;
diff --git a/spec/javascripts/files_comment_button_spec.js b/spec/javascripts/files_comment_button_spec.js
new file mode 100644
index 00000000000..01c9e4f5dff
--- /dev/null
+++ b/spec/javascripts/files_comment_button_spec.js
@@ -0,0 +1,59 @@
+import FilesCommentButton from '~/files_comment_button';
+import _ from 'underscore';
+
+describe('FilesCommentButton', () => {
+ let filesCommentButton;
+
+ describe('class constructor', () => {
+ let filesContainerElement;
+ let renderDebounce;
+
+ beforeEach(() => {
+ filesContainerElement = jasmine.createSpyObj('filesContainerElement', ['on']);
+ window.notes = jasmine.createSpyObj('notes', ['isParallelView']);
+ renderDebounce = () => {};
+
+ spyOn(_, 'debounce').and.returnValue(renderDebounce);
+ filesContainerElement.on.and.returnValue(filesContainerElement);
+
+ filesCommentButton = new FilesCommentButton(filesContainerElement);
+
+ return filesCommentButton;
+ });
+
+ it('should call _.debounce', () => {
+ expect(_.debounce).toHaveBeenCalledWith(jasmine.any(Function), 100);
+ });
+
+ it('should call .on', () => {
+ const allArgs = filesContainerElement.on.calls.allArgs();
+ const targetSelector = '.diff-line-num, .line_content';
+
+ expect(allArgs[0]).toEqual(['mouseover', targetSelector, renderDebounce]);
+ expect(allArgs[1]).toEqual(['mouseleave', targetSelector, jasmine.any(Function)]);
+ });
+
+ describe('mouseleave function', () => {
+ let mouseleaveFunction;
+
+ function onFake(eventName, targetSelector, handler) {
+ if (eventName === 'mouseleave') mouseleaveFunction = handler;
+
+ return filesContainerElement;
+ }
+
+ beforeEach(() => {
+ spyOn(window, 'setTimeout');
+ filesContainerElement.on.and.callFake(onFake);
+
+ filesCommentButton = new FilesCommentButton(filesContainerElement);
+
+ mouseleaveFunction();
+ });
+
+ it('should call setTimeout', () => {
+ expect(window.setTimeout).toHaveBeenCalledWith(jasmine.any(Function), 100);
+ });
+ });
+ });
+});