@@ -143,39 +143,125 @@ QUnit.module('Drawer behavior', () => {
143143 assert . equal ( $element . attr ( 'tabIndex' ) , undefined , 'tabIndex was removed' ) ;
144144 } ) ;
145145
146- QUnit . test ( 'subscribe on toggle function should fired at the end of animation' , function ( assert ) {
147- const $element = $ ( '#drawer' ) . dxDrawer ( {
148- opened : false
146+ [ true , false ] . forEach ( ( animationEnabled ) => {
147+ QUnit . test ( `Toggle promise should be resolved after toggle finished (animationEnabled=${ animationEnabled } )` , function ( assert ) {
148+ assert . expect ( 1 ) ;
149+
150+ const instance = $ ( '#drawer' ) . dxDrawer ( {
151+ animationEnabled,
152+ animationDuration : 0 ,
153+ } ) . dxDrawer ( 'instance' ) ;
154+
155+ const done = assert . async ( ) ;
156+
157+ const timeout = setTimeout ( ( ) => {
158+ assert . ok ( false , 'toggle promise was not resolved' ) ;
159+ done ( ) ;
160+ } , 10 ) ;
161+
162+ instance . toggle ( ) . then ( ( ) => {
163+ clearTimeout ( timeout ) ;
164+ assert . ok ( true , 'toggle promise was resolved' ) ;
165+ done ( ) ;
166+ } ) ;
167+ } ) ;
168+ } ) ;
169+
170+ [
171+ {
172+ opened : true ,
173+ scenario : 'show method call if drawer is already opened' ,
174+ } ,
175+ {
176+ opened : false ,
177+ scenario : 'hide method call if drawer is already closed' ,
178+ } ,
179+ ] . forEach ( ( { opened, scenario } ) => {
180+ QUnit . test ( `Promise should be resolved after ${ scenario } (T1263952)` , function ( assert ) {
181+ assert . expect ( 1 ) ;
182+
183+ const instance = $ ( '#drawer' ) . dxDrawer ( {
184+ opened
185+ } ) . dxDrawer ( 'instance' ) ;
186+
187+ const done = assert . async ( ) ;
188+
189+ const timeout = setTimeout ( ( ) => {
190+ assert . ok ( false , 'promise was not resolved' ) ;
191+ done ( ) ;
192+ } , 10 ) ;
193+
194+ const methodToCall = opened ? 'show' : 'hide' ;
195+
196+ instance [ methodToCall ] ( ) . then ( ( ) => {
197+ clearTimeout ( timeout ) ;
198+ assert . ok ( true , 'promise was resolved' ) ;
199+ done ( ) ;
200+ } ) ;
149201 } ) ;
202+ } ) ;
150203
204+ QUnit . test ( 'Drawer panel should add a hidden class after hide animation is completed, toggle method is used (T1239845)' , function ( assert ) {
205+ const $element = $ ( '#drawer' ) . dxDrawer ( { animationDuration : 0 , opened : true } ) ;
151206 const instance = $element . dxDrawer ( 'instance' ) ;
152- let count = 0 ;
207+ const $panel = $element . find ( `.${ DRAWER_PANEL_CONTENT_CLASS } ` ) ;
208+
153209 const done = assert . async ( ) ;
154210
155211 instance . toggle ( ) . then ( ( ) => {
156- count ++ ;
157- assert . equal ( count , 1 , 'callback not fired at animation start' ) ;
212+ assert . strictEqual ( $panel . hasClass ( DRAWER_PANEL_CONTENT_HIDDEN_CLASS ) , true , 'dx-drawer-panel-content-hidden is set after animation completed' ) ;
158213 done ( ) ;
159214 } ) ;
160215
161- assert . equal ( count , 0 , 'callback not fired at animation start' ) ;
216+ assert . strictEqual ( $panel . hasClass ( DRAWER_PANEL_CONTENT_HIDDEN_CLASS ) , false , 'dx-drawer-panel-content-hidden is not set before animation start' ) ;
162217 } ) ;
163218
164- [ true , false ] . forEach ( opened => {
165- QUnit . test ( `drawer panel should ${ opened ? '' : 'not' } have a hidden class before it was ${ opened ? 'closed' : 'shown' } (T1239845)` , function ( assert ) {
166- const $element = $ ( '#drawer' ) . dxDrawer ( { animationDuration : 0 , opened } ) ;
167- const instance = $element . dxDrawer ( 'instance' ) ;
168- const $panel = $element . find ( `.${ DRAWER_PANEL_CONTENT_CLASS } ` ) ;
219+ QUnit . test ( 'Drawer panel should add a hidden class after hide animation is completed, opened option is changed (T1277636)' , function ( assert ) {
220+ const $element = $ ( '#drawer' ) . dxDrawer ( { animationDuration : 0 , opened : true } ) ;
221+ const instance = $element . dxDrawer ( 'instance' ) ;
222+ const $panel = $element . find ( `.${ DRAWER_PANEL_CONTENT_CLASS } ` ) ;
169223
170- const done = assert . async ( ) ;
224+ const done = assert . async ( ) ;
171225
172- instance . toggle ( ) . then ( ( ) => {
173- assert . strictEqual ( $panel . hasClass ( DRAWER_PANEL_CONTENT_HIDDEN_CLASS ) , opened , 'dx-drawer-panel-content-hidden is not set' ) ;
174- done ( ) ;
175- } ) ;
226+ instance . option ( 'opened' , false ) ;
227+
228+ setTimeout ( ( ) => {
229+ assert . strictEqual ( $panel . hasClass ( DRAWER_PANEL_CONTENT_HIDDEN_CLASS ) , true , 'dx-drawer-panel-content-hidden is set after animation completed' ) ;
230+ done ( ) ;
231+ } , 0 ) ;
232+
233+ assert . strictEqual ( $panel . hasClass ( DRAWER_PANEL_CONTENT_HIDDEN_CLASS ) , false , 'dx-drawer-panel-content-hidden is not set before animation start' ) ;
234+ } ) ;
235+
236+ QUnit . test ( 'Drawer panel should remove a hidden class before show animation is started, toggle method is used (T1239845)' , function ( assert ) {
237+ const $element = $ ( '#drawer' ) . dxDrawer ( { animationDuration : 0 , opened : false } ) ;
238+ const instance = $element . dxDrawer ( 'instance' ) ;
239+ const $panel = $element . find ( `.${ DRAWER_PANEL_CONTENT_CLASS } ` ) ;
176240
177- assert . strictEqual ( $panel . hasClass ( DRAWER_PANEL_CONTENT_HIDDEN_CLASS ) , false , 'dx-drawer-panel-content-hidden is set' ) ;
241+ const done = assert . async ( ) ;
242+
243+ instance . toggle ( ) . then ( ( ) => {
244+ assert . strictEqual ( $panel . hasClass ( DRAWER_PANEL_CONTENT_HIDDEN_CLASS ) , false , 'dx-drawer-panel-content-hidden is not set after animation completed' ) ;
245+ done ( ) ;
178246 } ) ;
247+
248+ assert . strictEqual ( $panel . hasClass ( DRAWER_PANEL_CONTENT_HIDDEN_CLASS ) , false , 'dx-drawer-panel-content-hidden is not set before animation start' ) ;
249+ } ) ;
250+
251+ QUnit . test ( 'Drawer panel should remove a hidden class before show animation is started, opened option is changed (T1277636)' , function ( assert ) {
252+ const $element = $ ( '#drawer' ) . dxDrawer ( { animationDuration : 0 , opened : false } ) ;
253+ const instance = $element . dxDrawer ( 'instance' ) ;
254+ const $panel = $element . find ( `.${ DRAWER_PANEL_CONTENT_CLASS } ` ) ;
255+
256+ const done = assert . async ( ) ;
257+
258+ instance . option ( 'opened' , true ) ;
259+ setTimeout ( ( ) => {
260+ assert . strictEqual ( $panel . hasClass ( DRAWER_PANEL_CONTENT_HIDDEN_CLASS ) , false , 'dx-drawer-panel-content-hidden is not set after animation completed' ) ;
261+ done ( ) ;
262+ } , 0 ) ;
263+
264+ assert . strictEqual ( $panel . hasClass ( DRAWER_PANEL_CONTENT_HIDDEN_CLASS ) , false , 'dx-drawer-panel-content-hidden is not set before animation start' ) ;
179265 } ) ;
180266
181267 QUnit . test ( 'Check dxresize event: opened:false,animationEnabled:true -> drawer.toggle()' , function ( assert ) {
0 commit comments