123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691 |
- import { PluginSignatureStatus, PluginSignatureType, PluginType } from '@grafana/data';
- import { config } from '@grafana/runtime';
- import { getLocalPluginMock, getRemotePluginMock, getCatalogPluginMock } from './__mocks__';
- import {
- mapToCatalogPlugin,
- mapRemoteToCatalog,
- mapLocalToCatalog,
- mergeLocalAndRemote,
- mergeLocalsAndRemotes,
- sortPlugins,
- Sorters,
- isLocalPluginVisible,
- isRemotePluginVisible,
- } from './helpers';
- import { RemotePlugin, LocalPlugin } from './types';
- describe('Plugins/Helpers', () => {
- let remotePlugin: RemotePlugin;
- let localPlugin: LocalPlugin;
- beforeEach(() => {
- remotePlugin = getRemotePluginMock();
- localPlugin = getLocalPluginMock();
- });
- describe('mergeLocalsAndRemotes()', () => {
- const localPlugins = [
- getLocalPluginMock({ id: 'plugin-1' }),
- getLocalPluginMock({ id: 'plugin-2' }),
- getLocalPluginMock({ id: 'plugin-3' }), // only on local
- ];
- const remotePlugins = [
- getRemotePluginMock({ slug: 'plugin-1' }),
- getRemotePluginMock({ slug: 'plugin-2' }),
- getRemotePluginMock({ slug: 'plugin-4' }), // only on remote
- ];
- test('adds all available plugins only once', () => {
- const merged = mergeLocalsAndRemotes(localPlugins, remotePlugins);
- const mergedIds = merged.map(({ id }) => id);
- expect(merged.length).toBe(4);
- expect(mergedIds).toContain('plugin-1');
- expect(mergedIds).toContain('plugin-2');
- expect(mergedIds).toContain('plugin-3');
- expect(mergedIds).toContain('plugin-4');
- });
- test('merges all plugins with their counterpart (if available)', () => {
- const merged = mergeLocalsAndRemotes(localPlugins, remotePlugins);
- const findMerged = (mergedId: string) => merged.find(({ id }) => id === mergedId);
- // Both local & remote counterparts
- expect(findMerged('plugin-1')).toEqual(
- mergeLocalAndRemote(getLocalPluginMock({ id: 'plugin-1' }), getRemotePluginMock({ slug: 'plugin-1' }))
- );
- expect(findMerged('plugin-2')).toEqual(
- mergeLocalAndRemote(getLocalPluginMock({ id: 'plugin-2' }), getRemotePluginMock({ slug: 'plugin-2' }))
- );
- // Only local
- expect(findMerged('plugin-3')).toEqual(mergeLocalAndRemote(getLocalPluginMock({ id: 'plugin-3' })));
- // Only remote
- expect(findMerged('plugin-4')).toEqual(mergeLocalAndRemote(undefined, getRemotePluginMock({ slug: 'plugin-4' })));
- });
- });
- describe('mergeLocalAndRemote()', () => {
- test('merges using mapRemoteToCatalog() if there is only a remote version', () => {
- expect(mergeLocalAndRemote(undefined, remotePlugin)).toEqual(mapRemoteToCatalog(remotePlugin));
- });
- test('merges using mapLocalToCatalog() if there is only a local version', () => {
- expect(mergeLocalAndRemote(localPlugin)).toEqual(mapLocalToCatalog(localPlugin));
- });
- test('merges using mapToCatalogPlugin() if there is both a remote and a local version', () => {
- expect(mergeLocalAndRemote(localPlugin, remotePlugin)).toEqual(mapToCatalogPlugin(localPlugin, remotePlugin));
- });
- });
- describe('mapRemoteToCatalog()', () => {
- test('maps the remote response (GCOM /api/plugins/<id>) to PluginCatalog', () => {
- expect(mapRemoteToCatalog(remotePlugin)).toEqual({
- description: 'Zabbix plugin for Grafana',
- downloads: 33645089,
- hasUpdate: false,
- id: 'alexanderzobnin-zabbix-app',
- info: {
- logos: {
- large: 'https://grafana.com/api/plugins/alexanderzobnin-zabbix-app/versions/4.1.5/logos/large',
- small: 'https://grafana.com/api/plugins/alexanderzobnin-zabbix-app/versions/4.1.5/logos/small',
- },
- },
- error: undefined,
- isCore: false,
- isDev: false,
- isDisabled: false,
- isEnterprise: false,
- isInstalled: false,
- isPublished: true,
- name: 'Zabbix',
- orgName: 'Alexander Zobnin',
- popularity: 0.2111,
- publishedAt: '2016-04-06T20:23:41.000Z',
- signature: 'valid',
- type: 'app',
- updatedAt: '2021-05-18T14:53:01.000Z',
- });
- });
- test('adds the correct signature enum', () => {
- const pluginWithoutSignature = { ...remotePlugin, signatureType: '', versionSignatureType: '' } as RemotePlugin;
- // With only "signatureType" -> valid
- const pluginWithSignature1 = { ...remotePlugin, signatureType: PluginSignatureType.commercial } as RemotePlugin;
- // With only "versionSignatureType" -> valid
- const pluginWithSignature2 = { ...remotePlugin, versionSignatureType: PluginSignatureType.core } as RemotePlugin;
- expect(mapRemoteToCatalog(pluginWithoutSignature).signature).toBe(PluginSignatureStatus.missing);
- expect(mapRemoteToCatalog(pluginWithSignature1).signature).toBe(PluginSignatureStatus.valid);
- expect(mapRemoteToCatalog(pluginWithSignature2).signature).toBe(PluginSignatureStatus.valid);
- });
- test('adds an "isEnterprise" field', () => {
- const enterprisePlugin = { ...remotePlugin, status: 'enterprise' } as RemotePlugin;
- const notEnterprisePlugin = { ...remotePlugin, status: 'unknown' } as RemotePlugin;
- expect(mapRemoteToCatalog(enterprisePlugin).isEnterprise).toBe(true);
- expect(mapRemoteToCatalog(notEnterprisePlugin).isEnterprise).toBe(false);
- });
- test('adds an "isCore" field', () => {
- const corePlugin = { ...remotePlugin, internal: true } as RemotePlugin;
- const notCorePlugin = { ...remotePlugin, internal: false } as RemotePlugin;
- expect(mapRemoteToCatalog(corePlugin).isCore).toBe(true);
- expect(mapRemoteToCatalog(notCorePlugin).isCore).toBe(false);
- });
- });
- describe('mapLocalToCatalog()', () => {
- test('maps local response to PluginCatalog', () => {
- expect(mapLocalToCatalog(localPlugin)).toEqual({
- description: 'Zabbix plugin for Grafana',
- downloads: 0,
- id: 'alexanderzobnin-zabbix-app',
- info: {
- logos: {
- large: 'public/plugins/alexanderzobnin-zabbix-app/img/icn-zabbix-app.svg',
- small: 'public/plugins/alexanderzobnin-zabbix-app/img/icn-zabbix-app.svg',
- },
- },
- error: undefined,
- hasUpdate: false,
- isCore: false,
- isDev: false,
- isDisabled: false,
- isEnterprise: false,
- isInstalled: true,
- isPublished: false,
- name: 'Zabbix',
- orgName: 'Alexander Zobnin',
- popularity: 0,
- publishedAt: '',
- signature: 'valid',
- signatureOrg: 'Alexander Zobnin',
- signatureType: 'community',
- type: 'app',
- updatedAt: '2021-08-25',
- installedVersion: '4.2.2',
- });
- });
- test('isCore if signature is internal', () => {
- const pluginWithoutInternalSignature = { ...localPlugin };
- const pluginWithInternalSignature = { ...localPlugin, signature: 'internal' } as LocalPlugin;
- expect(mapLocalToCatalog(pluginWithoutInternalSignature).isCore).toBe(false);
- expect(mapLocalToCatalog(pluginWithInternalSignature).isCore).toBe(true);
- });
- test('isDev if local.dev', () => {
- const pluginWithoutDev = { ...localPlugin, dev: false };
- const pluginWithDev = { ...localPlugin, dev: true };
- expect(mapLocalToCatalog(pluginWithoutDev).isDev).toBe(false);
- expect(mapLocalToCatalog(pluginWithDev).isDev).toBe(true);
- });
- });
- describe('mapToCatalogPlugin()', () => {
- test('merges local and remote plugin data correctly', () => {
- expect(mapToCatalogPlugin(localPlugin, remotePlugin)).toEqual({
- description: 'Zabbix plugin for Grafana',
- downloads: 33645089,
- hasUpdate: false,
- id: 'alexanderzobnin-zabbix-app',
- info: {
- logos: {
- small: 'https://grafana.com/api/plugins/alexanderzobnin-zabbix-app/versions/4.1.5/logos/small',
- large: 'https://grafana.com/api/plugins/alexanderzobnin-zabbix-app/versions/4.1.5/logos/large',
- },
- },
- error: undefined,
- isCore: false,
- isDev: false,
- isDisabled: false,
- isEnterprise: false,
- isInstalled: true,
- isPublished: true,
- name: 'Zabbix',
- orgName: 'Alexander Zobnin',
- popularity: 0.2111,
- publishedAt: '2016-04-06T20:23:41.000Z',
- signature: 'valid',
- signatureOrg: 'Alexander Zobnin',
- signatureType: 'community',
- type: 'app',
- updatedAt: '2021-05-18T14:53:01.000Z',
- installedVersion: '4.2.2',
- });
- });
- test('`.description` - prefers the local', () => {
- // Local & Remote
- expect(
- mapToCatalogPlugin(
- { ...localPlugin, info: { ...localPlugin.info, description: 'Local description' } },
- { ...remotePlugin, description: 'Remote description' }
- )
- ).toMatchObject({ description: 'Local description' });
- // Remote only
- expect(mapToCatalogPlugin(undefined, { ...remotePlugin, description: 'Remote description' })).toMatchObject({
- description: 'Remote description',
- });
- // Local only
- expect(
- mapToCatalogPlugin({ ...localPlugin, info: { ...localPlugin.info, description: 'Local description' } })
- ).toMatchObject({ description: 'Local description' });
- // No local or remote
- expect(mapToCatalogPlugin()).toMatchObject({ description: '' });
- });
- test('`.hasUpdate` - prefers the local', () => {
- // Local only
- expect(mapToCatalogPlugin({ ...localPlugin })).toMatchObject({ hasUpdate: false });
- expect(mapToCatalogPlugin({ ...localPlugin, hasUpdate: true })).toMatchObject({ hasUpdate: true });
- // No local or remote
- expect(mapToCatalogPlugin()).toMatchObject({ hasUpdate: false });
- });
- test('`.downloads` - relies on the remote', () => {
- // Local & Remote
- expect(mapToCatalogPlugin(localPlugin, { ...remotePlugin, downloads: 99 })).toMatchObject({ downloads: 99 });
- // Remote only
- expect(mapToCatalogPlugin(undefined, { ...remotePlugin, downloads: 99 })).toMatchObject({ downloads: 99 });
- // Local only
- expect(mapToCatalogPlugin(localPlugin)).toMatchObject({ downloads: 0 });
- // No local or remote
- expect(mapToCatalogPlugin()).toMatchObject({ downloads: 0 });
- });
- test('`.isCore` - prefers the remote', () => {
- // Local & Remote
- expect(mapToCatalogPlugin(localPlugin, { ...remotePlugin, internal: true })).toMatchObject({ isCore: true });
- // Remote only
- expect(mapToCatalogPlugin(undefined, { ...remotePlugin, internal: true })).toMatchObject({ isCore: true });
- expect(mapToCatalogPlugin(undefined, { ...remotePlugin, internal: false })).toMatchObject({ isCore: false });
- // Local only
- expect(mapToCatalogPlugin({ ...localPlugin, signature: PluginSignatureStatus.internal })).toMatchObject({
- isCore: true,
- });
- expect(mapToCatalogPlugin({ ...localPlugin, signature: PluginSignatureStatus.valid })).toMatchObject({
- isCore: false,
- });
- // No local or remote
- expect(mapToCatalogPlugin()).toMatchObject({ isCore: false });
- });
- test('`.isDev` - prefers the local', () => {
- // Local & Remote
- expect(mapToCatalogPlugin({ ...localPlugin, dev: true }, remotePlugin)).toMatchObject({ isDev: true });
- // Remote only
- expect(mapToCatalogPlugin(undefined, remotePlugin)).toMatchObject({ isDev: false });
- // Local only
- expect(mapToCatalogPlugin({ ...localPlugin, dev: true }, undefined)).toMatchObject({ isDev: true });
- expect(mapToCatalogPlugin({ ...localPlugin, dev: undefined }, undefined)).toMatchObject({ isDev: false });
- // No local or remote
- expect(mapToCatalogPlugin()).toMatchObject({ isDev: false });
- });
- test('`.isEnterprise` - prefers the remote', () => {
- // Local & Remote
- expect(mapToCatalogPlugin(localPlugin, { ...remotePlugin, status: 'enterprise' })).toMatchObject({
- isEnterprise: true,
- });
- expect(mapToCatalogPlugin(localPlugin, { ...remotePlugin, status: 'unknown' })).toMatchObject({
- isEnterprise: false,
- });
- // Remote only
- expect(mapToCatalogPlugin(undefined, { ...remotePlugin, status: 'enterprise' })).toMatchObject({
- isEnterprise: true,
- });
- // Local only
- expect(mapToCatalogPlugin(localPlugin)).toMatchObject({ isEnterprise: false });
- // No local or remote
- expect(mapToCatalogPlugin()).toMatchObject({ isEnterprise: false });
- });
- test('`.isInstalled` - prefers the local', () => {
- // Local & Remote
- expect(mapToCatalogPlugin(localPlugin, remotePlugin)).toMatchObject({ isInstalled: true });
- // Remote only
- expect(mapToCatalogPlugin(undefined, remotePlugin)).toMatchObject({ isInstalled: false });
- // Local only
- expect(mapToCatalogPlugin(localPlugin, undefined)).toMatchObject({ isInstalled: true });
- // No local or remote
- expect(mapToCatalogPlugin()).toMatchObject({ isInstalled: false });
- });
- test('`.name` - prefers the remote', () => {
- // Local & Remote
- expect(
- mapToCatalogPlugin({ ...localPlugin, name: 'Local name' }, { ...remotePlugin, name: 'Remote name' })
- ).toMatchObject({ name: 'Remote name' });
- // Remote only
- expect(mapToCatalogPlugin(undefined, { ...remotePlugin, name: 'Remote name' })).toMatchObject({
- name: 'Remote name',
- });
- // Local only
- expect(mapToCatalogPlugin({ ...localPlugin, name: 'Local name' })).toMatchObject({ name: 'Local name' });
- // No local or remote
- expect(mapToCatalogPlugin()).toMatchObject({ name: '' });
- });
- test('`.orgName` - prefers the remote', () => {
- // Local & Remote
- expect(mapToCatalogPlugin(localPlugin, { ...remotePlugin, orgName: 'Remote org' })).toMatchObject({
- orgName: 'Remote org',
- });
- // Remote only
- expect(mapToCatalogPlugin(undefined, { ...remotePlugin, orgName: 'Remote org' })).toMatchObject({
- orgName: 'Remote org',
- });
- // Local only
- expect(mapToCatalogPlugin(localPlugin)).toMatchObject({ orgName: 'Alexander Zobnin' });
- // No local or remote
- expect(mapToCatalogPlugin()).toMatchObject({ orgName: '' });
- });
- test('`.popularity` - prefers the remote', () => {
- // Local & Remote
- expect(mapToCatalogPlugin(localPlugin, { ...remotePlugin, popularity: 10 })).toMatchObject({ popularity: 10 });
- // Remote only
- expect(mapToCatalogPlugin(undefined, { ...remotePlugin, popularity: 10 })).toMatchObject({ popularity: 10 });
- // Local only
- expect(mapToCatalogPlugin(localPlugin)).toMatchObject({ popularity: 0 });
- // No local or remote
- expect(mapToCatalogPlugin()).toMatchObject({ popularity: 0 });
- });
- test('`.publishedAt` - prefers the remote', () => {
- // Local & Remote
- expect(mapToCatalogPlugin(localPlugin, { ...remotePlugin, createdAt: '2020-01-01' })).toMatchObject({
- publishedAt: '2020-01-01',
- });
- // Remote only
- expect(mapToCatalogPlugin(undefined, { ...remotePlugin, createdAt: '2020-01-01' })).toMatchObject({
- publishedAt: '2020-01-01',
- });
- // Local only
- expect(mapToCatalogPlugin(localPlugin)).toMatchObject({ publishedAt: '' });
- // No local or remote
- expect(mapToCatalogPlugin()).toMatchObject({ publishedAt: '' });
- });
- test('`.type` - prefers the local', () => {
- // Local & Remote
- expect(
- mapToCatalogPlugin(
- { ...localPlugin, type: PluginType.app },
- { ...remotePlugin, typeCode: PluginType.datasource }
- )
- ).toMatchObject({
- type: PluginType.app,
- });
- // Remote only
- expect(mapToCatalogPlugin(undefined, { ...remotePlugin, typeCode: PluginType.datasource })).toMatchObject({
- type: PluginType.datasource,
- });
- // Local only
- expect(mapToCatalogPlugin({ ...localPlugin, type: PluginType.app })).toMatchObject({
- type: PluginType.app,
- });
- // No local or remote
- expect(mapToCatalogPlugin()).toMatchObject({ type: undefined });
- });
- test('`.signature` - prefers the local', () => {
- // Local & Remote
- expect(
- mapToCatalogPlugin(
- { ...localPlugin, signature: PluginSignatureStatus.valid },
- { ...remotePlugin, signatureType: '', versionSignatureType: '' }
- )
- ).toMatchObject({
- signature: PluginSignatureStatus.valid,
- });
- expect(
- mapToCatalogPlugin(
- { ...localPlugin, signature: PluginSignatureStatus.missing },
- {
- ...remotePlugin,
- signatureType: PluginSignatureType.grafana,
- versionSignatureType: PluginSignatureType.grafana,
- }
- )
- ).toMatchObject({
- signature: PluginSignatureStatus.missing,
- });
- // Remote only
- expect(
- mapToCatalogPlugin(undefined, { ...remotePlugin, signatureType: PluginSignatureType.grafana })
- ).toMatchObject({
- signature: PluginSignatureStatus.valid,
- });
- expect(
- mapToCatalogPlugin(undefined, { ...remotePlugin, versionSignatureType: PluginSignatureType.grafana })
- ).toMatchObject({
- signature: PluginSignatureStatus.valid,
- });
- expect(
- mapToCatalogPlugin(undefined, { ...remotePlugin, signatureType: '', versionSignatureType: '' })
- ).toMatchObject({
- signature: PluginSignatureStatus.missing,
- });
- // Local only
- expect(mapToCatalogPlugin({ ...localPlugin, signature: PluginSignatureStatus.valid })).toMatchObject({
- signature: PluginSignatureStatus.valid,
- });
- // No local or remote
- expect(mapToCatalogPlugin()).toMatchObject({ signature: PluginSignatureStatus.missing });
- });
- test('`.signatureOrg` - prefers the local', () => {
- // Local & Remote
- expect(
- mapToCatalogPlugin(
- { ...localPlugin, signatureOrg: 'Local Org' },
- { ...remotePlugin, versionSignedByOrgName: 'Remote Org' }
- )
- ).toMatchObject({
- signatureOrg: 'Local Org',
- });
- // Remote only
- expect(mapToCatalogPlugin(undefined, { ...remotePlugin, versionSignedByOrgName: 'Remote Org' })).toMatchObject({
- signatureOrg: 'Remote Org',
- });
- // Local only
- expect(mapToCatalogPlugin({ ...localPlugin, signatureOrg: 'Local Org' })).toMatchObject({
- signatureOrg: 'Local Org',
- });
- // No local or remote
- expect(mapToCatalogPlugin()).toMatchObject({ signatureOrg: undefined });
- });
- test('`.signatureType` - prefers the local', () => {
- // Local & Remote
- expect(
- mapToCatalogPlugin(
- { ...localPlugin, signatureType: PluginSignatureType.core },
- { ...remotePlugin, signatureType: PluginSignatureType.grafana }
- )
- ).toMatchObject({
- signatureType: PluginSignatureType.core,
- });
- // Remote only
- expect(
- mapToCatalogPlugin(undefined, {
- ...remotePlugin,
- versionSignatureType: PluginSignatureType.core,
- signatureType: PluginSignatureType.grafana,
- })
- ).toMatchObject({
- signatureType: PluginSignatureType.core,
- });
- expect(
- mapToCatalogPlugin(undefined, {
- ...remotePlugin,
- versionSignatureType: '',
- signatureType: PluginSignatureType.grafana,
- })
- ).toMatchObject({
- signatureType: PluginSignatureType.grafana,
- });
- // Local only
- expect(mapToCatalogPlugin({ ...localPlugin, signatureType: PluginSignatureType.core })).toMatchObject({
- signatureType: PluginSignatureType.core,
- });
- // No local or remote
- expect(mapToCatalogPlugin()).toMatchObject({ signatureType: undefined });
- });
- test('`.updatedAt` - prefers the remote', () => {
- // Local & Remote
- expect(
- mapToCatalogPlugin(
- { ...localPlugin, info: { ...localPlugin.info, updated: '2019-01-01' } },
- { ...remotePlugin, updatedAt: '2020-01-01' }
- )
- ).toMatchObject({
- updatedAt: '2020-01-01',
- });
- // Remote only
- expect(mapToCatalogPlugin(undefined, { ...remotePlugin, updatedAt: '2020-01-01' })).toMatchObject({
- updatedAt: '2020-01-01',
- });
- // Local only
- expect(
- mapToCatalogPlugin({ ...localPlugin, info: { ...localPlugin.info, updated: '2019-01-01' } })
- ).toMatchObject({
- updatedAt: '2019-01-01',
- });
- // No local or remote
- expect(mapToCatalogPlugin()).toMatchObject({ updatedAt: '' });
- });
- });
- describe('sortPlugins()', () => {
- test('should be possible to sort by `name` ASC', () => {
- const sorted = sortPlugins(
- [
- getCatalogPluginMock({ id: 'zabbix', name: 'Zabbix' }),
- getCatalogPluginMock({ id: 'snowflake', name: 'Snowflake' }),
- getCatalogPluginMock({ id: 'jira', name: 'Jira' }),
- getCatalogPluginMock({ id: 'pie-chart', name: 'Pie Chart' }),
- getCatalogPluginMock({ id: 'cloud-watch', name: 'CloudWatch' }),
- ],
- Sorters.nameAsc
- );
- expect(sorted.map(({ name }) => name)).toEqual(['CloudWatch', 'Jira', 'Pie Chart', 'Snowflake', 'Zabbix']);
- });
- test('should be possible to sort by `name` DESC', () => {
- const sorted = sortPlugins(
- [
- getCatalogPluginMock({ id: 'zabbix', name: 'Zabbix' }),
- getCatalogPluginMock({ id: 'snowflake', name: 'Snowflake' }),
- getCatalogPluginMock({ id: 'jira', name: 'Jira' }),
- getCatalogPluginMock({ id: 'pie-chart', name: 'Pie Chart' }),
- getCatalogPluginMock({ id: 'cloud-watch', name: 'CloudWatch' }),
- ],
- Sorters.nameDesc
- );
- expect(sorted.map(({ name }) => name)).toEqual(['Zabbix', 'Snowflake', 'Pie Chart', 'Jira', 'CloudWatch']);
- });
- test('should be possible to sort by `updated` (latest first)', () => {
- const sorted = sortPlugins(
- [
- getCatalogPluginMock({ id: 'zabbix', updatedAt: '2010-01-01' }),
- getCatalogPluginMock({ id: 'snowflake', updatedAt: '2012-01-01' }),
- getCatalogPluginMock({ id: 'jira', updatedAt: '2005-01-01' }),
- getCatalogPluginMock({ id: 'pie-chart', updatedAt: '2021-01-01' }),
- getCatalogPluginMock({ id: 'cloud-watch', updatedAt: '2009-01-01' }),
- ],
- Sorters.updated
- );
- expect(sorted.map(({ id }) => id)).toEqual(['pie-chart', 'snowflake', 'zabbix', 'cloud-watch', 'jira']);
- });
- test('should be possible to sort by `published` (latest first)', () => {
- const sorted = sortPlugins(
- [
- getCatalogPluginMock({ id: 'zabbix', publishedAt: '2010-01-01' }),
- getCatalogPluginMock({ id: 'snowflake', publishedAt: '2012-01-01' }),
- getCatalogPluginMock({ id: 'jira', publishedAt: '2005-01-01' }),
- getCatalogPluginMock({ id: 'pie-chart', publishedAt: '2021-01-01' }),
- getCatalogPluginMock({ id: 'cloud-watch', publishedAt: '2009-01-01' }),
- ],
- Sorters.published
- );
- expect(sorted.map(({ id }) => id)).toEqual(['pie-chart', 'snowflake', 'zabbix', 'cloud-watch', 'jira']);
- });
- test('should be possible to sort by `downloads` (greatest first)', () => {
- const sorted = sortPlugins(
- [
- getCatalogPluginMock({ id: 'zabbix', downloads: 30 }),
- getCatalogPluginMock({ id: 'snowflake', downloads: 10 }),
- getCatalogPluginMock({ id: 'jira', downloads: 100 }),
- getCatalogPluginMock({ id: 'pie-chart', downloads: 350 }),
- getCatalogPluginMock({ id: 'cloud-watch', downloads: 200 }),
- ],
- Sorters.downloads
- );
- expect(sorted.map(({ id }) => id)).toEqual(['pie-chart', 'cloud-watch', 'jira', 'zabbix', 'snowflake']);
- });
- });
- describe('isLocalPluginVisible()', () => {
- test('should return TRUE if the plugin is not listed as hidden in the main Grafana configuration', () => {
- config.pluginCatalogHiddenPlugins = ['akumuli-datasource'];
- const plugin = getLocalPluginMock({
- id: 'barchart',
- });
- expect(isLocalPluginVisible(plugin)).toBe(true);
- });
- test('should return FALSE if the plugin is listed as hidden in the main Grafana configuration', () => {
- config.pluginCatalogHiddenPlugins = ['akumuli-datasource'];
- const plugin = getLocalPluginMock({
- id: 'akumuli-datasource',
- });
- expect(isLocalPluginVisible(plugin)).toBe(false);
- });
- });
- describe('isRemotePluginVisible()', () => {
- test('should return TRUE if the plugin is not listed as hidden in the main Grafana configuration', () => {
- config.pluginCatalogHiddenPlugins = ['akumuli-datasource'];
- const plugin = getRemotePluginMock({
- slug: 'barchart',
- });
- expect(isRemotePluginVisible(plugin)).toBe(true);
- });
- test('should return FALSE if the plugin is listed as hidden in the main Grafana configuration', () => {
- config.pluginCatalogHiddenPlugins = ['akumuli-datasource'];
- const plugin = getRemotePluginMock({
- slug: 'akumuli-datasource',
- });
- expect(isRemotePluginVisible(plugin)).toBe(false);
- });
- });
- });
|