debian-mirror-gitlab/spec/frontend/branches/divergence_graph_spec.js

54 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-09-30 21:07:59 +05:30
import MockAdapter from 'axios-mock-adapter';
import init from '~/branches/divergence_graph';
2021-03-11 19:13:27 +05:30
import axios from '~/lib/utils/axios_utils';
2023-04-23 21:23:45 +05:30
import { HTTP_STATUS_OK } from '~/lib/utils/http_status';
2019-09-30 21:07:59 +05:30
describe('Divergence graph', () => {
let mock;
beforeEach(() => {
mock = new MockAdapter(axios);
2023-04-23 21:23:45 +05:30
mock.onGet('/-/diverging_counts').reply(HTTP_STATUS_OK, {
2021-06-08 01:23:25 +05:30
main: { ahead: 1, behind: 1 },
2019-09-30 21:07:59 +05:30
'test/hello-world': { ahead: 1, behind: 1 },
});
jest.spyOn(axios, 'get');
document.body.innerHTML = `
2021-06-08 01:23:25 +05:30
<div class="js-branch-item" data-name="main"><div class="js-branch-divergence-graph"></div></div>
2019-09-30 21:07:59 +05:30
<div class="js-branch-item" data-name="test/hello-world"><div class="js-branch-divergence-graph"></div></div>
`;
});
afterEach(() => {
mock.restore();
});
2019-12-04 20:38:33 +05:30
it('calls axios get with list of branch names', () =>
2019-09-30 21:07:59 +05:30
init('/-/diverging_counts').then(() => {
expect(axios.get).toHaveBeenCalledWith('/-/diverging_counts', {
2021-06-08 01:23:25 +05:30
params: { names: ['main', 'test/hello-world'] },
2019-09-30 21:07:59 +05:30
});
}));
2019-12-04 20:38:33 +05:30
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-09-30 21:07:59 +05:30
it('creates Vue components', () =>
init('/-/diverging_counts').then(() => {
2021-06-08 01:23:25 +05:30
expect(document.querySelector('[data-name="main"]').innerHTML).not.toEqual('');
2019-09-30 21:07:59 +05:30
expect(document.querySelector('[data-name="test/hello-world"]').innerHTML).not.toEqual('');
}));
});