summaryrefslogtreecommitdiff
path: root/spec/javascripts
diff options
context:
space:
mode:
authorSam Rose <sam@gitlab.com>2017-01-07 18:29:10 -0500
committersamrose3 <sam@gitlab.com>2017-01-25 19:25:27 -0500
commit72e0ed0aa9b2e5a3190854a486fcd3570ad1230b (patch)
tree85518d0f1486d4f8d648f91a3f41bbdfbfc1fabb /spec/javascripts
parentb60de9c0fd90c310d2a4146f75b67f9f360cbd6c (diff)
downloadgitlab-ce-72e0ed0aa9b2e5a3190854a486fcd3570ad1230b.tar.gz
Only search commits on input change since last search26448-unnecessary-request-is-made-when-filter-input-box-is-focused-by-keyboard
Diffstat (limited to 'spec/javascripts')
-rw-r--r--spec/javascripts/commits_spec.js.es650
1 files changed, 50 insertions, 0 deletions
diff --git a/spec/javascripts/commits_spec.js.es6 b/spec/javascripts/commits_spec.js.es6
new file mode 100644
index 00000000000..bb9a9072f3a
--- /dev/null
+++ b/spec/javascripts/commits_spec.js.es6
@@ -0,0 +1,50 @@
+/* global CommitsList */
+
+//= require jquery.endless-scroll
+//= require pager
+//= require commits
+
+(() => {
+ describe('Commits List', () => {
+ beforeEach(() => {
+ setFixtures(`
+ <form class="commits-search-form" action="/h5bp/html5-boilerplate/commits/master">
+ <input id="commits-search">
+ </form>
+ <ol id="commits-list"></ol>
+ `);
+ });
+
+ it('should be defined', () => {
+ expect(CommitsList).toBeDefined();
+ });
+
+ describe('on entering input', () => {
+ let ajaxSpy;
+
+ beforeEach(() => {
+ CommitsList.init(25);
+ CommitsList.searchField.val('');
+ spyOn(history, 'replaceState').and.stub();
+ ajaxSpy = spyOn(jQuery, 'ajax').and.callFake((req) => {
+ req.success({
+ data: '<li>Result</li>',
+ });
+ });
+ });
+
+ it('should save the last search string', () => {
+ CommitsList.searchField.val('GitLab');
+ CommitsList.filterResults();
+ expect(ajaxSpy).toHaveBeenCalled();
+ expect(CommitsList.lastSearch).toEqual('GitLab');
+ });
+
+ it('should not make ajax call if the input does not change', () => {
+ CommitsList.filterResults();
+ expect(ajaxSpy).not.toHaveBeenCalled();
+ expect(CommitsList.lastSearch).toEqual('');
+ });
+ });
+ });
+})();