2016-12-20 05:08:15 -05:00
|
|
|
/* eslint-disable no-new */
|
|
|
|
|
2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2018-02-01 05:34:12 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-03-09 13:26:15 -05:00
|
|
|
import MiniPipelineGraph from '~/mini_pipeline_graph_dropdown';
|
2018-02-01 05:34:12 -05:00
|
|
|
import timeoutPromise from './helpers/set_timeout_promise_helper';
|
2016-12-20 05:08:15 -05:00
|
|
|
|
2017-04-26 12:37:54 -04:00
|
|
|
describe('Mini Pipeline Graph Dropdown', () => {
|
|
|
|
preloadFixtures('static/mini_dropdown_graph.html.raw');
|
2016-12-20 05:08:15 -05:00
|
|
|
|
2017-04-26 12:37:54 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
loadFixtures('static/mini_dropdown_graph.html.raw');
|
|
|
|
});
|
2016-12-20 05:08:15 -05:00
|
|
|
|
2017-04-26 12:37:54 -04:00
|
|
|
describe('When is initialized', () => {
|
|
|
|
it('should initialize without errors when no options are given', () => {
|
|
|
|
const miniPipelineGraph = new MiniPipelineGraph();
|
2016-12-20 05:08:15 -05:00
|
|
|
|
2017-04-26 12:37:54 -04:00
|
|
|
expect(miniPipelineGraph.dropdownListSelector).toEqual('.js-builds-dropdown-container');
|
|
|
|
});
|
2016-12-20 05:08:15 -05:00
|
|
|
|
2017-04-26 12:37:54 -04:00
|
|
|
it('should set the container as the given prop', () => {
|
|
|
|
const container = '.foo';
|
2016-12-20 05:08:15 -05:00
|
|
|
|
2017-04-26 12:37:54 -04:00
|
|
|
const miniPipelineGraph = new MiniPipelineGraph({ container });
|
2016-12-20 05:08:15 -05:00
|
|
|
|
2017-04-26 12:37:54 -04:00
|
|
|
expect(miniPipelineGraph.container).toEqual(container);
|
2016-12-20 05:08:15 -05:00
|
|
|
});
|
2017-04-26 12:37:54 -04:00
|
|
|
});
|
2016-12-20 05:08:15 -05:00
|
|
|
|
2017-04-26 12:37:54 -04:00
|
|
|
describe('When dropdown is clicked', () => {
|
2018-02-01 05:34:12 -05:00
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
2017-04-26 12:37:54 -04:00
|
|
|
it('should call getBuildsList', () => {
|
|
|
|
const getBuildsListSpy = spyOn(
|
|
|
|
MiniPipelineGraph.prototype,
|
|
|
|
'getBuildsList',
|
|
|
|
).and.callFake(function () {});
|
2016-12-20 05:08:15 -05:00
|
|
|
|
2017-04-26 12:37:54 -04:00
|
|
|
new MiniPipelineGraph({ container: '.js-builds-dropdown-tests' }).bindEvents();
|
2016-12-20 05:08:15 -05:00
|
|
|
|
2017-04-26 12:37:54 -04:00
|
|
|
document.querySelector('.js-builds-dropdown-button').click();
|
2016-12-20 05:08:15 -05:00
|
|
|
|
2017-04-26 12:37:54 -04:00
|
|
|
expect(getBuildsListSpy).toHaveBeenCalled();
|
|
|
|
});
|
2016-12-20 05:08:15 -05:00
|
|
|
|
2017-04-26 12:37:54 -04:00
|
|
|
it('should make a request to the endpoint provided in the html', () => {
|
2018-02-01 05:34:12 -05:00
|
|
|
const ajaxSpy = spyOn(axios, 'get').and.callThrough();
|
|
|
|
|
|
|
|
mock.onGet('foobar').reply(200, {
|
|
|
|
html: '',
|
|
|
|
});
|
2016-12-20 05:08:15 -05:00
|
|
|
|
2017-04-26 12:37:54 -04:00
|
|
|
new MiniPipelineGraph({ container: '.js-builds-dropdown-tests' }).bindEvents();
|
2016-12-20 05:08:15 -05:00
|
|
|
|
2017-04-26 12:37:54 -04:00
|
|
|
document.querySelector('.js-builds-dropdown-button').click();
|
2018-02-01 05:34:12 -05:00
|
|
|
expect(ajaxSpy.calls.allArgs()[0][0]).toEqual('foobar');
|
2017-04-26 12:37:54 -04:00
|
|
|
});
|
2017-03-09 08:03:08 -05:00
|
|
|
|
2018-02-01 05:34:12 -05:00
|
|
|
it('should not close when user uses cmd/ctrl + click', (done) => {
|
|
|
|
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-04-26 12:37:54 -04:00
|
|
|
});
|
|
|
|
new MiniPipelineGraph({ container: '.js-builds-dropdown-tests' }).bindEvents();
|
2017-03-09 08:03:08 -05:00
|
|
|
|
2017-04-26 12:37:54 -04:00
|
|
|
document.querySelector('.js-builds-dropdown-button').click();
|
2017-03-09 08:03:08 -05:00
|
|
|
|
2018-02-01 05:34:12 -05:00
|
|
|
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);
|
2016-12-20 05:08:15 -05:00
|
|
|
});
|
2017-04-26 12:37:54 -04:00
|
|
|
|
2018-02-01 05:34:12 -05:00
|
|
|
it('should close the dropdown when request returns an error', (done) => {
|
|
|
|
mock.onGet('foobar').networkError();
|
2017-04-26 12:37:54 -04:00
|
|
|
|
2018-02-01 05:34:12 -05:00
|
|
|
new MiniPipelineGraph({ container: '.js-builds-dropdown-tests' }).bindEvents();
|
2017-04-26 12:37:54 -04:00
|
|
|
|
2018-02-01 05:34:12 -05:00
|
|
|
document.querySelector('.js-builds-dropdown-button').click();
|
2017-04-26 12:37:54 -04:00
|
|
|
|
2018-02-01 05:34:12 -05:00
|
|
|
setTimeout(() => {
|
|
|
|
expect($('.js-builds-dropdown-tests .dropdown').hasClass('open')).toEqual(false);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-04-26 12:37:54 -04:00
|
|
|
});
|
|
|
|
});
|