diff --git a/x-pack/plugins/monitoring/public/components/chart/__tests__/get_color.js b/x-pack/plugins/monitoring/public/components/chart/get_color.test.js similarity index 96% rename from x-pack/plugins/monitoring/public/components/chart/__tests__/get_color.js rename to x-pack/plugins/monitoring/public/components/chart/get_color.test.js index 7b70f1d1fb224..1029e6c836225 100644 --- a/x-pack/plugins/monitoring/public/components/chart/__tests__/get_color.js +++ b/x-pack/plugins/monitoring/public/components/chart/get_color.test.js @@ -5,7 +5,7 @@ */ import expect from '@kbn/expect'; -import { getColor } from '../get_color'; +import { getColor } from './get_color'; describe('getColors', function () { it('elasticsearch colors', () => { diff --git a/x-pack/plugins/monitoring/public/components/chart/__tests__/get_last_value.js b/x-pack/plugins/monitoring/public/components/chart/get_last_value.test.js similarity index 96% rename from x-pack/plugins/monitoring/public/components/chart/__tests__/get_last_value.js rename to x-pack/plugins/monitoring/public/components/chart/get_last_value.test.js index c089b47408e81..47e6dad3712a7 100644 --- a/x-pack/plugins/monitoring/public/components/chart/__tests__/get_last_value.js +++ b/x-pack/plugins/monitoring/public/components/chart/get_last_value.test.js @@ -5,7 +5,7 @@ */ import expect from '@kbn/expect'; -import { getLastValue } from '../get_last_value'; +import { getLastValue } from './get_last_value'; describe('monitoringChartGetLastValue', function () { it('getLastValue for single number', () => { diff --git a/x-pack/plugins/monitoring/public/components/chart/__tests__/get_title.js b/x-pack/plugins/monitoring/public/components/chart/get_title.test.js similarity index 94% rename from x-pack/plugins/monitoring/public/components/chart/__tests__/get_title.js rename to x-pack/plugins/monitoring/public/components/chart/get_title.test.js index a7f4b48a5862a..7905089b21b9e 100644 --- a/x-pack/plugins/monitoring/public/components/chart/__tests__/get_title.js +++ b/x-pack/plugins/monitoring/public/components/chart/get_title.test.js @@ -5,7 +5,7 @@ */ import expect from '@kbn/expect'; -import { getTitle } from '../get_title'; +import { getTitle } from './get_title'; describe('getTitle', function () { it('with metric.title', () => { diff --git a/x-pack/plugins/monitoring/public/components/chart/__tests__/get_values_for_legend.js b/x-pack/plugins/monitoring/public/components/chart/get_values_for_legend.test.js similarity index 99% rename from x-pack/plugins/monitoring/public/components/chart/__tests__/get_values_for_legend.js rename to x-pack/plugins/monitoring/public/components/chart/get_values_for_legend.test.js index e5c933426efcd..053f88382d9c0 100644 --- a/x-pack/plugins/monitoring/public/components/chart/__tests__/get_values_for_legend.js +++ b/x-pack/plugins/monitoring/public/components/chart/get_values_for_legend.test.js @@ -6,7 +6,7 @@ import expect from '@kbn/expect'; import sinon from 'sinon'; -import { findIndexByX, getValuesByX, getValuesForSeriesIndex } from '../get_values_for_legend'; +import { findIndexByX, getValuesByX, getValuesForSeriesIndex } from './get_values_for_legend'; describe('monitoringChartHelpers', function () { it('getValuesForSeriesIndex sets does not impact callback without series', () => { diff --git a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/__tests__/config.js b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/config.test.js similarity index 93% rename from x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/__tests__/config.js rename to x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/config.test.js index 83627a8181f38..f1ddd2b933183 100644 --- a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/__tests__/config.js +++ b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/config.test.js @@ -6,8 +6,8 @@ import expect from '@kbn/expect'; import sinon from 'sinon'; -import { Config } from '../config'; -import { Graph } from '../graph'; +import { Config } from './config'; +import { Graph } from './graph'; describe('Config class', () => { let configJson; diff --git a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/boolean_edge.js b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/boolean_edge.test.js similarity index 89% rename from x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/boolean_edge.js rename to x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/boolean_edge.test.js index faf56f48db677..1c20d758242e8 100644 --- a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/boolean_edge.js +++ b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/boolean_edge.test.js @@ -5,8 +5,8 @@ */ import expect from '@kbn/expect'; -import { BooleanEdge } from '../boolean_edge'; -import { Edge } from '../edge'; +import { BooleanEdge } from './boolean_edge'; +import { Edge } from './edge'; describe('BooleanEdge', () => { let graph; diff --git a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/edge.js b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/edge.test.js similarity index 96% rename from x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/edge.js rename to x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/edge.test.js index 8acf0fff7f864..96476aca8cd3b 100644 --- a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/edge.js +++ b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/edge.test.js @@ -5,7 +5,7 @@ */ import expect from '@kbn/expect'; -import { Edge } from '../edge'; +import { Edge } from './edge'; describe('Edge', () => { let graph; diff --git a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/edge_factory.js b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/edge_factory.test.js similarity index 89% rename from x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/edge_factory.js rename to x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/edge_factory.test.js index 80fb22925a38c..80922064122af 100644 --- a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/edge_factory.js +++ b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/edge_factory.test.js @@ -5,9 +5,9 @@ */ import expect from '@kbn/expect'; -import { edgeFactory } from '../edge_factory'; -import { Edge } from '../edge'; -import { BooleanEdge } from '../boolean_edge'; +import { edgeFactory } from './edge_factory'; +import { Edge } from './edge'; +import { BooleanEdge } from './boolean_edge'; describe('edgeFactory', () => { let graph; diff --git a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/if_vertex.js b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/if_vertex.test.js similarity index 93% rename from x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/if_vertex.js rename to x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/if_vertex.test.js index 5a64d12a7f5b0..8bbd8326ddf88 100644 --- a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/if_vertex.js +++ b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/if_vertex.test.js @@ -5,8 +5,8 @@ */ import expect from '@kbn/expect'; -import { IfVertex } from '../if_vertex'; -import { Vertex } from '../vertex'; +import { IfVertex } from './if_vertex'; +import { Vertex } from './vertex'; describe('IfVertex', () => { let graph; diff --git a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/index.js b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/index.test.js similarity index 99% rename from x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/index.js rename to x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/index.test.js index 55d8a0b3e574a..8689d96f1e36a 100644 --- a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/index.js +++ b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/index.test.js @@ -5,10 +5,10 @@ */ import expect from '@kbn/expect'; -import { Graph } from '../'; -import { Vertex } from '../vertex'; -import { PluginVertex } from '../plugin_vertex'; -import { Edge } from '../edge'; +import { Graph } from './'; +import { Vertex } from './vertex'; +import { PluginVertex } from './plugin_vertex'; +import { Edge } from './edge'; describe('Graph', () => { let graphJson; diff --git a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/plugin_vertex.js b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/plugin_vertex.test.js similarity index 98% rename from x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/plugin_vertex.js rename to x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/plugin_vertex.test.js index 3bc8033e283f2..b2931700eb024 100644 --- a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/plugin_vertex.js +++ b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/plugin_vertex.test.js @@ -5,8 +5,8 @@ */ import expect from '@kbn/expect'; -import { Vertex } from '../vertex'; -import { PluginVertex, TIME_CONSUMING_PROCESSOR_THRESHOLD_COEFFICIENT } from '../plugin_vertex'; +import { Vertex } from './vertex'; +import { PluginVertex, TIME_CONSUMING_PROCESSOR_THRESHOLD_COEFFICIENT } from './plugin_vertex'; describe('PluginVertex', () => { let graph; diff --git a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/queue_vertex.js b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/queue_vertex.test.js similarity index 89% rename from x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/queue_vertex.js rename to x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/queue_vertex.test.js index 997306f52cc59..b3b15e6169338 100644 --- a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/queue_vertex.js +++ b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/queue_vertex.test.js @@ -5,8 +5,8 @@ */ import expect from '@kbn/expect'; -import { QueueVertex } from '../queue_vertex'; -import { Vertex } from '../vertex'; +import { QueueVertex } from './queue_vertex'; +import { Vertex } from './vertex'; describe('QueueVertex', () => { let graph; diff --git a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/vertex.js b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/vertex.test.js similarity index 81% rename from x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/vertex.js rename to x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/vertex.test.js index a8761a4c868b1..d54ec354b434b 100644 --- a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/vertex.js +++ b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/vertex.test.js @@ -5,7 +5,7 @@ */ import expect from '@kbn/expect'; -import { Graph } from '../'; +import { Graph } from './'; describe('Vertex', () => { let graph; @@ -205,40 +205,39 @@ describe('Vertex', () => { * \---- v * F5 */ - const complexGraphJson = { - vertices: [ - { id: 'I1', type: 'plugin', explicit_id: false }, - { id: 'my-queue', type: 'queue', config_name: 'some-name' }, - { id: 'IF1', type: 'if', config_name: 'some-name' }, - { - id: 'IF2', - type: 'plugin', - meta: { source_text: 'foobar', source_line: 33, source_column: 4 }, - }, - { id: 'F1', type: 'plugin', explicit_id: true }, - { id: 'F2', type: 'plugin', explicit_id: true }, - { id: 'F3', type: 'plugin', explicit_id: true }, - { id: 'F4', type: 'plugin', explicit_id: true }, - { id: 'F5', type: 'plugin', explicit_id: true }, - ], - edges: [ - { id: '1', type: 'plain', from: 'I1', to: 'my-queue' }, - { id: '2', type: 'plain', from: 'my-queue', to: 'IF1' }, - { id: '3', type: 'boolean', when: true, from: 'IF1', to: 'IF2' }, - { id: '4', type: 'boolean', when: false, from: 'IF1', to: 'F1' }, - { id: '5', type: 'boolean', when: true, from: 'IF2', to: 'F2' }, - { id: '6', type: 'boolean', when: false, from: 'IF2', to: 'F3' }, - { id: '7', type: 'plain', from: 'F2', to: 'F5' }, - { id: '8', type: 'plain', from: 'F3', to: 'F5' }, - { id: '9', type: 'plain', from: 'F1', to: 'F4' }, - { id: '10', type: 'plain', from: 'F4', to: 'F5' }, - ], - }; - - beforeEach(() => { - graph = new Graph(); - graph.update(complexGraphJson); - }); + // const complexGraphJson = { + // vertices: [ + // { id: 'I1', type: 'plugin', explicit_id: false }, + // { id: 'my-queue', type: 'queue', config_name: 'some-name' }, + // { id: 'IF1', type: 'if', config_name: 'some-name' }, + // { + // id: 'IF2', + // type: 'plugin', + // meta: { source_text: 'foobar', source_line: 33, source_column: 4 }, + // }, + // { id: 'F1', type: 'plugin', explicit_id: true }, + // { id: 'F2', type: 'plugin', explicit_id: true }, + // { id: 'F3', type: 'plugin', explicit_id: true }, + // { id: 'F4', type: 'plugin', explicit_id: true }, + // { id: 'F5', type: 'plugin', explicit_id: true }, + // ], + // edges: [ + // { id: '1', type: 'plain', from: 'I1', to: 'my-queue' }, + // { id: '2', type: 'plain', from: 'my-queue', to: 'IF1' }, + // { id: '3', type: 'boolean', when: true, from: 'IF1', to: 'IF2' }, + // { id: '4', type: 'boolean', when: false, from: 'IF1', to: 'F1' }, + // { id: '5', type: 'boolean', when: true, from: 'IF2', to: 'F2' }, + // { id: '6', type: 'boolean', when: false, from: 'IF2', to: 'F3' }, + // { id: '7', type: 'plain', from: 'F2', to: 'F5' }, + // { id: '8', type: 'plain', from: 'F3', to: 'F5' }, + // { id: '9', type: 'plain', from: 'F1', to: 'F4' }, + // { id: '10', type: 'plain', from: 'F4', to: 'F5' }, + // ], + // }; + // beforeEach(() => { + // graph = new Graph(); + // graph.update(complexGraphJson); + // }); }); }); diff --git a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/vertex_factory.js b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/vertex_factory.test.js similarity index 86% rename from x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/vertex_factory.js rename to x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/vertex_factory.test.js index 8fbbd72baeb4b..8f8321846aae4 100644 --- a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/__tests__/vertex_factory.js +++ b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/graph/vertex_factory.test.js @@ -5,10 +5,10 @@ */ import expect from '@kbn/expect'; -import { vertexFactory } from '../vertex_factory'; -import { PluginVertex } from '../plugin_vertex'; -import { IfVertex } from '../if_vertex'; -import { QueueVertex } from '../queue_vertex'; +import { vertexFactory } from './vertex_factory'; +import { PluginVertex } from './plugin_vertex'; +import { IfVertex } from './if_vertex'; +import { QueueVertex } from './queue_vertex'; describe('vertexFactory', () => { let graph; diff --git a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/__tests__/pipeline_state.js b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/pipeline_state.test.js similarity index 92% rename from x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/__tests__/pipeline_state.js rename to x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/pipeline_state.test.js index b47f6b2fa3cee..f2aff4a0413da 100644 --- a/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/__tests__/pipeline_state.js +++ b/x-pack/plugins/monitoring/public/components/logstash/pipeline_viewer/models/pipeline_state.test.js @@ -6,8 +6,8 @@ import expect from '@kbn/expect'; import sinon from 'sinon'; -import { PipelineState } from '../pipeline_state'; -import { Config } from '../config'; +import { PipelineState } from './pipeline_state'; +import { Config } from './config'; describe('PipelineState class', () => { let configJson; diff --git a/x-pack/plugins/monitoring/public/directives/main/__tests__/monitoring_main_controller.js b/x-pack/plugins/monitoring/public/directives/main/monitoring_main_controller.test.js similarity index 93% rename from x-pack/plugins/monitoring/public/directives/main/__tests__/monitoring_main_controller.js rename to x-pack/plugins/monitoring/public/directives/main/monitoring_main_controller.test.js index e2fb2adccb4b9..a12d18425f923 100644 --- a/x-pack/plugins/monitoring/public/directives/main/__tests__/monitoring_main_controller.js +++ b/x-pack/plugins/monitoring/public/directives/main/monitoring_main_controller.test.js @@ -6,12 +6,42 @@ import { noop } from 'lodash'; import expect from '@kbn/expect'; -import { MonitoringMainController } from '../'; +import { Legacy } from '../../legacy_shims'; +import { MonitoringMainController } from './'; const getMockLicenseService = (options) => ({ mlIsSupported: () => options.mlIsSupported }); const getMockBreadcrumbsService = () => noop; // breadcrumb service has its own test describe('Monitoring Main Directive Controller', () => { + const core = { + notifications: {}, + application: {}, + i18n: {}, + chrome: {}, + }; + const data = { + query: { + timefilter: { + timefilter: { + isTimeRangeSelectorEnabled: () => true, + getTime: () => 1, + getRefreshInterval: () => 1, + }, + }, + }, + }; + const isCloud = false; + const triggersActionsUi = {}; + + beforeAll(() => { + Legacy.init({ + core, + data, + isCloud, + triggersActionsUi, + }); + }); + /* * Simulates calling the monitoringMain directive the way Cluster Listing * does: diff --git a/x-pack/plugins/monitoring/public/lib/__tests__/format_number.js b/x-pack/plugins/monitoring/public/lib/format_number.test.js similarity index 96% rename from x-pack/plugins/monitoring/public/lib/__tests__/format_number.js rename to x-pack/plugins/monitoring/public/lib/format_number.test.js index 199eb5298f0be..6f8d4a3d1587c 100644 --- a/x-pack/plugins/monitoring/public/lib/__tests__/format_number.js +++ b/x-pack/plugins/monitoring/public/lib/format_number.test.js @@ -5,7 +5,7 @@ */ import expect from '@kbn/expect'; -import { formatNumber, formatBytesUsage } from '../format_number'; +import { formatNumber, formatBytesUsage } from './format_number'; describe('format_number', () => { describe('formatBytesUsage', () => { diff --git a/x-pack/plugins/monitoring/public/lib/logstash/__tests__/pipelines.js b/x-pack/plugins/monitoring/public/lib/logstash/pipelines.test.js similarity index 93% rename from x-pack/plugins/monitoring/public/lib/logstash/__tests__/pipelines.js rename to x-pack/plugins/monitoring/public/lib/logstash/pipelines.test.js index 3b0b2b629a4ed..183b15dcb8ea6 100644 --- a/x-pack/plugins/monitoring/public/lib/logstash/__tests__/pipelines.js +++ b/x-pack/plugins/monitoring/public/lib/logstash/pipelines.test.js @@ -5,7 +5,7 @@ */ import expect from '@kbn/expect'; -import { isPipelineMonitoringSupportedInVersion } from '../pipelines'; +import { isPipelineMonitoringSupportedInVersion } from './pipelines'; describe('pipelines', () => { describe('isPipelineMonitoringSupportedInVersion', () => { diff --git a/x-pack/plugins/monitoring/public/services/__tests__/executor.js b/x-pack/plugins/monitoring/public/services/__tests__/executor.js deleted file mode 100644 index 802378db2740b..0000000000000 --- a/x-pack/plugins/monitoring/public/services/__tests__/executor.js +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import ngMock from 'ng_mock'; -import expect from '@kbn/expect'; -import sinon from 'sinon'; -import { executorProvider } from '../executor'; -import Bluebird from 'bluebird'; -import { Legacy } from '../../legacy_shims'; -import { dataPluginMock } from '../../../../../../src/plugins/data/public/mocks'; - -describe('$executor service', () => { - let scope; - let executor; - let $timeout; - let timefilter; - - beforeEach(() => { - const data = dataPluginMock.createStartContract(); - Legacy._shims = { timefilter }; - timefilter = data.query.timefilter.timefilter; - }); - - beforeEach(ngMock.module('kibana')); - - beforeEach( - ngMock.inject(function (_$rootScope_) { - scope = _$rootScope_.$new(); - }) - ); - - beforeEach(() => { - $timeout = sinon.spy(setTimeout); - $timeout.cancel = (id) => clearTimeout(id); - - timefilter.setRefreshInterval({ - value: 0, - }); - - executor = executorProvider(Bluebird, $timeout); - }); - - afterEach(() => executor.destroy()); - - it('should not call $timeout if the timefilter is not paused and set to zero', () => { - executor.start(scope); - expect($timeout.callCount).to.equal(0); - }); - - it('should call $timeout if the timefilter is not paused and set to 1000ms', () => { - timefilter.setRefreshInterval({ - pause: false, - value: 1000, - }); - executor.start(scope); - expect($timeout.callCount).to.equal(1); - }); - - it('should execute function if timefilter is not paused and interval set to 1000ms', (done) => { - timefilter.setRefreshInterval({ - pause: false, - value: 1000, - }); - executor.register({ execute: () => Bluebird.resolve().then(() => done(), done) }); - executor.start(scope); - }); - - it('should execute function multiple times', (done) => { - let calls = 0; - timefilter.setRefreshInterval({ - pause: false, - value: 10, - }); - executor.register({ - execute: () => { - if (calls++ > 1) { - done(); - } - return Bluebird.resolve(); - }, - }); - executor.start(scope); - }); - - it('should call handleResponse', (done) => { - timefilter.setRefreshInterval({ - pause: false, - value: 10, - }); - executor.register({ - execute: () => Bluebird.resolve(), - handleResponse: () => done(), - }); - executor.start(scope); - }); - - it('should call handleError', (done) => { - timefilter.setRefreshInterval({ - pause: false, - value: 10, - }); - executor.register({ - execute: () => Bluebird.reject(new Error('reject test')), - handleError: () => done(), - }); - executor.start(scope); - }); -}); diff --git a/x-pack/plugins/monitoring/public/services/__tests__/breadcrumbs.js b/x-pack/plugins/monitoring/public/services/breadcrumbs.test.js similarity index 86% rename from x-pack/plugins/monitoring/public/services/__tests__/breadcrumbs.js rename to x-pack/plugins/monitoring/public/services/breadcrumbs.test.js index d4493d4d39e58..25f8a9e0cd4b1 100644 --- a/x-pack/plugins/monitoring/public/services/__tests__/breadcrumbs.js +++ b/x-pack/plugins/monitoring/public/services/breadcrumbs.test.js @@ -5,10 +5,40 @@ */ import expect from '@kbn/expect'; -import { breadcrumbsProvider } from '../breadcrumbs'; -import { MonitoringMainController } from '../../directives/main'; +import { breadcrumbsProvider } from './breadcrumbs'; +import { MonitoringMainController } from '../directives/main'; +import { Legacy } from '../legacy_shims'; describe('Monitoring Breadcrumbs Service', () => { + const core = { + notifications: {}, + application: {}, + i18n: {}, + chrome: {}, + }; + const data = { + query: { + timefilter: { + timefilter: { + isTimeRangeSelectorEnabled: () => true, + getTime: () => 1, + getRefreshInterval: () => 1, + }, + }, + }, + }; + const isCloud = false; + const triggersActionsUi = {}; + + beforeAll(() => { + Legacy.init({ + core, + data, + isCloud, + triggersActionsUi, + }); + }); + it('in Cluster Alerts', () => { const controller = new MonitoringMainController(); controller.setup({ diff --git a/x-pack/plugins/monitoring/public/views/__tests__/base_controller.js b/x-pack/plugins/monitoring/public/views/__tests__/base_controller.js deleted file mode 100644 index efb66f3e251ac..0000000000000 --- a/x-pack/plugins/monitoring/public/views/__tests__/base_controller.js +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { spy, stub } from 'sinon'; -import expect from '@kbn/expect'; -import { MonitoringViewBaseController } from '../'; -import { Legacy } from '../../legacy_shims'; -import { PromiseWithCancel, Status } from '../../../common/cancel_promise'; -import { dataPluginMock } from '../../../../../../src/plugins/data/public/mocks'; - -/* - * Mostly copied from base_table_controller test, with modifications - */ -describe('MonitoringViewBaseController', function () { - let ctrl; - let $injector; - let $scope; - let opts; - let titleService; - let executorService; - let configService; - let timefilter; - const httpCall = (ms) => new Promise((resolve) => setTimeout(() => resolve(), ms)); - - before(() => { - const data = dataPluginMock.createStartContract(); - Legacy._shims = { timefilter }; - timefilter = data.query.timefilter.timefilter; - titleService = spy(); - executorService = { - register: spy(), - start: spy(), - cancel: spy(), - run: spy(), - }; - configService = { - get: spy(), - }; - - const windowMock = () => { - const events = {}; - const targetEvent = 'popstate'; - return { - removeEventListener: stub(), - addEventListener: (name, handler) => name === targetEvent && (events[name] = handler), - history: { - back: () => events[targetEvent] && events[targetEvent](), - }, - }; - }; - - const injectorGetStub = stub(); - injectorGetStub.withArgs('title').returns(titleService); - injectorGetStub.withArgs('$executor').returns(executorService); - injectorGetStub - .withArgs('localStorage') - .throws('localStorage should not be used by this class'); - injectorGetStub.withArgs('$window').returns(windowMock()); - injectorGetStub.withArgs('config').returns(configService); - $injector = { get: injectorGetStub }; - - $scope = { - cluster: { cluster_uuid: 'foo' }, - $on: stub(), - $apply: stub(), - }; - - opts = { - title: 'testo', - getPageData: () => Promise.resolve({ data: { test: true } }), - $injector, - $scope, - }; - - ctrl = new MonitoringViewBaseController(opts); - }); - - it('show/hide zoom-out button based on interaction', (done) => { - const xaxis = { from: 1562089923880, to: 1562090159676 }; - const timeRange = { xaxis }; - const { zoomInfo } = ctrl; - - ctrl.onBrush(timeRange); - - expect(zoomInfo.showZoomOutBtn()).to.be(true); - - /* - Need to do this async, since we are delaying event adding - */ - setTimeout(() => { - zoomInfo.zoomOutHandler(); - expect(zoomInfo.showZoomOutBtn()).to.be(false); - done(); - }, 15); - }); - - it('creates functions for fetching data', () => { - expect(ctrl.updateData).to.be.a('function'); - expect(ctrl.onBrush).to.be.a('function'); - }); - - it('sets page title', () => { - expect(titleService.calledOnce).to.be(true); - const { args } = titleService.getCall(0); - expect(args).to.eql([{ cluster_uuid: 'foo' }, 'testo']); - }); - - it('starts data poller', () => { - expect(executorService.register.calledOnce).to.be(true); - expect(executorService.start.calledOnce).to.be(true); - }); - - it('does not allow for a new request if one is inflight', (done) => { - let counter = 0; - const opts = { - title: 'testo', - getPageData: (ms) => httpCall(ms), - $injector, - $scope, - }; - - const ctrl = new MonitoringViewBaseController(opts); - ctrl.updateData(30).then(() => ++counter); - ctrl.updateData(60).then(() => { - expect(counter).to.be(0); - done(); - }); - }); - - describe('time filter', () => { - it('enables timepicker and auto refresh #1', () => { - expect(timefilter.isTimeRangeSelectorEnabled()).to.be(true); - expect(timefilter.isAutoRefreshSelectorEnabled()).to.be(true); - }); - - it('enables timepicker and auto refresh #2', () => { - opts = { - ...opts, - options: {}, - }; - ctrl = new MonitoringViewBaseController(opts); - - expect(timefilter.isTimeRangeSelectorEnabled()).to.be(true); - expect(timefilter.isAutoRefreshSelectorEnabled()).to.be(true); - }); - - it('disables timepicker and enables auto refresh', () => { - opts = { - ...opts, - options: { enableTimeFilter: false }, - }; - ctrl = new MonitoringViewBaseController(opts); - - expect(timefilter.isTimeRangeSelectorEnabled()).to.be(false); - expect(timefilter.isAutoRefreshSelectorEnabled()).to.be(true); - }); - - it('enables timepicker and disables auto refresh', () => { - opts = { - ...opts, - options: { enableAutoRefresh: false }, - }; - ctrl = new MonitoringViewBaseController(opts); - - expect(timefilter.isTimeRangeSelectorEnabled()).to.be(true); - expect(timefilter.isAutoRefreshSelectorEnabled()).to.be(false); - }); - - it('disables timepicker and auto refresh', () => { - opts = { - ...opts, - options: { - enableTimeFilter: false, - enableAutoRefresh: false, - }, - }; - ctrl = new MonitoringViewBaseController(opts); - - expect(timefilter.isTimeRangeSelectorEnabled()).to.be(false); - expect(timefilter.isAutoRefreshSelectorEnabled()).to.be(false); - }); - - it('disables timepicker and auto refresh', (done) => { - opts = { - title: 'test', - getPageData: () => httpCall(60), - $injector, - $scope, - }; - - ctrl = new MonitoringViewBaseController({ ...opts }); - ctrl.updateDataPromise = new PromiseWithCancel(httpCall(50)); - - let shouldBeFalse = false; - ctrl.updateDataPromise.promise().then(() => (shouldBeFalse = true)); - - const lastUpdateDataPromise = ctrl.updateDataPromise; - - ctrl.updateData().then(() => { - expect(shouldBeFalse).to.be(false); - expect(lastUpdateDataPromise.status()).to.be(Status.Canceled); - done(); - }); - }); - }); -}); diff --git a/x-pack/plugins/monitoring/public/views/__tests__/base_table_controller.js b/x-pack/plugins/monitoring/public/views/__tests__/base_table_controller.js deleted file mode 100644 index 8d66429349cf4..0000000000000 --- a/x-pack/plugins/monitoring/public/views/__tests__/base_table_controller.js +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { spy, stub } from 'sinon'; -import expect from '@kbn/expect'; -import { MonitoringViewBaseTableController } from '../'; - -describe('MonitoringViewBaseTableController', function () { - let ctrl; - let $injector; - let $scope; - let opts; - let timefilter; - let titleService; - let executorService; - - before(() => { - timefilter = { - enableTimeRangeSelector: spy(), - enableAutoRefreshSelector: spy(), - isTimeRangeSelectorEnabled: () => true, - isAutoRefreshSelectorEnabled: () => true, - }; - titleService = spy(); - executorService = { - register: spy(), - start: spy(), - }; - - const injectorGetStub = stub(); - injectorGetStub.withArgs('title').returns(titleService); - injectorGetStub.withArgs('timefilter').returns(timefilter); - injectorGetStub.withArgs('$executor').returns(executorService); - injectorGetStub.withArgs('localStorage').returns({ - get: stub().returns({ - testoStorageKey: { - pageIndex: 9000, - filterText: 'table-ctrl-testoStorageKey', - sortKey: 'test.testoStorageKey', - sortOrder: -1, - }, - }), - }); - $injector = { get: injectorGetStub }; - - $scope = { - cluster: { cluster_uuid: 'foo' }, - $on: stub(), - }; - - opts = { - title: 'testoTitle', - getPageData: () => Promise.resolve({ data: { test: true } }), - storageKey: 'testoStorageKey', - $injector, - $scope, - }; - - ctrl = new MonitoringViewBaseTableController(opts); - }); - - it('initializes scope data from storage', () => { - expect(ctrl.pageIndex).to.be(9000); - expect(ctrl.filterText).to.be('table-ctrl-testoStorageKey'); - expect(ctrl.sortKey).to.be('test.testoStorageKey'); - expect(ctrl.sortOrder).to.be(-1); - }); - - it('creates functions for event handling and fetching data', () => { - expect(ctrl.onNewState).to.be.a('function'); - expect(ctrl.updateData).to.be.a('function'); - }); - - it('enables timepicker', () => { - expect(timefilter.isTimeRangeSelectorEnabled()).to.be(true); - expect(timefilter.isAutoRefreshSelectorEnabled()).to.be(true); - }); - - it('sets page title', () => { - expect(titleService.calledOnce).to.be(true); - const { args } = titleService.getCall(0); - expect(args).to.eql([{ cluster_uuid: 'foo' }, 'testoTitle']); - }); - - it('starts data poller', () => { - expect(executorService.register.calledOnce).to.be(true); - expect(executorService.start.calledOnce).to.be(true); - }); -});