mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Playlists: Disable Create Playlist buttons for users with viewer role (#50840)
* Disable / hide buttons for creating playlist for users with viewer role * Update tests * Re-add mock for contextSrv module
This commit is contained in:
parent
fd63ed540f
commit
43839dc40b
@ -1,6 +1,8 @@
|
||||
import { render, waitFor } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
|
||||
import { contextSrv } from 'app/core/services/context_srv';
|
||||
|
||||
import { locationService } from '../../../../packages/grafana-runtime/src';
|
||||
|
||||
import { PlaylistPage, PlaylistPageProps } from './PlaylistPage';
|
||||
@ -56,6 +58,22 @@ describe('PlaylistPage', () => {
|
||||
const { getByText } = getTestContext();
|
||||
await waitFor(() => getByText('There are no playlists created yet'));
|
||||
});
|
||||
describe('and signed in user is not a viewer', () => {
|
||||
it('then create playlist button should not be disabled', async () => {
|
||||
contextSrv.isEditor = true;
|
||||
const { getByRole } = getTestContext();
|
||||
const createPlaylistButton = await waitFor(() => getByRole('link', { name: /create playlist/i }));
|
||||
expect(createPlaylistButton).not.toHaveStyle('pointer-events: none');
|
||||
});
|
||||
});
|
||||
describe('and signed in user is a viewer', () => {
|
||||
it('then create playlist button should be disabled', async () => {
|
||||
contextSrv.isEditor = false;
|
||||
const { getByRole } = getTestContext();
|
||||
const createPlaylistButton = await waitFor(() => getByRole('link', { name: /create playlist/i }));
|
||||
expect(createPlaylistButton).toHaveStyle('pointer-events: none');
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('when mounted with a playlist', () => {
|
||||
it('page should load', () => {
|
||||
@ -75,12 +93,27 @@ describe('PlaylistPage', () => {
|
||||
const { getByText } = getTestContext();
|
||||
expect(getByText(/loading/i)).toBeInTheDocument();
|
||||
});
|
||||
it('then playlist title and buttons should appear on the page', async () => {
|
||||
const { getByRole, getByText } = getTestContext();
|
||||
await waitFor(() => getByText('A test playlist'));
|
||||
expect(getByRole('button', { name: /Start playlist/i })).toBeInTheDocument();
|
||||
expect(getByRole('link', { name: /Edit playlist/i })).toBeInTheDocument();
|
||||
expect(getByRole('button', { name: /Delete playlist/i })).toBeInTheDocument();
|
||||
describe('and signed in user is not a viewer', () => {
|
||||
it('then playlist title and all playlist buttons should appear on the page', async () => {
|
||||
contextSrv.isEditor = true;
|
||||
const { getByRole, getByText } = getTestContext();
|
||||
await waitFor(() => getByText('A test playlist'));
|
||||
expect(getByRole('link', { name: /New playlist/i })).toBeInTheDocument();
|
||||
expect(getByRole('button', { name: /Start playlist/i })).toBeInTheDocument();
|
||||
expect(getByRole('link', { name: /Edit playlist/i })).toBeInTheDocument();
|
||||
expect(getByRole('button', { name: /Delete playlist/i })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
describe('and signed in user is a viewer', () => {
|
||||
it('then playlist title and only start playlist button should appear on the page', async () => {
|
||||
contextSrv.isEditor = false;
|
||||
const { getByRole, getByText, queryByRole } = getTestContext();
|
||||
await waitFor(() => getByText('A test playlist'));
|
||||
expect(queryByRole('link', { name: /New playlist/i })).not.toBeInTheDocument();
|
||||
expect(getByRole('button', { name: /Start playlist/i })).toBeInTheDocument();
|
||||
expect(queryByRole('link', { name: /Edit playlist/i })).not.toBeInTheDocument();
|
||||
expect(queryByRole('button', { name: /Delete playlist/i })).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -7,6 +7,7 @@ import { ConfirmModal } from '@grafana/ui';
|
||||
import Page from 'app/core/components/Page/Page';
|
||||
import PageActionBar from 'app/core/components/PageActionBar/PageActionBar';
|
||||
import { getNavModel } from 'app/core/selectors/navModel';
|
||||
import { contextSrv } from 'app/core/services/context_srv';
|
||||
import { StoreState } from 'app/types';
|
||||
|
||||
import EmptyListCTA from '../../core/components/EmptyListCTA/EmptyListCTA';
|
||||
@ -64,6 +65,7 @@ export const PlaylistPage: FC<PlaylistPageProps> = ({ navModel }) => {
|
||||
buttonIcon="plus"
|
||||
buttonLink="playlists/new"
|
||||
buttonTitle="Create Playlist"
|
||||
buttonDisabled={!contextSrv.isEditor}
|
||||
proTip="You can use playlists to cycle dashboards on TVs without user control"
|
||||
proTipLink="http://docs.grafana.org/reference/playlist/"
|
||||
proTipLinkTitle="Learn more"
|
||||
@ -79,7 +81,7 @@ export const PlaylistPage: FC<PlaylistPageProps> = ({ navModel }) => {
|
||||
{showSearch && (
|
||||
<PageActionBar
|
||||
searchQuery={searchQuery}
|
||||
linkButton={{ title: 'New playlist', href: '/playlists/new' }}
|
||||
linkButton={contextSrv.isEditor && { title: 'New playlist', href: '/playlists/new' }}
|
||||
setSearchQuery={setSearchQuery}
|
||||
/>
|
||||
)}
|
||||
|
Loading…
Reference in New Issue
Block a user