diff --git a/src/ui/public/stringify/__tests__/_color.js b/src/ui/public/stringify/__tests__/_color.js index f48823ea3d5e1..98686bacc3148 100644 --- a/src/ui/public/stringify/__tests__/_color.js +++ b/src/ui/public/stringify/__tests__/_color.js @@ -9,31 +9,58 @@ describe('Color Format', function () { beforeEach(ngMock.inject(function (Private) { fieldFormats = Private(RegistryFieldFormatsProvider); ColorFormat = fieldFormats.getType('color'); - })); - it('should add colors if the value is in range', function () { - let colorer = new ColorFormat({ - colors: [{ - range: '100:150', - text: 'blue', - background: 'yellow' - }] + context('field is a number', () => { + it('should add colors if the value is in range', function () { + let colorer = new ColorFormat({ + fieldType: 'number', + colors: [{ + range: '100:150', + text: 'blue', + background: 'yellow' + }] + }); + expect(colorer.convert(99, 'html')).to.eql('99'); + expect(colorer.convert(100, 'html')).to.eql('100'); + expect(colorer.convert(150, 'html')).to.eql('150'); + expect(colorer.convert(151, 'html')).to.eql('151'); + }); + + it('should not convert invalid ranges', function () { + let colorer = new ColorFormat({ + fieldType: 'number', + colors: [{ + range: '100150', + text: 'blue', + background: 'yellow' + }] + }); + expect(colorer.convert(99, 'html')).to.eql('99'); }); - expect(colorer.convert(99, 'html')).to.eql('99'); - expect(colorer.convert(100, 'html')).to.eql('100'); - expect(colorer.convert(150, 'html')).to.eql('150'); - expect(colorer.convert(151, 'html')).to.eql('151'); }); - it('should not convert invalid ranges', function () { - let colorer = new ColorFormat({ - colors: [{ - range: '100150', - text: 'blue', - background: 'yellow' - }] + context('field is a string', () => { + it('should add colors if the regex matches', function () { + let colorer = new ColorFormat({ + fieldType: 'string', + colors: [{ + regex: 'A.*', + text: 'blue', + background: 'yellow' + }] + }); + + let converter = colorer.getConverterFor('html'); + expect(converter('B', 'html')).to.eql('B'); + expect(converter('AAA', 'html')).to.eql('AAA'); + expect(converter('AB', 'html')).to.eql('AB'); + expect(converter('a', 'html')).to.eql('a'); + + expect(converter('B', 'html')).to.eql('B'); + expect(converter('AAA', 'html')).to.eql('AAA'); + expect(converter('AB', 'html')).to.eql('AB'); + expect(converter('a', 'html')).to.eql('a'); }); - expect(colorer.convert(99, 'html')).to.eql('99'); }); }); diff --git a/src/ui/public/stringify/editors/color.html b/src/ui/public/stringify/editors/color.html index a01a2ea665339..23ab3bd92fb02 100644 --- a/src/ui/public/stringify/editors/color.html +++ b/src/ui/public/stringify/editors/color.html @@ -4,16 +4,18 @@ -