mini_pipeline_graph_dropdown_spec.js 1.7 KB
Newer Older
1 2
/* eslint-disable no-new */

3 4
require('~/flash');
require('~/mini_pipeline_graph_dropdown');
5 6 7

(() => {
  describe('Mini Pipeline Graph Dropdown', () => {
8
    preloadFixtures('static/mini_dropdown_graph.html.raw');
9 10

    beforeEach(() => {
11
      loadFixtures('static/mini_dropdown_graph.html.raw');
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
    });

    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 () {});

34
        new gl.MiniPipelineGraph({ container: '.js-builds-dropdown-tests' }).bindEvents();
35 36 37 38 39 40 41 42 43

        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 () {});

44
        new gl.MiniPipelineGraph({ container: '.js-builds-dropdown-tests' }).bindEvents();
45 46 47 48 49 50 51

        document.querySelector('.js-builds-dropdown-button').click();
        expect(ajaxSpy.calls.allArgs()[0][0].url).toEqual('foobar');
      });
    });
  });
})();