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';
|
2018-03-17 18:26:18 +05:30
|
|
|
import timeoutPromise from './helpers/set_timeout_promise_helper';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe('Mini Pipeline Graph Dropdown', () => {
|
2019-05-18 00:54:41 +05:30
|
|
|
preloadFixtures('static/mini_dropdown_graph.html');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2019-05-18 00:54:41 +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', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
const getBuildsListSpy = spyOn(MiniPipelineGraph.prototype, 'getBuildsList').and.callFake(
|
|
|
|
function() {},
|
|
|
|
);
|
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', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const ajaxSpy = spyOn(axios, 'get').and.callThrough();
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(ajaxSpy.calls.allArgs()[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>
|
|
|
|
<span class="ci-build-text">build</span>
|
|
|
|
</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();
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
timeoutPromise()
|
|
|
|
.then(() => {
|
|
|
|
document.querySelector('a.mini-pipeline-graph-dropdown-item').click();
|
|
|
|
})
|
|
|
|
.then(timeoutPromise)
|
|
|
|
.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
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
setTimeout(() => {
|
|
|
|
expect($('.js-builds-dropdown-tests .dropdown').hasClass('open')).toEqual(false);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|