Skip to content

Commit

Permalink
fix: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-Antoine-Soucy committed Apr 18, 2024
1 parent 206ba29 commit 6b087f4
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 32 deletions.
13 changes: 8 additions & 5 deletions doc/ForcedUpdate.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ To force an update, we suscribe to the UpdateRequired Event from the UpdateRequi

void ForceUpdate(object sender, EventArgs e)
{
var navigationController = services.GetRequiredService<ISectionsNavigator>();
var navigationController = services.GetRequiredService<ISectionsNavigator>();

_ = Task.Run(async () =>
{
await navigationController.NavigateAndClear(CancellationToken.None, () => new ForcedUpdatePageViewModel());
});
_ = Task.Run(async () =>
{
await navigationController.NavigateAndClear(CancellationToken.None, () => new ForcedUpdatePageViewModel());
});

updateRequiredService.UpdateRequired -= ForceUpdate;
updateRequiredService.Dispose();
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ApplicationTemplate.DataAccess;
/// Gets the minimum version required to use the application.
/// This was created for mocking the IUpdateRequiredService.
/// </summary>
public interface IMinimumVersionReposiory
public interface IMinimumVersionReposiory : IDisposable
{
/// <summary>
/// Checks the minimum required version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ public void CheckMinimumVersion()
{
_minimumVersionSubject.OnNext(new Version(1, 0, 0, 0));
}

/// <inheritdoc/>
public void Dispose()
{
_minimumVersionSubject.Dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace ApplicationTemplate.Business;
/// <summary>
/// This service checks if the application is running the minimum required version.
/// </summary>
public interface IUpdateRequiredService
public interface IUpdateRequiredService : IDisposable
{
/// <summary>
/// Event that is raised when the application needs to be updated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,25 @@ namespace ApplicationTemplate.Business;
/// </summary>
public sealed class UpdateRequiredServiceMock : IUpdateRequiredService
{
private readonly IDisposable? _subscription;

/// <summary>
/// Initializes a new instance of the <see cref="UpdateRequiredServiceMock"/> class.
/// </summary>
/// <param name="minimumVersionReposiory"> A repository that contains an observable we can use to update the app. </param>
public UpdateRequiredServiceMock(IMinimumVersionReposiory minimumVersionReposiory)
{
minimumVersionReposiory.MinimumVersionObservable
_subscription = minimumVersionReposiory.MinimumVersionObservable
.Subscribe(_ => UpdateRequired?.Invoke(this, EventArgs.Empty));
}

/// <inheritdoc />
public event EventHandler UpdateRequired;

/// <inheritdoc />
public void Dispose()
{
_subscription.Dispose();
UpdateRequired = null;
}
}
3 changes: 3 additions & 0 deletions src/app/ApplicationTemplate.Presentation/CoreStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ void ForceUpdate(object sender, EventArgs e)
{
await navigationController.NavigateAndClear(CancellationToken.None, () => new ForcedUpdatePageViewModel());
});

updateRequiredService.UpdateRequired -= ForceUpdate;
updateRequiredService.Dispose();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/ApplicationTemplate.Presentation/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"IsMockEnabled": false
},
"ApplicationStoreUrls": {
// TODO: Update the URLs with the actual URLs
// TODO: Update the URLs with the actual URLs.
"IOS": "https://apps.apple.com/us/app/duolingo-language-lessons/id570060128",
"Android": "https://play.google.com/store/apps/details?id=com.duolingo",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Margin="0,0,0,20"
<TextBlock x:Uid="ForcedUpdateContent"
Margin="0,0,0,20"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="24"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public Uri GetAppStoreUri()
var mockOptions = _configuration.GetSection("ApplicationStoreUrls").Get<ApplicationStoreUrisOptions>();
Uri uri;

#if ANDROID
#if __ANDROID__
uri = mockOptions.Android;
#elif IOS
#elif __IOS__
uri = mockOptions.Ios;
#else
throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,7 @@ it's happening!</value>
<data name="ResetPassword_Reset.Content" xml:space="preserve">
<value>SAVE MY PASSWORD</value>
</data>
<data name="ForcedUpdateContent.Text" xml:space="preserve">
<value>An update is required to continue using the application.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,7 @@ Je pense que nous savons tous pourquoi nous sommes ici."</value>
<data name="ResetPassword_Reset.Content" xml:space="preserve">
<value>ENREGISTRER MON MOT DE PASSE</value>
</data>
<data name="ForcedUpdateContent.Text" xml:space="preserve">
<value>Une mise à jour de l'application est nécessaire pour continuer de l'utiliser.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ApplicationTemplate.Tests;
/// <summary>
/// Tests for the forced update flow.
/// </summary>
public class ForceUpdatesShould : FunctionalTestBase
public sealed class ForceUpdatesShould : FunctionalTestBase
{
/// <summary>
/// Tests that the force update page is shown when the update required event is raised.
Expand All @@ -20,14 +20,17 @@ public async Task RedirectTheAppToForceUpdatePage()
// Arrange
var vm = await this.ReachLoginPage();
var sectionNavigator = GetService<ISectionsNavigator>();
var minimumVersionReposiory = GetService<IMinimumVersionReposiory>();

// Act
// This will raise the update required event.
GetService<IMinimumVersionReposiory>().CheckMinimumVersion();
minimumVersionReposiory.CheckMinimumVersion();

// Waits for the navigation to be completed, we need the StartWith in case the navigation already finished before we started observing.
await sectionNavigator.ObserveCurrentState().StartWith(sectionNavigator.State).Where(x => x.LastRequestState != NavigatorRequestState.Processing).FirstAsync();

minimumVersionReposiory.Dispose();

// Assert
ActiveViewModel.Should().BeOfType<ForcedUpdatePageViewModel>();
}
Expand All @@ -42,10 +45,11 @@ public async Task DisableTheBackButton()
// Arrange
var vm = await this.ReachLoginPage();
var sectionNavigator = GetService<ISectionsNavigator>();
var minimumVersionReposiory = GetService<IMinimumVersionReposiory>();

// Act
// This will raise the update required event.
GetService<IMinimumVersionReposiory>().CheckMinimumVersion();
minimumVersionReposiory.CheckMinimumVersion();

// Waits for the navigation to be completed, we need the StartWith in case the navigation already finished before we started observing.
await sectionNavigator.ObserveCurrentState().StartWith(sectionNavigator.State).Where(x => x.LastRequestState != NavigatorRequestState.Processing).FirstAsync();
Expand All @@ -54,6 +58,8 @@ public async Task DisableTheBackButton()

await sectionNavigator.ObserveCurrentState().StartWith(sectionNavigator.State).Where(x => x.LastRequestState != NavigatorRequestState.Processing).FirstAsync();

minimumVersionReposiory.Dispose();

// Assert
ActiveViewModel.Should().BeOfType<ForcedUpdatePageViewModel>();
}
Expand Down
34 changes: 17 additions & 17 deletions src/app/ApplicationTemplate.Tests.Functional/FunctionalTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,6 @@ public void NavigateBackUsingHardwareButton()
_backButtonSource.RaiseBackRequested();
}

class BackButtonSource : IBackButtonSource
{
public string Name => "Test";

public event BackRequestedEventHandler BackRequested;

public void Dispose()
{
BackRequested = null;
}

public void RaiseBackRequested()
{
BackRequested?.Invoke(this, new BackRequestedEventArgs());
}
}

/// <summary>
/// Configures the services required for functional testing.
/// </summary>
Expand Down Expand Up @@ -211,4 +194,21 @@ async Task IAsyncLifetime.DisposeAsync()
{
_coreStartup.Dispose();
}

private sealed class BackButtonSource : IBackButtonSource
{
public string Name => "Test";

public event BackRequestedEventHandler BackRequested;

public void Dispose()
{
BackRequested = null;
}

public void RaiseBackRequested()
{
BackRequested?.Invoke(this, new BackRequestedEventArgs());
}
}
}

0 comments on commit 6b087f4

Please sign in to comment.