From 2006d4300e857b464f6d22881f5eae0bb728df7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Baptiste=20Li=C3=A8vremont?= Date: Fri, 10 Jan 2025 14:54:28 +0100 Subject: [PATCH] SLVSCODE-746 Use non trivial ID for first level nodes of connected mode view (#676) --- src/connected/connections.ts | 20 +++++++++++--------- test/suite/connections.test.ts | 14 +++++++------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/connected/connections.ts b/src/connected/connections.ts index 9b3c99d2c..1b1647065 100644 --- a/src/connected/connections.ts +++ b/src/connected/connections.ts @@ -70,9 +70,11 @@ export class Connection extends VSCode.TreeItem { } } +type ConnectionType = '__sonarqube__' | '__sonarcloud__'; + export class ConnectionGroup extends VSCode.TreeItem { constructor( - public readonly id: 'sonarqube' | 'sonarcloud', + public readonly id: ConnectionType, public readonly label: 'SonarQube Server' | 'SonarQube Cloud', public readonly contextValue: 'sonarQubeGroup' | 'sonarCloudGroup' ) { @@ -89,13 +91,13 @@ export class AllConnectionsTreeDataProvider implements VSCode.TreeDataProvider { - const contextValue = type === 'sonarqube' ? 'sonarqubeConnection' : 'sonarcloudConnection'; + async getConnections(type: ConnectionType): Promise { + const contextValue = type === '__sonarqube__' ? 'sonarqubeConnection' : 'sonarcloudConnection'; const labelKey = 'connectionId'; - const alternativeLabelKey = type === 'sonarqube' ? 'serverUrl' : 'organizationKey'; + const alternativeLabelKey = type === '__sonarqube__' ? 'serverUrl' : 'organizationKey'; const connectionsFromSettings: BaseConnection[] = - type === 'sonarqube' + type === '__sonarqube__' ? ConnectionSettingsService.instance.getSonarQubeConnections() : ConnectionSettingsService.instance.getSonarCloudConnections(); const connections = await Promise.all( @@ -141,9 +143,9 @@ export class AllConnectionsTreeDataProvider implements VSCode.TreeDataProvider 0 ? new ConnectionGroup('sonarqube', 'SonarQube Server', 'sonarQubeGroup') : null, - scConnections.length > 0 ? new ConnectionGroup('sonarcloud', 'SonarQube Cloud', 'sonarCloudGroup') : null + sqConnections.length > 0 ? new ConnectionGroup('__sonarqube__', 'SonarQube Server', 'sonarQubeGroup') : null, + scConnections.length > 0 ? new ConnectionGroup('__sonarcloud__', 'SonarQube Cloud', 'sonarCloudGroup') : null ]; } diff --git a/test/suite/connections.test.ts b/test/suite/connections.test.ts index 31c363d5c..f9b0ae29a 100644 --- a/test/suite/connections.test.ts +++ b/test/suite/connections.test.ts @@ -57,30 +57,30 @@ suite('Connected Mode Test Suite', () => { }); suite('getConnections()', () => { - let underTest; + let underTest: AllConnectionsTreeDataProvider; setup(() => { underTest = new AllConnectionsTreeDataProvider(mockClient); }); test('should return same number of sonarqube settings as in config file', async () => { const connectionConfig = vscode.workspace.getConfiguration('sonarlint.connectedMode.connections'); - expect(connectionConfig.sonarqube.length).to.equal((await underTest.getConnections('sonarqube')).length); + expect(connectionConfig.sonarqube.length).to.equal((await underTest.getConnections('__sonarqube__')).length); }); test('should return no sq/sc connections when config is blank', async () => { - expect((await underTest.getConnections('sonarqube')).length).to.equal(0); - expect((await underTest.getConnections('sonarcloud')).length).to.equal(0); + expect((await underTest.getConnections('__sonarqube__')).length).to.equal(0); + expect((await underTest.getConnections('__sonarcloud__')).length).to.equal(0); }); test('should return same number of sonarcloud settings as in config file', async () => { const connectionConfig = vscode.workspace.getConfiguration('sonarlint.connectedMode.connections'); - expect(connectionConfig.sonarcloud.length).to.equal((await underTest.getConnections('sonarcloud')).length); + expect(connectionConfig.sonarcloud.length).to.equal((await underTest.getConnections('__sonarcloud__')).length); }); }); suite('ConnectedMode TreeView', () => { - const SQGroup = new ConnectionGroup('sonarqube', 'SonarQube Server', 'sonarQubeGroup'); - const SCGroup = new ConnectionGroup('sonarcloud', 'SonarQube Cloud', 'sonarCloudGroup'); + const SQGroup = new ConnectionGroup('__sonarqube__', 'SonarQube Server', 'sonarQubeGroup'); + const SCGroup = new ConnectionGroup('__sonarcloud__', 'SonarQube Cloud', 'sonarCloudGroup'); test('should return empty lists when expanding SQ and SC tabs and no connections exist', async () => { const underTest = new AllConnectionsTreeDataProvider(mockClient);