mirror of
https://github.com/grafana/grafana.git
synced 2025-09-19 23:14:25 +08:00

Co-authored-by: Ivan Ortega <ivanortegaalba@gmail.com> Co-authored-by: Josh Hunt <joshhunt@users.noreply.github.com> Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com> Co-authored-by: polinaboneva <polina.boneva@grafana.com>
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import React from 'react';
|
|
|
|
import { logInfo } from '@grafana/runtime';
|
|
import { PanelModel } from 'app/features/dashboard/state';
|
|
import { createDashboardModelFixture } from 'app/features/dashboard/state/__fixtures__/dashboardFixtures';
|
|
|
|
import { LogMessages } from '../../Analytics';
|
|
|
|
import { NewRuleFromPanelButton } from './NewRuleFromPanelButton';
|
|
|
|
jest.mock('app/types', () => {
|
|
const original = jest.requireActual('app/types');
|
|
return {
|
|
...original,
|
|
useSelector: jest.fn(),
|
|
};
|
|
});
|
|
|
|
jest.mock('react-router-dom', () => ({
|
|
useLocation: () => ({
|
|
pathname: 'localhost:3000/example/path',
|
|
}),
|
|
}));
|
|
|
|
jest.mock('@grafana/runtime', () => {
|
|
const original = jest.requireActual('@grafana/runtime');
|
|
return {
|
|
...original,
|
|
logInfo: jest.fn(),
|
|
};
|
|
});
|
|
|
|
jest.mock('react-use', () => ({
|
|
useAsync: () => ({ loading: false, value: {} }),
|
|
}));
|
|
|
|
describe('Analytics', () => {
|
|
it('Sends log info when creating an alert rule from a panel', async () => {
|
|
const panel = new PanelModel({
|
|
id: 123,
|
|
});
|
|
const dashboard = createDashboardModelFixture({
|
|
id: 1,
|
|
});
|
|
render(<NewRuleFromPanelButton panel={panel} dashboard={dashboard} />);
|
|
|
|
const button = screen.getByText('Create alert rule from this panel');
|
|
|
|
button.addEventListener('click', (event) => event.preventDefault(), false);
|
|
|
|
await userEvent.click(button);
|
|
|
|
expect(logInfo).toHaveBeenCalledWith(LogMessages.alertRuleFromPanel);
|
|
});
|
|
});
|