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/GraphPeriod.test.tsx

39 lines
1.2 KiB

import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { select } from 'react-select-event';
import { GraphPeriod, Props } from './GraphPeriod';
const props: Props = {
onChange: jest.fn(),
refId: 'A',
variableOptionGroup: { options: [] },
};
describe('Graph Period', () => {
it('should enable graph_period by default', () => {
render(<GraphPeriod {...props} />);
expect(screen.getByLabelText('Graph period')).not.toBeDisabled();
});
it('should disable graph_period when toggled', async () => {
const onChange = jest.fn();
render(<GraphPeriod {...props} onChange={onChange} />);
const s = screen.getByTestId('A-switch-graph-period');
await userEvent.click(s);
expect(onChange).toHaveBeenCalledWith('disabled');
});
it('should set a different value when selected', async () => {
const onChange = jest.fn();
render(<GraphPeriod {...props} onChange={onChange} />);
const selectEl = screen.getByLabelText('Graph period');
expect(selectEl).toBeInTheDocument();
await select(selectEl, '1m', {
container: document.body,
});
expect(onChange).toHaveBeenCalledWith('1m');
});
});