From df469864b1ab1e0bfaa1e843d3d0a84042604646 Mon Sep 17 00:00:00 2001 From: "Luke \"Jared\" Bennett" Date: Tue, 7 Feb 2017 18:02:49 +0000 Subject: Updated the filename regex --- spec/javascripts/commits_spec.js | 62 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 spec/javascripts/commits_spec.js (limited to 'spec/javascripts/commits_spec.js') 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(` +
+ +
+
    + `); + }); + + 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: '
  1. Result
  2. ', + }); + }); + }); + + 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(''); + }); + }); + }); +})(); -- cgit v1.2.1