@ -10,10 +10,10 @@ import {
mergeLocalsAndRemotes ,
sortPlugins ,
Sorters ,
isLocalPluginVisible ,
isRemotePluginVisible ,
isLocalPluginVisibleByConfig ,
isRemotePluginVisibleByConfig ,
} from './helpers' ;
import { RemotePlugin , LocalPlugin } from './types' ;
import { RemotePlugin , LocalPlugin , RemotePluginStatus } from './types' ;
describe ( 'Plugins/Helpers' , ( ) = > {
let remotePlugin : RemotePlugin ;
@ -65,6 +65,29 @@ describe('Plugins/Helpers', () => {
// Only remote
expect ( findMerged ( 'plugin-4' ) ) . toEqual ( mergeLocalAndRemote ( undefined , getRemotePluginMock ( { slug : 'plugin-4' } ) ) ) ;
} ) ;
test ( 'skips deprecated plugins unless they have a local - installed - counterpart' , ( ) = > {
const merged = mergeLocalsAndRemotes ( localPlugins , [
. . . remotePlugins ,
getRemotePluginMock ( { slug : 'plugin-5' , status : RemotePluginStatus.Deprecated } ) ,
] ) ;
const findMerged = ( mergedId : string ) = > merged . find ( ( { id } ) = > id === mergedId ) ;
expect ( merged ) . toHaveLength ( 4 ) ;
expect ( findMerged ( 'plugin-5' ) ) . toBeUndefined ( ) ;
} ) ;
test ( 'keeps deprecated plugins in case they have a local counterpart' , ( ) = > {
const merged = mergeLocalsAndRemotes (
[ . . . localPlugins , getLocalPluginMock ( { id : 'plugin-5' } ) ] ,
[ . . . remotePlugins , getRemotePluginMock ( { slug : 'plugin-5' , status : RemotePluginStatus.Deprecated } ) ]
) ;
const findMerged = ( mergedId : string ) = > merged . find ( ( { id } ) = > id === mergedId ) ;
expect ( merged ) . toHaveLength ( 5 ) ;
expect ( findMerged ( 'plugin-5' ) ) . not . toBeUndefined ( ) ;
expect ( findMerged ( 'plugin-5' ) ? . isDeprecated ) . toBe ( true ) ;
} ) ;
} ) ;
describe ( 'mergeLocalAndRemote()' , ( ) = > {
@ -100,6 +123,7 @@ describe('Plugins/Helpers', () => {
isDisabled : false ,
isEnterprise : false ,
isInstalled : false ,
isDeprecated : false ,
isPublished : true ,
name : 'Zabbix' ,
orgName : 'Alexander Zobnin' ,
@ -139,8 +163,8 @@ describe('Plugins/Helpers', () => {
} ) ;
test ( 'adds an "isEnterprise" field' , ( ) = > {
const enterprisePlugin = { . . . remotePlugin , status : 'enterprise' } as RemotePlugin ;
const notEnterprisePlugin = { . . . remotePlugin , status : 'unknown' } as RemotePlugin ;
const enterprisePlugin = { . . . remotePlugin , status : RemotePluginStatus.Enterprise } as RemotePlugin ;
const notEnterprisePlugin = { . . . remotePlugin , status : RemotePluginStatus.Active } as RemotePlugin ;
expect ( mapRemoteToCatalog ( enterprisePlugin ) . isEnterprise ) . toBe ( true ) ;
expect ( mapRemoteToCatalog ( notEnterprisePlugin ) . isEnterprise ) . toBe ( false ) ;
@ -175,6 +199,7 @@ describe('Plugins/Helpers', () => {
isEnterprise : false ,
isInstalled : true ,
isPublished : false ,
isDeprecated : false ,
name : 'Zabbix' ,
orgName : 'Alexander Zobnin' ,
popularity : 0 ,
@ -223,6 +248,7 @@ describe('Plugins/Helpers', () => {
isEnterprise : false ,
isInstalled : true ,
isPublished : true ,
isDeprecated : false ,
name : 'Zabbix' ,
orgName : 'Alexander Zobnin' ,
popularity : 0.2111 ,
@ -319,15 +345,17 @@ describe('Plugins/Helpers', () => {
test ( '`.isEnterprise` - prefers the remote' , ( ) = > {
// Local & Remote
expect ( mapToCatalogPlugin ( localPlugin , { . . . remotePlugin , status : 'enterprise' } ) ) . toMatchObject ( {
isEnterprise : true ,
} ) ;
expect ( mapToCatalogPlugin ( localPlugin , { . . . remotePlugin , status : 'unknown' } ) ) . toMatchObject ( {
expect ( mapToCatalogPlugin ( localPlugin , { . . . remotePlugin , status : RemotePluginStatus.Enterprise } ) ) . toMatchObject (
{
isEnterprise : true ,
}
) ;
expect ( mapToCatalogPlugin ( localPlugin , { . . . remotePlugin , status : RemotePluginStatus.Active } ) ) . toMatchObject ( {
isEnterprise : false ,
} ) ;
// Remote only
expect ( mapToCatalogPlugin ( undefined , { . . . remotePlugin , status : 'enterprise' } ) ) . toMatchObject ( {
expect ( mapToCatalogPlugin ( undefined , { . . . remotePlugin , status : RemotePluginStatus.Enterprise } ) ) . toMatchObject ( {
isEnterprise : true ,
} ) ;
@ -338,6 +366,34 @@ describe('Plugins/Helpers', () => {
expect ( mapToCatalogPlugin ( ) ) . toMatchObject ( { isEnterprise : false } ) ;
} ) ;
test ( '`.isDeprecated` - comes from the remote' , ( ) = > {
// Local & Remote
expect ( mapToCatalogPlugin ( localPlugin , { . . . remotePlugin , status : RemotePluginStatus.Deprecated } ) ) . toMatchObject (
{
isDeprecated : true ,
}
) ;
expect ( mapToCatalogPlugin ( localPlugin , { . . . remotePlugin , status : RemotePluginStatus.Enterprise } ) ) . toMatchObject (
{
isDeprecated : false ,
}
) ;
// Remote only
expect ( mapToCatalogPlugin ( undefined , { . . . remotePlugin , status : RemotePluginStatus.Deprecated } ) ) . toMatchObject ( {
isDeprecated : true ,
} ) ;
expect ( mapToCatalogPlugin ( undefined , { . . . remotePlugin , status : RemotePluginStatus.Enterprise } ) ) . toMatchObject ( {
isDeprecated : false ,
} ) ;
// Local only
expect ( mapToCatalogPlugin ( localPlugin ) ) . toMatchObject ( { isDeprecated : false } ) ;
// No local or remote
expect ( mapToCatalogPlugin ( ) ) . toMatchObject ( { isDeprecated : false } ) ;
} ) ;
test ( '`.isInstalled` - prefers the local' , ( ) = > {
// Local & Remote
expect ( mapToCatalogPlugin ( localPlugin , remotePlugin ) ) . toMatchObject ( { isInstalled : true } ) ;
@ -671,7 +727,7 @@ describe('Plugins/Helpers', () => {
id : 'barchart' ,
} ) ;
expect ( isLocalPluginVisible ( plugin ) ) . toBe ( true ) ;
expect ( isLocalPluginVisibleByConfig ( plugin ) ) . toBe ( true ) ;
} ) ;
test ( 'should return FALSE if the plugin is listed as hidden in the main Grafana configuration' , ( ) = > {
@ -680,7 +736,7 @@ describe('Plugins/Helpers', () => {
id : 'akumuli-datasource' ,
} ) ;
expect ( isLocalPluginVisible ( plugin ) ) . toBe ( false ) ;
expect ( isLocalPluginVisibleByConfig ( plugin ) ) . toBe ( false ) ;
} ) ;
} ) ;
@ -691,7 +747,7 @@ describe('Plugins/Helpers', () => {
slug : 'barchart' ,
} ) ;
expect ( isRemotePluginVisible ( plugin ) ) . toBe ( true ) ;
expect ( isRemotePluginVisibleByConfig ( plugin ) ) . toBe ( true ) ;
} ) ;
test ( 'should return FALSE if the plugin is listed as hidden in the main Grafana configuration' , ( ) = > {
@ -700,7 +756,7 @@ describe('Plugins/Helpers', () => {
slug : 'akumuli-datasource' ,
} ) ;
expect ( isRemotePluginVisible ( plugin ) ) . toBe ( false ) ;
expect ( isRemotePluginVisibleByConfig ( plugin ) ) . toBe ( false ) ;
} ) ;
} ) ;
} ) ;