@@ -313,4 +313,174 @@ project:
313313 assert . instanceOf ( testManager , DeepnoteNotebookManager ) ;
314314 } ) ;
315315 } ) ;
316+
317+ suite ( 'default notebook selection' , ( ) => {
318+ test ( 'should not select Init notebook when other notebooks are available' , async ( ) => {
319+ const yamlContent = `
320+ version: 1.0
321+ metadata:
322+ createdAt: '2023-01-01T00:00:00Z'
323+ modifiedAt: '2023-01-02T00:00:00Z'
324+ project:
325+ id: 'project-with-init'
326+ name: 'Project with Init'
327+ initNotebookId: 'init-notebook'
328+ notebooks:
329+ - id: 'init-notebook'
330+ name: 'Init'
331+ blocks:
332+ - id: 'block-init'
333+ content: 'print("init")'
334+ sortingKey: 'a0'
335+ type: 'code'
336+ executionMode: 'block'
337+ isModule: false
338+ - id: 'main-notebook'
339+ name: 'Main'
340+ blocks:
341+ - id: 'block-main'
342+ content: 'print("main")'
343+ sortingKey: 'a0'
344+ type: 'code'
345+ executionMode: 'block'
346+ isModule: false
347+ settings: {}
348+ ` ;
349+
350+ const content = new TextEncoder ( ) . encode ( yamlContent ) ;
351+ const result = await serializer . deserializeNotebook ( content , { } as any ) ;
352+
353+ // Should select the Main notebook, not the Init notebook
354+ assert . strictEqual ( result . metadata ?. deepnoteNotebookId , 'main-notebook' ) ;
355+ assert . strictEqual ( result . metadata ?. deepnoteNotebookName , 'Main' ) ;
356+ } ) ;
357+
358+ test ( 'should select Init notebook when it is the only notebook' , async ( ) => {
359+ const yamlContent = `
360+ version: 1.0
361+ metadata:
362+ createdAt: '2023-01-01T00:00:00Z'
363+ modifiedAt: '2023-01-02T00:00:00Z'
364+ project:
365+ id: 'project-only-init'
366+ name: 'Project with only Init'
367+ initNotebookId: 'init-notebook'
368+ notebooks:
369+ - id: 'init-notebook'
370+ name: 'Init'
371+ blocks:
372+ - id: 'block-init'
373+ content: 'print("init")'
374+ sortingKey: 'a0'
375+ type: 'code'
376+ executionMode: 'block'
377+ isModule: false
378+ settings: {}
379+ ` ;
380+
381+ const content = new TextEncoder ( ) . encode ( yamlContent ) ;
382+ const result = await serializer . deserializeNotebook ( content , { } as any ) ;
383+
384+ // Should select the Init notebook since it's the only one
385+ assert . strictEqual ( result . metadata ?. deepnoteNotebookId , 'init-notebook' ) ;
386+ assert . strictEqual ( result . metadata ?. deepnoteNotebookName , 'Init' ) ;
387+ } ) ;
388+
389+ test ( 'should select alphabetically first notebook when no initNotebookId' , async ( ) => {
390+ const yamlContent = `
391+ version: 1.0
392+ metadata:
393+ createdAt: '2023-01-01T00:00:00Z'
394+ modifiedAt: '2023-01-02T00:00:00Z'
395+ project:
396+ id: 'project-alphabetical'
397+ name: 'Project Alphabetical'
398+ notebooks:
399+ - id: 'zebra-notebook'
400+ name: 'Zebra Notebook'
401+ blocks:
402+ - id: 'block-z'
403+ content: 'print("zebra")'
404+ sortingKey: 'a0'
405+ type: 'code'
406+ executionMode: 'block'
407+ isModule: false
408+ - id: 'alpha-notebook'
409+ name: 'Alpha Notebook'
410+ blocks:
411+ - id: 'block-a'
412+ content: 'print("alpha")'
413+ sortingKey: 'a0'
414+ type: 'code'
415+ executionMode: 'block'
416+ isModule: false
417+ - id: 'bravo-notebook'
418+ name: 'Bravo Notebook'
419+ blocks:
420+ - id: 'block-b'
421+ content: 'print("bravo")'
422+ sortingKey: 'a0'
423+ type: 'code'
424+ executionMode: 'block'
425+ isModule: false
426+ settings: {}
427+ ` ;
428+
429+ const content = new TextEncoder ( ) . encode ( yamlContent ) ;
430+ const result = await serializer . deserializeNotebook ( content , { } as any ) ;
431+
432+ // Should select the alphabetically first notebook
433+ assert . strictEqual ( result . metadata ?. deepnoteNotebookId , 'alpha-notebook' ) ;
434+ assert . strictEqual ( result . metadata ?. deepnoteNotebookName , 'Alpha Notebook' ) ;
435+ } ) ;
436+
437+ test ( 'should sort Init notebook last when multiple notebooks exist' , async ( ) => {
438+ const yamlContent = `
439+ version: 1.0
440+ metadata:
441+ createdAt: '2023-01-01T00:00:00Z'
442+ modifiedAt: '2023-01-02T00:00:00Z'
443+ project:
444+ id: 'project-multiple'
445+ name: 'Project with Multiple'
446+ initNotebookId: 'init-notebook'
447+ notebooks:
448+ - id: 'charlie-notebook'
449+ name: 'Charlie'
450+ blocks:
451+ - id: 'block-c'
452+ content: 'print("charlie")'
453+ sortingKey: 'a0'
454+ type: 'code'
455+ executionMode: 'block'
456+ isModule: false
457+ - id: 'init-notebook'
458+ name: 'Init'
459+ blocks:
460+ - id: 'block-init'
461+ content: 'print("init")'
462+ sortingKey: 'a0'
463+ type: 'code'
464+ executionMode: 'block'
465+ isModule: false
466+ - id: 'alpha-notebook'
467+ name: 'Alpha'
468+ blocks:
469+ - id: 'block-a'
470+ content: 'print("alpha")'
471+ sortingKey: 'a0'
472+ type: 'code'
473+ executionMode: 'block'
474+ isModule: false
475+ settings: {}
476+ ` ;
477+
478+ const content = new TextEncoder ( ) . encode ( yamlContent ) ;
479+ const result = await serializer . deserializeNotebook ( content , { } as any ) ;
480+
481+ // Should select Alpha, not Init even though "Init" comes before "Alpha" alphabetically when in upper case
482+ assert . strictEqual ( result . metadata ?. deepnoteNotebookId , 'alpha-notebook' ) ;
483+ assert . strictEqual ( result . metadata ?. deepnoteNotebookName , 'Alpha' ) ;
484+ } ) ;
485+ } ) ;
316486} ) ;
0 commit comments