@@ -5,6 +5,16 @@ import * as path from 'path';
55import { buildTreeNode } from '../extension' ;
66import * as fs from 'fs' ;
77import * as os from "os" ;
8+ // Import tree-utils functions for testing context menu options
9+ import {
10+ checkAllChildren ,
11+ checkAllFolders ,
12+ uncheckAllChildren ,
13+ checkWithoutChildren ,
14+ checkOnlyFoldersAtLevel ,
15+ checkOnlyFilesAtLevel ,
16+ checkAllChildrenAtLevel
17+ } from './tree-utils' ;
818
919suite ( 'JetTreeMark-vscode Test Suite' , ( ) => {
1020 test ( 'Extension is present in the registry' , ( ) => {
@@ -63,4 +73,150 @@ suite('JetTreeMark-vscode Test Suite', () => {
6373 assert . ok ( bNode && bNode . type === 'file' , 'b.txt should exist in subdir' ) ;
6474 } ) ;
6575 } ) ;
66- } ) ;
76+ // Test suite for context menu options
77+ suite ( 'Context Menu Options Tests' , ( ) => {
78+ // Sample tree structure for testing
79+ let sampleTree : any [ ] ;
80+
81+ setup ( ( ) => {
82+ // Create a sample tree structure before each test
83+ sampleTree = [
84+ {
85+ id : 'root' ,
86+ name : 'root' ,
87+ type : 'folder' ,
88+ checked : false ,
89+ indeterminate : false ,
90+ children : [
91+ {
92+ id : 'folder1' ,
93+ name : 'folder1' ,
94+ type : 'folder' ,
95+ checked : false ,
96+ indeterminate : false ,
97+ children : [
98+ {
99+ id : 'file1' ,
100+ name : 'file1.txt' ,
101+ type : 'file' ,
102+ checked : false
103+ } ,
104+ {
105+ id : 'file2' ,
106+ name : 'file2.txt' ,
107+ type : 'file' ,
108+ checked : false
109+ }
110+ ]
111+ } ,
112+ {
113+ id : 'folder2' ,
114+ name : 'folder2' ,
115+ type : 'folder' ,
116+ checked : false ,
117+ indeterminate : false ,
118+ children : [
119+ {
120+ id : 'file3' ,
121+ name : 'file3.txt' ,
122+ type : 'file' ,
123+ checked : false
124+ }
125+ ]
126+ } ,
127+ {
128+ id : 'file4' ,
129+ name : 'file4.txt' ,
130+ type : 'file' ,
131+ checked : false
132+ }
133+ ]
134+ }
135+ ] ;
136+ } ) ;
137+
138+ test ( 'checkAllChildren sets all nodes to checked' , ( ) => {
139+ const result = checkAllChildren ( sampleTree ) ;
140+
141+ // Check that all nodes are checked
142+ assert . strictEqual ( result [ 0 ] . checked , true , 'Root node should be checked' ) ;
143+ assert . strictEqual ( result [ 0 ] . children ! [ 0 ] . checked , true , 'folder1 should be checked' ) ;
144+ assert . strictEqual ( result [ 0 ] . children ! [ 0 ] . children ! [ 0 ] . checked , true , 'file1 should be checked' ) ;
145+ assert . strictEqual ( result [ 0 ] . children ! [ 0 ] . children ! [ 1 ] . checked , true , 'file2 should be checked' ) ;
146+ assert . strictEqual ( result [ 0 ] . children ! [ 1 ] . checked , true , 'folder2 should be checked' ) ;
147+ assert . strictEqual ( result [ 0 ] . children ! [ 1 ] . children ! [ 0 ] . checked , true , 'file3 should be checked' ) ;
148+ assert . strictEqual ( result [ 0 ] . children ! [ 2 ] . checked , true , 'file4 should be checked' ) ;
149+ } ) ;
150+
151+ test ( 'checkAllFolders sets only folder nodes to checked' , ( ) => {
152+ const result = checkAllFolders ( sampleTree ) ;
153+
154+ // Check that only folder nodes are checked
155+ assert . strictEqual ( result [ 0 ] . checked , true , 'Root node should be checked' ) ;
156+ assert . strictEqual ( result [ 0 ] . children ! [ 0 ] . checked , true , 'folder1 should be checked' ) ;
157+ assert . strictEqual ( result [ 0 ] . children ! [ 0 ] . children ! [ 0 ] . checked , false , 'file1 should not be checked' ) ;
158+ assert . strictEqual ( result [ 0 ] . children ! [ 0 ] . children ! [ 1 ] . checked , false , 'file2 should not be checked' ) ;
159+ assert . strictEqual ( result [ 0 ] . children ! [ 1 ] . checked , true , 'folder2 should be checked' ) ;
160+ assert . strictEqual ( result [ 0 ] . children ! [ 1 ] . children ! [ 0 ] . checked , false , 'file3 should not be checked' ) ;
161+ assert . strictEqual ( result [ 0 ] . children ! [ 2 ] . checked , false , 'file4 should not be checked' ) ;
162+ } ) ;
163+
164+ test ( 'uncheckAllChildren sets all nodes to unchecked' , ( ) => {
165+ // First check all nodes
166+ sampleTree = checkAllChildren ( sampleTree ) ;
167+
168+ // Then uncheck all nodes
169+ const result = uncheckAllChildren ( sampleTree ) ;
170+
171+ // Check that all nodes are unchecked
172+ assert . strictEqual ( result [ 0 ] . checked , false , 'Root node should be unchecked' ) ;
173+ assert . strictEqual ( result [ 0 ] . children ! [ 0 ] . checked , false , 'folder1 should be unchecked' ) ;
174+ assert . strictEqual ( result [ 0 ] . children ! [ 0 ] . children ! [ 0 ] . checked , false , 'file1 should be unchecked' ) ;
175+ assert . strictEqual ( result [ 0 ] . children ! [ 0 ] . children ! [ 1 ] . checked , false , 'file2 should be unchecked' ) ;
176+ assert . strictEqual ( result [ 0 ] . children ! [ 1 ] . checked , false , 'folder2 should be unchecked' ) ;
177+ assert . strictEqual ( result [ 0 ] . children ! [ 1 ] . children ! [ 0 ] . checked , false , 'file3 should be unchecked' ) ;
178+ assert . strictEqual ( result [ 0 ] . children ! [ 2 ] . checked , false , 'file4 should be unchecked' ) ;
179+ } ) ;
180+
181+ test ( 'checkWithoutChildren checks a node without affecting its children' , ( ) => {
182+ // Apply checkWithoutChildren to folder1
183+ const folder1 = sampleTree [ 0 ] . children ! [ 0 ] ;
184+ const result = checkWithoutChildren ( folder1 ) ;
185+
186+ // Check that folder1 is checked but its children are not
187+ assert . strictEqual ( result . checked , true , 'folder1 should be checked' ) ;
188+ assert . strictEqual ( result . children ! [ 0 ] . checked , false , 'file1 should not be checked' ) ;
189+ assert . strictEqual ( result . children ! [ 1 ] . checked , false , 'file2 should not be checked' ) ;
190+ } ) ;
191+
192+ test ( 'checkOnlyFoldersAtLevel checks only folder nodes at a specific level' , ( ) => {
193+ // Apply checkOnlyFoldersAtLevel to root's children
194+ const result = checkOnlyFoldersAtLevel ( sampleTree [ 0 ] . children ! ) ;
195+
196+ // Check that only folder nodes at this level are checked
197+ assert . strictEqual ( result [ 0 ] . checked , true , 'folder1 should be checked' ) ;
198+ assert . strictEqual ( result [ 1 ] . checked , true , 'folder2 should be checked' ) ;
199+ assert . strictEqual ( result [ 2 ] . checked , false , 'file4 should not be checked' ) ;
200+ } ) ;
201+
202+ test ( 'checkOnlyFilesAtLevel checks only file nodes at a specific level' , ( ) => {
203+ // Apply checkOnlyFilesAtLevel to root's children
204+ const result = checkOnlyFilesAtLevel ( sampleTree [ 0 ] . children ! ) ;
205+
206+ // Check that only file nodes at this level are checked
207+ assert . strictEqual ( result [ 0 ] . checked , false , 'folder1 should not be checked' ) ;
208+ assert . strictEqual ( result [ 1 ] . checked , false , 'folder2 should not be checked' ) ;
209+ assert . strictEqual ( result [ 2 ] . checked , true , 'file4 should be checked' ) ;
210+ } ) ;
211+
212+ test ( 'checkAllChildrenAtLevel checks all nodes at a specific level' , ( ) => {
213+ // Apply checkAllChildrenAtLevel to root's children
214+ const result = checkAllChildrenAtLevel ( sampleTree [ 0 ] . children ! ) ;
215+
216+ // Check that all nodes at this level are checked
217+ assert . strictEqual ( result [ 0 ] . checked , true , 'folder1 should be checked' ) ;
218+ assert . strictEqual ( result [ 1 ] . checked , true , 'folder2 should be checked' ) ;
219+ assert . strictEqual ( result [ 2 ] . checked , true , 'file4 should be checked' ) ;
220+ } ) ;
221+ } ) ;
222+ } ) ;
0 commit comments