Path: blob/main/src/vs/workbench/contrib/debug/test/browser/variablesView.test.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import * as assert from 'assert';6import * as dom from '../../../../../base/browser/dom.js';7import { HighlightedLabel } from '../../../../../base/browser/ui/highlightedlabel/highlightedLabel.js';8import { DisposableStore } from '../../../../../base/common/lifecycle.js';9import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';10import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';11import { TestConfigurationService } from '../../../../../platform/configuration/test/common/testConfigurationService.js';12import { IHoverService } from '../../../../../platform/hover/browser/hover.js';13import { NullHoverService } from '../../../../../platform/hover/test/browser/nullHoverService.js';14import { TestInstantiationService } from '../../../../../platform/instantiation/test/common/instantiationServiceMock.js';15import { workbenchInstantiationService } from '../../../../test/browser/workbenchTestServices.js';16import { DebugExpressionRenderer } from '../../browser/debugExpressionRenderer.js';17import { VariablesRenderer } from '../../browser/variablesView.js';18import { IDebugService, IViewModel } from '../../common/debug.js';19import { Scope, StackFrame, Thread, Variable } from '../../common/debugModel.js';20import { MockDebugService, MockSession } from '../common/mockDebug.js';2122const $ = dom.$;2324function assertVariable(disposables: Pick<DisposableStore, "add">, variablesRenderer: VariablesRenderer, displayType: boolean) {25const session = new MockSession();26const thread = new Thread(session, 'mockthread', 1);27const range = {28startLineNumber: 1,29startColumn: 1,30endLineNumber: undefined!,31endColumn: undefined!32};33const stackFrame = new StackFrame(thread, 1, null!, 'app.js', 'normal', range, 0, true);34const scope = new Scope(stackFrame, 1, 'local', 1, false, 10, 10);35const node = {36element: new Variable(session, 1, scope, 2, 'foo', 'bar.foo', undefined, 0, 0, undefined, {}, 'string'),37depth: 0,38visibleChildrenCount: 1,39visibleChildIndex: -1,40collapsible: false,41collapsed: false,42visible: true,43filterData: undefined,44children: []45};46const expression = $('.');47const name = $('.');48const type = $('.');49const value = $('.');50const label = disposables.add(new HighlightedLabel(name));51const lazyButton = $('.');52const inputBoxContainer = $('.');53const elementDisposable = disposables.add(new DisposableStore());54const templateDisposable = disposables.add(new DisposableStore());55const currentElement = undefined;56const data = {57expression,58name,59type,60value,61label,62lazyButton,63inputBoxContainer,64elementDisposable,65templateDisposable,66currentElement67};68variablesRenderer.renderElement(node, 0, data);69assert.strictEqual(value.textContent, '');70assert.strictEqual(label.element.textContent, 'foo');7172node.element.value = 'xpto';73variablesRenderer.renderElement(node, 0, data);74assert.strictEqual(value.textContent, 'xpto');75assert.strictEqual(type.textContent, displayType ? 'string =' : '');76assert.strictEqual(label.element.textContent, displayType ? 'foo: ' : 'foo =');7778variablesRenderer.disposeTemplate(data);79}8081suite('Debug - Variable Debug View', () => {82const disposables = ensureNoDisposablesAreLeakedInTestSuite();83let variablesRenderer: VariablesRenderer;84let instantiationService: TestInstantiationService;85let expressionRenderer: DebugExpressionRenderer;86let configurationService: TestConfigurationService;8788setup(() => {89instantiationService = workbenchInstantiationService(undefined, disposables);90configurationService = instantiationService.createInstance(TestConfigurationService);91instantiationService.stub(IConfigurationService, configurationService);92expressionRenderer = instantiationService.createInstance(DebugExpressionRenderer);93const debugService = new MockDebugService();94instantiationService.stub(IHoverService, NullHoverService);95debugService.getViewModel = () => <IViewModel>{ focusedStackFrame: undefined, getSelectedExpression: () => undefined };96debugService.getViewModel().getSelectedExpression = () => undefined;97instantiationService.stub(IDebugService, debugService);98});99100test('variable expressions with display type', () => {101configurationService.setUserConfiguration('debug.showVariableTypes', true);102instantiationService.stub(IConfigurationService, configurationService);103variablesRenderer = instantiationService.createInstance(VariablesRenderer, expressionRenderer);104assertVariable(disposables, variablesRenderer, true);105});106107test('variable expressions', () => {108configurationService.setUserConfiguration('debug.showVariableTypes', false);109instantiationService.stub(IConfigurationService, configurationService);110variablesRenderer = instantiationService.createInstance(VariablesRenderer, expressionRenderer);111assertVariable(disposables, variablesRenderer, false);112});113});114115116