2019-07-01 06:40:29 -04:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import init from '~/branches/divergence_graph';
|
2021-02-14 13:09:20 -05:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2019-07-01 06:40:29 -04:00
|
|
|
|
|
|
|
describe('Divergence graph', () => {
|
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
|
|
|
|
mock.onGet('/-/diverging_counts').reply(200, {
|
2021-04-26 20:10:25 -04:00
|
|
|
main: { ahead: 1, behind: 1 },
|
2019-07-05 06:50:07 -04:00
|
|
|
'test/hello-world': { ahead: 1, behind: 1 },
|
2019-07-01 06:40:29 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
jest.spyOn(axios, 'get');
|
|
|
|
|
|
|
|
document.body.innerHTML = `
|
2021-04-26 20:10:25 -04:00
|
|
|
<div class="js-branch-item" data-name="main"><div class="js-branch-divergence-graph"></div></div>
|
2019-07-05 06:50:07 -04:00
|
|
|
<div class="js-branch-item" data-name="test/hello-world"><div class="js-branch-divergence-graph"></div></div>
|
2019-07-01 06:40:29 -04:00
|
|
|
`;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
2019-09-02 12:50:09 -04:00
|
|
|
it('calls axios get with list of branch names', () =>
|
2019-07-01 06:40:29 -04:00
|
|
|
init('/-/diverging_counts').then(() => {
|
|
|
|
expect(axios.get).toHaveBeenCalledWith('/-/diverging_counts', {
|
2021-04-26 20:10:25 -04:00
|
|
|
params: { names: ['main', 'test/hello-world'] },
|
2019-07-01 06:40:29 -04:00
|
|
|
});
|
|
|
|
}));
|
2019-07-05 06:50:07 -04:00
|
|
|
|
2019-09-02 12:50:09 -04:00
|
|
|
describe('no branches listed', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
document.body.innerHTML = `<div></div>`;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('avoids requesting diverging commit counts', () => {
|
|
|
|
expect(axios.get).not.toHaveBeenCalledWith('/-/diverging_counts');
|
|
|
|
|
|
|
|
init('/-/diverging_counts');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-05 06:50:07 -04:00
|
|
|
it('creates Vue components', () =>
|
|
|
|
init('/-/diverging_counts').then(() => {
|
2021-04-26 20:10:25 -04:00
|
|
|
expect(document.querySelector('[data-name="main"]').innerHTML).not.toEqual('');
|
2019-07-05 06:50:07 -04:00
|
|
|
expect(document.querySelector('[data-name="test/hello-world"]').innerHTML).not.toEqual('');
|
|
|
|
}));
|
2019-07-01 06:40:29 -04:00
|
|
|
});
|