debian-mirror-gitlab/spec/frontend/mini_pipeline_graph_dropdown_spec.js

107 lines
3.2 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-17 18:26:18 +05:30
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
2017-08-17 22:00:37 +05:30
import MiniPipelineGraph from '~/mini_pipeline_graph_dropdown';
2020-06-23 00:09:42 +05:30
import waitForPromises from './helpers/wait_for_promises';
2017-08-17 22:00:37 +05:30
describe('Mini Pipeline Graph Dropdown', () => {
2019-07-07 11:18:12 +05:30
preloadFixtures('static/mini_dropdown_graph.html');
2017-08-17 22:00:37 +05:30
beforeEach(() => {
2019-07-07 11:18:12 +05:30
loadFixtures('static/mini_dropdown_graph.html');
2017-08-17 22:00:37 +05:30
});
describe('When is initialized', () => {
it('should initialize without errors when no options are given', () => {
const miniPipelineGraph = new MiniPipelineGraph();
expect(miniPipelineGraph.dropdownListSelector).toEqual('.js-builds-dropdown-container');
});
it('should set the container as the given prop', () => {
const container = '.foo';
const miniPipelineGraph = new MiniPipelineGraph({ container });
expect(miniPipelineGraph.container).toEqual(container);
});
});
describe('When dropdown is clicked', () => {
2018-03-17 18:26:18 +05:30
let mock;
beforeEach(() => {
mock = new MockAdapter(axios);
});
afterEach(() => {
mock.restore();
});
2017-08-17 22:00:37 +05:30
it('should call getBuildsList', () => {
2020-06-23 00:09:42 +05:30
const getBuildsListSpy = jest
.spyOn(MiniPipelineGraph.prototype, 'getBuildsList')
.mockImplementation(() => {});
2017-08-17 22:00:37 +05:30
new MiniPipelineGraph({ container: '.js-builds-dropdown-tests' }).bindEvents();
document.querySelector('.js-builds-dropdown-button').click();
expect(getBuildsListSpy).toHaveBeenCalled();
});
it('should make a request to the endpoint provided in the html', () => {
2020-06-23 00:09:42 +05:30
const ajaxSpy = jest.spyOn(axios, 'get');
2018-03-17 18:26:18 +05:30
mock.onGet('foobar').reply(200, {
html: '',
});
2017-08-17 22:00:37 +05:30
new MiniPipelineGraph({ container: '.js-builds-dropdown-tests' }).bindEvents();
document.querySelector('.js-builds-dropdown-button').click();
2018-12-13 13:39:08 +05:30
2020-06-23 00:09:42 +05:30
expect(ajaxSpy.mock.calls[0][0]).toEqual('foobar');
2017-08-17 22:00:37 +05:30
});
2018-12-13 13:39:08 +05:30
it('should not close when user uses cmd/ctrl + click', done => {
2018-03-17 18:26:18 +05:30
mock.onGet('foobar').reply(200, {
html: `<li>
<a class="mini-pipeline-graph-dropdown-item" href="#">
<span class="ci-status-icon ci-status-icon-failed"></span>
2021-01-03 14:25:43 +05:30
<span>build</span>
2018-03-17 18:26:18 +05:30
</a>
<a class="ci-action-icon-wrapper js-ci-action-icon" href="#"></a>
</li>`,
2017-08-17 22:00:37 +05:30
});
new MiniPipelineGraph({ container: '.js-builds-dropdown-tests' }).bindEvents();
document.querySelector('.js-builds-dropdown-button').click();
2020-06-23 00:09:42 +05:30
waitForPromises()
2018-03-17 18:26:18 +05:30
.then(() => {
document.querySelector('a.mini-pipeline-graph-dropdown-item').click();
})
2020-06-23 00:09:42 +05:30
.then(waitForPromises)
2018-03-17 18:26:18 +05:30
.then(() => {
expect($('.js-builds-dropdown-list').is(':visible')).toEqual(true);
})
.then(done)
.catch(done.fail);
2017-08-17 22:00:37 +05:30
});
2018-12-13 13:39:08 +05:30
it('should close the dropdown when request returns an error', done => {
2018-03-17 18:26:18 +05:30
mock.onGet('foobar').networkError();
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
new MiniPipelineGraph({ container: '.js-builds-dropdown-tests' }).bindEvents();
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
document.querySelector('.js-builds-dropdown-button').click();
2017-08-17 22:00:37 +05:30
2020-06-23 00:09:42 +05:30
setImmediate(() => {
2018-03-17 18:26:18 +05:30
expect($('.js-builds-dropdown-tests .dropdown').hasClass('open')).toEqual(false);
done();
});
});
2017-08-17 22:00:37 +05:30
});
});