Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[field formatters] IP should return - on null or undefined #7257

Merged
merged 1 commit into from
May 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/ui/public/stringify/__tests__/_ip.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ import expect from 'expect.js';
import ngMock from 'ng_mock';
import RegistryFieldFormatsProvider from 'ui/registry/field_formats';
describe('IP Address Format', function () {
let fieldFormats;

let ip;
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
fieldFormats = Private(RegistryFieldFormatsProvider);
const fieldFormats = Private(RegistryFieldFormatsProvider);
ip = fieldFormats.getInstance('ip');
}));

it('converts a value from a decimal to a string', function () {
let ip = fieldFormats.getInstance('ip');
expect(ip.convert(1186489492)).to.be('70.184.100.148');
});

it('converts null and undefined to -', function () {
expect(ip.convert(null)).to.be('-');
expect(ip.convert(undefined)).to.be('-');
});

});
1 change: 1 addition & 0 deletions src/ui/public/stringify/types/ip.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default function IpFormatProvider(Private) {
Ip.fieldType = 'ip';

Ip.prototype._convert = function (val) {
if (val === undefined || val === null) return '-';
if (!isFinite(val)) return val;

// shazzam!
Expand Down