node-details-health-link-item-test.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import moment from 'moment';
  2. import { appendTime } from '../node-details-health-link-item';
  3. describe('NodeDetailsHealthLinkItem', () => {
  4. describe('appendTime', () => {
  5. const time = '2017-06-01T00:00:00Z';
  6. const timeUnix = moment(time).unix();
  7. it('returns url for empty url or time', () => {
  8. expect(appendTime('', time)).toEqual('');
  9. expect(appendTime('foo', null)).toEqual('foo');
  10. expect(appendTime('', null)).toEqual('');
  11. });
  12. it('appends as json for cloud link', () => {
  13. const url = appendTime('/prom/:instanceid/notebook/new/%7B%22cells%22%3A%5B%7B%22queries%22%3A%5B%22go_goroutines%22%5D%7D%5D%7D', time);
  14. expect(url).toContain(timeUnix);
  15. const payload = JSON.parse(decodeURIComponent(url.substr(url.indexOf('new/') + 4)));
  16. expect(payload.time.queryEnd).toEqual(timeUnix);
  17. });
  18. it('appends as GET parameter', () => {
  19. expect(appendTime('http://example.test?q=foo', time)).toEqual('http://example.test?q=foo&time=1496275200');
  20. expect(appendTime('http://example.test/q=foo/', time)).toEqual('http://example.test/q=foo/?time=1496275200');
  21. });
  22. });
  23. });