@@ -114,5 +114,109 @@ define(function (require, exports, module) {
114114 await verifyToast ( NotificationUI . NOTIFICATION_STYLES_CSS_CLASS . DANGER ) ;
115115 await verifyToast ( "custom-class-name" ) ;
116116 } , 10000 ) ;
117+
118+ describe ( "showToastOn" , function ( ) {
119+ let $container ;
120+
121+ beforeAll ( function ( ) {
122+ $container = $ (
123+ '<div id="inline-toast-test-container" style="position:relative;width:200px;height:200px;"></div>' ) ;
124+ $ ( "body" ) . append ( $container ) ;
125+ } ) ;
126+
127+ afterAll ( function ( ) {
128+ $container . remove ( ) ;
129+ } ) ;
130+
131+ it ( "Should show an inline toast inside a container" , async function ( ) {
132+ let notification = NotificationUI . showToastOn ( $container [ 0 ] , "Hello inline toast" ) ;
133+ await awaitsFor ( function ( ) {
134+ return $container . find ( ".inline-toast" ) . length === 1 ;
135+ } , "waiting for inline toast to appear" ) ;
136+ expect ( $container . find ( ".inline-toast" ) . text ( ) ) . toBe ( "Hello inline toast" ) ;
137+ notification . close ( ) ;
138+ await awaitsFor ( function ( ) {
139+ return $container . find ( ".inline-toast" ) . length === 0 ;
140+ } , "waiting for inline toast to close" ) ;
141+ } ) ;
142+
143+ it ( "Should auto-close after autoCloseTimeS" , async function ( ) {
144+ NotificationUI . showToastOn ( $container [ 0 ] , "Auto close" , {
145+ autoCloseTimeS : 1
146+ } ) ;
147+ await awaitsFor ( function ( ) {
148+ return $container . find ( ".inline-toast" ) . length === 1 ;
149+ } , "waiting for inline toast to appear" ) ;
150+ await awaitsFor ( function ( ) {
151+ return $container . find ( ".inline-toast" ) . length === 0 ;
152+ } , "waiting for inline toast to auto-close" , 3000 ) ;
153+ } ) ;
154+
155+ it ( "Should dismiss on click by default" , async function ( ) {
156+ NotificationUI . showToastOn ( $container [ 0 ] , "Click me" ) ;
157+ await awaitsFor ( function ( ) {
158+ return $container . find ( ".inline-toast.visible" ) . length === 1 ;
159+ } , "waiting for inline toast to be visible" ) ;
160+ $container . find ( ".inline-toast" ) . click ( ) ;
161+ await awaitsFor ( function ( ) {
162+ return $container . find ( ".inline-toast" ) . length === 0 ;
163+ } , "waiting for inline toast to close on click" ) ;
164+ } ) ;
165+
166+ it ( "Should not dismiss on click when dismissOnClick is false" , async function ( ) {
167+ let notification = NotificationUI . showToastOn ( $container [ 0 ] , "No dismiss" , {
168+ dismissOnClick : false ,
169+ autoCloseTimeS : 0
170+ } ) ;
171+ await awaitsFor ( function ( ) {
172+ return $container . find ( ".inline-toast.visible" ) . length === 1 ;
173+ } , "waiting for inline toast to be visible" ) ;
174+ $container . find ( ".inline-toast" ) . click ( ) ;
175+ await awaits ( 250 ) ;
176+ expect ( $container . find ( ".inline-toast" ) . length ) . toBe ( 1 ) ;
177+ notification . close ( "manual" ) ;
178+ await awaitsFor ( function ( ) {
179+ return $container . find ( ".inline-toast" ) . length === 0 ;
180+ } , "waiting for inline toast to close manually" ) ;
181+ } ) ;
182+
183+ it ( "Should accept a jQuery selector string as container" , async function ( ) {
184+ NotificationUI . showToastOn ( "#inline-toast-test-container" , "Selector toast" ) ;
185+ await awaitsFor ( function ( ) {
186+ return $container . find ( ".inline-toast" ) . length === 1 ;
187+ } , "waiting for inline toast via selector" ) ;
188+ $container . find ( ".inline-toast" ) . click ( ) ;
189+ await awaitsFor ( function ( ) {
190+ return $container . find ( ".inline-toast" ) . length === 0 ;
191+ } , "waiting for inline toast to close" ) ;
192+ } ) ;
193+
194+ it ( "Should resolve done callback with close reason" , async function ( ) {
195+ let closeReason ;
196+ let notification = NotificationUI . showToastOn ( $container [ 0 ] , "Done test" ) ;
197+ notification . done ( function ( reason ) {
198+ closeReason = reason ;
199+ } ) ;
200+ await awaitsFor ( function ( ) {
201+ return $container . find ( ".inline-toast.visible" ) . length === 1 ;
202+ } , "waiting for inline toast to be visible" ) ;
203+ notification . close ( "testReason" ) ;
204+ await awaitsFor ( function ( ) {
205+ return closeReason === "testReason" ;
206+ } , "waiting for done callback" ) ;
207+ } ) ;
208+
209+ it ( "Should accept HTML template with elements" , async function ( ) {
210+ NotificationUI . showToastOn ( $container [ 0 ] , '<b>Bold</b> text' ) ;
211+ await awaitsFor ( function ( ) {
212+ return $container . find ( ".inline-toast" ) . length === 1 ;
213+ } , "waiting for inline toast" ) ;
214+ expect ( $container . find ( ".inline-toast b" ) . length ) . toBe ( 1 ) ;
215+ $container . find ( ".inline-toast" ) . click ( ) ;
216+ await awaitsFor ( function ( ) {
217+ return $container . find ( ".inline-toast" ) . length === 0 ;
218+ } , "waiting for inline toast to close" ) ;
219+ } ) ;
220+ } ) ;
117221 } ) ;
118222} ) ;
0 commit comments