Skip to content

Commit

Permalink
PMM-12356 Update unit tests for advisors
Browse files Browse the repository at this point in the history
  • Loading branch information
matejkubinec committed Feb 11, 2025
1 parent b42be4d commit 2fe3ede
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import React from 'react';
import { Provider } from 'react-redux';
import { Router } from 'react-router-dom';

import { NavIndex } from '@grafana/data';
import { locationService } from '@grafana/runtime';
import { NavIndex, OrgRole } from '@grafana/data';
import { config, locationService } from '@grafana/runtime';
import { getRouteComponentProps } from 'app/core/navigation/__mocks__/routeProps';
import { logger } from 'app/percona/shared/helpers/logger';
import { wrapWithGrafanaContextMock } from 'app/percona/shared/helpers/testUtils';
Expand All @@ -29,7 +29,12 @@ jest.mock('app/percona/check/Check.service');
jest.mock('app/percona/shared/services/advisors/Advisors.service.ts');

describe('AllChecksTab::', () => {
beforeEach(() => jest.clearAllMocks());
beforeEach(() => {
jest.clearAllMocks();

config.bootData.user.isGrafanaAdmin = true;
config.bootData.user.orgRole = OrgRole.Admin;
});

it('should render a table in category', async () => {
render(<AllChecksTabTesting />);
Expand Down Expand Up @@ -185,6 +190,17 @@ describe('AllChecksTab::', () => {
expect(runChecksSpy).toBeCalledTimes(1);
});
});

it("editors shouldn't be able to run advisor checks", async () => {
config.bootData.user.isGrafanaAdmin = false;
config.bootData.user.orgRole = OrgRole.Editor;

render(<AllChecksTabTesting />);

const runChecksButton = screen.queryByRole('button', { name: Messages.runDbChecks });

expect(runChecksButton).toBeNull();
});
});

const AllChecksTabTesting = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ import { render, screen } from '@testing-library/react';
import React from 'react';
import { Provider } from 'react-redux';

import { config } from '@grafana/runtime';
import { configureStore } from 'app/store/configureStore';
import { StoreState } from 'app/types';
import { OrgRole, StoreState } from 'app/types';

import { ChecksInfoAlert } from './CheckInfoAlert';
import { Messages } from './CheckInfoAlert.messages';

describe('CheckInfoAlert', () => {
beforeEach(() => {
config.bootData.user.isGrafanaAdmin = true;
config.bootData.user.orgRole = OrgRole.Admin;
});

it('should only show alert when PMM is not connected to portal', async () => {
render(
<Provider
Expand Down Expand Up @@ -40,4 +46,36 @@ describe('CheckInfoAlert', () => {
);
expect(screen.queryByText(Messages.title)).not.toBeInTheDocument();
});

it("shouldn't show alert to viewers", () => {
render(
<Provider
store={configureStore({
percona: {
user: { isAuthorized: true },
settings: { loading: false, result: { isConnectedToPortal: true } },
},
} as StoreState)}
>
<ChecksInfoAlert />
</Provider>
);
expect(screen.queryByText(Messages.title)).not.toBeInTheDocument();
});

it("shouldn't show alert to editors", () => {
render(
<Provider
store={configureStore({
percona: {
user: { isAuthorized: true },
settings: { loading: false, result: { isConnectedToPortal: true } },
},
} as StoreState)}
>
<ChecksInfoAlert />
</Provider>
);
expect(screen.queryByText(Messages.title)).not.toBeInTheDocument();
});
});

0 comments on commit 2fe3ede

Please sign in to comment.