Skip to content

Commit 05dda1b

Browse files
committed
fix dumb tests.
1 parent 595d867 commit 05dda1b

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/notebooks/deepnote/deepnoteTreeDataProvider.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ import { DeepnoteTreeItem, DeepnoteTreeItemType, DeepnoteTreeItemContext } from
1717
import type { DeepnoteProject, DeepnoteNotebook } from '../../platform/deepnote/deepnoteTypes';
1818
import { readDeepnoteProjectFile } from './deepnoteProjectUtils';
1919

20+
/**
21+
* Comparator function for sorting tree items alphabetically by label (case-insensitive)
22+
*/
23+
export function compareTreeItemsByLabel(a: DeepnoteTreeItem, b: DeepnoteTreeItem): number {
24+
const labelA = typeof a.label === 'string' ? a.label : '';
25+
const labelB = typeof b.label === 'string' ? b.label : '';
26+
return labelA.toLowerCase().localeCompare(labelB.toLowerCase());
27+
}
28+
2029
/**
2130
* Tree data provider for the Deepnote explorer view.
2231
* Manages the tree structure displaying Deepnote project files and their notebooks.
@@ -230,11 +239,7 @@ export class DeepnoteTreeDataProvider implements TreeDataProvider<DeepnoteTreeIt
230239
}
231240

232241
// Sort projects alphabetically by name (case-insensitive)
233-
deepnoteFiles.sort((a, b) => {
234-
const labelA = typeof a.label === 'string' ? a.label : '';
235-
const labelB = typeof b.label === 'string' ? b.label : '';
236-
return labelA.toLowerCase().localeCompare(labelB.toLowerCase());
237-
});
242+
deepnoteFiles.sort(compareTreeItemsByLabel);
238243

239244
return deepnoteFiles;
240245
}

src/notebooks/deepnote/deepnoteTreeDataProvider.unit.test.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { assert } from 'chai';
22
import { l10n } from 'vscode';
33

4-
import { DeepnoteTreeDataProvider } from './deepnoteTreeDataProvider';
4+
import { DeepnoteTreeDataProvider, compareTreeItemsByLabel } from './deepnoteTreeDataProvider';
55
import { DeepnoteTreeItem, DeepnoteTreeItemType } from './deepnoteTreeItem';
66
import type { DeepnoteProject } from '../../platform/deepnote/deepnoteTypes';
77

@@ -338,9 +338,8 @@ suite('DeepnoteTreeDataProvider', () => {
338338
});
339339

340340
suite('alphabetical sorting', () => {
341-
test('should sort projects alphabetically by name', async () => {
342-
// Note: This test verifies the concept, but actual sorting happens in getDeepnoteProjectFiles()
343-
// which scans the workspace. For now, we verify the tree items can be sorted.
341+
test('compareTreeItemsByLabel should sort items alphabetically (case-insensitive)', () => {
342+
// Test the comparator function in isolation
344343
const mockProjects: DeepnoteProject[] = [
345344
{
346345
metadata: {
@@ -383,7 +382,7 @@ suite('DeepnoteTreeDataProvider', () => {
383382
}
384383
];
385384

386-
// Create tree items
385+
// Create tree items in unsorted order
387386
const treeItems = mockProjects.map(
388387
(project) =>
389388
new DeepnoteTreeItem(
@@ -397,16 +396,13 @@ suite('DeepnoteTreeDataProvider', () => {
397396
)
398397
);
399398

400-
// Before sorting
399+
// Verify items are initially unsorted
401400
assert.strictEqual(treeItems[0].label, 'Zebra Project');
402401

403-
// Verify that sorting would work
404-
const sortedItems = [...treeItems].sort((a, b) => {
405-
const labelA = typeof a.label === 'string' ? a.label : '';
406-
const labelB = typeof b.label === 'string' ? b.label : '';
407-
return labelA.toLowerCase().localeCompare(labelB.toLowerCase());
408-
});
402+
// Sort using the exported comparator
403+
const sortedItems = [...treeItems].sort(compareTreeItemsByLabel);
409404

405+
// Verify alphabetical order
410406
assert.strictEqual(sortedItems[0].label, 'Apple Project');
411407
assert.strictEqual(sortedItems[1].label, 'Middle Project');
412408
assert.strictEqual(sortedItems[2].label, 'Zebra Project');

0 commit comments

Comments
 (0)