mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 10:03:33 -06:00
* logs: added a copy of the grafana-ui logs-files * fix: added the ansicolor package to the main grafana package * logs-components: import things from grafana-ui * import from local files * logs-components: other fixes * add betterer-exceptions * apply updates from grafana-ui package
46 lines
2.0 KiB
TypeScript
46 lines
2.0 KiB
TypeScript
import { render, screen, within } from '@testing-library/react';
|
|
import React from 'react';
|
|
|
|
import { createTheme } from '@grafana/data';
|
|
|
|
import { UnThemedLogMessageAnsi as LogMessageAnsi } from './LogMessageAnsi';
|
|
|
|
describe('<LogMessageAnsi />', () => {
|
|
it('renders string without ANSI codes', () => {
|
|
render(<LogMessageAnsi value="Lorem ipsum" theme={createTheme()} />);
|
|
|
|
expect(screen.queryByTestId('ansiLogLine')).not.toBeInTheDocument();
|
|
expect(screen.queryByText('Lorem ipsum')).toBeInTheDocument();
|
|
});
|
|
it('renders string with ANSI codes', () => {
|
|
const value = 'Lorem \u001B[31mipsum\u001B[0m et dolor';
|
|
render(<LogMessageAnsi value={value} theme={createTheme()} />);
|
|
|
|
expect(screen.queryByTestId('ansiLogLine')).toBeInTheDocument();
|
|
expect(screen.getAllByTestId('ansiLogLine')).toHaveLength(1);
|
|
expect(screen.getAllByTestId('ansiLogLine').at(0)).toHaveAttribute('style', expect.stringMatching('color'));
|
|
|
|
const { getByText } = within(screen.getAllByTestId('ansiLogLine').at(0)!);
|
|
expect(getByText('ipsum')).toBeInTheDocument();
|
|
});
|
|
it('renders string with ANSI codes with correctly converted css classnames', () => {
|
|
const value = 'Lorem \u001B[1;32mIpsum';
|
|
render(<LogMessageAnsi value={value} theme={createTheme()} />);
|
|
|
|
expect(screen.queryByTestId('ansiLogLine')).toBeInTheDocument();
|
|
expect(screen.getAllByTestId('ansiLogLine')).toHaveLength(1);
|
|
|
|
expect(screen.getAllByTestId('ansiLogLine').at(0)).toHaveAttribute('style', expect.stringMatching('font-weight'));
|
|
});
|
|
it('renders string with ANSI dim code with appropriate themed color', () => {
|
|
const value = 'Lorem \u001B[1;2mIpsum';
|
|
const theme = createTheme();
|
|
render(<LogMessageAnsi value={value} theme={createTheme()} />);
|
|
|
|
expect(screen.queryByTestId('ansiLogLine')).toBeInTheDocument();
|
|
expect(screen.getAllByTestId('ansiLogLine')).toHaveLength(1);
|
|
|
|
expect(screen.getAllByTestId('ansiLogLine').at(0)).toHaveStyle({ color: theme.colors.text.secondary });
|
|
});
|
|
});
|