@@ -18,7 +18,7 @@ function sleep(ms: number) {
18
18
return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
19
19
}
20
20
21
- const animationDuration : number = 25 ; // still needs to be some time, otherwise it goes too fast for the rendering and the test to work properly.
21
+ const ANIMATION_DURATION : number = 25 ; // still needs to be some time, otherwise it goes too fast for the rendering and the test to work properly.
22
22
23
23
describe ( 'UUIToastNotificationElement' , ( ) => {
24
24
let element : UUIToastNotificationElement ;
@@ -29,7 +29,7 @@ describe('UUIToastNotificationElement', () => {
29
29
) ;
30
30
element . style . setProperty (
31
31
'--uui-toast-notification-animation-duration' ,
32
- animationDuration + 'ms'
32
+ ANIMATION_DURATION + 'ms'
33
33
) ;
34
34
} ) ;
35
35
@@ -61,7 +61,7 @@ describe('UUIToastNotificationElement', () => {
61
61
. to . have . property ( '_getAnimationDuration' )
62
62
. that . is . a ( 'function' ) ;
63
63
expect ( ( element as any ) . _getAnimationDuration ( ) ) . to . be . equal (
64
- animationDuration
64
+ ANIMATION_DURATION
65
65
) ;
66
66
} ) ;
67
67
} ) ;
@@ -87,13 +87,22 @@ describe('UUIToastNotificationElement', () => {
87
87
88
88
describe ( 'closing' , ( ) => {
89
89
it ( 'emits a closing event when elements starts to closing' , async ( ) => {
90
+ const openedListener = oneEvent (
91
+ element ,
92
+ UUIToastNotificationEvent . OPENED
93
+ ) ;
94
+ const closingListener = oneEvent (
95
+ element ,
96
+ UUIToastNotificationEvent . CLOSING
97
+ ) ;
98
+
90
99
element . open = true ;
91
- await elementUpdated ( element ) ;
92
- const listener = oneEvent ( element , UUIToastNotificationEvent . CLOSING ) ;
93
- await sleep ( animationDuration + 1 ) ; // enough time for opening-animation to be done.
100
+ await openedListener ;
101
+
94
102
expect ( element . open ) . to . be . true ;
95
103
element . open = false ;
96
- const event = await listener ;
104
+ const event = await closingListener ;
105
+
97
106
expect ( event ) . to . exist ;
98
107
expect ( event . type ) . to . equal ( UUIToastNotificationEvent . CLOSING ) ;
99
108
expect ( element . open ) . to . be . false ;
@@ -102,7 +111,7 @@ describe('UUIToastNotificationElement', () => {
102
111
element . open = true ;
103
112
await elementUpdated ( element ) ;
104
113
const listener = oneEvent ( element , UUIToastNotificationEvent . CLOSING ) ;
105
- await sleep ( animationDuration / 2 ) ; // enough time for the rendering and opening-animation to start.
114
+ await sleep ( ANIMATION_DURATION / 2 ) ; // enough time for the rendering and opening-animation to start, but not finished .
106
115
expect ( element . open ) . to . be . true ;
107
116
element . open = false ;
108
117
const event = await listener ;
@@ -117,7 +126,7 @@ describe('UUIToastNotificationElement', () => {
117
126
element . addEventListener ( UUIToastNotificationEvent . CLOSING , e => {
118
127
e . preventDefault ( ) ;
119
128
} ) ;
120
- await sleep ( animationDuration / 2 ) ; // enough time for the rendering and opening-animation to start.
129
+ await sleep ( ANIMATION_DURATION / 2 ) ; // enough time for the rendering and opening-animation to start, but not finished .
121
130
expect ( element . open ) . to . be . true ;
122
131
element . open = false ;
123
132
const event = await listener ;
@@ -128,22 +137,33 @@ describe('UUIToastNotificationElement', () => {
128
137
} ) ;
129
138
describe ( 'closed' , ( ) => {
130
139
it ( 'emits a opening event when elements is closed' , async ( ) => {
131
- element . open = true ;
132
- await elementUpdated ( element ) ;
140
+ const openedListener = oneEvent (
141
+ element ,
142
+ UUIToastNotificationEvent . OPENED
143
+ ) ;
133
144
const listener = oneEvent ( element , UUIToastNotificationEvent . CLOSED ) ;
134
- await sleep ( animationDuration + 1 ) ; // enough time for opening-animation to be done.
145
+
146
+ element . open = true ;
147
+ await openedListener ;
148
+
135
149
expect ( element . open ) . to . be . true ;
150
+
136
151
element . open = false ;
137
152
const event = await listener ;
138
153
expect ( event ) . to . exist ;
139
154
expect ( event . type ) . to . equal ( UUIToastNotificationEvent . CLOSED ) ;
140
155
expect ( element . open ) . to . be . false ;
141
156
} ) ;
142
157
it ( 'emits a close event though toast is still running its opening-animation' , async ( ) => {
143
- element . open = true ;
144
- await elementUpdated ( element ) ;
158
+ const openedListener = oneEvent (
159
+ element ,
160
+ UUIToastNotificationEvent . OPENED
161
+ ) ;
145
162
const listener = oneEvent ( element , UUIToastNotificationEvent . CLOSED ) ;
146
- await sleep ( animationDuration / 2 ) ; // enough time for the rendering and opening-animation to start.
163
+
164
+ element . open = true ;
165
+ await openedListener ;
166
+
147
167
expect ( element . open ) . to . be . true ;
148
168
element . open = false ;
149
169
const event = await listener ;
@@ -165,7 +185,7 @@ describe('UUIToastNotificationElement', () => {
165
185
expect ( openEvent . type ) . to . equal ( UUIToastNotificationEvent . OPENING ) ;
166
186
expect ( element . open ) . to . be . true ;
167
187
168
- await sleep ( animationDuration / 2 ) ; // enough time for the rendering and opening-animation to start.
188
+ await sleep ( ANIMATION_DURATION / 2 ) ; // enough time for the rendering and opening-animation to start, but not finished .
169
189
170
190
const closeListener = oneEvent (
171
191
element ,
0 commit comments