|
1 | | -import { basename, join } from 'path' |
| 1 | +import { basename, join, resolve } from 'path' |
2 | 2 | import { commands, EventEmitter, TreeItem, Uri, window } from 'vscode' |
3 | 3 | import { Disposable, Disposer } from '@hediet/std/disposable' |
4 | 4 | import { exists, isDirectory } from '.' |
5 | 5 | import { TrackedExplorerTree } from './tree' |
| 6 | +import { getWorkspaceFolders } from '../vscode/workspaceFolders' |
6 | 7 | import { InternalCommands } from '../commands/internal' |
7 | 8 | import { RegisteredCommands } from '../commands/external' |
8 | 9 | import { OutputChannel } from '../vscode/outputChannel' |
@@ -44,10 +45,13 @@ const mockedInternalCommands = new InternalCommands({ |
44 | 45 | const mockedExists = jest.mocked(exists) |
45 | 46 | const mockedIsDirectory = jest.mocked(isDirectory) |
46 | 47 |
|
| 48 | +const mockedGetWorkspaceFolders = jest.mocked(getWorkspaceFolders) |
| 49 | + |
47 | 50 | jest.mock('vscode') |
48 | 51 | jest.mock('@hediet/std/disposable') |
49 | 52 | jest.mock('.') |
50 | 53 | jest.mock('../cli/reader') |
| 54 | +jest.mock('../vscode/workspaceFolders') |
51 | 55 |
|
52 | 56 | beforeEach(() => { |
53 | 57 | jest.resetAllMocks() |
@@ -102,8 +106,33 @@ describe('TrackedTreeView', () => { |
102 | 106 | expect(mockedGetChildren).toBeCalledTimes(0) |
103 | 107 | }) |
104 | 108 |
|
| 109 | + it('should return the single dvc root if it is nested', async () => { |
| 110 | + const mockedDvcRoots = [dvcDemoPath] |
| 111 | + mockedGetWorkspaceFolders.mockReturnValueOnce([ |
| 112 | + resolve(dvcDemoPath, '..') |
| 113 | + ]) |
| 114 | + |
| 115 | + const trackedTreeView = new TrackedExplorerTree( |
| 116 | + mockedInternalCommands, |
| 117 | + mockedRepositories |
| 118 | + ) |
| 119 | + trackedTreeView.initialize(mockedDvcRoots) |
| 120 | + |
| 121 | + const rootElements = await trackedTreeView.getChildren() |
| 122 | + |
| 123 | + expect(rootElements).toStrictEqual([ |
| 124 | + { |
| 125 | + dvcRoot: dvcDemoPath, |
| 126 | + isDirectory: true, |
| 127 | + isTracked: true, |
| 128 | + resourceUri: Uri.file(dvcDemoPath) |
| 129 | + } |
| 130 | + ]) |
| 131 | + }) |
| 132 | + |
105 | 133 | it('should return directories first in the list of root items', async () => { |
106 | 134 | const mockedDvcRoots = [dvcDemoPath] |
| 135 | + mockedGetWorkspaceFolders.mockReturnValueOnce(mockedDvcRoots) |
107 | 136 |
|
108 | 137 | const trackedTreeView = new TrackedExplorerTree( |
109 | 138 | mockedInternalCommands, |
@@ -150,6 +179,7 @@ describe('TrackedTreeView', () => { |
150 | 179 |
|
151 | 180 | it('should get the children for the provided element', async () => { |
152 | 181 | const data = Uri.file(join(dvcDemoPath, 'data')) |
| 182 | + mockedGetWorkspaceFolders.mockReturnValueOnce([dvcDemoPath]) |
153 | 183 |
|
154 | 184 | const trackedTreeView = new TrackedExplorerTree( |
155 | 185 | mockedInternalCommands, |
|
0 commit comments