mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 09:33:34 -06:00
grafana-ui: removed obsolete test that cause jest warnings (#56444)
This commit is contained in:
parent
c5171b84a0
commit
3a76c7aac3
@ -1,130 +0,0 @@
|
|||||||
import { render, screen, within } from '@testing-library/react';
|
|
||||||
import React from 'react';
|
|
||||||
|
|
||||||
import { Field, GrafanaTheme2, LogLevel, LogRowModel, MutableDataFrame } from '@grafana/data';
|
|
||||||
|
|
||||||
import { LogDetails, Props } from './LogDetails';
|
|
||||||
import { createLogRow } from './__mocks__/logRow';
|
|
||||||
|
|
||||||
const setup = (propOverrides?: Partial<Props>, rowOverrides?: Partial<LogRowModel>) => {
|
|
||||||
const props: Props = {
|
|
||||||
theme: {} as GrafanaTheme2,
|
|
||||||
showDuplicates: false,
|
|
||||||
wrapLogMessage: false,
|
|
||||||
row: createLogRow({ logLevel: LogLevel.error, timeEpochMs: 1546297200000, ...rowOverrides }),
|
|
||||||
getRows: () => [],
|
|
||||||
onClickFilterLabel: () => {},
|
|
||||||
onClickFilterOutLabel: () => {},
|
|
||||||
...(propOverrides || {}),
|
|
||||||
};
|
|
||||||
|
|
||||||
render(
|
|
||||||
<table>
|
|
||||||
<tbody>
|
|
||||||
<LogDetails {...props} />
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
describe('LogDetails', () => {
|
|
||||||
describe('when labels are present', () => {
|
|
||||||
it('should render heading', () => {
|
|
||||||
setup(undefined, { labels: { key1: 'label1', key2: 'label2' } });
|
|
||||||
expect(screen.getAllByLabelText('Log labels')).toHaveLength(1);
|
|
||||||
});
|
|
||||||
it('should render labels', () => {
|
|
||||||
setup(undefined, { labels: { key1: 'label1', key2: 'label2' } });
|
|
||||||
expect(screen.getByRole('cell', { name: 'key1' })).toBeInTheDocument();
|
|
||||||
expect(screen.getByRole('cell', { name: 'label1' })).toBeInTheDocument();
|
|
||||||
expect(screen.getByRole('cell', { name: 'key2' })).toBeInTheDocument();
|
|
||||||
expect(screen.getByRole('cell', { name: 'label2' })).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
describe('when log row has error', () => {
|
|
||||||
it('should not render log level border', () => {
|
|
||||||
// Is this a good test case for RTL??
|
|
||||||
setup({ hasError: true }, undefined);
|
|
||||||
expect(screen.getByLabelText('Log level').classList.toString()).not.toContain('logs-row__level');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
describe('when row entry has parsable fields', () => {
|
|
||||||
it('should render heading ', () => {
|
|
||||||
setup(undefined, { entry: 'test=successful' });
|
|
||||||
expect(screen.getAllByTitle('Ad-hoc statistics')).toHaveLength(1);
|
|
||||||
});
|
|
||||||
it('should render detected fields', () => {
|
|
||||||
setup(undefined, { entry: 'test=successful' });
|
|
||||||
expect(screen.getByRole('cell', { name: 'test' })).toBeInTheDocument();
|
|
||||||
expect(screen.getByRole('cell', { name: 'successful' })).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
describe('when row entry have parsable fields and labels are present', () => {
|
|
||||||
it('should render all headings', () => {
|
|
||||||
setup(undefined, { entry: 'test=successful', labels: { key: 'label' } });
|
|
||||||
expect(screen.getAllByLabelText('Log labels')).toHaveLength(1);
|
|
||||||
expect(screen.getAllByLabelText('Detected fields')).toHaveLength(1);
|
|
||||||
});
|
|
||||||
it('should render all labels and detected fields', () => {
|
|
||||||
setup(undefined, { entry: 'test=successful', labels: { key: 'label' } });
|
|
||||||
expect(screen.getByRole('cell', { name: 'key' })).toBeInTheDocument();
|
|
||||||
expect(screen.getByRole('cell', { name: 'label' })).toBeInTheDocument();
|
|
||||||
expect(screen.getByRole('cell', { name: 'test' })).toBeInTheDocument();
|
|
||||||
expect(screen.getByRole('cell', { name: 'successful' })).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
describe('when row entry and labels are not present', () => {
|
|
||||||
it('should render no details available message', () => {
|
|
||||||
setup(undefined, { entry: '' });
|
|
||||||
expect(screen.getByText('No details available')).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
it('should not render headings', () => {
|
|
||||||
setup(undefined, { entry: '' });
|
|
||||||
expect(screen.queryAllByLabelText('Log labels')).toHaveLength(0);
|
|
||||||
expect(screen.queryAllByLabelText('Detected fields')).toHaveLength(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should render fields from dataframe with links', () => {
|
|
||||||
const entry = 'traceId=1234 msg="some message"';
|
|
||||||
const dataFrame = new MutableDataFrame({
|
|
||||||
fields: [
|
|
||||||
{ name: 'entry', values: [entry] },
|
|
||||||
// As we have traceId in message already this will shadow it.
|
|
||||||
{
|
|
||||||
name: 'traceId',
|
|
||||||
values: ['1234'],
|
|
||||||
config: { links: [{ title: 'link', url: 'localhost:3210/${__value.text}' }] },
|
|
||||||
},
|
|
||||||
{ name: 'userId', values: ['5678'] },
|
|
||||||
],
|
|
||||||
});
|
|
||||||
setup(
|
|
||||||
{
|
|
||||||
getFieldLinks: (field: Field, rowIndex: number) => {
|
|
||||||
if (field.config && field.config.links) {
|
|
||||||
return field.config.links.map((link) => {
|
|
||||||
return {
|
|
||||||
href: link.url.replace('${__value.text}', field.values.get(rowIndex)),
|
|
||||||
title: link.title,
|
|
||||||
target: '_blank',
|
|
||||||
origin: field,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ entry, dataFrame, entryFieldIndex: 0, rowIndex: 0 }
|
|
||||||
);
|
|
||||||
expect(screen.getAllByRole('table')).toHaveLength(2);
|
|
||||||
const rowDetailsTable = screen.getAllByRole('table')[1];
|
|
||||||
const rowDetailRows = within(rowDetailsTable).getAllByRole('row');
|
|
||||||
expect(rowDetailRows).toHaveLength(4); // 3 LogDetailsRow + 1 header
|
|
||||||
const traceIdRow = within(rowDetailsTable).getByRole('cell', { name: 'traceId' }).closest('tr');
|
|
||||||
expect(traceIdRow).toBeInTheDocument();
|
|
||||||
const link = within(traceIdRow!).getByRole('link', { name: 'link' });
|
|
||||||
expect(link).toBeInTheDocument();
|
|
||||||
expect(link).toHaveAttribute('href', 'localhost:3210/1234');
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,178 +0,0 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
|
||||||
import React from 'react';
|
|
||||||
|
|
||||||
import { FieldType, LogRowModel, MutableDataFrame, DataQueryResponse } from '@grafana/data';
|
|
||||||
|
|
||||||
import { getRowContexts, LogRowContextProvider, RowContextOptions } from './LogRowContextProvider';
|
|
||||||
import { createLogRow } from './__mocks__/logRow';
|
|
||||||
|
|
||||||
const row = createLogRow({ entry: '4', timeEpochMs: 4 });
|
|
||||||
|
|
||||||
describe('getRowContexts', () => {
|
|
||||||
describe('when called with a DataFrame and results are returned', () => {
|
|
||||||
it('then the result should be in correct format and filtered', async () => {
|
|
||||||
const firstResult = new MutableDataFrame({
|
|
||||||
refId: 'B',
|
|
||||||
fields: [
|
|
||||||
{ name: 'ts', type: FieldType.time, values: [3, 2, 1] },
|
|
||||||
{ name: 'line', type: FieldType.string, values: ['3', '2', '1'], labels: {} },
|
|
||||||
{ name: 'id', type: FieldType.string, values: ['3', '2', '1'], labels: {} },
|
|
||||||
],
|
|
||||||
});
|
|
||||||
const secondResult = new MutableDataFrame({
|
|
||||||
refId: 'B',
|
|
||||||
fields: [
|
|
||||||
{ name: 'ts', type: FieldType.time, values: [6, 5, 4] },
|
|
||||||
{ name: 'line', type: FieldType.string, values: ['6', '5', '4'], labels: {} },
|
|
||||||
{ name: 'id', type: FieldType.string, values: ['6', '5', '4'], labels: {} },
|
|
||||||
],
|
|
||||||
});
|
|
||||||
let called = false;
|
|
||||||
const getRowContextMock = (row: LogRowModel, options?: RowContextOptions): Promise<DataQueryResponse> => {
|
|
||||||
if (!called) {
|
|
||||||
called = true;
|
|
||||||
return Promise.resolve({ data: [firstResult] });
|
|
||||||
}
|
|
||||||
return Promise.resolve({ data: [secondResult] });
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = await getRowContexts(getRowContextMock, row, 10);
|
|
||||||
|
|
||||||
expect(result).toEqual({
|
|
||||||
data: [
|
|
||||||
['3', '2'],
|
|
||||||
['6', '5', '4'],
|
|
||||||
],
|
|
||||||
errors: ['', ''],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('then the result should be in correct format and filtered without uid', async () => {
|
|
||||||
const firstResult = new MutableDataFrame({
|
|
||||||
refId: 'B',
|
|
||||||
fields: [
|
|
||||||
{ name: 'ts', type: FieldType.time, values: [3, 2, 1] },
|
|
||||||
{ name: 'line', type: FieldType.string, values: ['3', '2', '1'], labels: {} },
|
|
||||||
],
|
|
||||||
});
|
|
||||||
const secondResult = new MutableDataFrame({
|
|
||||||
refId: 'B',
|
|
||||||
fields: [
|
|
||||||
{ name: 'ts', type: FieldType.time, values: [6, 5, 4] },
|
|
||||||
{ name: 'line', type: FieldType.string, values: ['6', '5', '4'], labels: {} },
|
|
||||||
],
|
|
||||||
});
|
|
||||||
let called = false;
|
|
||||||
const getRowContextMock = (row: LogRowModel, options?: RowContextOptions): Promise<DataQueryResponse> => {
|
|
||||||
if (!called) {
|
|
||||||
called = true;
|
|
||||||
return Promise.resolve({ data: [firstResult] });
|
|
||||||
}
|
|
||||||
return Promise.resolve({ data: [secondResult] });
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = await getRowContexts(getRowContextMock, row, 10);
|
|
||||||
|
|
||||||
expect(result).toEqual({
|
|
||||||
data: [
|
|
||||||
['3', '2', '1'],
|
|
||||||
['6', '5'],
|
|
||||||
],
|
|
||||||
errors: ['', ''],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when called with a DataFrame and errors occur', () => {
|
|
||||||
it('then the result should be in correct format', async () => {
|
|
||||||
const firstError = new Error('Error 1');
|
|
||||||
const secondError = new Error('Error 2');
|
|
||||||
let called = false;
|
|
||||||
const getRowContextMock = (row: LogRowModel, options?: RowContextOptions): Promise<DataQueryResponse> => {
|
|
||||||
if (!called) {
|
|
||||||
called = true;
|
|
||||||
return Promise.reject(firstError);
|
|
||||||
}
|
|
||||||
return Promise.reject(secondError);
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = await getRowContexts(getRowContextMock, row, 10);
|
|
||||||
|
|
||||||
expect(result).toEqual({ data: [[], []], errors: ['Error 1', 'Error 2'] });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('LogRowContextProvider', () => {
|
|
||||||
describe('when requesting longer context', () => {
|
|
||||||
it('can request more log lines', async () => {
|
|
||||||
const firstResult = new MutableDataFrame({
|
|
||||||
refId: 'B',
|
|
||||||
fields: [
|
|
||||||
{ name: 'ts', type: FieldType.time, values: [10, 9, 8, 7, 6, 5] },
|
|
||||||
{
|
|
||||||
name: 'line',
|
|
||||||
type: FieldType.string,
|
|
||||||
values: ['10', '9', '8', '7', '6', '5'],
|
|
||||||
labels: {},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'id',
|
|
||||||
type: FieldType.string,
|
|
||||||
values: ['10', '9', '8', '7', '6', '5'],
|
|
||||||
labels: {},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
const secondResult = new MutableDataFrame({
|
|
||||||
refId: 'B',
|
|
||||||
fields: [
|
|
||||||
{ name: 'ts', type: FieldType.time, values: [14, 13, 12] },
|
|
||||||
{ name: 'line', type: FieldType.string, values: ['14', '13', '12'], labels: {} },
|
|
||||||
{ name: 'id', type: FieldType.string, values: ['14', '13', '12'], labels: {} },
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
let called = false;
|
|
||||||
const getRowContextMock = (row: LogRowModel, options?: RowContextOptions): Promise<DataQueryResponse> => {
|
|
||||||
if (!called) {
|
|
||||||
called = true;
|
|
||||||
return Promise.resolve({ data: [firstResult] });
|
|
||||||
}
|
|
||||||
return Promise.resolve({ data: [secondResult] });
|
|
||||||
};
|
|
||||||
let updateLimitCalled = false;
|
|
||||||
|
|
||||||
const mockedChildren = jest.fn((mockState) => {
|
|
||||||
const { result, errors, hasMoreContextRows, updateLimit, limit } = mockState;
|
|
||||||
if (!updateLimitCalled && result.before.length === 0) {
|
|
||||||
expect(result).toEqual({ before: [], after: [] });
|
|
||||||
expect(errors).toEqual({ before: undefined, after: undefined });
|
|
||||||
expect(hasMoreContextRows).toEqual({ before: true, after: true });
|
|
||||||
expect(limit).toBe(10);
|
|
||||||
return <div data-testid="mockChild" />;
|
|
||||||
}
|
|
||||||
if (!updateLimitCalled && result.before.length > 0) {
|
|
||||||
expect(result).toEqual({ before: ['10', '9', '8', '7', '6', '5'], after: ['14', '13', '12'] });
|
|
||||||
expect(errors).toEqual({ before: '', after: '' });
|
|
||||||
expect(hasMoreContextRows).toEqual({ before: true, after: true });
|
|
||||||
expect(limit).toBe(10);
|
|
||||||
updateLimit();
|
|
||||||
updateLimitCalled = true;
|
|
||||||
return <div data-testid="mockChild" />;
|
|
||||||
}
|
|
||||||
if (updateLimitCalled && result.before.length > 0 && limit > 10) {
|
|
||||||
expect(limit).toBe(20);
|
|
||||||
}
|
|
||||||
return <div data-testid="mockChild" />;
|
|
||||||
});
|
|
||||||
render(
|
|
||||||
<LogRowContextProvider row={row} getRowContext={getRowContextMock}>
|
|
||||||
{mockedChildren}
|
|
||||||
</LogRowContextProvider>
|
|
||||||
);
|
|
||||||
await screen.findByTestId('mockChild');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,165 +0,0 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
|
||||||
import { range } from 'lodash';
|
|
||||||
import React from 'react';
|
|
||||||
|
|
||||||
import { LogRowModel, LogsDedupStrategy, LogsSortOrder } from '@grafana/data';
|
|
||||||
|
|
||||||
import { LogRows, PREVIEW_LIMIT } from './LogRows';
|
|
||||||
import { createLogRow } from './__mocks__/logRow';
|
|
||||||
|
|
||||||
describe('LogRows', () => {
|
|
||||||
it('renders rows', () => {
|
|
||||||
const rows: LogRowModel[] = [createLogRow({ uid: '1' }), createLogRow({ uid: '2' }), createLogRow({ uid: '3' })];
|
|
||||||
render(
|
|
||||||
<LogRows
|
|
||||||
logRows={rows}
|
|
||||||
dedupStrategy={LogsDedupStrategy.none}
|
|
||||||
showLabels={false}
|
|
||||||
showTime={false}
|
|
||||||
wrapLogMessage={true}
|
|
||||||
prettifyLogMessage={true}
|
|
||||||
timeZone={'utc'}
|
|
||||||
enableLogDetails={true}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(screen.queryAllByRole('row')).toHaveLength(3);
|
|
||||||
expect(screen.queryAllByRole('row').at(0)).toHaveTextContent('log message 1');
|
|
||||||
expect(screen.queryAllByRole('row').at(1)).toHaveTextContent('log message 2');
|
|
||||||
expect(screen.queryAllByRole('row').at(2)).toHaveTextContent('log message 3');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders rows only limited number of rows first', () => {
|
|
||||||
const rows: LogRowModel[] = [createLogRow({ uid: '1' }), createLogRow({ uid: '2' }), createLogRow({ uid: '3' })];
|
|
||||||
jest.useFakeTimers();
|
|
||||||
const { rerender } = render(
|
|
||||||
<LogRows
|
|
||||||
logRows={rows}
|
|
||||||
dedupStrategy={LogsDedupStrategy.none}
|
|
||||||
showLabels={false}
|
|
||||||
showTime={false}
|
|
||||||
wrapLogMessage={true}
|
|
||||||
prettifyLogMessage={true}
|
|
||||||
timeZone={'utc'}
|
|
||||||
previewLimit={1}
|
|
||||||
enableLogDetails={true}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
// There is an extra row with the rows that are rendering
|
|
||||||
expect(screen.queryAllByRole('row')).toHaveLength(2);
|
|
||||||
expect(screen.queryAllByRole('row').at(0)).toHaveTextContent('log message 1');
|
|
||||||
|
|
||||||
jest.runAllTimers();
|
|
||||||
rerender(
|
|
||||||
<LogRows
|
|
||||||
logRows={rows}
|
|
||||||
dedupStrategy={LogsDedupStrategy.none}
|
|
||||||
showLabels={false}
|
|
||||||
showTime={false}
|
|
||||||
wrapLogMessage={true}
|
|
||||||
prettifyLogMessage={true}
|
|
||||||
timeZone={'utc'}
|
|
||||||
previewLimit={1}
|
|
||||||
enableLogDetails={true}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(screen.queryAllByRole('row')).toHaveLength(3);
|
|
||||||
expect(screen.queryAllByRole('row').at(0)).toHaveTextContent('log message 1');
|
|
||||||
expect(screen.queryAllByRole('row').at(1)).toHaveTextContent('log message 2');
|
|
||||||
expect(screen.queryAllByRole('row').at(2)).toHaveTextContent('log message 3');
|
|
||||||
|
|
||||||
jest.useRealTimers();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders deduped rows if supplied', () => {
|
|
||||||
const rows: LogRowModel[] = [createLogRow({ uid: '1' }), createLogRow({ uid: '2' }), createLogRow({ uid: '3' })];
|
|
||||||
const dedupedRows: LogRowModel[] = [createLogRow({ uid: '4' }), createLogRow({ uid: '5' })];
|
|
||||||
render(
|
|
||||||
<LogRows
|
|
||||||
logRows={rows}
|
|
||||||
deduplicatedRows={dedupedRows}
|
|
||||||
dedupStrategy={LogsDedupStrategy.none}
|
|
||||||
showLabels={false}
|
|
||||||
showTime={false}
|
|
||||||
wrapLogMessage={true}
|
|
||||||
prettifyLogMessage={true}
|
|
||||||
timeZone={'utc'}
|
|
||||||
enableLogDetails={true}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
expect(screen.queryAllByRole('row')).toHaveLength(2);
|
|
||||||
expect(screen.queryAllByRole('row').at(0)).toHaveTextContent('log message 4');
|
|
||||||
expect(screen.queryAllByRole('row').at(1)).toHaveTextContent('log message 5');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders with default preview limit', () => {
|
|
||||||
// PREVIEW_LIMIT * 2 is there because otherwise we just render all rows
|
|
||||||
const rows: LogRowModel[] = range(PREVIEW_LIMIT * 2 + 1).map((num) => createLogRow({ uid: num.toString() }));
|
|
||||||
render(
|
|
||||||
<LogRows
|
|
||||||
logRows={rows}
|
|
||||||
dedupStrategy={LogsDedupStrategy.none}
|
|
||||||
showLabels={false}
|
|
||||||
showTime={false}
|
|
||||||
wrapLogMessage={true}
|
|
||||||
prettifyLogMessage={true}
|
|
||||||
timeZone={'utc'}
|
|
||||||
enableLogDetails={true}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
// There is an extra row with the rows that are rendering
|
|
||||||
expect(screen.queryAllByRole('row')).toHaveLength(101);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders asc ordered rows if order and function supplied', () => {
|
|
||||||
const rows: LogRowModel[] = [
|
|
||||||
createLogRow({ uid: '1', timeEpochMs: 1 }),
|
|
||||||
createLogRow({ uid: '3', timeEpochMs: 3 }),
|
|
||||||
createLogRow({ uid: '2', timeEpochMs: 2 }),
|
|
||||||
];
|
|
||||||
render(
|
|
||||||
<LogRows
|
|
||||||
logRows={rows}
|
|
||||||
dedupStrategy={LogsDedupStrategy.none}
|
|
||||||
showLabels={false}
|
|
||||||
showTime={false}
|
|
||||||
wrapLogMessage={true}
|
|
||||||
prettifyLogMessage={true}
|
|
||||||
timeZone={'utc'}
|
|
||||||
logsSortOrder={LogsSortOrder.Ascending}
|
|
||||||
enableLogDetails={true}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(screen.queryAllByRole('row').at(0)).toHaveTextContent('log message 1');
|
|
||||||
expect(screen.queryAllByRole('row').at(1)).toHaveTextContent('log message 2');
|
|
||||||
expect(screen.queryAllByRole('row').at(2)).toHaveTextContent('log message 3');
|
|
||||||
});
|
|
||||||
it('renders desc ordered rows if order and function supplied', () => {
|
|
||||||
const rows: LogRowModel[] = [
|
|
||||||
createLogRow({ uid: '1', timeEpochMs: 1 }),
|
|
||||||
createLogRow({ uid: '3', timeEpochMs: 3 }),
|
|
||||||
createLogRow({ uid: '2', timeEpochMs: 2 }),
|
|
||||||
];
|
|
||||||
render(
|
|
||||||
<LogRows
|
|
||||||
logRows={rows}
|
|
||||||
dedupStrategy={LogsDedupStrategy.none}
|
|
||||||
showLabels={false}
|
|
||||||
showTime={false}
|
|
||||||
wrapLogMessage={true}
|
|
||||||
prettifyLogMessage={true}
|
|
||||||
timeZone={'utc'}
|
|
||||||
logsSortOrder={LogsSortOrder.Descending}
|
|
||||||
enableLogDetails={true}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(screen.queryAllByRole('row').at(0)).toHaveTextContent('log message 3');
|
|
||||||
expect(screen.queryAllByRole('row').at(1)).toHaveTextContent('log message 2');
|
|
||||||
expect(screen.queryAllByRole('row').at(2)).toHaveTextContent('log message 1');
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,27 +0,0 @@
|
|||||||
import { LogLevel, LogRowModel, MutableDataFrame } from '@grafana/data';
|
|
||||||
|
|
||||||
export const createLogRow = (overrides?: Partial<LogRowModel>): LogRowModel => {
|
|
||||||
const uid = overrides?.uid || '1';
|
|
||||||
const timeEpochMs = overrides?.timeEpochMs || 1;
|
|
||||||
const entry = overrides?.entry || `log message ${uid}`;
|
|
||||||
|
|
||||||
return {
|
|
||||||
entryFieldIndex: 0,
|
|
||||||
rowIndex: 0,
|
|
||||||
dataFrame: new MutableDataFrame(),
|
|
||||||
uid,
|
|
||||||
logLevel: LogLevel.info,
|
|
||||||
entry,
|
|
||||||
hasAnsi: false,
|
|
||||||
hasUnescapedContent: false,
|
|
||||||
labels: {},
|
|
||||||
raw: entry,
|
|
||||||
timeFromNow: '',
|
|
||||||
timeEpochMs,
|
|
||||||
timeEpochNs: (timeEpochMs * 1000000).toString(),
|
|
||||||
timeLocal: '',
|
|
||||||
timeUtc: '',
|
|
||||||
searchWords: [],
|
|
||||||
...overrides,
|
|
||||||
};
|
|
||||||
};
|
|
@ -1,168 +0,0 @@
|
|||||||
import { ArrayVector, FieldType, MutableDataFrame } from '@grafana/data';
|
|
||||||
|
|
||||||
import { createLogRow } from './__mocks__/logRow';
|
|
||||||
import { getAllFields } from './logParser';
|
|
||||||
|
|
||||||
describe('getAllFields', () => {
|
|
||||||
it('should filter out field with labels name and other type', () => {
|
|
||||||
const logRow = createLogRow({
|
|
||||||
entryFieldIndex: 10,
|
|
||||||
dataFrame: new MutableDataFrame({
|
|
||||||
refId: 'A',
|
|
||||||
fields: [
|
|
||||||
testStringField,
|
|
||||||
{
|
|
||||||
name: 'labels',
|
|
||||||
type: FieldType.other,
|
|
||||||
config: {},
|
|
||||||
values: new ArrayVector([{ place: 'luna', source: 'data' }]),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const fields = getAllFields(logRow);
|
|
||||||
expect(fields.length).toBe(1);
|
|
||||||
expect(fields.find((field) => field.key === 'labels')).toBe(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not filter out field with labels name and string type', () => {
|
|
||||||
const logRow = createLogRow({
|
|
||||||
entryFieldIndex: 10,
|
|
||||||
dataFrame: new MutableDataFrame({
|
|
||||||
refId: 'A',
|
|
||||||
fields: [
|
|
||||||
testStringField,
|
|
||||||
{
|
|
||||||
name: 'labels',
|
|
||||||
type: FieldType.string,
|
|
||||||
config: {},
|
|
||||||
values: new ArrayVector([{ place: 'luna', source: 'data' }]),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
const fields = getAllFields(logRow);
|
|
||||||
expect(fields.length).toBe(2);
|
|
||||||
expect(fields.find((field) => field.key === 'labels')).not.toBe(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should filter out field with id name', () => {
|
|
||||||
const logRow = createLogRow({
|
|
||||||
entryFieldIndex: 10,
|
|
||||||
dataFrame: new MutableDataFrame({
|
|
||||||
refId: 'A',
|
|
||||||
fields: [
|
|
||||||
testStringField,
|
|
||||||
{
|
|
||||||
name: 'id',
|
|
||||||
type: FieldType.string,
|
|
||||||
config: {},
|
|
||||||
values: new ArrayVector(['1659620138401000000_8b1f7688_']),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const fields = getAllFields(logRow);
|
|
||||||
expect(fields.length).toBe(1);
|
|
||||||
expect(fields.find((field) => field.key === 'id')).toBe(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should filter out entry field which is shown as the log message', () => {
|
|
||||||
const logRow = createLogRow({
|
|
||||||
entryFieldIndex: 3,
|
|
||||||
dataFrame: new MutableDataFrame({
|
|
||||||
refId: 'A',
|
|
||||||
fields: [
|
|
||||||
testStringField,
|
|
||||||
{
|
|
||||||
name: 'labels',
|
|
||||||
type: FieldType.other,
|
|
||||||
config: {},
|
|
||||||
values: new ArrayVector([{ place: 'luna', source: 'data' }]),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Time',
|
|
||||||
type: FieldType.time,
|
|
||||||
config: {},
|
|
||||||
values: new ArrayVector([1659620138401]),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Line',
|
|
||||||
type: FieldType.string,
|
|
||||||
config: {},
|
|
||||||
values: new ArrayVector([
|
|
||||||
'_entry="log text with ANSI \u001b[31mpart of the text\u001b[0m [616951240]" counter=300 float=NaN label=val3 level=info',
|
|
||||||
]),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const fields = getAllFields(logRow);
|
|
||||||
expect(fields.find((field) => field.key === 'Line')).toBe(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should filter out field with config hidden field', () => {
|
|
||||||
const testField = { ...testStringField };
|
|
||||||
testField.config = {
|
|
||||||
custom: {
|
|
||||||
hidden: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const logRow = createLogRow({
|
|
||||||
entryFieldIndex: 10,
|
|
||||||
dataFrame: new MutableDataFrame({
|
|
||||||
refId: 'A',
|
|
||||||
fields: [{ ...testField }],
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const fields = getAllFields(logRow);
|
|
||||||
expect(fields.length).toBe(0);
|
|
||||||
expect(fields.find((field) => field.key === testField.name)).toBe(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should filter out field with null values', () => {
|
|
||||||
const logRow = createLogRow({
|
|
||||||
entryFieldIndex: 10,
|
|
||||||
dataFrame: new MutableDataFrame({
|
|
||||||
refId: 'A',
|
|
||||||
fields: [{ ...testFieldWithNullValue }],
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const fields = getAllFields(logRow);
|
|
||||||
expect(fields.length).toBe(0);
|
|
||||||
expect(fields.find((field) => field.key === testFieldWithNullValue.name)).toBe(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not filter out field with string values', () => {
|
|
||||||
const logRow = createLogRow({
|
|
||||||
entryFieldIndex: 10,
|
|
||||||
dataFrame: new MutableDataFrame({
|
|
||||||
refId: 'A',
|
|
||||||
fields: [{ ...testStringField }],
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const fields = getAllFields(logRow);
|
|
||||||
expect(fields.length).toBe(1);
|
|
||||||
expect(fields.find((field) => field.key === testStringField.name)).not.toBe(undefined);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const testStringField = {
|
|
||||||
name: 'test_field_string',
|
|
||||||
type: FieldType.string,
|
|
||||||
config: {},
|
|
||||||
values: new ArrayVector(['abc']),
|
|
||||||
};
|
|
||||||
|
|
||||||
const testFieldWithNullValue = {
|
|
||||||
name: 'test_field_null',
|
|
||||||
type: FieldType.string,
|
|
||||||
config: {},
|
|
||||||
values: new ArrayVector([null]),
|
|
||||||
};
|
|
Loading…
Reference in New Issue
Block a user