|
4 | 4 | EnvManagerTreeItem, |
5 | 5 | getEnvironmentParentDirName, |
6 | 6 | PythonEnvTreeItem, |
| 7 | + PythonGroupEnvTreeItem, |
7 | 8 | } from '../../../features/views/treeViewItems'; |
8 | 9 | import { InternalEnvironmentManager, PythonEnvironmentImpl } from '../../../internal.api'; |
9 | 10 |
|
@@ -73,6 +74,17 @@ function createMockManager( |
73 | 74 |
|
74 | 75 | suite('Test TreeView Items', () => { |
75 | 76 | suite('EnvManagerTreeItem', () => { |
| 77 | + test('Sets id to manager id for tree item identification', () => { |
| 78 | + // Arrange |
| 79 | + const manager = createMockManager({ id: 'ms-python.python:venv' }); |
| 80 | + |
| 81 | + // Act |
| 82 | + const item = new EnvManagerTreeItem(manager); |
| 83 | + |
| 84 | + // Assert |
| 85 | + assert.strictEqual(item.treeItem.id, 'ms-python.python:venv'); |
| 86 | + }); |
| 87 | + |
76 | 88 | test('Context value excludes create when manager does not support it', () => { |
77 | 89 | // Arrange |
78 | 90 | const manager = createMockManager({ supportsCreate: false }); |
@@ -127,6 +139,20 @@ suite('Test TreeView Items', () => { |
127 | 139 | managerWithRemove = new EnvManagerTreeItem(createMockManager({ supportsRemove: true })); |
128 | 140 | }); |
129 | 141 |
|
| 142 | + test('Sets id to environment id for tree item identification', () => { |
| 143 | + // Arrange |
| 144 | + const env = createMockEnvironment({ |
| 145 | + id: 'unique-env-id-123', |
| 146 | + environmentPath: '/home/user/envs/.venv/bin/python', |
| 147 | + }); |
| 148 | + |
| 149 | + // Act |
| 150 | + const item = new PythonEnvTreeItem(env, managerWithoutRemove); |
| 151 | + |
| 152 | + // Assert |
| 153 | + assert.strictEqual(item.treeItem.id, 'unique-env-id-123'); |
| 154 | + }); |
| 155 | + |
130 | 156 | test('Context value excludes remove and activatable when not supported', () => { |
131 | 157 | // Arrange |
132 | 158 | const env = createMockEnvironment({ |
@@ -242,6 +268,60 @@ suite('Test TreeView Items', () => { |
242 | 268 | }); |
243 | 269 | }); |
244 | 270 |
|
| 271 | + suite('PythonGroupEnvTreeItem', () => { |
| 272 | + let parentManager: EnvManagerTreeItem; |
| 273 | + |
| 274 | + setup(() => { |
| 275 | + parentManager = new EnvManagerTreeItem(createMockManager({ id: 'ms-python.python:conda' })); |
| 276 | + }); |
| 277 | + |
| 278 | + test('Sets id combining manager id and group name for tree item identification', () => { |
| 279 | + // Arrange & Act |
| 280 | + const item = new PythonGroupEnvTreeItem(parentManager, 'base'); |
| 281 | + |
| 282 | + // Assert |
| 283 | + assert.strictEqual(item.treeItem.id, 'ms-python.python:conda:base'); |
| 284 | + }); |
| 285 | + |
| 286 | + test('Sets id correctly when group is EnvironmentGroupInfo object', () => { |
| 287 | + // Arrange |
| 288 | + const groupInfo = { name: 'dev-envs', description: 'Development environments' }; |
| 289 | + |
| 290 | + // Act |
| 291 | + const item = new PythonGroupEnvTreeItem(parentManager, groupInfo); |
| 292 | + |
| 293 | + // Assert |
| 294 | + assert.strictEqual(item.treeItem.id, 'ms-python.python:conda:dev-envs'); |
| 295 | + }); |
| 296 | + |
| 297 | + test('Uses string group as label', () => { |
| 298 | + // Arrange & Act |
| 299 | + const item = new PythonGroupEnvTreeItem(parentManager, 'my-group'); |
| 300 | + |
| 301 | + // Assert |
| 302 | + assert.strictEqual(item.treeItem.label, 'my-group'); |
| 303 | + }); |
| 304 | + |
| 305 | + test('Uses group name from EnvironmentGroupInfo as label', () => { |
| 306 | + // Arrange |
| 307 | + const groupInfo = { name: 'production', description: 'Production environments' }; |
| 308 | + |
| 309 | + // Act |
| 310 | + const item = new PythonGroupEnvTreeItem(parentManager, groupInfo); |
| 311 | + |
| 312 | + // Assert |
| 313 | + assert.strictEqual(item.treeItem.label, 'production'); |
| 314 | + }); |
| 315 | + |
| 316 | + test('Sets contextValue with manager id and group name', () => { |
| 317 | + // Arrange & Act |
| 318 | + const item = new PythonGroupEnvTreeItem(parentManager, 'test-group'); |
| 319 | + |
| 320 | + // Assert |
| 321 | + assert.strictEqual(item.treeItem.contextValue, 'pythonEnvGroup;ms-python.python:conda:test-group;'); |
| 322 | + }); |
| 323 | + }); |
| 324 | + |
245 | 325 | suite('getEnvironmentParentDirName', () => { |
246 | 326 | test('Extracts parent folder from Unix path with bin directory', () => { |
247 | 327 | // Arrange |
|
0 commit comments