annotation_query_specs.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import "../datasource";
  2. import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common';
  3. import moment from 'moment';
  4. import helpers from 'test/specs/helpers';
  5. import {CloudWatchDatasource} from "../datasource";
  6. import CloudWatchAnnotationQuery from '../annotation_query';
  7. describe('CloudWatchAnnotationQuery', function() {
  8. var ctx = new helpers.ServiceTestContext();
  9. var instanceSettings = {
  10. jsonData: {defaultRegion: 'us-east-1', access: 'proxy'},
  11. };
  12. beforeEach(angularMocks.module('grafana.core'));
  13. beforeEach(angularMocks.module('grafana.services'));
  14. beforeEach(angularMocks.module('grafana.controllers'));
  15. beforeEach(ctx.providePhase(['templateSrv', 'backendSrv']));
  16. beforeEach(angularMocks.inject(function($q, $rootScope, $httpBackend, $injector) {
  17. ctx.$q = $q;
  18. ctx.$httpBackend = $httpBackend;
  19. ctx.$rootScope = $rootScope;
  20. ctx.ds = $injector.instantiate(CloudWatchDatasource, {instanceSettings: instanceSettings});
  21. }));
  22. describe('When performing annotationQuery', function() {
  23. var parameter = {
  24. annotation: {
  25. region: 'us-east-1',
  26. namespace: 'AWS/EC2',
  27. metricName: 'CPUUtilization',
  28. dimensions: {
  29. InstanceId: 'i-12345678'
  30. },
  31. statistics: ['Average'],
  32. period: 300
  33. },
  34. range: {
  35. from: moment(1443438674760),
  36. to: moment(1443460274760)
  37. }
  38. };
  39. var alarmResponse = {
  40. MetricAlarms: [
  41. {
  42. AlarmName: 'test_alarm_name'
  43. }
  44. ]
  45. };
  46. var historyResponse = {
  47. AlarmHistoryItems: [
  48. {
  49. Timestamp: '2015-01-01T00:00:00.000Z',
  50. HistoryItemType: 'StateUpdate',
  51. AlarmName: 'test_alarm_name',
  52. HistoryData: '{}',
  53. HistorySummary: 'test_history_summary'
  54. }
  55. ]
  56. };
  57. beforeEach(function() {
  58. ctx.backendSrv.datasourceRequest = function(params) {
  59. switch (params.data.action) {
  60. case 'DescribeAlarmsForMetric':
  61. return ctx.$q.when({data: alarmResponse});
  62. case 'DescribeAlarmHistory':
  63. return ctx.$q.when({data: historyResponse});
  64. }
  65. };
  66. });
  67. it('should return annotation list', function(done) {
  68. var annotationQuery = new CloudWatchAnnotationQuery(ctx.ds, parameter.annotation, ctx.$q, ctx.templateSrv);
  69. annotationQuery.process(parameter.range.from, parameter.range.to).then(function(result) {
  70. expect(result[0].title).to.be('test_alarm_name');
  71. expect(result[0].text).to.be('test_history_summary');
  72. done();
  73. });
  74. ctx.$rootScope.$apply();
  75. });
  76. });
  77. });