1+ import assert from 'assert' ;
2+ import { Uri } from 'vscode' ;
3+ import { PythonProjectManagerImpl } from '../../features/projectManager' ;
4+
5+ suite ( 'Project Manager Update URI tests' , ( ) => {
6+ let projectManager : PythonProjectManagerImpl ;
7+
8+ setup ( ( ) => {
9+ projectManager = new PythonProjectManagerImpl ( ) ;
10+ } ) ;
11+
12+ teardown ( ( ) => {
13+ projectManager . dispose ( ) ;
14+ } ) ;
15+
16+ test ( 'updateProjectUri should update existing project URI' , ( ) => {
17+ const oldUri = Uri . file ( '/path/to/old/project' ) ;
18+ const newUri = Uri . file ( '/path/to/new/project' ) ;
19+
20+ // Create a project and manually add it to the internal map to bypass the complex add method
21+ const project = projectManager . create ( 'TestProject' , oldUri , {
22+ description : 'Test project' ,
23+ tooltip : 'Test tooltip'
24+ } ) ;
25+
26+ // Access private _projects map to manually add the project for testing
27+ ( projectManager as any ) . _projects . set ( oldUri . toString ( ) , project ) ;
28+
29+ // Verify project exists with old URI
30+ const oldProject = projectManager . get ( oldUri ) ;
31+ assert . ok ( oldProject , 'Project should exist with old URI' ) ;
32+ assert . equal ( oldProject . uri . fsPath , oldUri . fsPath , 'Old URI should match' ) ;
33+
34+ // Update the project URI
35+ projectManager . updateProjectUri ( oldUri , newUri ) ;
36+
37+ // Verify project no longer exists with old URI
38+ const oldProjectAfterUpdate = projectManager . get ( oldUri ) ;
39+ assert . equal ( oldProjectAfterUpdate , undefined , 'Project should not exist with old URI after update' ) ;
40+
41+ // Verify project exists with new URI
42+ const newProject = projectManager . get ( newUri ) ;
43+ assert . ok ( newProject , 'Project should exist with new URI' ) ;
44+ assert . equal ( newProject . uri . fsPath , newUri . fsPath , 'New URI should match' ) ;
45+ assert . equal ( newProject . name , 'project' , 'Project name should be based on new path' ) ;
46+ assert . equal ( newProject . description , 'Test project' , 'Description should be preserved' ) ;
47+ assert . equal ( newProject . tooltip , 'Test tooltip' , 'Tooltip should be preserved' ) ;
48+ } ) ;
49+
50+ test ( 'updateProjectUri should handle non-existent project gracefully' , ( ) => {
51+ const oldUri = Uri . file ( '/path/to/nonexistent/project' ) ;
52+ const newUri = Uri . file ( '/path/to/new/project' ) ;
53+
54+ // Try to update a project that doesn't exist
55+ // This should not throw an error
56+ assert . doesNotThrow ( ( ) => {
57+ projectManager . updateProjectUri ( oldUri , newUri ) ;
58+ } , 'Should handle non-existent project gracefully' ) ;
59+
60+ // Verify no project was created
61+ const newProject = projectManager . get ( newUri ) ;
62+ assert . equal ( newProject , undefined , 'No project should be created for non-existent old project' ) ;
63+ } ) ;
64+
65+ test ( 'remove should remove multiple projects' , ( ) => {
66+ const project1Uri = Uri . file ( '/path/to/project1' ) ;
67+ const project2Uri = Uri . file ( '/path/to/project2' ) ;
68+
69+ // Create projects and manually add them to the internal map
70+ const project1 = projectManager . create ( 'Project1' , project1Uri ) ;
71+ const project2 = projectManager . create ( 'Project2' , project2Uri ) ;
72+
73+ // Access private _projects map to manually add projects for testing
74+ ( projectManager as any ) . _projects . set ( project1Uri . toString ( ) , project1 ) ;
75+ ( projectManager as any ) . _projects . set ( project2Uri . toString ( ) , project2 ) ;
76+
77+ // Verify both projects exist
78+ assert . ok ( projectManager . get ( project1Uri ) , 'Project1 should exist' ) ;
79+ assert . ok ( projectManager . get ( project2Uri ) , 'Project2 should exist' ) ;
80+
81+ // Remove both projects
82+ projectManager . remove ( [ project1 , project2 ] ) ;
83+
84+ // Verify both projects are removed
85+ assert . equal ( projectManager . get ( project1Uri ) , undefined , 'Project1 should be removed' ) ;
86+ assert . equal ( projectManager . get ( project2Uri ) , undefined , 'Project2 should be removed' ) ;
87+ } ) ;
88+ } ) ;
0 commit comments