@@ -621,46 +621,72 @@ mod tests {
621621 fn test_text_input_json_includes_id ( ) {
622622 let mut store = HookStore :: default ( ) ;
623623 let mut ctx = BuildContext :: new ( & mut store, None ) ;
624- let input = TextInput :: new ( ) . build ( & mut ctx) ;
625- let json = input. to_json ( ) ;
626- assert_eq ! ( json[ "id" ] , "w-0" ) ;
627- assert_eq ! ( json[ "type" ] , "text_input" ) ;
624+ let mut element: Element = TextInput :: new ( ) . into ( ) ;
625+ element. assign_ids ( & mut ctx) ;
626+ if let Element :: Widget ( ref w) = element {
627+ let json = w. to_json ( ) ;
628+ assert_eq ! ( json[ "id" ] , "w-0" ) ;
629+ assert_eq ! ( json[ "type" ] , "text_input" ) ;
630+ } else {
631+ panic ! ( "Expected Element::Widget" ) ;
632+ }
628633 }
629634
630635 #[ test]
631636 fn test_number_input_json_includes_id ( ) {
632637 let mut store = HookStore :: default ( ) ;
633638 let mut ctx = BuildContext :: new ( & mut store, None ) ;
634- let input = NumberInput :: new ( ) . build ( & mut ctx) ;
635- let json = input. to_json ( ) ;
636- assert_eq ! ( json[ "id" ] , "w-0" ) ;
639+ let mut element: Element = NumberInput :: new ( ) . into ( ) ;
640+ element. assign_ids ( & mut ctx) ;
641+ if let Element :: Widget ( ref w) = element {
642+ let json = w. to_json ( ) ;
643+ assert_eq ! ( json[ "id" ] , "w-0" ) ;
644+ } else {
645+ panic ! ( "Expected Element::Widget" ) ;
646+ }
637647 }
638648
639649 #[ test]
640650 fn test_select_json_includes_id ( ) {
641651 let mut store = HookStore :: default ( ) ;
642652 let mut ctx = BuildContext :: new ( & mut store, None ) ;
643- let select = Select :: new ( vec ! [ ] ) . build ( & mut ctx) ;
644- let json = select. to_json ( ) ;
645- assert_eq ! ( json[ "id" ] , "w-0" ) ;
653+ let mut element: Element = Select :: new ( vec ! [ ] ) . into ( ) ;
654+ element. assign_ids ( & mut ctx) ;
655+ if let Element :: Widget ( ref w) = element {
656+ let json = w. to_json ( ) ;
657+ assert_eq ! ( json[ "id" ] , "w-0" ) ;
658+ } else {
659+ panic ! ( "Expected Element::Widget" ) ;
660+ }
646661 }
647662
648663 #[ test]
649664 fn test_checkbox_json_includes_id ( ) {
650665 let mut store = HookStore :: default ( ) ;
651666 let mut ctx = BuildContext :: new ( & mut store, None ) ;
652- let cb = Checkbox :: new ( false ) . build ( & mut ctx) ;
653- let json = cb. to_json ( ) ;
654- assert_eq ! ( json[ "id" ] , "w-0" ) ;
667+ let mut element: Element = Checkbox :: new ( false ) . into ( ) ;
668+ element. assign_ids ( & mut ctx) ;
669+ if let Element :: Widget ( ref w) = element {
670+ let json = w. to_json ( ) ;
671+ assert_eq ! ( json[ "id" ] , "w-0" ) ;
672+ } else {
673+ panic ! ( "Expected Element::Widget" ) ;
674+ }
655675 }
656676
657677 #[ test]
658678 fn test_widget_ids_are_sequential ( ) {
659679 let mut store = HookStore :: default ( ) ;
660680 let mut ctx = BuildContext :: new ( & mut store, None ) ;
661- let input1 = TextInput :: new ( ) . build ( & mut ctx) ;
662- let input2 = TextInput :: new ( ) . build ( & mut ctx) ;
663- assert_eq ! ( input1. id, Some ( "w-0" . to_string( ) ) ) ;
664- assert_eq ! ( input2. id, Some ( "w-1" . to_string( ) ) ) ;
681+ let mut el1: Element = TextInput :: new ( ) . into ( ) ;
682+ let mut el2: Element = TextInput :: new ( ) . into ( ) ;
683+ el1. assign_ids ( & mut ctx) ;
684+ el2. assign_ids ( & mut ctx) ;
685+ if let ( Element :: Widget ( ref w1) , Element :: Widget ( ref w2) ) = ( & el1, & el2) {
686+ assert_eq ! ( w1. get_id( ) , Some ( "w-0" ) ) ;
687+ assert_eq ! ( w2. get_id( ) , Some ( "w-1" ) ) ;
688+ } else {
689+ panic ! ( "Expected Element::Widget" ) ;
690+ }
665691 }
666692}
0 commit comments