mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
* test url formatter Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Matthew Kime <matt@mattki.me>
This commit is contained in:
parent
2797f7753a
commit
7e8eed447a
2 changed files with 20 additions and 4 deletions
|
@ -70,6 +70,13 @@ describe('UrlFormat', () => {
|
|||
'<img src="http://elastic.co" alt="A dynamically-specified image located at http://elastic.co" ' +
|
||||
'style="width:auto; height:auto; max-width:none; max-height:none;">'
|
||||
);
|
||||
|
||||
const url2 = new UrlFormat({ type: 'img', width: '123not a number' });
|
||||
|
||||
expect(url2.convert('http://elastic.co', HTML_CONTEXT_TYPE)).toBe(
|
||||
'<img src="http://elastic.co" alt="A dynamically-specified image located at http://elastic.co" ' +
|
||||
'style="width:auto; height:auto; max-width:123px; max-height:none;">'
|
||||
);
|
||||
});
|
||||
|
||||
test('only accepts valid numbers for height', () => {
|
||||
|
@ -79,6 +86,13 @@ describe('UrlFormat', () => {
|
|||
'<img src="http://elastic.co" alt="A dynamically-specified image located at http://elastic.co" ' +
|
||||
'style="width:auto; height:auto; max-width:none; max-height:none;">'
|
||||
);
|
||||
|
||||
const url2 = new UrlFormat({ type: 'img', height: '123not a number' });
|
||||
|
||||
expect(url2.convert('http://elastic.co', HTML_CONTEXT_TYPE)).toBe(
|
||||
'<img src="http://elastic.co" alt="A dynamically-specified image located at http://elastic.co" ' +
|
||||
'style="width:auto; height:auto; max-width:none; max-height:123px;">'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -122,10 +122,12 @@ export class UrlFormat extends FieldFormat {
|
|||
}
|
||||
|
||||
private generateImgHtml(url: string, imageLabel: string): string {
|
||||
const isValidWidth = !isNaN(parseInt(this.param('width'), 10));
|
||||
const isValidHeight = !isNaN(parseInt(this.param('height'), 10));
|
||||
const maxWidth = isValidWidth ? `${this.param('width')}px` : 'none';
|
||||
const maxHeight = isValidHeight ? `${this.param('height')}px` : 'none';
|
||||
const parsedWidth = parseInt(this.param('width'), 10);
|
||||
const parsedHeight = parseInt(this.param('height'), 10);
|
||||
const isValidWidth = !isNaN(parsedWidth);
|
||||
const isValidHeight = !isNaN(parsedHeight);
|
||||
const maxWidth = isValidWidth ? `${parsedWidth}px` : 'none';
|
||||
const maxHeight = isValidHeight ? `${parsedHeight}px` : 'none';
|
||||
|
||||
return `<img src="${url}" alt="${imageLabel}" style="width:auto; height:auto; max-width:${maxWidth}; max-height:${maxHeight};">`;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue