Adds tests for the MiniPipelineGraph class
This commit is contained in:
parent
51353a6bc7
commit
11040589c8
3 changed files with 63 additions and 2 deletions
|
@ -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',
|
||||
|
|
8
spec/javascripts/fixtures/mini_dropdown_graph.html.haml
Normal file
8
spec/javascripts/fixtures/mini_dropdown_graph.html.haml
Normal file
|
@ -0,0 +1,8 @@
|
|||
%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
|
51
spec/javascripts/mini_pipeline_graph_dropdown_spec.js.es6
Normal file
51
spec/javascripts/mini_pipeline_graph_dropdown_spec.js.es6
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* 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');
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
Loading…
Reference in a new issue