@@ -214,42 +214,62 @@ describe('collectSelected', () => {
214214 resourceUri : makeUri ( 'logs' , 'loss.tsv' )
215215 }
216216
217- it ( 'should return an empty object if no path items are provided' , ( ) => {
218- expect ( collectSelected ( [ ] ) ) . toStrictEqual ( { } )
217+ it ( 'should return the original item if no other items are selected' , ( ) => {
218+ const selected = collectSelected ( logsPathItem , [ ] )
219+
220+ expect ( selected ) . toStrictEqual ( {
221+ [ dvcDemoPath ] : [ logsPathItem ]
222+ } )
219223 } )
220224
221- it ( 'should return the original item if only one is provided ' , ( ) => {
222- const selected = collectSelected ( [ logsPathItem ] )
225+ it ( 'should return only the invoked item if it is not included in the selected paths ' , ( ) => {
226+ const selected = collectSelected ( lossPathItem , [ accPathItem ] )
223227
224228 expect ( selected ) . toStrictEqual ( {
225- [ dvcDemoPath ] : [ logsPathItem ]
229+ [ dvcDemoPath ] : [ lossPathItem ]
226230 } )
227231 } )
228232
229233 it ( 'should return a root given it is select' , ( ) => {
230- const selected = collectSelected ( [ dvcDemoPath , logsPathItem , accPathItem ] )
234+ const selected = collectSelected ( logsPathItem , [
235+ dvcDemoPath ,
236+ logsPathItem ,
237+ accPathItem
238+ ] )
231239
232240 expect ( selected ) . toStrictEqual ( {
233241 [ dvcDemoPath ] : [ dvcDemoPath ]
234242 } )
235243 } )
236244
237245 it ( 'should return siblings if a parent is not provided' , ( ) => {
238- const selected = collectSelected ( [ accPathItem , lossPathItem ] )
246+ const selected = collectSelected ( lossPathItem , [ accPathItem , lossPathItem ] )
239247
240248 expect ( selected ) . toStrictEqual ( {
241249 [ dvcDemoPath ] : [ accPathItem , lossPathItem ]
242250 } )
243251 } )
244252
245253 it ( 'should exclude all children from the final list' , ( ) => {
246- const selected = collectSelected ( [ lossPathItem , accPathItem , logsPathItem ] )
254+ const selected = collectSelected ( logsPathItem , [
255+ lossPathItem ,
256+ accPathItem ,
257+ logsPathItem
258+ ] )
247259
248260 expect ( selected ) . toStrictEqual ( {
249261 [ dvcDemoPath ] : [ logsPathItem ]
250262 } )
251263 } )
252264
265+ it ( 'should not exclude children from the final list if the invoked item is not in the selected list' , ( ) => {
266+ const selected = collectSelected ( accPathItem , [ lossPathItem , logsPathItem ] )
267+
268+ expect ( selected ) . toStrictEqual ( {
269+ [ dvcDemoPath ] : [ accPathItem ]
270+ } )
271+ } )
272+
253273 it ( 'should return multiple entries when multiple roots are provided' , ( ) => {
254274 const mockOtherRepoItem = {
255275 dvcRoot : __dirname ,
@@ -258,7 +278,7 @@ describe('collectSelected', () => {
258278 resourceUri : Uri . file ( join ( __dirname , 'mock' , 'path' ) )
259279 }
260280
261- const selected = collectSelected ( [
281+ const selected = collectSelected ( logsPathItem , [
262282 mockOtherRepoItem ,
263283 {
264284 dvcRoot : dvcDemoPath ,
@@ -274,4 +294,27 @@ describe('collectSelected', () => {
274294 [ dvcDemoPath ] : [ logsPathItem ]
275295 } )
276296 } )
297+
298+ it ( 'should only return the invoked item if multiple roots are provided but the invoked item is not selected' , ( ) => {
299+ const mockOtherRepoItem = {
300+ dvcRoot : __dirname ,
301+ isDirectory : true ,
302+ isTracked : true ,
303+ resourceUri : Uri . file ( join ( __dirname , 'mock' , 'path' ) )
304+ }
305+
306+ const selected = collectSelected ( logsPathItem , [
307+ mockOtherRepoItem ,
308+ {
309+ dvcRoot : dvcDemoPath ,
310+ isDirectory : false ,
311+ isTracked : true ,
312+ resourceUri : makeUri ( 'logs' , 'acc.tsv' )
313+ }
314+ ] )
315+
316+ expect ( selected ) . toStrictEqual ( {
317+ [ dvcDemoPath ] : [ logsPathItem ]
318+ } )
319+ } )
277320} )
0 commit comments