import 'vendor/jquery.endless-scroll'; import MockAdapter from 'axios-mock-adapter'; import axios from '~/lib/utils/axios_utils'; import CommitsList from '~/commits'; describe('Commits List', () => { beforeEach(() => { setFixtures(`
    `); }); it('should be defined', () => { expect(CommitsList).toBeDefined(); }); describe('processCommits', () => { it('should join commit headers', () => { CommitsList.$contentList = $(`
  1. 20 Sep, 2016 1 commit
  2. `); const data = `
  3. 20 Sep, 2016 1 commit
  4. `; // The last commit header should be removed // since the previous one has the same data-day value. expect(CommitsList.processCommits(data).find('li.commit-header').length).toBe(0); }); }); describe('on entering input', () => { let ajaxSpy; let mock; beforeEach(() => { CommitsList.init(25); CommitsList.searchField.val(''); spyOn(history, 'replaceState').and.stub(); mock = new MockAdapter(axios); mock.onGet('/h5bp/html5-boilerplate/commits/master').reply(200, { html: '
  5. Result
  6. ', }); ajaxSpy = spyOn(axios, 'get').and.callThrough(); }); afterEach(() => { mock.restore(); }); it('should save the last search string', (done) => { CommitsList.searchField.val('GitLab'); CommitsList.filterResults() .then(() => { expect(ajaxSpy).toHaveBeenCalled(); expect(CommitsList.lastSearch).toEqual('GitLab'); done(); }) .catch(done.fail); }); it('should not make ajax call if the input does not change', (done) => { CommitsList.filterResults() .then(() => { expect(ajaxSpy).not.toHaveBeenCalled(); expect(CommitsList.lastSearch).toEqual(''); done(); }) .catch(done.fail); }); }); });