summaryrefslogtreecommitdiff
path: root/spec/javascripts/pipelines/stage_spec.js
blob: 2f1154bd9995a5cc89b3436a957ce2367572977a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import Vue from 'vue';
import { SUCCESS_SVG } from '~/ci_status_icons';
import Stage from '~/pipelines/components/stage';

function minify(string) {
  return string.replace(/\s/g, '');
}

describe('Pipelines Stage', () => {
  describe('data', () => {
    let stageReturnValue;

    beforeEach(() => {
      stageReturnValue = Stage.data();
    });

    it('should return object with .builds and .spinner', () => {
      expect(stageReturnValue).toEqual({
        builds: '',
        spinner: '<span class="fa fa-spinner fa-spin"></span>',
      });
    });
  });

  describe('computed', () => {
    describe('svgHTML', function () {
      let stage;
      let svgHTML;

      beforeEach(() => {
        stage = { stage: { status: { icon: 'icon_status_success' } } };

        svgHTML = Stage.computed.svgHTML.call(stage);
      });

      it("should return the correct icon for the stage's status", () => {
        expect(svgHTML).toBe(SUCCESS_SVG);
      });
    });
  });

  describe('when mounted', () => {
    let StageComponent;
    let renderedComponent;
    let stage;

    beforeEach(() => {
      stage = { status: { icon: 'icon_status_success' } };

      StageComponent = Vue.extend(Stage);

      renderedComponent = new StageComponent({
        propsData: {
          stage,
        },
      }).$mount();
    });

    it('should render the correct status svg', () => {
      const minifiedComponent = minify(renderedComponent.$el.outerHTML);
      const expectedSVG = minify(SUCCESS_SVG);

      expect(minifiedComponent).toContain(expectedSVG);
    });
  });

  describe('when request fails', () => {
    it('closes dropdown', () => {
      spyOn($, 'ajax').and.callFake(options => options.error());
      const StageComponent = Vue.extend(Stage);

      const component = new StageComponent({
        propsData: { stage: { status: { icon: 'foo' } } },
      }).$mount();

      expect(
        component.$el.classList.contains('open'),
      ).toEqual(false);
    });
  });
});