BigW Consortium Gitlab

deployments_spec.js 3.46 KB
Newer Older
Phil Hughes committed
1 2 3 4 5
import d3 from 'd3';
import PrometheusGraph from '~/monitoring/prometheus_graph';
import Deployments from '~/monitoring/deployments';
import { prometheusMockData } from './prometheus_mock_data';

Phil Hughes committed
6
describe('Metrics deployments', () => {
7
  const fixtureName = 'environments/metrics/metrics.html.raw';
Phil Hughes committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
  let deployment;
  let prometheusGraph;

  const graphElement = () => document.querySelector('.prometheus-graph');

  preloadFixtures(fixtureName);

  beforeEach((done) => {
    // Setup the view
    loadFixtures(fixtureName);

    d3.selectAll('.prometheus-graph')
      .append('g')
      .attr('class', 'graph-container');

    prometheusGraph = new PrometheusGraph();
    deployment = new Deployments(1000, 500);

    spyOn(prometheusGraph, 'init');
    spyOn($, 'ajax').and.callFake(() => {
      const d = $.Deferred();
Phil Hughes committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
      d.resolve({
        deployments: [{
          id: 1,
          created_at: deployment.chartData[10].time,
          sha: 'testing',
          tag: false,
          ref: {
            name: 'testing',
          },
        }, {
          id: 2,
          created_at: deployment.chartData[15].time,
          sha: '',
          tag: true,
          ref: {
            name: 'tag',
          },
        }],
      });
Phil Hughes committed
48 49 50 51 52 53

      setTimeout(done);

      return d.promise();
    });

Phil Hughes committed
54
    prometheusGraph.configureGraph();
Phil Hughes committed
55 56
    prometheusGraph.transformData(prometheusMockData.metrics);

Phil Hughes committed
57
    deployment.init(prometheusGraph.graphSpecificProperties.memory_values.data);
Phil Hughes committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
  });

  it('creates line on graph for deploment', () => {
    expect(
      graphElement().querySelectorAll('.deployment-line').length,
    ).toBe(2);
  });

  it('creates hidden deploy boxes', () => {
    expect(
      graphElement().querySelectorAll('.prometheus-graph .js-deploy-info-box').length,
    ).toBe(2);
  });

  it('hides the info boxes by default', () => {
    expect(
      graphElement().querySelectorAll('.prometheus-graph .js-deploy-info-box.hidden').length,
    ).toBe(2);
  });

  it('shows sha short code when tag is false', () => {
    expect(
Phil Hughes committed
80
      graphElement().querySelector('.deploy-info-1-cpu_values .js-deploy-info-box').textContent.trim(),
Phil Hughes committed
81 82 83 84 85
    ).toContain('testin');
  });

  it('shows ref name when tag is true', () => {
    expect(
Phil Hughes committed
86
      graphElement().querySelector('.deploy-info-2-cpu_values .js-deploy-info-box').textContent.trim(),
Phil Hughes committed
87 88 89 90
    ).toContain('tag');
  });

  it('shows info box when moving mouse over line', () => {
Phil Hughes committed
91
    deployment.mouseOverDeployInfo(deployment.data[0].xPos, 'cpu_values');
Phil Hughes committed
92 93 94 95 96 97

    expect(
      graphElement().querySelectorAll('.prometheus-graph .js-deploy-info-box.hidden').length,
    ).toBe(1);

    expect(
Phil Hughes committed
98
      graphElement().querySelector('.deploy-info-1-cpu_values .js-deploy-info-box.hidden'),
Phil Hughes committed
99 100 101 102
    ).toBeNull();
  });

  it('hides previously visible info box when moving mouse away', () => {
Phil Hughes committed
103
    deployment.mouseOverDeployInfo(500, 'cpu_values');
Phil Hughes committed
104 105 106 107 108 109

    expect(
      graphElement().querySelectorAll('.prometheus-graph .js-deploy-info-box.hidden').length,
    ).toBe(2);

    expect(
Phil Hughes committed
110
      graphElement().querySelector('.deploy-info-1-cpu_values .js-deploy-info-box.hidden'),
Phil Hughes committed
111 112
    ).not.toBeNull();
  });
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132

  describe('refText', () => {
    it('returns shortened SHA', () => {
      expect(
        Deployments.refText({
          tag: false,
          sha: '123456789',
        }),
      ).toBe('123456');
    });

    it('returns tag name', () => {
      expect(
        Deployments.refText({
          tag: true,
          ref: 'v1.0',
        }),
      ).toBe('v1.0');
    });
  });
Phil Hughes committed
133
});