Skip to content

Commit

Permalink
Tests (#79-2)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Aug 9, 2024
1 parent 684f096 commit de08859
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 15 deletions.
25 changes: 14 additions & 11 deletions src/services/ExtensionController.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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');

Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions src/util/__snapshots__/uiUtils.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -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",
}
`;
22 changes: 22 additions & 0 deletions src/util/uiUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
}
);
});
8 changes: 4 additions & 4 deletions src/util/uiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
STATUS_BAR_DISCONNECTED_TEXT,
STATUS_BAR_DISCONNECT_TEXT,
} from '../common';
import { Config } from '../services';

export interface ConnectionOption {
type: ConnectionType;
Expand Down Expand Up @@ -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')),
];
Expand Down

0 comments on commit de08859

Please sign in to comment.