From 74bf80962d395ce2280434bf52ea4a44626f934c Mon Sep 17 00:00:00 2001 From: Tobias Skarhed Date: Wed, 4 Jul 2018 11:16:31 +0200 Subject: [PATCH] Add mock to test files --- .../cloudwatch/specs/datasource.jest.ts | 15 ++++++++++++--- .../datasource/mysql/specs/datasource.jest.ts | 7 ++++--- .../postgres/specs/datasource.jest.ts | 5 +++-- public/test/specs/helpers.ts | 18 ------------------ 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/public/app/plugins/datasource/cloudwatch/specs/datasource.jest.ts b/public/app/plugins/datasource/cloudwatch/specs/datasource.jest.ts index 4e479e6a83e..fbeaaad8e67 100644 --- a/public/app/plugins/datasource/cloudwatch/specs/datasource.jest.ts +++ b/public/app/plugins/datasource/cloudwatch/specs/datasource.jest.ts @@ -1,15 +1,24 @@ import '../datasource'; -//import { describe, beforeEach, it, expect, angularMocks } from 'test/lib/common'; -import { TemplateSrvStub, jestTimeSrvStub } from 'test/specs/helpers'; +import { TemplateSrvStub } from 'test/specs/helpers'; import CloudWatchDatasource from '../datasource'; import 'app/features/dashboard/time_srv'; +import * as dateMath from 'app/core/utils/datemath'; describe('CloudWatchDatasource', function() { let instanceSettings = { jsonData: { defaultRegion: 'us-east-1', access: 'proxy' }, }; let templateSrv = new TemplateSrvStub(); - let timeSrv = new jestTimeSrvStub(); + + let timeSrv = { + time: { from: 'now-1h', to: 'now' }, + timeRange: jest.fn(() => { + return { + from: dateMath.parse(timeSrv.time.from, false), + to: dateMath.parse(timeSrv.time.to, true), + }; + }), + }; let backendSrv = {}; let ctx = { backendSrv, diff --git a/public/app/plugins/datasource/mysql/specs/datasource.jest.ts b/public/app/plugins/datasource/mysql/specs/datasource.jest.ts index 5a97e4b441d..be33f5f8858 100644 --- a/public/app/plugins/datasource/mysql/specs/datasource.jest.ts +++ b/public/app/plugins/datasource/mysql/specs/datasource.jest.ts @@ -1,13 +1,14 @@ -//import { describe, beforeEach, it, expect, angularMocks } from 'test/lib/common'; import moment from 'moment'; -import { TemplateSrvStub } from 'test/specs/helpers'; import { MysqlDatasource } from '../datasource'; import { CustomVariable } from 'app/features/templating/custom_variable'; describe('MySQLDatasource', function() { let instanceSettings = { name: 'mysql' }; let backendSrv = {}; - let templateSrv = new TemplateSrvStub(); + let templateSrv = { + replace: jest.fn(text => text), + }; + let ctx = { backendSrv, }; diff --git a/public/app/plugins/datasource/postgres/specs/datasource.jest.ts b/public/app/plugins/datasource/postgres/specs/datasource.jest.ts index 87e4c348379..107cd76e6c5 100644 --- a/public/app/plugins/datasource/postgres/specs/datasource.jest.ts +++ b/public/app/plugins/datasource/postgres/specs/datasource.jest.ts @@ -1,13 +1,14 @@ import moment from 'moment'; import { PostgresDatasource } from '../datasource'; import { CustomVariable } from 'app/features/templating/custom_variable'; -import { TemplateSrvStub } from 'test/specs/helpers'; describe('PostgreSQLDatasource', function() { let instanceSettings = { name: 'postgresql' }; let backendSrv = {}; - let templateSrv = new TemplateSrvStub(); + let templateSrv = { + replace: jest.fn(text => text), + }; let ctx = { backendSrv, }; diff --git a/public/test/specs/helpers.ts b/public/test/specs/helpers.ts index 811587b2c91..677419f3f75 100644 --- a/public/test/specs/helpers.ts +++ b/public/test/specs/helpers.ts @@ -195,24 +195,6 @@ export function TemplateSrvStub() { }; } -export function jestTimeSrvStub() { - this.init = jest.fn(); - this.time = { from: 'now-1h', to: 'now' }; - this.timeRange = jest.fn(parse => { - if (parse === false) { - return this.time; - } - return { - from: dateMath.parse(this.time.from, false), - to: dateMath.parse(this.time.to, true), - }; - }); - this.replace = jest.fn(target => target); - this.setTime = jest.fn(time => { - this.time = time; - }); -} - var allDeps = { ContextSrvStub, TemplateSrvStub,