11import { expect } from "chai" ;
22import Flicking from "~/Flicking" ;
33import { connectFlickingStateApi } from "~/state-api" ;
4- import { cleanup , createFlicking , createSandbox , tick } from "../helper/test-util" ;
4+ import {
5+ cleanup ,
6+ createFlicking ,
7+ createSandbox ,
8+ tick
9+ } from "../helper/test-util" ;
510import El from "../helper/El" ;
611
712describe ( "State API" , ( ) => {
@@ -33,7 +38,7 @@ describe("State API", () => {
3338
3439 describe ( "State Updates" , ( ) => {
3540 it ( "should update state when moving to next panel" , async ( ) => {
36- const promise = flicking . next ( ) ;
41+ const promise = flicking . next ( ) ;
3742 tick ( 1000 ) ;
3843 await promise ;
3944
@@ -53,6 +58,7 @@ describe("State API", () => {
5358 expect ( stateApi . isReachEnd ) . to . be . true ;
5459 expect ( stateApi . currentPanelIndex ) . to . equal ( 2 ) ;
5560 expect ( stateApi . indexProgress ) . to . equal ( 100 ) ;
61+ expect ( stateApi . scrollProgress ) . to . equal ( 100 ) ;
5662 } ) ;
5763
5864 it ( "should update state when adding panels" , async ( ) => {
@@ -78,6 +84,37 @@ describe("State API", () => {
7884
7985 expect ( stateApi . currentPanelIndex ) . to . equal ( 1 ) ;
8086 expect ( stateApi . indexProgress ) . to . equal ( 50 ) ;
87+ expect ( stateApi . scrollProgress ) . to . equal ( 50 ) ;
88+ } ) ;
89+ } ) ;
90+
91+ describe ( "Progress" , ( ) => {
92+ it ( "should show difference between indexProgress and scrollProgress with different panel sizes" , async ( ) => {
93+ // Create flicking with panels of different sizes
94+ const customFlicking = await createFlicking (
95+ El . viewport ( "1000px" , "400px" ) . add (
96+ El . camera ( ) . add (
97+ El . panel ( "200px" , "100%" ) , // 200px wide
98+ El . panel ( "400px" , "100%" ) , // 400px wide
99+ El . panel ( "600px" , "100%" ) // 600px wide
100+ )
101+ )
102+ ) ;
103+ const customStateApi = connectFlickingStateApi ( customFlicking ) ;
104+
105+ // Move to second panel
106+ const promise = customFlicking . moveTo ( 1 ) ;
107+ tick ( 1000 ) ;
108+ await promise ;
109+
110+ // indexProgress is based on panel index
111+ // scrollProgress is based on actual scroll position
112+ // They should be different when panels have different sizes
113+ expect ( customStateApi . indexProgress ) . to . not . equal (
114+ customStateApi . scrollProgress
115+ ) ;
116+
117+ await customStateApi . unsubscribe ( ) ;
81118 } ) ;
82119 } ) ;
83120} ) ;
0 commit comments