@@ -100,6 +100,50 @@ describe("Select2", function () {
100100 expect ( select2 . options . ajax . url ) . toEqual ( "select2-users-vocabulary" ) ;
101101 } ) ;
102102
103+ it ( "renders the preset value of a single-select input widget" , async function ( ) {
104+ document . body . innerHTML = `
105+ <input class="pat-select2"
106+ value="Europe/Vienna"
107+ data-pat-select2='{
108+ "multiple": false,
109+ "allowNewItems": "false",
110+ "vocabularyUrl": "select2-timezone-vocabulary"
111+ }'
112+ />
113+ ` ;
114+
115+ registry . scan ( document . body ) ;
116+ await utils . timeout ( 1 ) ;
117+
118+ const el = document . querySelector ( "input.pat-select2" ) ;
119+ expect ( $ ( el ) . select2 ( "data" ) ) . toEqual ( {
120+ id : "Europe/Vienna" ,
121+ text : "Europe/Vienna" ,
122+ } ) ;
123+ expect ( $ ( el ) . parent ( ) . find ( ".select2-chosen" ) . text ( ) ) . toEqual ( "Europe/Vienna" ) ;
124+ } ) ;
125+
126+ it ( "renders the preset value of a single-select select widget" , async function ( ) {
127+ document . body . innerHTML = `
128+ <select class="pat-select2">
129+ <option value="Europe/Paris">Europe/Paris</option>
130+ <option value="Europe/Vienna" selected>Europe/Vienna</option>
131+ </select>
132+ ` ;
133+
134+ registry . scan ( document . body ) ;
135+ await utils . timeout ( 1 ) ;
136+
137+ const el = document . querySelector ( "select.pat-select2" ) ;
138+ // For a native <select>, select2 v3 attaches extra metadata to the
139+ // data object (element, disabled, locked, ...), so match a subset.
140+ expect ( $ ( el ) . select2 ( "data" ) ) . toMatchObject ( {
141+ id : "Europe/Vienna" ,
142+ text : "Europe/Vienna" ,
143+ } ) ;
144+ expect ( $ ( el ) . parent ( ) . find ( ".select2-chosen" ) . text ( ) ) . toEqual ( "Europe/Vienna" ) ;
145+ } ) ;
146+
103147 it ( "displays the vocabulary when clicking an empty checkbox" , async function ( ) {
104148 document . body . innerHTML = `
105149 <input type="hidden"
0 commit comments