rangeutil_specs.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {describe, beforeEach, it, sinon, expect} from 'test/lib/common'
  2. import rangeUtil = require('app/core/utils/rangeutil')
  3. import _ = require('lodash')
  4. import moment = require('moment')
  5. describe("rangeUtil", () => {
  6. describe("Can get range text described", () => {
  7. it('should handle simple old expression with only amount and unit', () => {
  8. var info = rangeUtil.describeTextRange('5m');
  9. expect(info.display).to.be('Last 5 minutes')
  10. });
  11. it('should have singular when amount is 1', () => {
  12. var info = rangeUtil.describeTextRange('1h');
  13. expect(info.display).to.be('Last 1 hour')
  14. });
  15. it('should handle non default amount', () => {
  16. var info = rangeUtil.describeTextRange('13h');
  17. expect(info.display).to.be('Last 13 hours')
  18. expect(info.from).to.be('now-13h')
  19. });
  20. it('should handle now/d', () => {
  21. var info = rangeUtil.describeTextRange('now/d');
  22. expect(info.display).to.be('The day so far');
  23. });
  24. it('should handle now/w', () => {
  25. var info = rangeUtil.describeTextRange('now/w');
  26. expect(info.display).to.be('Week to date');
  27. });
  28. });
  29. describe("Can get date range described", () => {
  30. it('Date range with simple ranges', () => {
  31. var text = rangeUtil.describeTimeRange({from: 'now-1h', to: 'now'});
  32. expect(text).to.be('Last 1 hour')
  33. });
  34. it('Date range with absolute to now', () => {
  35. var text = rangeUtil.describeTimeRange({from: moment([2014,10,10,2,3,4]), to: 'now'});
  36. expect(text).to.be('Nov 10, 2014 02:03:04 to a few seconds ago')
  37. });
  38. it('Date range with absolute to relative', () => {
  39. var text = rangeUtil.describeTimeRange({from: moment([2014,10,10,2,3,4]), to: 'now-1d'});
  40. expect(text).to.be('Nov 10, 2014 02:03:04 to a day ago')
  41. });
  42. it('Date range with relative to absolute', () => {
  43. var text = rangeUtil.describeTimeRange({from: 'now-7d', to: moment([2014,10,10,2,3,4])});
  44. expect(text).to.be('7 days ago to Nov 10, 2014 02:03:04')
  45. });
  46. it('Date range with non matching default ranges', () => {
  47. var text = rangeUtil.describeTimeRange({from: 'now-13h', to: 'now'});
  48. expect(text).to.be('Last 13 hours')
  49. });
  50. });
  51. });