11import Toolbar from "../../src/Toolbar.js" ;
22import ToolbarSelect from "../../src/ToolbarSelect.js" ;
33import ToolbarSelectOption from "../../src/ToolbarSelectOption.js" ;
4+ import Button from "../../src/Button.js" ;
45
56describe ( "Toolbar general interaction" , ( ) => {
67 it ( "Should render the select with the correct attributes" , ( ) => {
@@ -264,10 +265,10 @@ describe("Toolbar general interaction", () => {
264265 cy . mount (
265266 < Toolbar id = "otb_d" >
266267 < ToolbarSelect style = "width: 201px;" id = "toolbar-select" >
267- < ToolbarSelectOption > 1</ ToolbarSelectOption >
268- < ToolbarSelectOption selected > 2</ ToolbarSelectOption >
269- < ToolbarSelectOption > 3</ ToolbarSelectOption >
270- </ ToolbarSelect >
268+ < ToolbarSelectOption > 1</ ToolbarSelectOption >
269+ < ToolbarSelectOption selected > 2</ ToolbarSelectOption >
270+ < ToolbarSelectOption > 3</ ToolbarSelectOption >
271+ </ ToolbarSelect >
271272 </ Toolbar >
272273 ) ;
273274 cy . viewport ( 220 , 1080 ) ; // Set a small viewport width to trigger overflow
@@ -282,4 +283,65 @@ describe("Toolbar general interaction", () => {
282283 // Verify the toolbar-select is rendered inside the popover
283284 cy . get ( "ui5-toolbar-select" ) . should ( "be.visible" ) ;
284285 } ) ;
286+
287+ it ( "Should update selection when option's selected property is changed programmatically" , ( ) => {
288+ cy . mount (
289+ < >
290+ < Toolbar >
291+ < ToolbarSelect >
292+ < ToolbarSelectOption > 1</ ToolbarSelectOption >
293+ < ToolbarSelectOption id = "opt2" > 2</ ToolbarSelectOption >
294+ < ToolbarSelectOption > 3</ ToolbarSelectOption >
295+ < ToolbarSelectOption > 4</ ToolbarSelectOption >
296+ </ ToolbarSelect >
297+ </ Toolbar >
298+ < Button id = "btn" > select option 2</ Button >
299+ </ >
300+ ) ;
301+
302+ // Set up button click handler
303+ cy . get ( "#btn" ) . then ( $btn => {
304+ $btn . get ( 0 ) . addEventListener ( "ui5-click" , ( ) => {
305+ // First, deselect all options
306+ const select = document . querySelector ( "ui5-toolbar-select" ) ;
307+ const options = select ?. querySelectorAll ( "ui5-toolbar-select-option" ) ;
308+ options ?. forEach ( opt => {
309+ ( opt as ToolbarSelectOption ) . selected = false ;
310+ } ) ;
311+ // Then select option 2
312+ const opt2 = document . getElementById ( "opt2" ) as ToolbarSelectOption ;
313+ opt2 . selected = true ;
314+ } ) ;
315+ } ) ;
316+
317+ // Verify initial state - first option has selected attribute
318+ cy . get ( "[ui5-toolbar]" )
319+ . find ( "[ui5-toolbar-select]" )
320+ . shadow ( )
321+ . find ( "[ui5-select]" )
322+ . find ( "[ui5-option]" )
323+ . eq ( 0 )
324+ . should ( "have.attr" , "selected" ) ;
325+
326+ // Click button using realClick
327+ cy . get ( "#btn" ) . realClick ( ) ;
328+
329+ // Verify option 2 now has the selected attribute
330+ cy . get ( "[ui5-toolbar]" )
331+ . find ( "[ui5-toolbar-select]" )
332+ . shadow ( )
333+ . find ( "[ui5-select]" )
334+ . find ( "[ui5-option]" )
335+ . eq ( 1 )
336+ . should ( "have.attr" , "selected" ) ;
337+
338+ // Verify option 1 no longer has selected attribute
339+ cy . get ( "[ui5-toolbar]" )
340+ . find ( "[ui5-toolbar-select]" )
341+ . shadow ( )
342+ . find ( "[ui5-select]" )
343+ . find ( "[ui5-option]" )
344+ . eq ( 0 )
345+ . should ( "not.have.attr" , "selected" ) ;
346+ } ) ;
285347} ) ;
0 commit comments