2018-09-25 09:50:13 -05:00
|
|
|
import React from 'react';
|
|
|
|
import { PluginListPage, Props } from './PluginListPage';
|
2020-10-27 07:08:08 -05:00
|
|
|
import { NavModel, PluginErrorCode, PluginMeta } from '@grafana/data';
|
2020-01-13 01:03:22 -06:00
|
|
|
import { mockToolkitActionCreator } from 'test/core/redux/mocks';
|
2020-04-23 04:52:11 -05:00
|
|
|
import { setPluginsSearchQuery } from './state/reducers';
|
2020-10-27 07:08:08 -05:00
|
|
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
|
|
import { selectors } from '@grafana/e2e-selectors';
|
|
|
|
import { Provider } from 'react-redux';
|
|
|
|
import { configureStore } from '../../store/configureStore';
|
|
|
|
import { afterEach } from '../../../test/lib/common';
|
|
|
|
|
|
|
|
let errorsReturnMock: any = [];
|
|
|
|
|
2021-09-30 01:34:03 -05:00
|
|
|
jest.mock('@grafana/runtime', () => {
|
|
|
|
const original = jest.requireActual('@grafana/runtime');
|
|
|
|
const mockedRuntime = {
|
|
|
|
...original,
|
|
|
|
getBackendSrv: () => ({
|
|
|
|
get: () => {
|
|
|
|
return errorsReturnMock as any;
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
mockedRuntime.config.pluginAdminEnabled = false;
|
|
|
|
|
|
|
|
return mockedRuntime;
|
|
|
|
});
|
2018-09-25 09:50:13 -05:00
|
|
|
|
|
|
|
const setup = (propOverrides?: object) => {
|
2020-10-27 07:08:08 -05:00
|
|
|
const store = configureStore();
|
2018-09-25 09:50:13 -05:00
|
|
|
const props: Props = {
|
2019-01-16 09:29:07 -06:00
|
|
|
navModel: {
|
|
|
|
main: {
|
2019-02-13 04:14:53 -06:00
|
|
|
text: 'Configuration',
|
2019-01-16 09:29:07 -06:00
|
|
|
},
|
|
|
|
node: {
|
2019-02-13 04:14:53 -06:00
|
|
|
text: 'Plugins',
|
|
|
|
},
|
2019-01-16 09:29:07 -06:00
|
|
|
} as NavModel,
|
2019-04-29 11:14:39 -05:00
|
|
|
plugins: [] as PluginMeta[],
|
2018-10-03 02:43:10 -05:00
|
|
|
searchQuery: '',
|
2020-01-13 01:03:22 -06:00
|
|
|
setPluginsSearchQuery: mockToolkitActionCreator(setPluginsSearchQuery),
|
2018-09-25 09:50:13 -05:00
|
|
|
loadPlugins: jest.fn(),
|
2018-10-11 04:49:34 -05:00
|
|
|
hasFetched: false,
|
2018-09-25 09:50:13 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
Object.assign(props, propOverrides);
|
|
|
|
|
2020-10-27 07:08:08 -05:00
|
|
|
return render(
|
|
|
|
<Provider store={store}>
|
|
|
|
<PluginListPage {...props} />
|
|
|
|
</Provider>
|
|
|
|
);
|
2018-09-25 09:50:13 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
describe('Render', () => {
|
2020-10-27 07:08:08 -05:00
|
|
|
afterEach(() => {
|
|
|
|
errorsReturnMock = [];
|
|
|
|
});
|
2018-10-11 04:49:34 -05:00
|
|
|
|
2020-10-27 07:08:08 -05:00
|
|
|
it('should render component', async () => {
|
|
|
|
errorsReturnMock = [];
|
|
|
|
setup();
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(screen.queryByLabelText(selectors.pages.PluginsList.page)).toBeInTheDocument();
|
|
|
|
expect(screen.queryByLabelText(selectors.pages.PluginsList.list)).not.toBeInTheDocument();
|
|
|
|
});
|
2018-10-11 04:49:34 -05:00
|
|
|
});
|
|
|
|
|
2020-10-27 07:08:08 -05:00
|
|
|
it('should render list', async () => {
|
|
|
|
errorsReturnMock = [];
|
|
|
|
setup({
|
2018-10-11 04:49:34 -05:00
|
|
|
hasFetched: true,
|
|
|
|
});
|
2020-10-27 07:08:08 -05:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(screen.queryByLabelText(selectors.pages.PluginsList.list)).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
2018-09-25 09:50:13 -05:00
|
|
|
|
2020-10-27 07:08:08 -05:00
|
|
|
describe('Plugin signature errors', () => {
|
|
|
|
it('should render notice if there are plugins with signing errors', async () => {
|
|
|
|
errorsReturnMock = [{ pluginId: 'invalid-sig', errorCode: PluginErrorCode.invalidSignature }];
|
|
|
|
setup({
|
|
|
|
hasFetched: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
await waitFor(() =>
|
|
|
|
expect(screen.getByLabelText(selectors.pages.PluginsList.signatureErrorNotice)).toBeInTheDocument()
|
|
|
|
);
|
|
|
|
});
|
2018-09-25 09:50:13 -05:00
|
|
|
});
|
|
|
|
});
|