mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fix regex in convertCSSToStyle, add test coverage (#21508)
This commit is contained in:
parent
a35b2ac463
commit
dce4d184a1
@ -33,4 +33,20 @@ describe('<LogMessageAnsi />', () => {
|
|||||||
.text()
|
.text()
|
||||||
).toBe('ipsum');
|
).toBe('ipsum');
|
||||||
});
|
});
|
||||||
|
it('renders string with ANSI codes with correctly converted css classnames', () => {
|
||||||
|
const value = 'Lorem [1;32mIpsum';
|
||||||
|
const wrapper = shallow(<LogMessageAnsi value={value} />);
|
||||||
|
|
||||||
|
expect(wrapper.find('span')).toHaveLength(1);
|
||||||
|
expect(
|
||||||
|
wrapper
|
||||||
|
.find('span')
|
||||||
|
.first()
|
||||||
|
.prop('style')
|
||||||
|
).toMatchObject(
|
||||||
|
expect.objectContaining({
|
||||||
|
fontWeight: expect.any(String),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -15,7 +15,7 @@ function convertCSSToStyle(css: string): Style {
|
|||||||
const match = line.match(/([^:\s]+)\s*:\s*(.+)/);
|
const match = line.match(/([^:\s]+)\s*:\s*(.+)/);
|
||||||
|
|
||||||
if (match && match[1] && match[2]) {
|
if (match && match[1] && match[2]) {
|
||||||
const key = match[1].replace(/-(a-z)/g, (_, character) => character.toUpperCase());
|
const key = match[1].replace(/-([a-z])/g, (_, character) => character.toUpperCase());
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
accumulated[key] = match[2];
|
accumulated[key] = match[2];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user