mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* Add angularDeprecationUI feature toggle * Add angular notice in angular panel header * Show angular notice for angular datasources * Show angular notice at the top of the dashboard * Changed Angular deprecation messages * Fix angular deprecation alert displayed for new dashboards * re-generate feature flags * Removed unnecessary changes * Add angular deprecation dashboard notice tests * Add test for angular deprecation panel icon * Update test suite name * Moved isAngularDatasourcePlugin to app/features/plugins/angularDeprecation * Add hasAngularPlugins to DashboardModel * re-generate feature toggles * Fix tests * Fix data source spelling * Fix typing issues * Extract plugin type into a separate function * re-generate feature flags * reportInteraction on angular dashboard notice dismiss * re-generate feature flags * Re-generate feature flags * lint
67 lines
2.3 KiB
TypeScript
67 lines
2.3 KiB
TypeScript
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import React from 'react';
|
|
|
|
import { reportInteraction } from '@grafana/runtime';
|
|
|
|
import { AngularDeprecationNotice } from './AngularDeprecationNotice';
|
|
|
|
jest.mock('@grafana/runtime', () => ({
|
|
...jest.requireActual('@grafana/runtime'),
|
|
reportInteraction: jest.fn(),
|
|
}));
|
|
|
|
function localStorageKey(dsUid: string) {
|
|
return `grafana.angularDeprecation.dashboardNotice.isDismissed.${dsUid}`;
|
|
}
|
|
|
|
describe('AngularDeprecationNotice', () => {
|
|
const noticeText = /This dashboard depends on Angular/i;
|
|
const dsUid = 'abc';
|
|
|
|
afterAll(() => {
|
|
jest.resetAllMocks();
|
|
});
|
|
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
window.localStorage.clear();
|
|
});
|
|
|
|
it('should render', () => {
|
|
render(<AngularDeprecationNotice dashboardUid={dsUid} />);
|
|
expect(screen.getByText(noticeText)).toBeInTheDocument();
|
|
});
|
|
|
|
it('should be dismissable', async () => {
|
|
render(<AngularDeprecationNotice dashboardUid={dsUid} />);
|
|
const closeButton = screen.getByRole('button');
|
|
expect(closeButton).toBeInTheDocument();
|
|
await userEvent.click(closeButton);
|
|
expect(screen.queryByText(noticeText)).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('should persist dismission status in localstorage', async () => {
|
|
render(<AngularDeprecationNotice dashboardUid={dsUid} />);
|
|
expect(window.localStorage.getItem(localStorageKey(dsUid))).toBeNull();
|
|
const closeButton = screen.getByRole('button');
|
|
expect(closeButton).toBeInTheDocument();
|
|
await userEvent.click(closeButton);
|
|
expect(window.localStorage.getItem(localStorageKey(dsUid))).toBe('true');
|
|
});
|
|
|
|
it('should not re-render alert if already dismissed', () => {
|
|
window.localStorage.setItem(localStorageKey(dsUid), 'true');
|
|
render(<AngularDeprecationNotice dashboardUid={dsUid} />);
|
|
expect(screen.queryByText(noticeText)).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('should call reportInteraction when dismissing', async () => {
|
|
render(<AngularDeprecationNotice dashboardUid={dsUid} />);
|
|
const closeButton = screen.getByRole('button');
|
|
expect(closeButton).toBeInTheDocument();
|
|
await userEvent.click(closeButton);
|
|
expect(reportInteraction).toHaveBeenCalledWith('angular_deprecation_notice_dismissed');
|
|
});
|
|
});
|