Przeglądaj źródła

Add mocks in test file

Tobias Skarhed 7 lat temu
rodzic
commit
12d158f391

+ 18 - 3
public/app/plugins/datasource/elasticsearch/specs/datasource.jest.ts

@@ -2,7 +2,8 @@ import _ from 'lodash';
 import moment from 'moment';
 import moment from 'moment';
 import angular from 'angular';
 import angular from 'angular';
 import { ElasticDatasource } from '../datasource';
 import { ElasticDatasource } from '../datasource';
-import { jestTimeSrvStub, TemplateSrvStub } from 'test/specs/helpers';
+
+import * as dateMath from 'app/core/utils/datemath';
 
 
 describe('ElasticDatasource', function() {
 describe('ElasticDatasource', function() {
   let backendSrv = {
   let backendSrv = {
@@ -14,9 +15,23 @@ describe('ElasticDatasource', function() {
     appEvent: jest.fn(),
     appEvent: jest.fn(),
   };
   };
 
 
-  let templateSrv = new TemplateSrvStub();
+  let templateSrv = {
+    replace: jest.fn(text => text),
+    getAdhocFilters: jest.fn(() => []),
+  };
 
 
-  let timeSrv = new jestTimeSrvStub();
+  let timeSrv = {
+    time: { from: 'now-1h', to: 'now' },
+    timeRange: jest.fn(parse => {
+      return {
+        from: dateMath.parse(this.time.from, false),
+        to: dateMath.parse(this.time.to, true),
+      };
+    }),
+    setTime: jest.fn(time => {
+      this.time = time;
+    }),
+  };
 
 
   let ctx = <any>{
   let ctx = <any>{
     $rootScope,
     $rootScope,