@@ -18,13 +18,19 @@ function sleep(ms: number) {
18
18
return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
19
19
}
20
20
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
+
21
23
describe ( 'UUIToastNotificationElement' , ( ) => {
22
24
let element : UUIToastNotificationElement ;
23
25
24
26
beforeEach ( async ( ) => {
25
27
element = await fixture (
26
28
html ` < uui-toast-notification > </ uui-toast-notification > `
27
29
) ;
30
+ element . style . setProperty (
31
+ '--uui-toast-notification-animation-duration' ,
32
+ ANIMATION_DURATION + 'ms'
33
+ ) ;
28
34
} ) ;
29
35
30
36
it ( 'passes the a11y audit' , async ( ) => {
@@ -50,6 +56,14 @@ describe('UUIToastNotificationElement', () => {
50
56
it ( 'has a resumeAutoClose method' , ( ) => {
51
57
expect ( element ) . to . have . property ( 'resumeAutoClose' ) . that . is . a ( 'function' ) ;
52
58
} ) ;
59
+ it ( 'private _getAnimationDuration' , ( ) => {
60
+ expect ( element )
61
+ . to . have . property ( '_getAnimationDuration' )
62
+ . that . is . a ( 'function' ) ;
63
+ expect ( ( element as any ) . _getAnimationDuration ( ) ) . to . be . equal (
64
+ ANIMATION_DURATION
65
+ ) ;
66
+ } ) ;
53
67
} ) ;
54
68
55
69
describe ( 'template' , ( ) => {
@@ -73,13 +87,22 @@ describe('UUIToastNotificationElement', () => {
73
87
74
88
describe ( 'closing' , ( ) => {
75
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
+
76
99
element . open = true ;
77
- await elementUpdated ( element ) ;
78
- const listener = oneEvent ( element , UUIToastNotificationEvent . CLOSING ) ;
79
- await sleep ( 600 ) ; // enough time for opening-animation to be done.
100
+ await openedListener ;
101
+
80
102
expect ( element . open ) . to . be . true ;
81
103
element . open = false ;
82
- const event = await listener ;
104
+ const event = await closingListener ;
105
+
83
106
expect ( event ) . to . exist ;
84
107
expect ( event . type ) . to . equal ( UUIToastNotificationEvent . CLOSING ) ;
85
108
expect ( element . open ) . to . be . false ;
@@ -88,7 +111,7 @@ describe('UUIToastNotificationElement', () => {
88
111
element . open = true ;
89
112
await elementUpdated ( element ) ;
90
113
const listener = oneEvent ( element , UUIToastNotificationEvent . CLOSING ) ;
91
- await sleep ( 100 ) ; // 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 .
92
115
expect ( element . open ) . to . be . true ;
93
116
element . open = false ;
94
117
const event = await listener ;
@@ -103,7 +126,7 @@ describe('UUIToastNotificationElement', () => {
103
126
element . addEventListener ( UUIToastNotificationEvent . CLOSING , e => {
104
127
e . preventDefault ( ) ;
105
128
} ) ;
106
- await sleep ( 100 ) ; // 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 .
107
130
expect ( element . open ) . to . be . true ;
108
131
element . open = false ;
109
132
const event = await listener ;
@@ -114,22 +137,33 @@ describe('UUIToastNotificationElement', () => {
114
137
} ) ;
115
138
describe ( 'closed' , ( ) => {
116
139
it ( 'emits a opening event when elements is closed' , async ( ) => {
117
- element . open = true ;
118
- await elementUpdated ( element ) ;
140
+ const openedListener = oneEvent (
141
+ element ,
142
+ UUIToastNotificationEvent . OPENED
143
+ ) ;
119
144
const listener = oneEvent ( element , UUIToastNotificationEvent . CLOSED ) ;
120
- await sleep ( 600 ) ; // enough time for opening-animation to be done.
145
+
146
+ element . open = true ;
147
+ await openedListener ;
148
+
121
149
expect ( element . open ) . to . be . true ;
150
+
122
151
element . open = false ;
123
152
const event = await listener ;
124
153
expect ( event ) . to . exist ;
125
154
expect ( event . type ) . to . equal ( UUIToastNotificationEvent . CLOSED ) ;
126
155
expect ( element . open ) . to . be . false ;
127
156
} ) ;
128
157
it ( 'emits a close event though toast is still running its opening-animation' , async ( ) => {
129
- element . open = true ;
130
- await elementUpdated ( element ) ;
158
+ const openedListener = oneEvent (
159
+ element ,
160
+ UUIToastNotificationEvent . OPENED
161
+ ) ;
131
162
const listener = oneEvent ( element , UUIToastNotificationEvent . CLOSED ) ;
132
- await sleep ( 100 ) ; // enough time for the rendering and opening-animation to start.
163
+
164
+ element . open = true ;
165
+ await openedListener ;
166
+
133
167
expect ( element . open ) . to . be . true ;
134
168
element . open = false ;
135
169
const event = await listener ;
@@ -151,7 +185,7 @@ describe('UUIToastNotificationElement', () => {
151
185
expect ( openEvent . type ) . to . equal ( UUIToastNotificationEvent . OPENING ) ;
152
186
expect ( element . open ) . to . be . true ;
153
187
154
- await sleep ( 100 ) ; // 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 .
155
189
156
190
const closeListener = oneEvent (
157
191
element ,
0 commit comments