mirror of
https://github.com/grafana/grafana.git
synced 2025-09-29 06:34:04 +08:00

* refactor(plugins): use routes specific to the new plugins/admin * refactor(plugins): remove unused pages (PluginList, PluginItem) * refactor(plugins): remove PluginPage * refactor(plugins): remove UpdatePluginModal * refactor(plugins): move AppConfigWrapper under plugins/admin * refactor(plugins): move PluginDashboards under plugins/admin * refactor(plugins): rename the "specs" folder to "tests" * refactor(plugins): move test files to /tests folder * refactor(plugins): move AppRootPage into a /components folder * refactor(plugins): move PluginsErrorsInfo into a /plugins folder * refactor(plugins): move PluginSettingsCache into a /components folder * refactor(plugins): move PluginStateInfo into a /plugins folder * refactor(plugins): move AppRootPage.test.tsx next to the tested component * refactor(plugins): remove old snapshot tests * fix(plugins): fix tests * refactor(plugins/admin): move & rename PluginSettingsCache * fix(plugins): fix a few rebase issues * Plugins: remove deprecated code (state handling) (#41739) * refactor(plugins): use the plugins/admin reducer only * refactor(plugins): remove tests for the deprecated plugins reducer * refactor(plugins): remove tests for the deprecated plugins selectors * refactor(plugins/state): add a short comment note to selectors * feat(plugins/state): add a selector for selecting errors * feat(plugins/state): add a hook for getting plugin errors * refactor(plugins): udpate the PluginsErrorsInfo component to use the new state selectors * refactor(plugins/state): remove the old (deprecated) selectors * refactor(plugins/state): use the new actions under /admin * refactor(plugins/state): remove old (deprecated) reducers and actions * refactor(plugins): update component definition * fix(plugins): remove unnecessary {children} prop for PluginsErrorsInfo * Plugins: show / hide install controls based on the `pluginAdminEnabled` flag (#41749) * docs(plugins): update documentation for the `plugin_admin_enabled` flag * refactor(InstallControls): move the main component to a named module * feat(plugins): use the `pluginAdminEnable` flag to hide / show install controls in the UI * test(plugins): add tests for enabling/disabling install controls
69 lines
1.6 KiB
TypeScript
69 lines
1.6 KiB
TypeScript
// Use the real plugin_loader (stubbed by default)
|
|
jest.unmock('app/features/plugins/plugin_loader');
|
|
|
|
(global as any).ace = {
|
|
define: jest.fn(),
|
|
};
|
|
|
|
jest.mock('app/core/core', () => {
|
|
return {
|
|
coreModule: {
|
|
directive: jest.fn(),
|
|
},
|
|
};
|
|
});
|
|
|
|
import { SystemJS } from '@grafana/runtime';
|
|
import { AppPluginMeta, PluginMetaInfo, PluginType, AppPlugin } from '@grafana/data';
|
|
|
|
// Loaded after the `unmock` abve
|
|
import { importAppPlugin } from '../plugin_loader';
|
|
|
|
class MyCustomApp extends AppPlugin {
|
|
initWasCalled = false;
|
|
calledTwice = false;
|
|
|
|
init(meta: AppPluginMeta) {
|
|
this.initWasCalled = true;
|
|
this.calledTwice = this.meta === meta;
|
|
}
|
|
}
|
|
|
|
describe('Load App', () => {
|
|
const app = new MyCustomApp();
|
|
const modulePath = 'my/custom/plugin/module';
|
|
|
|
beforeAll(() => {
|
|
SystemJS.set(modulePath, SystemJS.newModule({ plugin: app }));
|
|
});
|
|
|
|
afterAll(() => {
|
|
SystemJS.delete(modulePath);
|
|
});
|
|
|
|
it('should call init and set meta', async () => {
|
|
const meta: AppPluginMeta = {
|
|
id: 'test-app',
|
|
module: modulePath,
|
|
baseUrl: 'xxx',
|
|
info: {} as PluginMetaInfo,
|
|
type: PluginType.app,
|
|
name: 'test',
|
|
};
|
|
|
|
// Check that we mocked the import OK
|
|
const m = await SystemJS.import(modulePath);
|
|
expect(m.plugin).toBe(app);
|
|
|
|
const loaded = await importAppPlugin(meta);
|
|
expect(loaded).toBe(app);
|
|
expect(app.meta).toBe(meta);
|
|
expect(app.initWasCalled).toBeTruthy();
|
|
expect(app.calledTwice).toBeFalsy();
|
|
|
|
const again = await importAppPlugin(meta);
|
|
expect(again).toBe(app);
|
|
expect(app.calledTwice).toBeTruthy();
|
|
});
|
|
});
|