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/features/alerting/unified/components/mute-timings/MuteTimingsTable.test.tsx

61 lines
2.2 KiB

import { render, waitFor, screen } from '@testing-library/react';
import { Provider } from 'react-redux';
import { Router } from 'react-router-dom';
import { locationService } from '@grafana/runtime';
import { configureStore } from 'app/store/configureStore';
import { AccessControlAction } from 'app/types';
import { grantUserPermissions } from '../../mocks';
import { AlertmanagerProvider } from '../../state/AlertmanagerContext';
import { GRAFANA_DATASOURCE_NAME } from '../../utils/datasource';
import { MuteTimingsTable } from './MuteTimingsTable';
jest.mock('app/types', () => ({
...jest.requireActual('app/types'),
useDispatch: () => jest.fn(),
}));
const renderWithProvider = (alertManagerSource?: string) => {
const store = configureStore();
return render(
<Provider store={store}>
<Router history={locationService.getHistory()}>
<AlertmanagerProvider accessType={'notification'} alertmanagerSourceName={alertManagerSource}>
<MuteTimingsTable alertManagerSourceName={alertManagerSource ?? GRAFANA_DATASOURCE_NAME} />
</AlertmanagerProvider>
</Router>
</Provider>
);
};
describe('MuteTimingsTable', () => {
it(' shows export button when allowed and supported', async () => {
grantUserPermissions([
AccessControlAction.AlertingNotificationsRead,
AccessControlAction.AlertingNotificationsWrite,
]);
renderWithProvider();
expect(await screen.findByRole('button', { name: /export all/i })).toBeInTheDocument();
});
it('It does not show export button when not allowed ', async () => {
// when not allowed
grantUserPermissions([]);
renderWithProvider();
await waitFor(() => {
expect(screen.queryByRole('button', { name: /export all/i })).not.toBeInTheDocument();
});
});
it('It does not show export button when not supported ', async () => {
// when not supported
grantUserPermissions([
AccessControlAction.AlertingNotificationsRead,
AccessControlAction.AlertingNotificationsWrite,
]);
renderWithProvider('potato');
await waitFor(() => {
expect(screen.queryByRole('button', { name: /export all/i })).not.toBeInTheDocument();
});
});
});