diff --git a/e2e/playwright/file-tree.spec.ts b/e2e/playwright/file-tree.spec.ts index edafbac9c2..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: 1, }, ], sortBy: 'last-modified-desc', @@ -233,7 +232,6 @@ 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 }, ], sortBy: 'last-modified-desc', diff --git a/e2e/playwright/fixtures/homePageFixture.ts b/e2e/playwright/fixtures/homePageFixture.ts index 4987ad1f23..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,15 +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()), ]) projectCardStates.push({ title: title, fileCount, - folderCount, }) } return projectCardStates 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) } }