summaryrefslogtreecommitdiff
path: root/spec/javascripts
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2017-01-27 20:54:19 +0000
committerFatih Acet <acetfatih@gmail.com>2017-01-27 20:54:19 +0000
commit1f875e8e37a2144cd6c87b4735fa9c1e93e4dde7 (patch)
treecb4d7b29ef24ce9439c54b3e084c9cedcd80d183 /spec/javascripts
parenta5ad8a0c7f278d4970aa119b499f731b21e49dbb (diff)
parent72e0ed0aa9b2e5a3190854a486fcd3570ad1230b (diff)
downloadgitlab-ce-1f875e8e37a2144cd6c87b4735fa9c1e93e4dde7.tar.gz
Merge branch '26448-unnecessary-request-is-made-when-filter-input-box-is-focused-by-keyboard' into 'master'
Only search commits on input change since last search Closes #26448 See merge request !8488
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('');
+ });
+ });
+ });
+})();