Path: blob/main/src/vs/workbench/contrib/debug/test/browser/watchExpressionView.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 { TestInstantiationService } from '../../../../../platform/instantiation/test/common/instantiationServiceMock.js';11import { WatchExpressionsRenderer } from '../../browser/watchExpressionsView.js';12import { Scope, StackFrame, Thread, Variable } from '../../common/debugModel.js';13import { MockDebugService, MockSession } from '../common/mockDebug.js';14import { workbenchInstantiationService } from '../../../../test/browser/workbenchTestServices.js';15import { IHoverService } from '../../../../../platform/hover/browser/hover.js';16import { NullHoverService } from '../../../../../platform/hover/test/browser/nullHoverService.js';17import { IDebugService, IViewModel } from '../../common/debug.js';18import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';19import { TestConfigurationService } from '../../../../../platform/configuration/test/common/testConfigurationService.js';20import { DebugExpressionRenderer } from '../../browser/debugExpressionRenderer.js';21const $ = dom.$;2223function assertWatchVariable(disposables: Pick<DisposableStore, "add">, watchExpressionsRenderer: WatchExpressionsRenderer, displayType: boolean) {24const session = new MockSession();25const thread = new Thread(session, 'mockthread', 1);26const range = {27startLineNumber: 1,28startColumn: 1,29endLineNumber: undefined!,30endColumn: undefined!31};32const stackFrame = new StackFrame(thread, 1, null!, 'app.js', 'normal', range, 0, true);33const scope = new Scope(stackFrame, 1, 'local', 1, false, 10, 10);34const node = {35element: new Variable(session, 1, scope, 2, 'foo', 'bar.foo', undefined, 0, 0, undefined, {}, 'string'),36depth: 0,37visibleChildrenCount: 1,38visibleChildIndex: -1,39collapsible: false,40collapsed: false,41visible: true,42filterData: undefined,43children: []44};45const expression = $('.');46const name = $('.');47const type = $('.');48const value = $('.');49const label = disposables.add(new HighlightedLabel(name));50const lazyButton = $('.');51const inputBoxContainer = $('.');52const elementDisposable = disposables.add(new DisposableStore());53const templateDisposable = disposables.add(new DisposableStore());54const currentElement = undefined;55const data = {56expression,57name,58type,59value,60label,61lazyButton,62inputBoxContainer,63elementDisposable,64templateDisposable,65currentElement66};67watchExpressionsRenderer.renderElement(node, 0, data);68assert.strictEqual(value.textContent, '');69assert.strictEqual(label.element.textContent, displayType ? 'foo: ' : 'foo =');7071node.element.value = 'xpto';72watchExpressionsRenderer.renderElement(node, 0, data);73assert.strictEqual(value.textContent, 'xpto');74assert.strictEqual(type.textContent, displayType ? 'string =' : '');75assert.strictEqual(label.element.textContent, displayType ? 'foo: ' : 'foo =');76}7778suite('Debug - Watch Debug View', () => {79const disposables = ensureNoDisposablesAreLeakedInTestSuite();80let watchExpressionsRenderer: WatchExpressionsRenderer;81let instantiationService: TestInstantiationService;82let configurationService: TestConfigurationService;83let expressionRenderer: DebugExpressionRenderer;8485setup(() => {86instantiationService = workbenchInstantiationService(undefined, disposables);87configurationService = instantiationService.createInstance(TestConfigurationService);88instantiationService.stub(IConfigurationService, configurationService);89expressionRenderer = instantiationService.createInstance(DebugExpressionRenderer);90const debugService = new MockDebugService();91instantiationService.stub(IHoverService, NullHoverService);92debugService.getViewModel = () => <IViewModel>{ focusedStackFrame: undefined, getSelectedExpression: () => undefined };93debugService.getViewModel().getSelectedExpression = () => undefined;94instantiationService.stub(IDebugService, debugService);95});9697test('watch expressions with display type', () => {98configurationService.setUserConfiguration('debug', { showVariableTypes: true });99instantiationService.stub(IConfigurationService, configurationService);100watchExpressionsRenderer = instantiationService.createInstance(WatchExpressionsRenderer, expressionRenderer);101assertWatchVariable(disposables, watchExpressionsRenderer, true);102});103104test('watch expressions', () => {105configurationService.setUserConfiguration('debug', { showVariableTypes: false });106instantiationService.stub(IConfigurationService, configurationService);107watchExpressionsRenderer = instantiationService.createInstance(WatchExpressionsRenderer, expressionRenderer);108assertWatchVariable(disposables, watchExpressionsRenderer, false);109});110});111112113