From 71bee5716bf07e613c04ee82d263c89bdbfcd6f2 Mon Sep 17 00:00:00 2001 From: Giuseppe Guerra Date: Fri, 5 Apr 2024 11:46:05 +0200 Subject: [PATCH] [v10.4.x] Angular deprecation: Prefer local "angularDetected" value to the remote one (#85631) Angular deprecation: Prefer local "angularDetected" value to the remote one (#85571) * Angular deprecation: Prefer local value to remote * Update tests (cherry picked from commit c033a15aaa76f113a0cd93b01407dab258ac78a3) --- .../admin/__mocks__/localPlugin.mock.ts | 1 + .../admin/__mocks__/remotePlugin.mock.ts | 1 + .../features/plugins/admin/helpers.test.ts | 32 +++++++++++++++++++ public/app/features/plugins/admin/helpers.ts | 2 +- 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/public/app/features/plugins/admin/__mocks__/localPlugin.mock.ts b/public/app/features/plugins/admin/__mocks__/localPlugin.mock.ts index b0744b0a2d8..341be1f83b5 100644 --- a/public/app/features/plugins/admin/__mocks__/localPlugin.mock.ts +++ b/public/app/features/plugins/admin/__mocks__/localPlugin.mock.ts @@ -68,4 +68,5 @@ export default { signature: 'valid', signatureType: 'community', signatureOrg: 'Alexander Zobnin', + angularDetected: false, } as LocalPlugin; diff --git a/public/app/features/plugins/admin/__mocks__/remotePlugin.mock.ts b/public/app/features/plugins/admin/__mocks__/remotePlugin.mock.ts index d716ae4df5b..52b9d0a825c 100644 --- a/public/app/features/plugins/admin/__mocks__/remotePlugin.mock.ts +++ b/public/app/features/plugins/admin/__mocks__/remotePlugin.mock.ts @@ -47,4 +47,5 @@ export default { links: [], }, }, + angularDetected: false, } as RemotePlugin; diff --git a/public/app/features/plugins/admin/helpers.test.ts b/public/app/features/plugins/admin/helpers.test.ts index faef81ce920..6def922c53d 100644 --- a/public/app/features/plugins/admin/helpers.test.ts +++ b/public/app/features/plugins/admin/helpers.test.ts @@ -158,6 +158,7 @@ describe('Plugins/Helpers', () => { type: 'app', updatedAt: '2021-05-18T14:53:01.000Z', isFullyInstalled: false, + angularDetected: false, }); }); @@ -237,6 +238,7 @@ describe('Plugins/Helpers', () => { updatedAt: '2021-08-25', installedVersion: '4.2.2', isFullyInstalled: true, + angularDetected: false, }); }); @@ -288,6 +290,7 @@ describe('Plugins/Helpers', () => { updatedAt: '2021-05-18T14:53:01.000Z', installedVersion: '4.2.2', isFullyInstalled: true, + angularDetected: false, }); }); @@ -670,6 +673,35 @@ describe('Plugins/Helpers', () => { // No local or remote expect(mapToCatalogPlugin()).toMatchObject({ updatedAt: '' }); }); + + test('`.angularDetected` - prefers the local', () => { + // Both false shoul return false + expect( + mapToCatalogPlugin({ ...localPlugin, angularDetected: false }, { ...remotePlugin, angularDetected: false }) + ).toMatchObject({ angularDetected: false }); + + // Remote version is using angular, local isn't, should prefer local + expect( + mapToCatalogPlugin({ ...localPlugin, angularDetected: false }, { ...remotePlugin, angularDetected: true }) + ).toMatchObject({ angularDetected: false }); + + // Remote only + expect(mapToCatalogPlugin(undefined, remotePlugin)).toMatchObject({ angularDetected: false }); + expect(mapToCatalogPlugin(undefined, { ...remotePlugin, angularDetected: true })).toMatchObject({ + angularDetected: true, + }); + + // Local only + expect(mapToCatalogPlugin({ ...localPlugin, angularDetected: false }, undefined)).toMatchObject({ + angularDetected: false, + }); + expect(mapToCatalogPlugin({ ...localPlugin, angularDetected: true }, undefined)).toMatchObject({ + angularDetected: true, + }); + + // No local or remote + expect(mapToCatalogPlugin()).toMatchObject({ angularDetected: undefined }); + }); }); describe('sortPlugins()', () => { diff --git a/public/app/features/plugins/admin/helpers.ts b/public/app/features/plugins/admin/helpers.ts index 621d342b626..a860691a937 100644 --- a/public/app/features/plugins/admin/helpers.ts +++ b/public/app/features/plugins/admin/helpers.ts @@ -225,7 +225,7 @@ export function mapToCatalogPlugin(local?: LocalPlugin, remote?: RemotePlugin, e error: error?.errorCode, // Only local plugins have access control metadata accessControl: local?.accessControl, - angularDetected: local?.angularDetected || remote?.angularDetected, + angularDetected: local?.angularDetected ?? remote?.angularDetected, isFullyInstalled: Boolean(local) || isDisabled, iam: local?.iam, };