grafana/public/app/features/logs/components/LogRowMessage.test.tsx
Sven Grossmann 68637059c4
Logs: Add permalink to log lines (#69464)
* create explore panel state for logs

* add props to LogRows and unify

* pass properties from explore to logs

* add css

* implement button and scrolling

* export and use `getUrlStateFromPaneState`

* make `scrollIntoView` optional

* change state handling for permalinks

* change link icon

* removed unused state

* add tests for `LogRowMessage`

* remove unused prop

* fix name

* reorg component

* add `LogRow` tests

* add test for `Logs`

* Update public/app/features/logs/components/LogRow.test.tsx

Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>

* Update public/app/features/explore/Logs/Logs.test.tsx

Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>

* improve types in test

* fix props export in Logs.tsx

* fix props export in LogRowMessage.tsx

* fix props export in LogRow.tsx

* fixed import

* fix theme import

* remove hidden style

* add better test names

* change to `log line` rather logline

Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>

* fix tooltips

* remove unused css

---------

Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
2023-06-16 14:07:51 +02:00

87 lines
2.8 KiB
TypeScript

import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React, { ComponentProps } from 'react';
import { CoreApp, createTheme, LogLevel, LogRowModel } from '@grafana/data';
import { LogRowMessage } from './LogRowMessage';
import { createLogRow } from './__mocks__/logRow';
import { getLogRowStyles } from './getLogRowStyles';
const setup = (propOverrides?: Partial<ComponentProps<typeof LogRowMessage>>, rowOverrides?: Partial<LogRowModel>) => {
const theme = createTheme();
const styles = getLogRowStyles(theme);
const props: ComponentProps<typeof LogRowMessage> = {
wrapLogMessage: false,
row: createLogRow({ entry: 'test123', logLevel: LogLevel.error, timeEpochMs: 1546297200000, ...rowOverrides }),
onOpenContext: () => {},
prettifyLogMessage: false,
app: CoreApp.Explore,
styles,
...(propOverrides || {}),
};
render(
<table>
<tbody>
<tr>
<LogRowMessage {...props} />
</tr>
</tbody>
</table>
);
return props;
};
describe('LogRowMessage', () => {
it('renders row entry', () => {
setup();
expect(screen.queryByText('test123')).toBeInTheDocument();
});
describe('with show context', () => {
it('should show context button', () => {
setup({ showContextToggle: () => true });
expect(screen.queryByLabelText('Show context')).toBeInTheDocument();
});
it('should not show context button', () => {
setup({ showContextToggle: () => false });
expect(screen.queryByLabelText('Show context')).not.toBeInTheDocument();
});
it('should call `onOpenContext` with row on click', async () => {
const showContextToggle = jest.fn();
const props = setup({ showContextToggle: () => true, onOpenContext: showContextToggle });
const button = screen.getByLabelText('Show context');
await userEvent.click(button);
expect(showContextToggle).toHaveBeenCalledWith(props.row);
});
});
describe('with permalinking', () => {
it('should show permalinking button when no `onPermalinkClick` is defined', () => {
setup({ onPermalinkClick: jest.fn() });
expect(screen.queryByLabelText('Copy shortlink')).toBeInTheDocument();
});
it('should not show permalinking button when `onPermalinkClick` is defined', () => {
setup();
expect(screen.queryByLabelText('Copy shortlink')).not.toBeInTheDocument();
});
it('should call `onPermalinkClick` with row on click', async () => {
const permalinkClick = jest.fn();
const props = setup({ onPermalinkClick: permalinkClick });
const button = screen.getByLabelText('Copy shortlink');
await userEvent.click(button);
expect(permalinkClick).toHaveBeenCalledWith(props.row);
});
});
});