2017-01-07 18:29:10 -05:00
|
|
|
/* global CommitsList */
|
|
|
|
|
2017-05-16 17:01:51 -04:00
|
|
|
import 'vendor/jquery.endless-scroll';
|
|
|
|
import '~/pager';
|
|
|
|
import '~/commits';
|
2017-01-07 18:29:10 -05:00
|
|
|
|
|
|
|
(() => {
|
2017-01-28 12:38:30 -05:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2017-01-07 18:29:10 -05:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2017-06-02 21:40:20 -04:00
|
|
|
describe('processCommits', () => {
|
|
|
|
it('should join commit headers', () => {
|
|
|
|
CommitsList.$contentList = $(`
|
|
|
|
<div>
|
|
|
|
<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>
|
|
|
|
</div>
|
|
|
|
`);
|
|
|
|
|
|
|
|
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-01-07 18:29:10 -05:00
|
|
|
describe('on entering input', () => {
|
|
|
|
let ajaxSpy;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
CommitsList.init(25);
|
|
|
|
CommitsList.searchField.val('');
|
2017-01-28 12:38:30 -05:00
|
|
|
|
|
|
|
if (!phantomjs) {
|
|
|
|
spyOn(history, 'replaceState').and.stub();
|
|
|
|
}
|
2017-01-07 18:29:10 -05:00
|
|
|
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('');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})();
|