From de088592b004e955c833034d166eb1042b53e405 Mon Sep 17 00:00:00 2001 From: Brian Ingles Date: Fri, 9 Aug 2024 17:43:01 -0500 Subject: [PATCH] Tests (#79-2) --- src/services/ExtensionController.ts | 25 ++++++++++++--------- src/util/__snapshots__/uiUtils.spec.ts.snap | 22 ++++++++++++++++++ src/util/uiUtils.spec.ts | 22 ++++++++++++++++++ src/util/uiUtils.ts | 8 +++---- 4 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 src/util/__snapshots__/uiUtils.spec.ts.snap create mode 100644 src/util/uiUtils.spec.ts diff --git a/src/services/ExtensionController.ts b/src/services/ExtensionController.ts index 1834f097..5f2c2fbd 100644 --- a/src/services/ExtensionController.ts +++ b/src/services/ExtensionController.ts @@ -1,6 +1,11 @@ import * as vscode from 'vscode'; -import { Disposable } from '../common'; -import { DhService } from './DhService'; +import { + Disposable, + DOWNLOAD_LOGS_CMD, + RUN_CODE_COMMAND, + RUN_SELECTION_COMMAND, + SELECT_CONNECTION_COMMAND, +} from '../common'; import { assertDefined, ConnectionOption, @@ -18,13 +23,9 @@ import { } from '../util'; import { RunCommandCodeLensProvider } from './RunCommandCodeLensProvider'; import { DhServiceRegistry } from './DhServiceRegistry'; -import DhcService from './DhcService'; -import { - DOWNLOAD_LOGS_CMD, - RUN_CODE_COMMAND, - RUN_SELECTION_COMMAND, - SELECT_CONNECTION_COMMAND, -} from '../common'; +import { DhService } from './DhService'; +import { DhcService } from './DhcService'; +import { Config } from './Config'; const logger = new Logger('ExtensionController'); @@ -91,12 +92,14 @@ export class ExtensionController implements Disposable { * Initialize connection options. */ initializeConnectionOptions = (): void => { - this.connectionOptions = createConnectionOptions(); + this.connectionOptions = createConnectionOptions(Config.getCoreServers()); // Update connection options when configuration changes vscode.workspace.onDidChangeConfiguration( () => { - this.connectionOptions = createConnectionOptions(); + this.connectionOptions = createConnectionOptions( + Config.getCoreServers() + ); }, null, this.context.subscriptions diff --git a/src/util/__snapshots__/uiUtils.spec.ts.snap b/src/util/__snapshots__/uiUtils.spec.ts.snap new file mode 100644 index 00000000..b36ffea8 --- /dev/null +++ b/src/util/__snapshots__/uiUtils.spec.ts.snap @@ -0,0 +1,22 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`createConnectTextAndTooltip > should return text and tooltip: 'connected' 1`] = ` +{ + "text": "$(vm-connect) DHC: localhost:10000", + "tooltip": "Connected to http://localhost:10000", +} +`; + +exports[`createConnectTextAndTooltip > should return text and tooltip: 'connecting' 1`] = ` +{ + "text": "$(sync~spin) Deephaven: Connecting...", + "tooltip": "Connecting to http://localhost:10000...", +} +`; + +exports[`createConnectTextAndTooltip > should return text and tooltip: 'disconnected' 1`] = ` +{ + "text": "$(debug-disconnect) Deephaven: Disconnected", + "tooltip": "Connect to Deephaven", +} +`; diff --git a/src/util/uiUtils.spec.ts b/src/util/uiUtils.spec.ts new file mode 100644 index 00000000..cb5d54df --- /dev/null +++ b/src/util/uiUtils.spec.ts @@ -0,0 +1,22 @@ +import { describe, it, expect, vi } from 'vitest'; +import { createConnectTextAndTooltip, ConnectionOption } from './uiUtils'; + +// See __mocks__/vscode.ts for the mock implementation +vi.mock('vscode'); + +describe('createConnectTextAndTooltip', () => { + const option: ConnectionOption = { + type: 'DHC', + consoleType: 'python', + label: 'DHC: localhost:10000', + url: 'http://localhost:10000', + }; + + it.each([['connecting'], ['connected'], ['disconnected']] as const)( + `should return text and tooltip: '%s'`, + status => { + const actual = createConnectTextAndTooltip(status, option); + expect(actual).toMatchSnapshot(); + } + ); +}); diff --git a/src/util/uiUtils.ts b/src/util/uiUtils.ts index 97f014a9..55774053 100644 --- a/src/util/uiUtils.ts +++ b/src/util/uiUtils.ts @@ -8,7 +8,6 @@ import { STATUS_BAR_DISCONNECTED_TEXT, STATUS_BAR_DISCONNECT_TEXT, } from '../common'; -import { Config } from '../services'; export interface ConnectionOption { type: ConnectionType; @@ -99,10 +98,11 @@ export function createConnectionOption(type: ConnectionType) { /** * Create connection options from current extension config. + * @param dhcServerUrls The server urls from the extension config */ -export function createConnectionOptions(): ConnectionOption[] { - const dhcServerUrls = Config.getCoreServers(); - +export function createConnectionOptions( + dhcServerUrls: ConnectionConfig[] +): ConnectionOption[] { const connectionOptions: ConnectionOption[] = [ ...dhcServerUrls.map(createConnectionOption('DHC')), ];