BigW Consortium Gitlab

commits_spec.js 1.62 KB
Newer Older
1 2
/* global CommitsList */

Mike Greiling committed
3 4 5
require('vendor/jquery.endless-scroll');
require('~/pager');
require('~/commits');
6 7

(() => {
Mike Greiling committed
8 9 10 11 12 13 14 15 16
  // 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;
  }

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
  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('');
Mike Greiling committed
37 38 39 40

        if (!phantomjs) {
          spyOn(history, 'replaceState').and.stub();
        }
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
        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('');
      });
    });
  });
})();