summaryrefslogtreecommitdiff
path: root/spec/javascripts/monitoring/graph/flag_spec.js
blob: a837b71db0b602ae3916719ac2dc71f798284259 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import Vue from 'vue';
import GraphFlag from '~/monitoring/components/graph/flag.vue';
import { deploymentData } from '../mock_data';

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

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

const defaultValuesComponent = {
  currentXCoordinate: 200,
  currentYCoordinate: 100,
  currentFlagPosition: 100,
  currentData: {
    time: new Date('2017-06-04T18:17:33.501Z'),
    value: '1.49609375',
  },
  graphHeight: 300,
  graphHeightOffset: 120,
  showFlagContent: true,
  realPixelRatio: 1,
  timeSeries: [
    {
      values: [
        {
          time: new Date('2017-06-04T18:17:33.501Z'),
          value: '1.49609375',
        },
      ],
    },
  ],
  unitOfDisplay: 'ms',
  currentDataIndex: 0,
  legendTitle: 'Average',
  currentCoordinates: {},
};

const deploymentFlagData = {
  ...deploymentData[0],
  ref: deploymentData[0].ref.name,
  xPos: 10,
  time: new Date(deploymentData[0].created_at),
};

describe('GraphFlag', () => {
  let component;

  it('has a line at the currentXCoordinate', () => {
    component = createComponent(defaultValuesComponent);

    expect(component.$el.style.left)
      .toEqual(`${70 + component.currentXCoordinate}px`);
  });

  describe('Deployment flag', () => {
    it('shows a deployment flag when deployment data provided', () => {
      const deploymentFlagComponent = createComponent({
        ...defaultValuesComponent,
        deploymentFlagData,
      });

      expect(
        deploymentFlagComponent.$el.querySelector('.popover-title'),
      ).toContainText('Deployed');
    });

    it('contains the ref when a tag is available', () => {
      const deploymentFlagComponent = createComponent({
        ...defaultValuesComponent,
        deploymentFlagData: {
          ...deploymentFlagData,
          sha: 'f5bcd1d9dac6fa4137e2510b9ccd134ef2e84187',
          tag: true,
          ref: '1.0',
        },
      });

      expect(
        deploymentFlagComponent.$el.querySelector('.deploy-meta-content'),
      ).toContainText('f5bcd1d9');

      expect(
        deploymentFlagComponent.$el.querySelector('.deploy-meta-content'),
      ).toContainText('1.0');
    });

    it('does not contain the ref when a tag is unavailable', () => {
      const deploymentFlagComponent = createComponent({
        ...defaultValuesComponent,
        deploymentFlagData: {
          ...deploymentFlagData,
          sha: 'f5bcd1d9dac6fa4137e2510b9ccd134ef2e84187',
          tag: false,
          ref: '1.0',
        },
      });

      expect(
        deploymentFlagComponent.$el.querySelector('.deploy-meta-content'),
      ).toContainText('f5bcd1d9');

      expect(
        deploymentFlagComponent.$el.querySelector('.deploy-meta-content'),
      ).not.toContainText('1.0');
    });
  });

  describe('Computed props', () => {
    beforeEach(() => {
      component = createComponent(defaultValuesComponent);
    });

    it('formatTime', () => {
      expect(component.formatTime).toMatch(/\d:17PM/);
    });

    it('formatDate', () => {
      expect(component.formatDate).toEqual('04 Jun 2017, ');
    });

    it('cursorStyle', () => {
      expect(component.cursorStyle).toEqual({
        top: '20px',
        left: '270px',
        height: '180px',
      });
    });

    it('flagOrientation', () => {
      expect(component.flagOrientation).toEqual('left');
    });
  });
});