summaryrefslogtreecommitdiff
path: root/spec/javascripts/monitoring/graph/flag_spec.js
blob: 731076a7d2a52735d305414af4dbcb172fc54067 (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
import Vue from 'vue';
import GraphFlag from '~/monitoring/components/graph/flag.vue';

const createComponent = (propsData) => {
  const Component = Vue.extend(GraphFlag);

  return new Component({
    propsData,
  }).$mount();
};

function getCoordinate(component, selector, coordinate) {
  const coordinateVal = component.$el.querySelector(selector).getAttribute(coordinate);
  return parseInt(coordinateVal, 10);
}

describe('GraphFlag', () => {
  it('has a line and a circle located at the currentXCoordinate and currentYCoordinate', () => {
    const component = createComponent({
      currentXCoordinate: 200,
      currentYCoordinate: 100,
      currentFlagPosition: 100,
      currentData: {
        time: new Date('2017-06-04T18:17:33.501Z'),
        value: '1.49609375',
      },
      graphHeight: 300,
      graphHeightOffset: 120,
    });

    expect(getCoordinate(component, '.selected-metric-line', 'x1'))
      .toEqual(component.currentXCoordinate);
    expect(getCoordinate(component, '.selected-metric-line', 'x2'))
      .toEqual(component.currentXCoordinate);
    expect(getCoordinate(component, '.circle-metric', 'cx'))
      .toEqual(component.currentXCoordinate);
    expect(getCoordinate(component, '.circle-metric', 'cy'))
      .toEqual(component.currentYCoordinate);
  });

  it('has a SVG with the class rect-text-metric at the currentFlagPosition', () => {
    const component = createComponent({
      currentXCoordinate: 200,
      currentYCoordinate: 100,
      currentFlagPosition: 100,
      currentData: {
        time: new Date('2017-06-04T18:17:33.501Z'),
        value: '1.49609375',
      },
      graphHeight: 300,
      graphHeightOffset: 120,
    });

    const svg = component.$el.querySelector('.rect-text-metric');
    expect(svg.tagName).toEqual('svg');
    expect(parseInt(svg.getAttribute('x'), 10)).toEqual(component.currentFlagPosition);
  });

  describe('Computed props', () => {
    it('calculatedHeight', () => {
      const component = createComponent({
        currentXCoordinate: 200,
        currentYCoordinate: 100,
        currentFlagPosition: 100,
        currentData: {
          time: new Date('2017-06-04T18:17:33.501Z'),
          value: '1.49609375',
        },
        graphHeight: 300,
        graphHeightOffset: 120,
      });

      expect(component.calculatedHeight).toEqual(180);
    });
  });
});