The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/plugins/datasource/cloud-monitoring/components/GroupBy.test.tsx

43 lines
1.4 KiB

import { render, screen } from '@testing-library/react';
import React from 'react';
import { openMenu, select } from 'react-select-event';
import { createMockTimeSeriesList } from '../__mocks__/cloudMonitoringQuery';
import { MetricDescriptor } from '../types/types';
import { GroupBy, Props } from './GroupBy';
const props: Props = {
onChange: jest.fn(),
refId: 'refId',
metricDescriptor: {
valueType: '',
metricKind: '',
} as unknown as MetricDescriptor,
variableOptionGroup: { options: [] },
labels: [],
query: createMockTimeSeriesList(),
};
describe('GroupBy', () => {
it('renders group by fields', () => {
render(<GroupBy {...props} />);
expect(screen.getByLabelText('Group by')).toBeInTheDocument();
expect(screen.getByLabelText('Group by function')).toBeInTheDocument();
});
it('can select a group by', async () => {
const onChange = jest.fn();
render(<GroupBy {...props} onChange={onChange} />);
const groupBy = screen.getByLabelText('Group by');
const option = 'metadata.system_labels.cloud_account';
expect(screen.queryByText(option)).not.toBeInTheDocument();
await openMenu(groupBy);
expect(screen.getByText(option)).toBeInTheDocument();
await select(groupBy, option, { container: document.body });
expect(onChange).toBeCalledWith(expect.objectContaining({ groupBys: expect.arrayContaining([option]) }));
});
});