@@ -2,7 +2,7 @@ import { visit, click, triggerKeyEvent, waitUntil } from '@ember/test-helpers';
2
2
import { setupApplicationTest } from 'ember-qunit' ;
3
3
import { module , test } from 'qunit' ;
4
4
5
- import sinon from 'sinon ' ;
5
+ import Modal1 from 'dummy/components/modal1 ' ;
6
6
7
7
import { setupPromiseModals } from 'ember-promise-modals/test-support' ;
8
8
@@ -71,6 +71,45 @@ module('Application | basics', function (hooks) {
71
71
assert . dom ( 'body' , document ) . hasStyle ( { overflow : 'visible' } ) ;
72
72
} ) ;
73
73
74
+ test ( 'opening a modal calls onAnimationModal*End once the animation ends' , async function ( assert ) {
75
+ await visit ( '/' ) ;
76
+
77
+ assert . dom ( '.epm-backdrop' ) . doesNotExist ( ) ;
78
+ assert . dom ( '.epm-modal' ) . doesNotExist ( ) ;
79
+
80
+ const applicationController = this . owner . lookup ( 'controller:application' ) ;
81
+ const modalsService = applicationController . modals ;
82
+ const showModal = applicationController . actions . showModal ;
83
+
84
+ applicationController . actions . showModal = ( ) => {
85
+ assert . step ( 'open' ) ;
86
+
87
+ modalsService . open (
88
+ Modal1 ,
89
+ { } ,
90
+ {
91
+ onAnimationModalInEnd : ( ) => {
92
+ assert . step ( 'onAnimationModalInEnd' ) ;
93
+ } ,
94
+ onAnimationModalOutEnd : ( ) => {
95
+ assert . step ( 'onAnimationModalOutEnd' ) ;
96
+ } ,
97
+ } ,
98
+ ) ;
99
+ } ;
100
+
101
+ await click ( '[data-test-show-modal]' ) ;
102
+ await waitUntil ( ( ) => ! document . body . classList . contains ( 'epm-animating' ) ) ;
103
+ await click ( '.epm-backdrop' ) ;
104
+
105
+ assert . dom ( '.epm-backdrop' ) . doesNotExist ( ) ;
106
+ assert . dom ( '.epm-modal' ) . doesNotExist ( ) ;
107
+
108
+ assert . verifySteps ( [ 'open' , 'onAnimationModalInEnd' , 'onAnimationModalOutEnd' ] ) ;
109
+
110
+ applicationController . actions . showModal = showModal ;
111
+ } ) ;
112
+
74
113
test ( 'pressing the Escape keyboard button closes the modal' , async function ( assert ) {
75
114
await visit ( '/' ) ;
76
115
@@ -100,29 +139,4 @@ module('Application | basics', function (hooks) {
100
139
foo : 'bar' ,
101
140
} ) ;
102
141
} ) ;
103
-
104
- test ( 'closing a modal will trigger the animation start on the `modals` service' , async function ( assert ) {
105
- await visit ( '/' ) ;
106
-
107
- let modalsService = this . owner . lookup ( 'service:modals' ) ;
108
- let spy = sinon . spy ( modalsService , '_onModalAnimationStart' ) ;
109
-
110
- assert . dom ( '.epm-modal' ) . doesNotExist ( ) ;
111
-
112
- await click ( '[data-test-show-modal]' ) ;
113
-
114
- assert . dom ( '.epm-modal' ) . exists ( ) ;
115
-
116
- await waitUntil ( ( ) => {
117
- let { opacity } = window . getComputedStyle ( document . querySelector ( '.epm-backdrop' ) ) ;
118
- return opacity === '1' ;
119
- } ) ;
120
-
121
- assert . strictEqual ( spy . callCount , 1 , '_onModalAnimationStart is called when opening a modal' ) ;
122
-
123
- await triggerKeyEvent ( document , 'keydown' , 'Escape' ) ;
124
-
125
- assert . dom ( '.epm-modal' ) . doesNotExist ( ) ;
126
- assert . strictEqual ( spy . callCount , 2 , '_onModalAnimationStart is called again when closing it' ) ;
127
- } ) ;
128
142
} ) ;
0 commit comments