|
| 1 | +import * as assert from 'assert'; |
| 2 | +import * as sinon from 'sinon'; |
| 3 | +import { Terminal } from 'vscode'; |
| 4 | +import { PythonEnvironment } from '../../../api'; |
| 5 | +import * as commandApi from '../../../common/command.api'; |
| 6 | +import * as activation from '../../../features/common/activation'; |
| 7 | +import { setActivateMenuButtonContext } from '../../../features/terminal/activateMenuButton'; |
| 8 | +import * as utils from '../../../features/terminal/utils'; |
| 9 | + |
| 10 | +suite('Terminal - Activate Menu Button', () => { |
| 11 | + let executeCommandStub: sinon.SinonStub; |
| 12 | + let isTaskTerminalStub: sinon.SinonStub; |
| 13 | + let isActivatableEnvironmentStub: sinon.SinonStub; |
| 14 | + |
| 15 | + const mockTerminal = { name: 'test-terminal' } as Terminal; |
| 16 | + const mockEnv = {} as PythonEnvironment; // Stubbed, so no properties needed |
| 17 | + |
| 18 | + setup(() => { |
| 19 | + executeCommandStub = sinon.stub(commandApi, 'executeCommand').resolves(); |
| 20 | + isTaskTerminalStub = sinon.stub(utils, 'isTaskTerminal'); |
| 21 | + isActivatableEnvironmentStub = sinon.stub(activation, 'isActivatableEnvironment'); |
| 22 | + }); |
| 23 | + |
| 24 | + teardown(() => { |
| 25 | + sinon.restore(); |
| 26 | + }); |
| 27 | + |
| 28 | + test('should show activate icon when isTaskTerminal returns false', async () => { |
| 29 | + // Arrange: terminal is NOT a task terminal, env is activatable |
| 30 | + isTaskTerminalStub.returns(false); |
| 31 | + isActivatableEnvironmentStub.returns(true); |
| 32 | + |
| 33 | + // Act |
| 34 | + await setActivateMenuButtonContext(mockTerminal, mockEnv); |
| 35 | + |
| 36 | + // Assert: icon should be shown (pythonTerminalActivation = true) |
| 37 | + assert.ok( |
| 38 | + executeCommandStub.calledWith('setContext', 'pythonTerminalActivation', true), |
| 39 | + 'Should set pythonTerminalActivation to true for non-task terminal', |
| 40 | + ); |
| 41 | + }); |
| 42 | + |
| 43 | + test('should hide activate icon when isTaskTerminal returns true', async () => { |
| 44 | + // Arrange: terminal IS a task terminal (even if env is activatable) |
| 45 | + isTaskTerminalStub.returns(true); |
| 46 | + isActivatableEnvironmentStub.returns(true); |
| 47 | + |
| 48 | + // Act |
| 49 | + await setActivateMenuButtonContext(mockTerminal, mockEnv); |
| 50 | + |
| 51 | + // Assert: icon should be hidden (pythonTerminalActivation = false) |
| 52 | + assert.ok( |
| 53 | + executeCommandStub.calledWith('setContext', 'pythonTerminalActivation', false), |
| 54 | + 'Should set pythonTerminalActivation to false for task terminal', |
| 55 | + ); |
| 56 | + }); |
| 57 | +}); |
0 commit comments