rangeutil_specs.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 non matching default ranges', () => {
  35. var text = rangeUtil.describeTimeRange({from: 'now-13h', to: 'now'});
  36. expect(text).to.be('Last 13 hours')
  37. });
  38. });
  39. });