@@ -30,6 +30,13 @@ describe('WebPlatform', () => {
3030 expect ( platform . getHumanReadableName ( ) ) . toEqual ( 'Web Platform' ) ;
3131 } ) ;
3232
33+ it ( 'registers service worker' , ( ) => {
34+ // @ts -ignore - mocking readonly object
35+ navigator . serviceWorker = { register : jest . fn ( ) } ;
36+ new WebPlatform ( ) ;
37+ expect ( navigator . serviceWorker . register ) . toHaveBeenCalled ( ) ;
38+ } ) ;
39+
3340 describe ( 'notification support' , ( ) => {
3441 const mockNotification = {
3542 requestPermission : jest . fn ( ) ,
@@ -50,7 +57,7 @@ describe('WebPlatform', () => {
5057 it ( 'supportsNotifications returns true when platform supports notifications' , ( ) => {
5158 expect ( new WebPlatform ( ) . supportsNotifications ( ) ) . toBe ( true ) ;
5259 } ) ;
53-
60+
5461 it ( 'maySendNotifications returns true when notification permissions are not granted' , ( ) => {
5562 expect ( new WebPlatform ( ) . maySendNotifications ( ) ) . toBe ( false ) ;
5663 } ) ;
@@ -109,78 +116,76 @@ describe('WebPlatform', () => {
109116 } ) ;
110117
111118 describe ( 'pollForUpdate()' , ( ) => {
112-
113119 it ( 'should return not available and call showNoUpdate when current version matches most recent version' , async ( ) => {
114120 process . env . VERSION = prodVersion ;
115121 setRequestMockImplementation ( undefined , { status : 200 } , prodVersion ) ;
116122 const platform = new WebPlatform ( ) ;
117-
123+
118124 const showUpdate = jest . fn ( ) ;
119125 const showNoUpdate = jest . fn ( ) ;
120126 const result = await platform . pollForUpdate ( showUpdate , showNoUpdate ) ;
121-
127+
122128 expect ( result ) . toEqual ( { status : UpdateCheckStatus . NotAvailable } ) ;
123129 expect ( showUpdate ) . not . toHaveBeenCalled ( ) ;
124130 expect ( showNoUpdate ) . toHaveBeenCalled ( ) ;
125131 } ) ;
126-
132+
127133 it ( 'should strip v prefix from versions before comparing' , async ( ) => {
128134 process . env . VERSION = prodVersion ;
129135 setRequestMockImplementation ( undefined , { status : 200 } , `v${ prodVersion } ` ) ;
130136 const platform = new WebPlatform ( ) ;
131-
137+
132138 const showUpdate = jest . fn ( ) ;
133139 const showNoUpdate = jest . fn ( ) ;
134140 const result = await platform . pollForUpdate ( showUpdate , showNoUpdate ) ;
135-
141+
136142 // versions only differ by v prefix, no update
137143 expect ( result ) . toEqual ( { status : UpdateCheckStatus . NotAvailable } ) ;
138144 expect ( showUpdate ) . not . toHaveBeenCalled ( ) ;
139145 expect ( showNoUpdate ) . toHaveBeenCalled ( ) ;
140146 } ) ;
141-
147+
142148 it ( 'should return ready and call showUpdate when current version differs from most recent version' , async ( ) => {
143149 process . env . VERSION = '0.0.0' ; // old version
144150 setRequestMockImplementation ( undefined , { status : 200 } , prodVersion ) ;
145151 const platform = new WebPlatform ( ) ;
146-
152+
147153 const showUpdate = jest . fn ( ) ;
148154 const showNoUpdate = jest . fn ( ) ;
149155 const result = await platform . pollForUpdate ( showUpdate , showNoUpdate ) ;
150-
156+
151157 expect ( result ) . toEqual ( { status : UpdateCheckStatus . Ready } ) ;
152158 expect ( showUpdate ) . toHaveBeenCalledWith ( '0.0.0' , prodVersion ) ;
153159 expect ( showNoUpdate ) . not . toHaveBeenCalled ( ) ;
154160 } ) ;
155-
161+
156162 it ( 'should return ready without showing update when user registered in last 24' , async ( ) => {
157163 process . env . VERSION = '0.0.0' ; // old version
158164 jest . spyOn ( MatrixClientPeg , 'userRegisteredWithinLastHours' ) . mockReturnValue ( true ) ;
159165 setRequestMockImplementation ( undefined , { status : 200 } , prodVersion ) ;
160166 const platform = new WebPlatform ( ) ;
161-
167+
162168 const showUpdate = jest . fn ( ) ;
163169 const showNoUpdate = jest . fn ( ) ;
164170 const result = await platform . pollForUpdate ( showUpdate , showNoUpdate ) ;
165-
171+
166172 expect ( result ) . toEqual ( { status : UpdateCheckStatus . Ready } ) ;
167173 expect ( showUpdate ) . not . toHaveBeenCalled ( ) ;
168174 expect ( showNoUpdate ) . not . toHaveBeenCalled ( ) ;
169175 } ) ;
170-
176+
171177 it ( 'should return error when version check fails' , async ( ) => {
172178 setRequestMockImplementation ( 'oups' ) ;
173179 const platform = new WebPlatform ( ) ;
174-
180+
175181 const showUpdate = jest . fn ( ) ;
176182 const showNoUpdate = jest . fn ( ) ;
177183 const result = await platform . pollForUpdate ( showUpdate , showNoUpdate ) ;
178-
184+
179185 expect ( result ) . toEqual ( { status : UpdateCheckStatus . Error , detail : 'Unknown Error' } ) ;
180186 expect ( showUpdate ) . not . toHaveBeenCalled ( ) ;
181187 expect ( showNoUpdate ) . not . toHaveBeenCalled ( ) ;
182188 } ) ;
183189 } ) ;
184-
185190 } ) ;
186191} ) ;
0 commit comments