@@ -68,13 +68,32 @@ describe('ChartIFrameEventBroker Tests', () => {
6868 expect ( chart . onMount ) . toHaveBeenCalledWith ( mockOptions , mockContext ) ;
6969 } ) ;
7070
71- test ( 'should call chart onUpdated lifecycle after mounted' , ( ) => {
71+ test ( 'should call chart onUpdated lifecycle after mounted' , async ( ) => {
7272 const chart = {
7373 state : 'ready' ,
7474 onUpdated : jest . fn ( ) . mockImplementation ( ) ,
7575 } ;
7676 broker . register ( chart ) ;
7777 broker . publish ( 'updated' , mockOptions , mockContext ) ;
78+
79+ // NOTE: the milliseconds is from EVENT_ACTION_DELAY_MS
80+ await new Promise ( r => setTimeout ( r , 300 ) ) ;
81+ expect ( chart . onUpdated ) . toHaveBeenCalledTimes ( 1 ) ;
82+ expect ( chart . onUpdated ) . toHaveBeenCalledWith ( mockOptions , mockContext ) ;
83+ } ) ;
84+
85+ test ( 'should invoke once onUpdated lifecycle with many update events' , async ( ) => {
86+ const chart = {
87+ state : 'ready' ,
88+ onUpdated : jest . fn ( ) . mockImplementation ( ) ,
89+ } ;
90+ broker . register ( chart ) ;
91+ broker . publish ( 'updated' , mockOptions , mockContext ) ;
92+ broker . publish ( 'updated' , mockOptions , mockContext ) ;
93+ broker . publish ( 'updated' , mockOptions , mockContext ) ;
94+
95+ // NOTE: the milliseconds is from EVENT_ACTION_DELAY_MS
96+ await new Promise ( r => setTimeout ( r , 300 ) ) ;
7897 expect ( chart . onUpdated ) . toHaveBeenCalledTimes ( 1 ) ;
7998 expect ( chart . onUpdated ) . toHaveBeenCalledWith ( mockOptions , mockContext ) ;
8099 } ) ;
@@ -88,13 +107,32 @@ describe('ChartIFrameEventBroker Tests', () => {
88107 expect ( chart . onUpdated ) . toHaveBeenCalledTimes ( 0 ) ;
89108 } ) ;
90109
91- test ( 'should call chart onResize lifecycle after mounted' , ( ) => {
110+ test ( 'should call chart onResize lifecycle after mounted' , async ( ) => {
92111 const chart = {
93112 state : 'ready' ,
94113 onResize : jest . fn ( ) . mockImplementation ( ) ,
95114 } ;
96115 broker . register ( chart ) ;
97116 broker . publish ( 'resize' , mockOptions , mockContext ) ;
117+
118+ // NOTE: the milliseconds is from EVENT_ACTION_DELAY_MS
119+ await new Promise ( r => setTimeout ( r , 300 ) ) ;
120+ expect ( chart . onResize ) . toHaveBeenCalledTimes ( 1 ) ;
121+ expect ( chart . onResize ) . toHaveBeenCalledWith ( mockOptions , mockContext ) ;
122+ } ) ;
123+
124+ test ( 'should invoke once onResize lifecycle with many resize events' , async ( ) => {
125+ const chart = {
126+ state : 'ready' ,
127+ onResize : jest . fn ( ) . mockImplementation ( ) ,
128+ } ;
129+ broker . register ( chart ) ;
130+ broker . publish ( 'resize' , mockOptions , mockContext ) ;
131+ broker . publish ( 'resize' , mockOptions , mockContext ) ;
132+ broker . publish ( 'resize' , mockOptions , mockContext ) ;
133+
134+ // NOTE: the milliseconds is from EVENT_ACTION_DELAY_MS
135+ await new Promise ( r => setTimeout ( r , 300 ) ) ;
98136 expect ( chart . onResize ) . toHaveBeenCalledTimes ( 1 ) ;
99137 expect ( chart . onResize ) . toHaveBeenCalledWith ( mockOptions , mockContext ) ;
100138 } ) ;
@@ -160,13 +198,16 @@ describe('ChartIFrameEventBroker Tests', () => {
160198 expect ( chart . state ) . toEqual ( 'ready' ) ;
161199 } ) ;
162200
163- test ( 'should set state to ready after updated' , ( ) => {
201+ test ( 'should set state to ready after updated' , async ( ) => {
164202 const chart = {
165203 state : 'ready' ,
166204 onUpdated : jest . fn ( ) . mockImplementation ( ) ,
167205 } ;
168206 broker . register ( chart ) ;
169207 broker . publish ( 'updated' , mockOptions , mockContext ) ;
208+
209+ // NOTE: the milliseconds is from EVENT_ACTION_DELAY_MS
210+ await new Promise ( r => setTimeout ( r , 300 ) ) ;
170211 expect ( chart . onUpdated ) . toHaveBeenCalledTimes ( 1 ) ;
171212 expect ( chart . state ) . toEqual ( 'ready' ) ;
172213 } ) ;
0 commit comments