@@ -84,5 +84,43 @@ describe("NativeRenderer", () => {
8484 expect ( returnVal . every ( panel => panel . size !== 0 ) ) . toBe ( true ) ;
8585 } ) ;
8686 } ) ;
87+
88+ describe ( "render (useCSSOrder)" , ( ) => {
89+ it ( "should keep DOM order and inject CSS order matching the rendering order" , async ( ) => {
90+ const flicking = await createFlicking ( El . DEFAULT_HORIZONTAL_WITH_PANELS ( 5 ) , {
91+ circular : true ,
92+ useCSSOrder : true
93+ } ) ;
94+
95+ const cameraChildren = [ ...flicking . camera . element . children ] ;
96+
97+ // DOM order stays identical to the original panel order
98+ expect ( cameraChildren ) . toEqual ( flicking . panels . map ( panel => panel . element ) ) ;
99+
100+ // CSS `order` follows the visual rendering order instead
101+ flicking . renderer . strategy . getRenderingElementsByOrder ( flicking ) . forEach ( ( el , orderIndex ) => {
102+ expect ( el . style . order ) . toBe ( `${ orderIndex } ` ) ;
103+ } ) ;
104+ } ) ;
105+
106+ it ( "should not throw when combined with renderOnlyVisible and keep only visible panels in DOM" , async ( ) => {
107+ // Previously threw a TypeError, as the rendered-only panel array was accessed with global panel indexes
108+ const flicking = await createFlicking ( El . DEFAULT_HORIZONTAL_WITH_PANELS ( 5 ) , {
109+ circular : true ,
110+ useCSSOrder : true ,
111+ renderOnlyVisible : true
112+ } ) ;
113+
114+ const cameraChildren = [ ...flicking . camera . element . children ] ;
115+
116+ expect ( cameraChildren . length ) . toBeGreaterThan ( 0 ) ;
117+ expect ( cameraChildren . length ) . toBeLessThan ( flicking . panelCount ) ;
118+
119+ // CSS `order` is injected only on the rendered panels, following the visual rendering order
120+ flicking . renderer . strategy . getRenderingElementsByOrder ( flicking ) . forEach ( ( el , orderIndex ) => {
121+ expect ( el . style . order ) . toBe ( `${ orderIndex } ` ) ;
122+ } ) ;
123+ } ) ;
124+ } ) ;
87125 } ) ;
88126} ) ;
0 commit comments