Commit 11040589 authored by Filipa Lacerda's avatar Filipa Lacerda

Adds tests for the MiniPipelineGraph class

parent 51353a6b
......@@ -16,8 +16,8 @@
*/
(() => {
class MiniPipelineGraph {
constructor({ container }) {
this.container = container;
constructor(opts = {}) {
this.container = opts.container || '';
this.dropdownListSelector = '.js-builds-dropdown-container';
this.getBuildsList = this.getBuildsList.bind(this);
......@@ -57,6 +57,8 @@
getBuildsList(e) {
const endpoint = e.currentTarget.dataset.stageEndpoint;
console.log('ENDPOINT', endpoint);
return $.ajax({
dataType: 'json',
type: 'GET',
......
%div.js-builds-dropdown-tests
%button.dropdown.js-builds-dropdown-button{'data-stage-endpoint' => 'foobar'}
Dropdown
%div.js-builds-dropdown-container
%div.js-builds-dropdown-list
%div.js-builds-dropdown-loading.builds-dropdown-loading.hidden
%span.fa.fa-spinner.fa-spin
/* eslint-disable no-new */
//= require flash
//= require mini_pipeline_graph_dropdown
(() => {
describe('Mini Pipeline Graph Dropdown', () => {
fixture.preload('mini_dropdown_graph');
beforeEach(() => {
fixture.load('mini_dropdown_graph');
});
describe('When is initialized', () => {
it('should initialize without errors when no options are given', () => {
const miniPipelineGraph = new window.gl.MiniPipelineGraph();
expect(miniPipelineGraph.dropdownListSelector).toEqual('.js-builds-dropdown-container');
});
it('should set the container as the given prop', () => {
const container = '.foo';
const miniPipelineGraph = new window.gl.MiniPipelineGraph({ container });
expect(miniPipelineGraph.container).toEqual(container);
});
});
describe('When dropdown is clicked', () => {
it('should call getBuildsList', () => {
const getBuildsListSpy = spyOn(gl.MiniPipelineGraph.prototype, 'getBuildsList').and.callFake(function () {});
new gl.MiniPipelineGraph({ container: '.js-builds-dropdown-tests' });
document.querySelector('.js-builds-dropdown-button').click();
expect(getBuildsListSpy).toHaveBeenCalled();
});
it('should make a request to the endpoint provided in the html', () => {
const ajaxSpy = spyOn($, 'ajax').and.callFake(function () {});
new gl.MiniPipelineGraph({ container: '.js-builds-dropdown-tests' });
document.querySelector('.js-builds-dropdown-button').click();
expect(ajaxSpy.calls.allArgs()[0][0].url).toEqual('foobar');
});
});
});
})();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment