diff options
author | winniehell <git@winniehell.de> | 2017-03-05 22:43:05 +0300 |
---|---|---|
committer | winniehell <git@winniehell.de> | 2017-03-05 23:22:40 +0300 |
commit | 572f9782d5e8d6307784b61db0dfce48f5118445 (patch) | |
tree | 11b25c46733462729e4303b26b4895d983f14df0 /spec/javascripts/commits_spec.js | |
parent | 4cd2ab52548e89cd7259cfb7ce320fdfa203fe84 (diff) |
Remove .es6 from file extensions (!9241)
Diffstat (limited to 'spec/javascripts/commits_spec.js')
-rw-r--r-- | spec/javascripts/commits_spec.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/javascripts/commits_spec.js b/spec/javascripts/commits_spec.js new file mode 100644 index 00000000000..05260760c43 --- /dev/null +++ b/spec/javascripts/commits_spec.js @@ -0,0 +1,62 @@ +/* global CommitsList */ + +require('vendor/jquery.endless-scroll'); +require('~/pager'); +require('~/commits'); + +(() => { + // TODO: remove this hack! + // PhantomJS causes spyOn to panic because replaceState isn't "writable" + let phantomjs; + try { + phantomjs = !Object.getOwnPropertyDescriptor(window.history, 'replaceState').writable; + } catch (err) { + phantomjs = false; + } + + 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(''); + + if (!phantomjs) { + 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(''); + }); + }); + }); +})(); |