index_pattern_specs.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ///<amd-dependency path="../index_pattern" name="IndexPattern"/>
  2. ///<amd-dependency path="test/specs/helpers" name="helpers" />
  3. import {describe, beforeEach, it, sinon, expect} from 'test/lib/common';
  4. import moment = require('moment');
  5. declare var IndexPattern: any;
  6. describe('IndexPattern', function() {
  7. describe('when getting index for today', function() {
  8. it('should return correct index name', function() {
  9. var pattern = new IndexPattern('[asd-]YYYY.MM.DD', 'Daily');
  10. var expected = 'asd-' + moment.utc().format('YYYY.MM.DD');
  11. expect(pattern.getIndexForToday()).to.be(expected);
  12. });
  13. });
  14. describe('when getting index list for time range', function() {
  15. describe('no interval', function() {
  16. it('should return correct index', function() {
  17. var pattern = new IndexPattern('my-metrics');
  18. var from = new Date(2015, 4, 30, 1, 2, 3);
  19. var to = new Date(2015, 5, 1, 12, 5 , 6);
  20. expect(pattern.getIndexList(from, to)).to.eql('my-metrics');
  21. });
  22. });
  23. describe('daily', function() {
  24. it('should return correct index list', function() {
  25. var pattern = new IndexPattern('[asd-]YYYY.MM.DD', 'Daily');
  26. var from = new Date(1432940523000);
  27. var to = new Date(1433153106000);
  28. var expected = [
  29. 'asd-2015.05.29',
  30. 'asd-2015.05.30',
  31. 'asd-2015.05.31',
  32. 'asd-2015.06.01',
  33. ];
  34. expect(pattern.getIndexList(from, to)).to.eql(expected);
  35. });
  36. });
  37. });
  38. });