summaryrefslogtreecommitdiff
path: root/spec/javascripts/monitoring/utils_spec.js
blob: e3c455d168625d2b79f090e12634898f05c1bfcc (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
import { getTimeDiff } from '~/monitoring/utils';
import { timeWindows } from '~/monitoring/constants';

describe('getTimeDiff', () => {
  it('defaults to an 8 hour (28800s) difference', () => {
    const params = getTimeDiff();

    expect(params.end - params.start).toEqual(28800);
  });

  it('accepts time window as an argument', () => {
    const params = getTimeDiff(timeWindows.thirtyMinutes);

    expect(params.end - params.start).not.toEqual(28800);
  });

  it('returns a value for every defined time window', () => {
    const nonDefaultWindows = Object.keys(timeWindows).filter(window => window !== 'eightHours');

    nonDefaultWindows.forEach(window => {
      const params = getTimeDiff(timeWindows[window]);
      const diff = params.end - params.start;

      // Ensure we're not returning the default, 28800 (the # of seconds in 8 hrs)
      expect(diff).not.toEqual(28800);
      expect(typeof diff).toEqual('number');
    });
  });
});