@@ -4,28 +4,30 @@ import sinon from 'sinon';
44import '../src/vaadin-notification.js' ;
55
66describe ( 'vaadin-notification' , ( ) => {
7- let notification ;
7+ let notification , container , showPopoverSpy , hidePopoverSpy ;
88
99 beforeEach ( async ( ) => {
1010 notification = fixtureSync ( `
1111 <vaadin-notification duration="20"></vaadin-notification>
1212 ` ) ;
13+ container = notification . _container ;
14+ showPopoverSpy = sinon . spy ( container , 'showPopover' ) ;
15+ hidePopoverSpy = sinon . spy ( container , 'hidePopover' ) ;
16+
1317 await nextFrame ( ) ;
1418
1519 notification . renderer = ( root ) => {
1620 root . innerHTML = `Your work has been <strong>saved</strong>` ;
1721 } ;
1822
19- // Force sync card attaching and removal instead of waiting for the animation
20- sinon . stub ( notification , '_animatedAppendNotificationCard' ) . callsFake ( ( ) => notification . _appendNotificationCard ( ) ) ;
21- sinon . stub ( notification , '_animatedRemoveNotificationCard' ) . callsFake ( ( ) => notification . _removeNotificationCard ( ) ) ;
22-
2323 notification . open ( ) ;
2424 } ) ;
2525
2626 afterEach ( ( ) => {
27- // Close to stop all pending timers.
28- notification . close ( ) ;
27+ // Close all notifications to stop all pending timers.
28+ document . querySelectorAll ( 'vaadin-notification' ) . forEach ( ( n ) => {
29+ n . close ( ) ;
30+ } ) ;
2931 // Delete singleton reference, so as it's created in next test
3032 delete notification . constructor . _container ;
3133 } ) ;
@@ -98,6 +100,42 @@ describe('vaadin-notification', () => {
98100 expect ( isVisible ( document . body . querySelector ( 'vaadin-notification-container' ) ) ) . to . be . true ;
99101 } ) ;
100102
103+ it ( 'should open as native popover' , ( ) => {
104+ expect ( container . popover ) . to . equal ( 'manual' ) ;
105+ expect ( container . opened ) . to . be . true ;
106+ expect ( showPopoverSpy . calledOnce ) . to . be . true ;
107+ } ) ;
108+
109+ it ( 'should close native popover when notifications close' , ( ) => {
110+ notification . close ( ) ;
111+
112+ expect ( container . opened ) . to . be . false ;
113+ expect ( hidePopoverSpy . calledOnce ) . to . be . true ;
114+ } ) ;
115+
116+ it ( 'should reopen native popover when notifications open' , ( ) => {
117+ notification . close ( ) ;
118+ notification . _removeNotificationCard ( ) ;
119+ notification . open ( ) ;
120+
121+ expect ( container . opened ) . to . be . true ;
122+ expect ( showPopoverSpy . calledTwice ) . to . be . true ;
123+ } ) ;
124+
125+ it ( 'should bring native popover to top of overlay stack when another notification opens' , ( ) => {
126+ showPopoverSpy . resetHistory ( ) ;
127+
128+ const anotherNotification = fixtureSync ( `
129+ <vaadin-notification duration="20"></vaadin-notification>
130+ ` ) ;
131+ anotherNotification . open ( ) ;
132+
133+ // Bringing to front involves hiding and showing the popover again
134+ expect ( hidePopoverSpy . calledOnce ) . to . be . true ;
135+ expect ( showPopoverSpy . calledOnce ) . to . be . true ;
136+ expect ( hidePopoverSpy . calledBefore ( showPopoverSpy ) ) . to . be . true ;
137+ } ) ;
138+
101139 it ( 'should cancel vaadin-overlay-close events when the source event occurred within the container' , ( done ) => {
102140 listenOnce ( document , 'click' , ( clickEvent ) => {
103141 const overlayCloseEvent = new CustomEvent ( 'vaadin-overlay-close' , {
@@ -163,13 +201,6 @@ describe('vaadin-notification', () => {
163201 expect ( container . _detectIosNavbar . called ) . to . be . true ;
164202 container . _detectIosNavbar . restore ( ) ;
165203 } ) ;
166-
167- it ( 'should bring to front on notification open ' , ( ) => {
168- notification . opened = false ;
169- const spy = sinon . spy ( container , 'bringToFront' ) ;
170- notification . opened = true ;
171- expect ( spy ) . to . be . calledOnce ;
172- } ) ;
173204 } ) ;
174205 } ) ;
175206
0 commit comments