2017-09-10 17:25:29 +05:30
|
|
|
import 'vendor/jquery.endless-scroll';
|
2018-03-17 18:26:18 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import CommitsList from '~/commits';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
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>
|
|
|
|
`);
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it('should be defined', () => {
|
|
|
|
expect(CommitsList).toBeDefined();
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe('processCommits', () => {
|
|
|
|
it('should join commit headers', () => {
|
|
|
|
CommitsList.$contentList = $(`
|
|
|
|
<div>
|
2017-09-10 17:25:29 +05:30
|
|
|
<li class="commit-header" data-day="2016-09-20">
|
|
|
|
<span class="day">20 Sep, 2016</span>
|
|
|
|
<span class="commits-count">1 commit</span>
|
|
|
|
</li>
|
|
|
|
<li class="commit"></li>
|
2018-03-17 18:26:18 +05:30
|
|
|
</div>
|
|
|
|
`);
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
const data = `
|
|
|
|
<li class="commit-header" data-day="2016-09-20">
|
|
|
|
<span class="day">20 Sep, 2016</span>
|
|
|
|
<span class="commits-count">1 commit</span>
|
|
|
|
</li>
|
|
|
|
<li class="commit"></li>
|
|
|
|
`;
|
|
|
|
|
|
|
|
// 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);
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe('on entering input', () => {
|
|
|
|
let ajaxSpy;
|
|
|
|
let mock;
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
CommitsList.init(25);
|
|
|
|
CommitsList.searchField.val('');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
spyOn(history, 'replaceState').and.stub();
|
|
|
|
mock = new MockAdapter(axios);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
mock.onGet('/h5bp/html5-boilerplate/commits/master').reply(200, {
|
|
|
|
html: '<li>Result</li>',
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
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);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|