[ML] Move the hide() function outside the show() function's scope. (#18900)
The mlChartTooltipService's hide() method was inside the show() method scope. If hide() was called before show() was called for the first time this would result in an error. This could have happened in angular directive's which called hide() on some cleanup action without a previous call to show(). This fix moves the hide() method outside the show() method's scope and adds a unit test to check for the correct structure of mlChartTooltipService.
This commit is contained in:
parent
3c898a58aa
commit
9894355490
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* 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 'expect.js';
|
||||
|
||||
describe('ML - mlChartTooltipService', () => {
|
||||
let mlChartTooltipService;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(() => {
|
||||
ngMock.inject(function ($injector) {
|
||||
mlChartTooltipService = $injector.get('mlChartTooltipService');
|
||||
});
|
||||
});
|
||||
|
||||
it('service API duck typing', () => {
|
||||
expect(mlChartTooltipService).to.be.an('object');
|
||||
expect(mlChartTooltipService.show).to.be.a('function');
|
||||
expect(mlChartTooltipService.hide).to.be.a('function');
|
||||
});
|
||||
|
||||
});
|
|
@ -68,6 +68,7 @@ module.directive('mlChartTooltip', function (mlChartTooltipService) {
|
|||
'display': 'block'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.hide = function () {
|
||||
if (this.element !== null) {
|
||||
|
@ -83,5 +84,4 @@ module.directive('mlChartTooltip', function (mlChartTooltipService) {
|
|||
}, FADE_TIMEOUT_MS);
|
||||
}
|
||||
};
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue