|
1 | 1 | import { describe, expect, test } from 'bun:test'; |
2 | 2 | import { JSDOM } from 'jsdom'; |
3 | 3 |
|
4 | | -import { prepareFileTreeInput } from '../src/index'; |
| 4 | +import { |
| 5 | + prepareFileTreeInput, |
| 6 | + preparePresortedFileTreeInput, |
| 7 | +} from '../src/index'; |
5 | 8 | import { flushDom, installDom } from './helpers/dom'; |
6 | 9 | import { loadFileTree, loadFileTreeController } from './helpers/loadFileTree'; |
7 | 10 |
|
@@ -141,6 +144,61 @@ describe('file-tree dynamic files / mutation API', () => { |
141 | 144 | controller.destroy(); |
142 | 145 | }); |
143 | 146 |
|
| 147 | + test('resetPaths accepts a preparedInput-only call with no raw paths', async () => { |
| 148 | + const FileTreeController = await loadFileTreeController(); |
| 149 | + |
| 150 | + // Server-canonical (already sorted) folder paths, the scale-oriented input |
| 151 | + // that preparePresortedFileTreeInput exists to fast-path. |
| 152 | + const folderPaths = ['src/', 'src/index.ts', 'README.md'] as const; |
| 153 | + const controller = new FileTreeController({ |
| 154 | + flattenEmptyDirectories: false, |
| 155 | + initialExpansion: 'open', |
| 156 | + paths: ['README.md'], |
| 157 | + }); |
| 158 | + |
| 159 | + // The preparedInput-only overload: no dummy `paths` argument required. |
| 160 | + controller.resetPaths({ |
| 161 | + preparedInput: preparePresortedFileTreeInput([...folderPaths]), |
| 162 | + }); |
| 163 | + |
| 164 | + expect(controller.getVisibleRows(0, 3).map((row) => row.path)).toEqual([ |
| 165 | + 'src/', |
| 166 | + 'src/index.ts', |
| 167 | + 'README.md', |
| 168 | + ]); |
| 169 | + |
| 170 | + controller.destroy(); |
| 171 | + }); |
| 172 | + |
| 173 | + test('resetPaths overloads type-check as documented (compile-only assertions)', async () => { |
| 174 | + const FileTreeController = await loadFileTreeController(); |
| 175 | + |
| 176 | + const controller = new FileTreeController({ |
| 177 | + flattenEmptyDirectories: false, |
| 178 | + initialExpansion: 'open', |
| 179 | + paths: ['README.md'], |
| 180 | + }); |
| 181 | + |
| 182 | + const assertOverloadTyping = (): void => { |
| 183 | + // Passing only preparedInput type-checks: `paths` is no longer required. |
| 184 | + controller.resetPaths({ |
| 185 | + preparedInput: prepareFileTreeInput(['README.md']), |
| 186 | + }); |
| 187 | + |
| 188 | + // Passing only raw paths still type-checks. |
| 189 | + controller.resetPaths(['README.md']); |
| 190 | + |
| 191 | + // @ts-expect-error neither paths nor preparedInput is supplied |
| 192 | + controller.resetPaths({}); |
| 193 | + |
| 194 | + // @ts-expect-error neither paths nor preparedInput is supplied |
| 195 | + controller.resetPaths(); |
| 196 | + }; |
| 197 | + void assertOverloadTyping; |
| 198 | + |
| 199 | + controller.destroy(); |
| 200 | + }); |
| 201 | + |
144 | 202 | test('typed onMutation listeners stay filtered while subscribe still tracks non-mutation rerenders', async () => { |
145 | 203 | const FileTreeController = await loadFileTreeController(); |
146 | 204 |
|
|
0 commit comments