gitlab-org--gitlab-foss/spec/frontend/commits_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

92 lines
2.5 KiB
JavaScript
Raw Normal View History

import MockAdapter from 'axios-mock-adapter';
import $ from 'jquery';
import 'vendor/jquery.endless-scroll';
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
import CommitsList from '~/commits';
import axios from '~/lib/utils/axios_utils';
2018-04-24 21:35:32 +00:00
import Pager from '~/pager';
describe('Commits List', () => {
2018-02-15 17:17:29 +00:00
let commitsList;
beforeEach(() => {
setHTMLFixture(`
<form class="commits-search-form" action="/h5bp/html5-boilerplate/commits/main">
<input id="commits-search">
</form>
<ol id="commits-list"></ol>
`);
jest.spyOn(Pager, 'init').mockImplementation(() => {});
2018-02-15 17:17:29 +00:00
commitsList = new CommitsList(25);
});
afterEach(() => {
resetHTMLFixture();
});
it('should be defined', () => {
expect(CommitsList).toBeDefined();
});
describe('processCommits', () => {
it('should join commit headers', () => {
2018-02-15 17:17:29 +00:00
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.
2018-02-15 17:17:29 +00:00
expect(commitsList.processCommits(data).find('li.commit-header').length).toBe(0);
});
});
describe('on entering input', () => {
let ajaxSpy;
2018-01-26 09:41:13 +00:00
let mock;
beforeEach(() => {
2018-02-15 17:17:29 +00:00
commitsList.searchField.val('');
2017-01-28 17:38:30 +00:00
jest.spyOn(window.history, 'replaceState').mockImplementation(() => {});
2018-01-26 09:41:13 +00:00
mock = new MockAdapter(axios);
mock.onGet('/h5bp/html5-boilerplate/commits/main').reply(200, {
2018-01-26 09:41:13 +00:00
html: '<li>Result</li>',
});
2018-01-26 09:41:13 +00:00
ajaxSpy = jest.spyOn(axios, 'get');
2018-01-26 09:41:13 +00:00
});
afterEach(() => {
mock.restore();
});
it('should save the last search string', async () => {
2018-02-15 17:17:29 +00:00
commitsList.searchField.val('GitLab');
await commitsList.filterResults();
expect(ajaxSpy).toHaveBeenCalled();
expect(commitsList.lastSearch).toEqual('GitLab');
});
it('should not make ajax call if the input does not change', async () => {
await commitsList.filterResults();
expect(ajaxSpy).not.toHaveBeenCalled();
expect(commitsList.lastSearch).toEqual('');
});
});
});