[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:
Walter Rafelsberger 2018-05-08 13:53:22 +02:00 committed by GitHub
parent 3c898a58aa
commit 9894355490
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 13 deletions

View file

@ -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');
});
});

View file

@ -68,20 +68,20 @@ module.directive('mlChartTooltip', function (mlChartTooltipService) {
'display': 'block'
});
}
};
this.hide = function () {
if (this.element !== null) {
this.element.css({
'opacity': '0',
});
this.hide = function () {
if (this.element !== null) {
this.element.css({
'opacity': '0',
});
// after the fade out transition has finished, set the display to
// none so it doesn't block any mouse events underneath it.
this.fadeTimeout = $timeout(() => {
this.element.css('display', 'none');
this.fadeTimeout = null;
}, FADE_TIMEOUT_MS);
}
};
// after the fade out transition has finished, set the display to
// none so it doesn't block any mouse events underneath it.
this.fadeTimeout = $timeout(() => {
this.element.css('display', 'none');
this.fadeTimeout = null;
}, FADE_TIMEOUT_MS);
}
};
});