2018-02-01 05:34:12 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2021-02-14 13:09:20 -05:00
|
|
|
import $ from 'jquery';
|
2021-01-14 19:10:45 -05:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2018-02-01 05:34:12 -05:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-03-09 13:26:15 -05:00
|
|
|
import MiniPipelineGraph from '~/mini_pipeline_graph_dropdown';
|
2016-12-20 05:08:15 -05:00
|
|
|
|
2017-04-26 12:37:54 -04:00
|
|
|
describe('Mini Pipeline Graph Dropdown', () => {
|
|
|
|
beforeEach(() => {
|
2019-03-26 12:03:28 -04:00
|
|
|
loadFixtures('static/mini_dropdown_graph.html');
|
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 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', () => {
|
2020-05-20 08:07:52 -04:00
|
|
|
const getBuildsListSpy = jest
|
|
|
|
.spyOn(MiniPipelineGraph.prototype, 'getBuildsList')
|
|
|
|
.mockImplementation(() => {});
|
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', () => {
|
2020-05-20 08:07:52 -04:00
|
|
|
const ajaxSpy = jest.spyOn(axios, 'get');
|
2018-02-01 05:34:12 -05:00
|
|
|
|
|
|
|
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-10-09 14:03:09 -04:00
|
|
|
|
2020-05-20 08:07:52 -04:00
|
|
|
expect(ajaxSpy.mock.calls[0][0]).toEqual('foobar');
|
2017-04-26 12:37:54 -04:00
|
|
|
});
|
2017-03-09 08:03:08 -05:00
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it('should not close when user uses cmd/ctrl + click', (done) => {
|
2018-02-01 05:34:12 -05:00
|
|
|
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>
|
2020-10-16 08:09:33 -04:00
|
|
|
<span>build</span>
|
2018-02-01 05:34:12 -05:00
|
|
|
</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
|
|
|
|
2020-05-20 08:07:52 -04:00
|
|
|
waitForPromises()
|
2018-02-01 05:34:12 -05:00
|
|
|
.then(() => {
|
|
|
|
document.querySelector('a.mini-pipeline-graph-dropdown-item').click();
|
|
|
|
})
|
2020-05-20 08:07:52 -04:00
|
|
|
.then(waitForPromises)
|
2018-02-01 05:34:12 -05:00
|
|
|
.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
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it('should close the dropdown when request returns an error', (done) => {
|
2018-02-01 05:34:12 -05:00
|
|
|
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
|
|
|
|
2020-05-20 08:07:52 -04:00
|
|
|
setImmediate(() => {
|
2018-02-01 05:34:12 -05:00
|
|
|
expect($('.js-builds-dropdown-tests .dropdown').hasClass('open')).toEqual(false);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-04-26 12:37:54 -04:00
|
|
|
});
|
|
|
|
});
|