From 976595a73d6c4628f0218525047d56c38e5580fd Mon Sep 17 00:00:00 2001 From: Tom Pridham Date: Sat, 23 Nov 2024 12:00:31 -0700 Subject: [PATCH 1/4] fix: only count something as a directory if it has children --- src/lib/desktop.test.ts | 25 +++++++++++++++++++++++-- src/lib/desktop.ts | 5 ++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/lib/desktop.test.ts b/src/lib/desktop.test.ts index 922cfbf827..5edcdf894a 100644 --- a/src/lib/desktop.test.ts +++ b/src/lib/desktop.test.ts @@ -46,9 +46,21 @@ describe('desktop utilities', () => { 'project-without-kcl-files', 'another-valid-project', ], - '/test/projects/valid-project': ['file1.kcl', 'file2.stp'], + '/test/projects/valid-project': [ + 'file1.kcl', + 'file2.stp', + 'file3.kcl', + 'directory1', + ], + '/test/projects/valid-project/directory1': [], '/test/projects/project-without-kcl-files': ['file3.glb'], - '/test/projects/another-valid-project': ['file4.kcl'], + '/test/projects/another-valid-project': [ + 'file4.kcl', + 'directory2', + 'directory3', + ], + '/test/projects/another-valid-project/directory2': [], + '/test/projects/another-valid-project/directory3': [], } beforeEach(() => { @@ -119,6 +131,15 @@ describe('desktop utilities', () => { ) }) + it('correctly counts directories and files', async () => { + const projects = await listProjects(mockConfig) + // Verify that directories and files are counted correctly + expect(projects[0].directory_count).toEqual(1) + expect(projects[0].kcl_file_count).toEqual(2) + expect(projects[1].directory_count).toEqual(2) + expect(projects[1].kcl_file_count).toEqual(1) + }) + it('handles empty project directory', async () => { // Adjust mockFileSystem to simulate empty directory mockFileSystem['/test/projects'] = [] diff --git a/src/lib/desktop.ts b/src/lib/desktop.ts index 035f2ca81e..b9f8b971e8 100644 --- a/src/lib/desktop.ts +++ b/src/lib/desktop.ts @@ -307,7 +307,10 @@ const directoryCount = (file: FileEntry) => { let count = 0 if (file.children) { for (let entry of file.children) { - count += 1 + // We only want to count FileEntries with children, e.g. folders + if (entry.children !== null) { + count += 1 + } directoryCount(entry) } } From 58df5766271d808d5d32a1831e3165ff849c0fcc Mon Sep 17 00:00:00 2001 From: Tom Pridham Date: Wed, 27 Nov 2024 14:54:19 -0700 Subject: [PATCH 2/4] fix: playwright tests --- e2e/playwright/file-tree.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/playwright/file-tree.spec.ts b/e2e/playwright/file-tree.spec.ts index edafbac9c2..b62fe96d5a 100644 --- a/e2e/playwright/file-tree.spec.ts +++ b/e2e/playwright/file-tree.spec.ts @@ -45,7 +45,7 @@ test.describe('integrations tests', () => { { title: 'test-sample', fileCount: 1, - folderCount: 1, + folderCount: 0, }, ], sortBy: 'last-modified-desc', @@ -233,7 +233,7 @@ test.describe('when using the file tree to', () => { { title: projectName, fileCount: 2, - folderCount: 2, // TODO: This is a pre-existing bug, there are no folders within the project + folderCount: 0, }, ], sortBy: 'last-modified-desc', From 9a0f27fb9474d97bcdbbe64254bf70e16d9ff8b8 Mon Sep 17 00:00:00 2001 From: Tom Pridham Date: Wed, 27 Nov 2024 21:47:59 -0700 Subject: [PATCH 3/4] fix: return 0 if you cant find the projectfolder --- e2e/playwright/fixtures/homePageFixture.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/e2e/playwright/fixtures/homePageFixture.ts b/e2e/playwright/fixtures/homePageFixture.ts index 4987ad1f23..1c86fe2207 100644 --- a/e2e/playwright/fixtures/homePageFixture.ts +++ b/e2e/playwright/fixtures/homePageFixture.ts @@ -64,7 +64,12 @@ export class HomePageFixture { const [title, fileCount, folderCount] = await Promise.all([ (await projectCard.locator(this.projectCardTitle).textContent()) || '', Number(await projectCard.locator(this.projectCardFile).textContent()), - Number(await projectCard.locator(this.projectCardFolder).textContent()), + Number( + (await projectCard + .locator(this.projectCardFolder) + .textContent() + .catch(() => 0)) + ), ]) projectCardStates.push({ title: title, From 5d41e9fc3963175e27ac6b84fd8909f90090e82c Mon Sep 17 00:00:00 2001 From: Tom Pridham Date: Mon, 2 Dec 2024 09:51:50 -0700 Subject: [PATCH 4/4] fix: remove folder count from e2e tests since it is unused currently --- e2e/playwright/file-tree.spec.ts | 2 -- e2e/playwright/fixtures/homePageFixture.ts | 10 +--------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/e2e/playwright/file-tree.spec.ts b/e2e/playwright/file-tree.spec.ts index b62fe96d5a..923273804f 100644 --- a/e2e/playwright/file-tree.spec.ts +++ b/e2e/playwright/file-tree.spec.ts @@ -45,7 +45,6 @@ test.describe('integrations tests', () => { { title: 'test-sample', fileCount: 1, - folderCount: 0, }, ], sortBy: 'last-modified-desc', @@ -233,7 +232,6 @@ test.describe('when using the file tree to', () => { { title: projectName, fileCount: 2, - folderCount: 0, }, ], sortBy: 'last-modified-desc', diff --git a/e2e/playwright/fixtures/homePageFixture.ts b/e2e/playwright/fixtures/homePageFixture.ts index 1c86fe2207..a5d444f81f 100644 --- a/e2e/playwright/fixtures/homePageFixture.ts +++ b/e2e/playwright/fixtures/homePageFixture.ts @@ -4,7 +4,6 @@ import { expect } from '@playwright/test' interface ProjectCardState { title: string fileCount: number - folderCount: number } interface HomePageState { @@ -61,20 +60,13 @@ export class HomePageFixture { const projectCards = await this.projectCard.all() const projectCardStates: Array = [] for (const projectCard of projectCards) { - const [title, fileCount, folderCount] = await Promise.all([ + const [title, fileCount] = await Promise.all([ (await projectCard.locator(this.projectCardTitle).textContent()) || '', Number(await projectCard.locator(this.projectCardFile).textContent()), - Number( - (await projectCard - .locator(this.projectCardFolder) - .textContent() - .catch(() => 0)) - ), ]) projectCardStates.push({ title: title, fileCount, - folderCount, }) } return projectCardStates