Files
grafana/public/app/features/logs/components/log-context/LogContextButtons.test.tsx
Sven Grossmann a6a7cebbe5 Logs: Redesign and improve LogContext (#65939)
* Logs: Add new LogRowContext types to grafana/data

* use right type for `RowContextOptions`

* add missing renames

* add show context modal

* no need to call

* removed unused css

* sort properties

* rename

* use correct

* use

* add tests for

* wip

* remove add/minus buttons

* add tests

* disable processing of context results in Loki

* moved into table to align properly

* remove imports

* add highlighting of opened logline

* improve scrolling behavior

* correct style for the table

* use correct query direction

* fix text

* use LoadingBar

* use overflow auto

* rename `onToggleContext` to `onOpenContext`

* add missing import

* mock scrollIntoView

* update unused props

* remove unused import

* no need to process context dataframes

* only show `LogRowContextModal` if `getRowContext` is defined

* remove unused param

* use `userEvent` rather `fireEvent`

* change to `TimeZone`

* directly use style classes

* revert change to public_dashboard_service_mock.go

* improved styling

* add missing await in test

* fix lint

* fix lint

* remove LogRow scrolling when context is opened

* remove references to `scrollElement`

* Update public/app/features/logs/components/log-context/LogRowContextModal.tsx

Co-authored-by: Matias Chomicki <matyax@gmail.com>

* fix lint

* add comment explaining `onCloseContext`

* add comment about debounced onClose

* add comments and remove `showRowMenu`

* scroll twice to correctly center the element

* revert double scrolling

* remove unnecessary `processDataFrame`

* trigger drone

---------

Co-authored-by: Matias Chomicki <matyax@gmail.com>
2023-04-14 17:05:43 +02:00

48 lines
1.6 KiB
TypeScript

import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { SelectableValue } from '@grafana/data';
import { LogContextButtons, LoadMoreOptions } from './LogContextButtons';
describe('LogContextButtons', () => {
const onChangeOption = jest.fn();
const option: SelectableValue<number> = { label: '10 lines', value: 10 };
const position: 'top' | 'bottom' = 'bottom';
beforeEach(() => {
render(<LogContextButtons option={option} onChangeOption={onChangeOption} position={position} />);
});
it('should render a ButtonGroup with one button', () => {
const buttons = screen.getAllByRole('button');
expect(buttons.length).toBe(1);
});
it('should render a ButtonSelect with LoadMoreOptions', async () => {
const tenLinesButton = screen.getByRole('button', {
name: /10 lines/i,
});
await userEvent.click(tenLinesButton);
const options = screen.getAllByRole('menuitemradio');
expect(options.length).toBe(LoadMoreOptions.length);
options.forEach((optionEl, index) => {
expect(optionEl).toHaveTextContent(LoadMoreOptions[index].label!);
});
});
it('should call onChangeOption when an option is selected', async () => {
const tenLinesButton = screen.getByRole('button', {
name: /10 lines/i,
});
await userEvent.click(tenLinesButton);
const twentyLinesButton = screen.getByRole('menuitemradio', {
name: /20 lines/i,
});
await userEvent.click(twentyLinesButton);
const newOption = { label: '20 lines', value: 20 };
expect(onChangeOption).toHaveBeenCalledWith(newOption);
});
});