@@ -200,6 +200,76 @@ public void MapsUpdateMessagesAndActions()
200200 Assert . True ( viewModel . CanInstallUpdate ) ;
201201 }
202202
203+ [ Fact ]
204+ public void ShowsDeterminateDownloadProgress ( )
205+ {
206+ SettingsViewModel viewModel = new ( ) ;
207+
208+ viewModel . SetUpdateState ( UpdateState . CreateInitial ( "0.2.3" ) with
209+ {
210+ Download = new UpdateDownloadProgress ( UpdateDownloadStatus . Downloading , 20_971_520 , 52_428_800 , 40 )
211+ } ) ;
212+
213+ Assert . True ( viewModel . IsUpdateDownloading ) ;
214+ Assert . False ( viewModel . IsUpdateDownloadIndeterminate ) ;
215+ Assert . Equal ( 40 , viewModel . UpdateDownloadPercent ) ;
216+ Assert . Equal ( "Downloading update..." , viewModel . UpdateDownloadMessage ) ;
217+ Assert . Equal ( "Downloading 40% (20.0 MB of 50.0 MB)." , viewModel . UpdateDownloadProgressText ) ;
218+ }
219+
220+ [ Fact ]
221+ public void ShowsIndeterminateDownloadProgressWhenPercentIsUnknown ( )
222+ {
223+ SettingsViewModel viewModel = new ( ) ;
224+
225+ viewModel . SetUpdateState ( UpdateState . CreateInitial ( "0.2.3" ) with
226+ {
227+ Download = new UpdateDownloadProgress ( UpdateDownloadStatus . Downloading , 20_971_520 , null , null )
228+ } ) ;
229+
230+ Assert . True ( viewModel . IsUpdateDownloading ) ;
231+ Assert . True ( viewModel . IsUpdateDownloadIndeterminate ) ;
232+ Assert . Equal ( 0 , viewModel . UpdateDownloadPercent ) ;
233+ Assert . Equal ( "Downloading 20.0 MB." , viewModel . UpdateDownloadProgressText ) ;
234+ }
235+
236+ [ Fact ]
237+ public void HidesDownloadProgressWhenDownloaded ( )
238+ {
239+ SettingsViewModel viewModel = new ( ) ;
240+
241+ viewModel . SetUpdateState ( UpdateState . CreateInitial ( "0.2.3" ) with
242+ {
243+ Download = new UpdateDownloadProgress ( UpdateDownloadStatus . Downloaded , 52_428_800 , 52_428_800 , 100 )
244+ } ) ;
245+
246+ Assert . False ( viewModel . IsUpdateDownloading ) ;
247+ Assert . False ( viewModel . IsUpdateDownloadIndeterminate ) ;
248+ Assert . Equal ( 100 , viewModel . UpdateDownloadPercent ) ;
249+ Assert . Equal ( "Update downloaded and ready to install." , viewModel . UpdateDownloadMessage ) ;
250+ Assert . Equal ( string . Empty , viewModel . UpdateDownloadProgressText ) ;
251+ }
252+
253+ [ Fact ]
254+ public void HidesDownloadProgressWhenFailed ( )
255+ {
256+ SettingsViewModel viewModel = new ( ) ;
257+
258+ viewModel . SetUpdateState ( UpdateState . CreateInitial ( "0.2.3" ) with
259+ {
260+ Download = new UpdateDownloadProgress (
261+ UpdateDownloadStatus . DownloadFailed ,
262+ 20_971_520 ,
263+ 52_428_800 ,
264+ 40 ,
265+ UpdateFailureReason . NetworkError )
266+ } ) ;
267+
268+ Assert . False ( viewModel . IsUpdateDownloading ) ;
269+ Assert . Equal ( "Could not download the update." , viewModel . UpdateDownloadMessage ) ;
270+ Assert . Equal ( string . Empty , viewModel . UpdateDownloadProgressText ) ;
271+ }
272+
203273 [ Fact ]
204274 public void MapsUpdateInstallFailureMessages ( )
205275 {
@@ -224,11 +294,19 @@ public void RaisesChangedProperties()
224294 viewModel . PropertyChanged += ( _ , eventArgs ) => changed . Add ( eventArgs . PropertyName ) ;
225295
226296 viewModel . SetPointerMovementSettings ( new PointerMovementSettings ( 50 ) ) ;
297+ viewModel . SetUpdateState ( UpdateState . CreateInitial ( "0.2.3" ) with
298+ {
299+ Download = new UpdateDownloadProgress ( UpdateDownloadStatus . Downloading , 1024 , 2048 , 50 )
300+ } ) ;
227301
228302 Assert . Contains ( nameof ( SettingsViewModel . PointerScalePercent ) , changed ) ;
229303 Assert . Contains ( nameof ( SettingsViewModel . IsPointerScale50 ) , changed ) ;
230304 Assert . Contains ( nameof ( SettingsViewModel . PointerSmall ) , changed ) ;
231305 Assert . Contains ( nameof ( SettingsViewModel . PointerMedium ) , changed ) ;
232306 Assert . Contains ( nameof ( SettingsViewModel . PointerLarge ) , changed ) ;
307+ Assert . Contains ( nameof ( SettingsViewModel . IsUpdateDownloading ) , changed ) ;
308+ Assert . Contains ( nameof ( SettingsViewModel . IsUpdateDownloadIndeterminate ) , changed ) ;
309+ Assert . Contains ( nameof ( SettingsViewModel . UpdateDownloadPercent ) , changed ) ;
310+ Assert . Contains ( nameof ( SettingsViewModel . UpdateDownloadProgressText ) , changed ) ;
233311 }
234312}
0 commit comments