Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move common user input into a dedicated manager #523

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
138 changes: 5 additions & 133 deletions src/DebugConfigurationProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import * as path from 'path';
import type { SinonStub } from 'sinon';
import { createSandbox } from 'sinon';
import type { WorkspaceFolder } from 'vscode';
import { QuickPickItemKind } from 'vscode';
import Uri from 'vscode-uri';
import type { BrightScriptLaunchConfiguration } from './DebugConfigurationProvider';
import { manualHostItemId } from './DebugConfigurationProvider';
import { UserInputManager } from './managers/UserInputManager';
import { BrightScriptDebugConfigurationProvider } from './DebugConfigurationProvider';
import { vscode } from './mockVscode.spec';
import { standardizePath as s } from 'brighterscript';
import * as fsExtra from 'fs-extra';
import type { RokuDeviceDetails } from './ActiveDeviceManager';
import { ActiveDeviceManager } from './ActiveDeviceManager';
import { rokuDeploy } from 'roku-deploy';
import { GlobalStateManager } from './GlobalStateManager';
Expand All @@ -38,6 +36,7 @@ describe('BrightScriptConfigurationProvider', () => {
let configProvider: BrightScriptDebugConfigurationProvider;
let folder: WorkspaceFolder;
let globalStateManager: GlobalStateManager;
let userInputManager: UserInputManager;

beforeEach(() => {
fsExtra.emptyDirSync(tempDir);
Expand All @@ -52,13 +51,15 @@ describe('BrightScriptConfigurationProvider', () => {
//prevent the 'start' method from actually running
sinon.stub(ActiveDeviceManager.prototype as any, 'start').callsFake(() => { });
let activeDeviceManager = new ActiveDeviceManager();
userInputManager = new UserInputManager(activeDeviceManager);

configProvider = new BrightScriptDebugConfigurationProvider(
vscode.context,
activeDeviceManager,
null,
vscode.window.createOutputChannel('Extension'),
globalStateManager
globalStateManager,
userInputManager
);
});

Expand Down Expand Up @@ -331,135 +332,6 @@ describe('BrightScriptConfigurationProvider', () => {
});
});

describe('createHostQuickPickList', () => {
const devices: Array<RokuDeviceDetails> = [{
deviceInfo: {
'user-device-name': 'roku1',
'serial-number': 'alpha',
'model-number': 'model1'
},
id: '1',
ip: '1.1.1.1',
location: '???'
}, {
deviceInfo: {
'user-device-name': 'roku2',
'serial-number': 'beta',
'model-number': 'model2'
},
id: '2',
ip: '1.1.1.2',
location: '???'
}, {
deviceInfo: {
'user-device-name': 'roku3',
'serial-number': 'charlie',
'model-number': 'model3'
},
id: '3',
ip: '1.1.1.3',
location: '???'
}];
function label(device: RokuDeviceDetails) {
return `${device.ip} | ${device.deviceInfo['user-device-name']} - ${device.deviceInfo['serial-number']} - ${device.deviceInfo['model-number']}`;
}

it('includes "manual', () => {
expect(
configProvider['createHostQuickPickList']([], undefined)
).to.eql([{
label: 'Enter manually',
device: {
id: manualHostItemId
}
}]);
});

it('includes separators for devices and manual options', () => {
expect(
configProvider['createHostQuickPickList']([devices[0]], undefined)
).to.eql([
{
kind: QuickPickItemKind.Separator,
label: 'devices'
},
{
label: '1.1.1.1 | roku1 - alpha - model1',
device: devices[0]
},
{
kind: QuickPickItemKind.Separator,
label: ' '
}, {
label: 'Enter manually',
device: {
id: manualHostItemId
}
}]
);
});

it('moves active device to the top', () => {
expect(
configProvider['createHostQuickPickList']([devices[0], devices[1], devices[2]], devices[1]).map(x => x.label)
).to.eql([
'last used',
label(devices[1]),
'other devices',
label(devices[0]),
label(devices[2]),
' ',
'Enter manually'
]);
});

it('includes the spinner text when "last used" and "other devices" separators are both present', () => {
expect(
configProvider['createHostQuickPickList'](devices, devices[1]).map(x => x.label)
).to.eql([
'last used',
label(devices[1]),
'other devices',
label(devices[0]),
label(devices[2]),
' ',
'Enter manually'
]);
});

it('includes the spinner text if "devices" separator is present', () => {
expect(
configProvider['createHostQuickPickList'](devices, null).map(x => x.label)
).to.eql([
'devices',
label(devices[0]),
label(devices[1]),
label(devices[2]),
' ',
'Enter manually'
]);
});

it('includes the spinner text if only "last used" separator is present', () => {
expect(
configProvider['createHostQuickPickList']([devices[0]], devices[0]).map(x => x.label)
).to.eql([
'last used',
label(devices[0]),
' ',
'Enter manually'
]);
});

it('includes the spinner text when no other device entries are present', () => {
expect(
configProvider['createHostQuickPickList']([], null).map(x => x.label)
).to.eql([
'Enter manually'
]);
});
});

describe('processEnableDebugProtocolParameter', () => {
let value: string;
let stub: SinonStub;
Expand Down