import 'vendor/jquery.endless-scroll';
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 = $(`
`);
const data = `
`;
// 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;
beforeEach(() => {
CommitsList.init(25);
CommitsList.searchField.val('');
spyOn(history, 'replaceState').and.stub();
ajaxSpy = spyOn(jQuery, 'ajax').and.callFake((req) => {
req.success({
data: 'Result',
});
});
});
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('');
});
});
});