index_pattern.test.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. ///<amd-dependency path="test/specs/helpers" name="helpers" />
  2. import moment from 'moment';
  3. import { IndexPattern } from '../index_pattern';
  4. describe('IndexPattern', () => {
  5. describe('when getting index for today', () => {
  6. test('should return correct index name', () => {
  7. const pattern = new IndexPattern('[asd-]YYYY.MM.DD', 'Daily');
  8. const expected = 'asd-' + moment.utc().format('YYYY.MM.DD');
  9. expect(pattern.getIndexForToday()).toBe(expected);
  10. });
  11. });
  12. describe('when getting index list for time range', () => {
  13. describe('no interval', () => {
  14. test('should return correct index', () => {
  15. const pattern = new IndexPattern('my-metrics', null);
  16. const from = new Date(2015, 4, 30, 1, 2, 3);
  17. const to = new Date(2015, 5, 1, 12, 5, 6);
  18. expect(pattern.getIndexList(from, to)).toEqual('my-metrics');
  19. });
  20. });
  21. describe('daily', () => {
  22. test('should return correct index list', () => {
  23. const pattern = new IndexPattern('[asd-]YYYY.MM.DD', 'Daily');
  24. const from = new Date(1432940523000);
  25. const to = new Date(1433153106000);
  26. const expected = ['asd-2015.05.29', 'asd-2015.05.30', 'asd-2015.05.31', 'asd-2015.06.01'];
  27. expect(pattern.getIndexList(from, to)).toEqual(expected);
  28. });
  29. });
  30. });
  31. });