mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-12-01 00:49:33 +01:00
feat(files): load directories on demand
This commit is contained in:
1 parent
5548c17c4a
commit
349d21f75e
16 files changed
+1681
-78
No files matched your search
@@ -28,6 +28,15 @@ describe('File browser on a phone (issue #759)', () => {
|
||||
await writeFile(join(workspace, 'README.md'), 'Phone browser fixture');
|
||||
await writeFile(join(workspace, '.hidden.txt'), 'Hidden fixture');
|
||||
await writeFile(join(workspace, 'src', 'note.txt'), 'Nested fixture');
|
||||
await mkdir(join(workspace, 'src', 'deep'), { recursive: true });
|
||||
await writeFile(join(workspace, 'src', 'deep', 'needle.ts'), 'Deep fixture');
|
||||
await mkdir(join(workspace, 'bulk'));
|
||||
await mkdir(join(workspace, 'unavailable'));
|
||||
await Promise.all(
|
||||
Array.from({ length: 501 }, (_, index) =>
|
||||
writeFile(join(workspace, 'bulk', `entry-${String(index).padStart(4, '0')}.txt`), 'x')
|
||||
)
|
||||
);
|
||||
server = await createTestServer();
|
||||
baseUrl = `http://localhost:${server.boundPort}`;
|
||||
const response = await fetch(`${baseUrl}/api/sessions`, {
|
||||
@@ -70,16 +79,17 @@ describe('File browser on a phone (issue #759)', () => {
|
||||
});
|
||||
|
||||
async function saveSetting(id: string, checked: boolean) {
|
||||
await page.locator('.btn-settings-mobile').tap();
|
||||
const mobileSettings = page.locator('.btn-settings-mobile');
|
||||
const opener = (await mobileSettings.isVisible()) ? mobileSettings : page.locator('.btn-settings');
|
||||
await opener.click();
|
||||
const control = page.locator(`#${id}`);
|
||||
// The chip's native checkbox is visually hidden; the label is the touch target.
|
||||
if ((await control.isChecked()) !== checked) {
|
||||
await page.locator(`label:has(#${id})`).tap();
|
||||
await page.locator(`label:has(#${id})`).click();
|
||||
}
|
||||
await page
|
||||
.locator('#appSettingsModal .set-head-save')
|
||||
.filter({ hasText: /^Save$/ })
|
||||
.tap();
|
||||
const headSave = page.locator('#appSettingsModal .set-head-save').filter({ hasText: /^Save$/ });
|
||||
const save = (await headSave.isVisible()) ? headSave : page.locator('#appSettingsModal .set-foot .btn-primary');
|
||||
await save.click();
|
||||
await expect.poll(() => page.locator('#appSettingsModal').isVisible()).toBe(false);
|
||||
}
|
||||
|
||||
@@ -166,6 +176,8 @@ describe('File browser on a phone (issue #759)', () => {
|
||||
}
|
||||
|
||||
await panel.locator('#fileBrowserExpandBtn').tap();
|
||||
expect(await tree.locator('[data-path="src/note.txt"]').count()).toBe(0);
|
||||
await tree.locator('[data-path="src"]').tap();
|
||||
await tree.locator('[data-path="src/note.txt"]').waitFor({ state: 'visible' });
|
||||
await panel.locator('#fileBrowserHiddenBtn').tap();
|
||||
await tree.locator('[data-path=".hidden.txt"]').waitFor({ state: 'visible' });
|
||||
@@ -178,4 +190,91 @@ describe('File browser on a phone (issue #759)', () => {
|
||||
await panel.locator('button[title="Close"]').tap();
|
||||
await expect.poll(() => panel.isVisible()).toBe(false);
|
||||
});
|
||||
|
||||
it.each(['phone', 'desktop'])(
|
||||
'loads folders and pages on demand and reveals a workspace-search folder on %s',
|
||||
async (device) => {
|
||||
const activate = (control: Locator) => (device === 'phone' ? control.tap() : control.click());
|
||||
if (device === 'desktop') {
|
||||
await context.close();
|
||||
({ context, page } = await createDevicePage(
|
||||
{
|
||||
...REPRESENTATIVE_DEVICES['standard-phone'],
|
||||
viewport: { width: 1280, height: 900 },
|
||||
deviceScaleFactor: 1,
|
||||
isMobile: false,
|
||||
hasTouch: false,
|
||||
userAgent:
|
||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36',
|
||||
},
|
||||
baseUrl,
|
||||
'chromium'
|
||||
));
|
||||
await page.waitForFunction((id) => (window as any).app?.sessions.has(id), sessionId);
|
||||
await page.evaluate(async (id) => (window as any).app.selectSession(id), sessionId);
|
||||
}
|
||||
// The desktop may restore the panel from synced settings saved by the phone cases.
|
||||
// Start this request-count assertion from an explicit close/open on either device.
|
||||
const panel = page.locator('#fileBrowserPanel');
|
||||
if (await panel.isVisible()) {
|
||||
await activate(panel.locator('button[title="Close"]'));
|
||||
await expect.poll(() => panel.isVisible()).toBe(false);
|
||||
}
|
||||
const requests: URL[] = [];
|
||||
page.on('request', (request) => {
|
||||
const url = new URL(request.url());
|
||||
if (request.method() === 'GET' && url.pathname.endsWith(`/sessions/${sessionId}/files`)) requests.push(url);
|
||||
});
|
||||
await saveSetting('appSettingsShowFileBrowser', true);
|
||||
const tree = panel.locator('#fileBrowserTree');
|
||||
await tree.locator('[data-path="README.md"]').waitFor({ state: 'visible' });
|
||||
expect(requests).toHaveLength(1);
|
||||
expect(requests[0].searchParams.get('lazy')).toBe('1');
|
||||
|
||||
const input = panel.locator('#fileBrowserSearch');
|
||||
await input.fill('deep');
|
||||
await page.waitForTimeout(350); // Outwait the former automatic server-search debounce.
|
||||
expect(requests).toHaveLength(1);
|
||||
await input.press('Enter');
|
||||
await tree.locator('[data-path="src/deep"]').waitFor({ state: 'visible' });
|
||||
expect(requests.at(-1)!.searchParams.get('q')).toBe('deep');
|
||||
await activate(tree.locator('[data-path="src/deep"]'));
|
||||
await tree.locator('[data-path="src/deep/needle.ts"]').waitFor({ state: 'visible' });
|
||||
expect(await input.inputValue()).toBe('');
|
||||
expect(requests.filter((url) => url.searchParams.has('path')).map((url) => url.searchParams.get('path'))).toEqual(
|
||||
['src', 'src/deep']
|
||||
);
|
||||
|
||||
await activate(tree.locator('[data-path="bulk"]'));
|
||||
const more = tree.locator('[data-file-browser-load="more"]');
|
||||
await more.waitFor({ state: 'visible' });
|
||||
if (device === 'phone') await assertTouchTarget(more);
|
||||
expect(await tree.locator('[data-path^="bulk/"][data-type="file"]').count()).toBe(500);
|
||||
await activate(more);
|
||||
await expect.poll(() => tree.locator('[data-path^="bulk/"][data-type="file"]').count()).toBe(501);
|
||||
expect(await more.count()).toBe(0);
|
||||
expect(requests.at(-1)!.searchParams.get('cursor')).toBeTruthy();
|
||||
expect(await tree.locator('[data-path="src/deep/needle.ts"]').isVisible()).toBe(true);
|
||||
|
||||
const unavailable = (url: URL) =>
|
||||
url.pathname.endsWith(`/sessions/${sessionId}/files`) && url.searchParams.get('path') === 'unavailable';
|
||||
await page.route(unavailable, (route) =>
|
||||
route.fulfill({
|
||||
status: 503,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ success: false, error: 'Folder unavailable; retry or refresh files' }),
|
||||
})
|
||||
);
|
||||
await activate(tree.locator('[data-path="unavailable"]'));
|
||||
const retry = tree.locator('[data-file-browser-load="retry"]');
|
||||
await retry.waitFor({ state: 'visible' });
|
||||
await retry.scrollIntoViewIfNeeded();
|
||||
await expectReachable(retry);
|
||||
if (device === 'phone') await assertTouchTarget(retry);
|
||||
await page.unroute(unavailable);
|
||||
await activate(retry);
|
||||
await expect.poll(() => retry.count()).toBe(0);
|
||||
expect(await tree.locator('[data-path="src/deep/needle.ts"]').isVisible()).toBe(true);
|
||||
}
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user