@@ -308,25 +308,27 @@ suite('InputSelectBlockConverter', () => {
308308 } ) ;
309309
310310 suite ( 'applyChangesToBlock' , ( ) => {
311- test ( 'applies selected value from cell ' , ( ) => {
311+ test ( 'preserves existing metadata (select blocks are readonly) ' , ( ) => {
312312 const block : DeepnoteBlock = {
313313 blockGroup : 'test-group' ,
314314 content : '' ,
315315 id : 'block-123' ,
316316 metadata : {
317317 deepnote_variable_name : 'input_3' ,
318- deepnote_variable_options : [ 'Option A' , 'Option B' ]
318+ deepnote_variable_options : [ 'Option A' , 'Option B' ] ,
319+ deepnote_variable_value : 'Option A'
319320 } ,
320321 sortingKey : 'a0' ,
321322 type : 'input-select'
322323 } ;
324+ // Cell content is ignored since select blocks are readonly
323325 const cell = new NotebookCellData ( NotebookCellKind . Code , '"Option B"' , 'python' ) ;
324326
325327 converter . applyChangesToBlock ( block , cell ) ;
326328
327329 assert . strictEqual ( block . content , '' ) ;
328- assert . strictEqual ( block . metadata ?. deepnote_variable_value , 'Option B' ) ;
329- // Variable name should be preserved
330+ // Value should be preserved from metadata, not parsed from cell
331+ assert . strictEqual ( block . metadata ?. deepnote_variable_value , 'Option A' ) ;
330332 assert . strictEqual ( block . metadata ?. deepnote_variable_name , 'input_3' ) ;
331333 assert . deepStrictEqual ( block . metadata ?. deepnote_variable_options , [ 'Option A' , 'Option B' ] ) ;
332334 } ) ;
@@ -534,34 +536,37 @@ suite('InputCheckboxBlockConverter', () => {
534536 } ) ;
535537
536538 suite ( 'applyChangesToBlock' , ( ) => {
537- test ( 'applies True value from cell ' , ( ) => {
539+ test ( 'preserves existing metadata (checkbox blocks are readonly) ' , ( ) => {
538540 const block : DeepnoteBlock = {
539541 blockGroup : 'test-group' ,
540542 content : '' ,
541543 id : 'block-123' ,
542544 metadata : {
543- deepnote_variable_name : 'checkbox1'
545+ deepnote_variable_name : 'checkbox1' ,
546+ deepnote_variable_value : false
544547 } ,
545548 sortingKey : 'a0' ,
546549 type : 'input-checkbox'
547550 } ;
551+ // Cell content is ignored since checkbox blocks are readonly
548552 const cell = new NotebookCellData ( NotebookCellKind . Code , 'True' , 'python' ) ;
549553
550554 converter . applyChangesToBlock ( block , cell ) ;
551555
552556 assert . strictEqual ( block . content , '' ) ;
553- assert . strictEqual ( block . metadata ?. deepnote_variable_value , true ) ;
554- // Variable name should be preserved
557+ // Value should be preserved from metadata, not parsed from cell
558+ assert . strictEqual ( block . metadata ?. deepnote_variable_value , false ) ;
555559 assert . strictEqual ( block . metadata ?. deepnote_variable_name , 'checkbox1' ) ;
556560 } ) ;
557561
558- test ( 'applies False value' , ( ) => {
562+ test ( 'preserves default value' , ( ) => {
559563 const block : DeepnoteBlock = {
560564 blockGroup : 'test-group' ,
561565 content : '' ,
562566 id : 'block-123' ,
563567 metadata : {
564568 deepnote_variable_name : 'checkbox1' ,
569+ deepnote_variable_value : true ,
565570 deepnote_variable_default_value : true
566571 } ,
567572 sortingKey : 'a0' ,
@@ -571,23 +576,8 @@ suite('InputCheckboxBlockConverter', () => {
571576
572577 converter . applyChangesToBlock ( block , cell ) ;
573578
574- assert . strictEqual ( block . metadata ?. deepnote_variable_value , false ) ;
575- assert . strictEqual ( block . metadata ?. deepnote_variable_default_value , true ) ;
576- } ) ;
577-
578- test ( 'handles lowercase true' , ( ) => {
579- const block : DeepnoteBlock = {
580- blockGroup : 'test-group' ,
581- content : '' ,
582- id : 'block-123' ,
583- sortingKey : 'a0' ,
584- type : 'input-checkbox'
585- } ;
586- const cell = new NotebookCellData ( NotebookCellKind . Code , 'true' , 'python' ) ;
587-
588- converter . applyChangesToBlock ( block , cell ) ;
589-
590579 assert . strictEqual ( block . metadata ?. deepnote_variable_value , true ) ;
580+ assert . strictEqual ( block . metadata ?. deepnote_variable_default_value , true ) ;
591581 } ) ;
592582 } ) ;
593583} ) ;
@@ -638,46 +628,30 @@ suite('InputDateBlockConverter', () => {
638628 } ) ;
639629
640630 suite ( 'applyChangesToBlock' , ( ) => {
641- test ( 'applies date value from cell ' , ( ) => {
631+ test ( 'preserves existing metadata ( date blocks are readonly) ' , ( ) => {
642632 const block : DeepnoteBlock = {
643633 blockGroup : 'test-group' ,
644634 content : '' ,
645635 id : 'block-123' ,
646636 metadata : {
647637 deepnote_variable_name : 'date1' ,
648- deepnote_input_date_version : 2
638+ deepnote_input_date_version : 2 ,
639+ deepnote_variable_value : '2025-01-01T00:00:00.000Z'
649640 } ,
650641 sortingKey : 'a0' ,
651642 type : 'input-date'
652643 } ;
644+ // Cell content is ignored since date blocks are readonly
653645 const cell = new NotebookCellData ( NotebookCellKind . Code , '"2025-12-31T00:00:00.000Z"' , 'python' ) ;
654646
655647 converter . applyChangesToBlock ( block , cell ) ;
656648
657649 assert . strictEqual ( block . content , '' ) ;
658- assert . strictEqual ( block . metadata ?. deepnote_variable_value , '2025-12-31T00:00:00.000Z' ) ;
659- // Other metadata should be preserved
650+ // Value should be preserved from metadata, not parsed from cell
651+ assert . strictEqual ( block . metadata ?. deepnote_variable_value , '2025-01-01T00:00:00.000Z' ) ;
660652 assert . strictEqual ( block . metadata ?. deepnote_variable_name , 'date1' ) ;
661653 assert . strictEqual ( block . metadata ?. deepnote_input_date_version , 2 ) ;
662654 } ) ;
663-
664- test ( 'handles unquoted date value' , ( ) => {
665- const block : DeepnoteBlock = {
666- blockGroup : 'test-group' ,
667- content : '' ,
668- id : 'block-123' ,
669- metadata : {
670- deepnote_variable_name : 'date1'
671- } ,
672- sortingKey : 'a0' ,
673- type : 'input-date'
674- } ;
675- const cell = new NotebookCellData ( NotebookCellKind . Code , '2025-12-31' , 'python' ) ;
676-
677- converter . applyChangesToBlock ( block , cell ) ;
678-
679- assert . strictEqual ( block . metadata ?. deepnote_variable_value , '2025-12-31' ) ;
680- } ) ;
681655 } ) ;
682656} ) ;
683657
@@ -745,66 +719,28 @@ suite('InputDateRangeBlockConverter', () => {
745719 } ) ;
746720
747721 suite ( 'applyChangesToBlock' , ( ) => {
748- test ( 'applies date range tuple from cell ' , ( ) => {
722+ test ( 'preserves existing metadata ( date range blocks are readonly) ' , ( ) => {
749723 const block : DeepnoteBlock = {
750724 blockGroup : 'test-group' ,
751725 content : '' ,
752726 id : 'block-123' ,
753727 metadata : {
754- deepnote_variable_name : 'range1'
728+ deepnote_variable_name : 'range1' ,
729+ deepnote_variable_value : [ '2025-06-01' , '2025-06-30' ]
755730 } ,
756731 sortingKey : 'a0' ,
757732 type : 'input-date-range'
758733 } ;
734+ // Cell content is ignored since date range blocks are readonly
759735 const cell = new NotebookCellData ( NotebookCellKind . Code , '("2025-01-01", "2025-12-31")' , 'python' ) ;
760736
761737 converter . applyChangesToBlock ( block , cell ) ;
762738
763739 assert . strictEqual ( block . content , '' ) ;
764- assert . deepStrictEqual ( block . metadata ?. deepnote_variable_value , [ '2025-01-01' , '2025-12-31' ] ) ;
765- // Variable name should be preserved
740+ // Value should be preserved from metadata, not parsed from cell
741+ assert . deepStrictEqual ( block . metadata ?. deepnote_variable_value , [ '2025-06-01' , '2025-06-30' ] ) ;
766742 assert . strictEqual ( block . metadata ?. deepnote_variable_name , 'range1' ) ;
767743 } ) ;
768-
769- test ( 'handles invalid tuple format' , ( ) => {
770- const block : DeepnoteBlock = {
771- blockGroup : 'test-group' ,
772- content : '' ,
773- id : 'block-123' ,
774- metadata : {
775- deepnote_variable_name : 'range1' ,
776- deepnote_variable_value : [ '2025-01-01' , '2025-12-31' ]
777- } ,
778- sortingKey : 'a0' ,
779- type : 'input-date-range'
780- } ;
781- const cell = new NotebookCellData ( NotebookCellKind . Code , 'invalid' , 'python' ) ;
782-
783- converter . applyChangesToBlock ( block , cell ) ;
784-
785- // Should preserve existing value when parse fails
786- assert . deepStrictEqual ( block . metadata ?. deepnote_variable_value , [ '2025-01-01' , '2025-12-31' ] ) ;
787- } ) ;
788-
789- test ( 'handles empty value' , ( ) => {
790- const block : DeepnoteBlock = {
791- blockGroup : 'test-group' ,
792- content : '' ,
793- id : 'block-123' ,
794- metadata : {
795- deepnote_variable_name : 'range1' ,
796- deepnote_variable_value : [ '2025-01-01' , '2025-12-31' ]
797- } ,
798- sortingKey : 'a0' ,
799- type : 'input-date-range'
800- } ;
801- const cell = new NotebookCellData ( NotebookCellKind . Code , '' , 'python' ) ;
802-
803- converter . applyChangesToBlock ( block , cell ) ;
804-
805- // Should preserve existing value when cell is empty
806- assert . deepStrictEqual ( block . metadata ?. deepnote_variable_value , [ '2025-01-01' , '2025-12-31' ] ) ;
807- } ) ;
808744 } ) ;
809745} ) ;
810746
0 commit comments