@@ -903,3 +903,103 @@ describe("element_uuid", function () {
903
903
window . crypto . randomUUID = orig_randomUUID ;
904
904
} ) ;
905
905
} ) ;
906
+
907
+ describe ( "find_form" , function ( ) {
908
+ it ( "example 1" , function ( ) {
909
+ document . body . innerHTML = `
910
+ <form>
911
+ <div id="start"></div>
912
+ </form>
913
+ ` ;
914
+ const el = document . querySelector ( "#start" ) ;
915
+ const form = document . querySelector ( "form" ) ;
916
+ expect ( dom . find_form ( el ) ) . toBe ( form ) ;
917
+ } ) ;
918
+
919
+ it ( "example 2" , function ( ) {
920
+ document . body . innerHTML = `
921
+ <form>
922
+ <input>
923
+ </form>
924
+ ` ;
925
+ const el = document . querySelector ( "input" ) ;
926
+ const form = document . querySelector ( "form" ) ;
927
+ expect ( dom . find_form ( el ) ) . toBe ( form ) ;
928
+ } ) ;
929
+
930
+ it ( "example 3" , function ( ) {
931
+ document . body . innerHTML = `
932
+ <form id="the-form">
933
+ </form>
934
+ <input form="the-form">
935
+ ` ;
936
+ const el = document . querySelector ( "input" ) ;
937
+ const form = document . querySelector ( "#the-form" ) ;
938
+ expect ( dom . find_form ( el ) ) . toBe ( form ) ;
939
+ } ) ;
940
+
941
+ it ( "example 4" , function ( ) {
942
+ document . body . innerHTML = `
943
+ <form id="the-form">
944
+ </form>
945
+ <form id="other-form">
946
+ <input form="the-form">
947
+ </form>
948
+ ` ;
949
+ const el = document . querySelector ( "input" ) ;
950
+ const form = document . querySelector ( "#the-form" ) ;
951
+ expect ( dom . find_form ( el ) ) . toBe ( form ) ;
952
+ } ) ;
953
+
954
+ it ( "example 5" , function ( ) {
955
+ document . body . innerHTML = `
956
+ <form id="the-form">
957
+ </form>
958
+ <form id="other-form">
959
+ <input form="the-form">
960
+ </form>
961
+ ` ;
962
+ const el = document . querySelector ( "#other-form" ) ;
963
+ const form = document . querySelector ( "#the-form" ) ;
964
+ expect ( dom . find_form ( el ) ) . toBe ( form ) ;
965
+ } ) ;
966
+
967
+ it ( "example 6" , function ( ) {
968
+ document . body . innerHTML = `
969
+ <form id="the-form">
970
+ </form>
971
+ <form id="other-form">
972
+ <select form="the-form"></select>
973
+ </form>
974
+ ` ;
975
+ const el = document . querySelector ( "#other-form" ) ;
976
+ const form = document . querySelector ( "#the-form" ) ;
977
+ expect ( dom . find_form ( el ) ) . toBe ( form ) ;
978
+ } ) ;
979
+
980
+ it ( "example 7" , function ( ) {
981
+ document . body . innerHTML = `
982
+ <form id="the-form">
983
+ </form>
984
+ <form id="other-form">
985
+ <textarea form="the-form"></textarea>
986
+ </form>
987
+ ` ;
988
+ const el = document . querySelector ( "#other-form" ) ;
989
+ const form = document . querySelector ( "#the-form" ) ;
990
+ expect ( dom . find_form ( el ) ) . toBe ( form ) ;
991
+ } ) ;
992
+
993
+ it ( "example 8" , function ( ) {
994
+ document . body . innerHTML = `
995
+ <form id="the-form">
996
+ </form>
997
+ <form id="other-form">
998
+ <button form="the-form"></button>
999
+ </form>
1000
+ ` ;
1001
+ const el = document . querySelector ( "#other-form" ) ;
1002
+ const form = document . querySelector ( "#the-form" ) ;
1003
+ expect ( dom . find_form ( el ) ) . toBe ( form ) ;
1004
+ } ) ;
1005
+ } ) ;
0 commit comments