@@ -139,6 +139,7 @@ test("resolves directory autocomplete from the current browser root", async () = |
139 | 139 | directories.push(input.location?.directory ?? "") |
140 | 140 | return Promise.resolve({ data: [] }) |
141 | 141 | }, |
| 142 | + list: () => Promise.resolve({ data: [] }), |
142 | 143 | }, |
143 | 144 | }, |
144 | 145 | } as unknown as Parameters<typeof createDirectorySearch>[0]["sdk"] |
@@ -152,6 +153,70 @@ test("resolves directory autocomplete from the current browser root", async () = |
152 | 153 | expect(directories).toEqual(["/repo", "/repo/src"]) |
153 | 154 | }) |
154 | 155 |
|
| 156 | +test("keeps indexed directory results for servers that support empty search", async () => { |
| 157 | + const sdk = { |
| 158 | + api: { |
| 159 | + file: { |
| 160 | + find: () => Promise.resolve({ data: [{ path: "projects/", type: "directory" }] }), |
| 161 | + list: () => Promise.reject(new Error("listing should not run when search returns results")), |
| 162 | + }, |
| 163 | + }, |
| 164 | + } as unknown as Parameters<typeof createDirectorySearch>[0]["sdk"] |
| 165 | + const search = createDirectorySearch({ sdk, home: () => "/home/luke", base: () => "/home/luke" }) |
| 166 | + |
| 167 | + expect(await search("")).toEqual(["/home/luke/projects"]) |
| 168 | +}) |
| 169 | + |
| 170 | +test("lists the default directory when empty search is unsupported", async () => { |
| 171 | + const calls: string[] = [] |
| 172 | + const directories = Array.from({ length: 60 }, (_, index) => ({ |
| 173 | + path: `project-${index}/`, |
| 174 | + type: "directory" as const, |
| 175 | + })) |
| 176 | + const sdk = { |
| 177 | + api: { |
| 178 | + file: { |
| 179 | + find: () => Promise.resolve({ data: [] }), |
| 180 | + list: (input: { location?: { directory?: string } }) => { |
| 181 | + calls.push(input.location?.directory ?? "") |
| 182 | + return Promise.resolve({ |
| 183 | + data: [ |
| 184 | + ...directories, |
| 185 | + { path: "README.md", type: "file" }, |
| 186 | + ], |
| 187 | + }) |
| 188 | + }, |
| 189 | + }, |
| 190 | + }, |
| 191 | + } as unknown as Parameters<typeof createDirectorySearch>[0]["sdk"] |
| 192 | + const search = createDirectorySearch({ sdk, home: () => "/home/luke", base: () => "/home/luke" }) |
| 193 | + |
| 194 | + const results = await search("") |
| 195 | + expect(results).toHaveLength(60) |
| 196 | + expect(results.at(-1)).toBe("/home/luke/project-59") |
| 197 | + expect(calls).toEqual(["/home/luke"]) |
| 198 | +}) |
| 199 | + |
| 200 | +test("matches the default directory listing when typed search is unsupported", async () => { |
| 201 | + const sdk = { |
| 202 | + api: { |
| 203 | + file: { |
| 204 | + find: () => Promise.resolve({ data: [] }), |
| 205 | + list: () => |
| 206 | + Promise.resolve({ |
| 207 | + data: [ |
| 208 | + { path: "Documents/", type: "directory" }, |
| 209 | + { path: "Downloads/", type: "directory" }, |
| 210 | + ], |
| 211 | + }), |
| 212 | + }, |
| 213 | + }, |
| 214 | + } as unknown as Parameters<typeof createDirectorySearch>[0]["sdk"] |
| 215 | + const search = createDirectorySearch({ sdk, home: () => "/home/luke", base: () => "/home/luke" }) |
| 216 | + |
| 217 | + expect(await search("documents")).toEqual(["/home/luke/Documents"]) |
| 218 | +}) |
| 219 | + |
155 | 220 | test("searches from an absolute root without a default base", async () => { |
156 | 221 | const directories: string[] = [] |
157 | 222 | const sdk = { |
|