Saved Queries: Hide save button when user is not an editor (#112585)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { screen } from '@testing-library/react';
|
||||
import { render } from 'test/test-utils';
|
||||
|
||||
import { OrgRole } from '@grafana/data';
|
||||
import { contextSrv } from 'app/core/core';
|
||||
|
||||
import { QueryLibraryContextProviderMock } from '../QueryLibrary/mocks';
|
||||
@@ -10,6 +9,7 @@ import { RichHistoryAddToLibrary } from './RichHistoryAddToLibrary';
|
||||
|
||||
describe('RichHistoryAddToLibrary', () => {
|
||||
it('should render button when save query is enabled', () => {
|
||||
contextSrv.isEditor = true;
|
||||
render(
|
||||
<QueryLibraryContextProviderMock queryLibraryEnabled={true}>
|
||||
<RichHistoryAddToLibrary query={{ refId: 'A' }} />
|
||||
@@ -28,7 +28,7 @@ describe('RichHistoryAddToLibrary', () => {
|
||||
expect(screen.queryByRole('button', { name: /Save query/i })).not.toBeInTheDocument();
|
||||
});
|
||||
it('should not render button when user has Viewer role', () => {
|
||||
contextSrv.user.orgRole = OrgRole.Viewer;
|
||||
contextSrv.isEditor = false;
|
||||
render(
|
||||
<QueryLibraryContextProviderMock queryLibraryEnabled={true}>
|
||||
<RichHistoryAddToLibrary query={{ refId: 'A' }} />
|
||||
|
||||
@@ -31,7 +31,7 @@ export const RichHistoryAddToLibrary = ({ query }: Props) => {
|
||||
|
||||
const buttonLabel = t('explore.rich-history-card.add-to-library', 'Save query');
|
||||
|
||||
if (contextSrv.hasRole('Viewer')) {
|
||||
if (!contextSrv.isEditor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user