Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Navigation.Test/NavigationStackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,34 @@
AssertStack("X,Y", "Y");
}

[TestMethod]
public async Task LoadStateAsync_OfTheCurrentStack_RecordsNoUndoAndRaisesNoEvent()
{
// Arrange
NavigationItem a = new("A", "A");
NavigationItem b = new("B", "B");
_navigation!.NavigateTo(a);
_navigation.NavigateTo(b);
await _navigation.SaveStateAsync().ConfigureAwait(false);

Check warning on line 390 in Navigation.Test/NavigationStackTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Consider using the overload that accepts a CancellationToken and pass 'TestContext.CancellationToken'

See more on https://sonarcloud.io/project/issues?id=ktsu-dev_Navigation&issues=AaG3R5WrE7uBDFkTikUS&open=AaG3R5WrE7uBDFkTikUS&pullRequest=110
List<NavigationEventArgs<NavigationItem>> events = [];
_navigation.NavigationChanged += (sender, e) => events.Add(e);

// Act
bool loaded = await _navigation.LoadStateAsync().ConfigureAwait(false);

Check warning on line 395 in Navigation.Test/NavigationStackTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Consider using the overload that accepts a CancellationToken and pass 'TestContext.CancellationToken'

See more on https://sonarcloud.io/project/issues?id=ktsu-dev_Navigation&issues=AaG3R5WrE7uBDFkTikUT&open=AaG3R5WrE7uBDFkTikUT&pullRequest=110

// Assert
Assert.IsTrue(loaded);
Assert.IsEmpty(events);
AssertStack("A,B", "B");

// The first undo goes back to A, not through a step that changes nothing
Assert.IsTrue(_undoRedoProvider!.Undo());
AssertStack("A", "A");
Assert.HasCount(1, events);
Assert.AreSame(b, events[0].PreviousItem);
Assert.AreSame(a, events[0].CurrentItem);
}

[TestMethod]
public void GoBack_WithoutUndoProvider_StillNavigates()
{
Expand Down
8 changes: 8 additions & 0 deletions Navigation/Services/NavigationStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,14 @@ public async Task<bool> LoadStateAsync(CancellationToken cancellationToken = def
T? currentItem;
lock (_sync)
{
// A load that matches the stack changes nothing, so it records no undo step that would itself do nothing
// and raises no event from the current page to itself. Items are compared by reference, as RestoreState
// compares them
if (currentIndex == _currentIndex && IsSameItems(items))
{
return true;
}

previousItem = CurrentUnlocked;
int beforeIndex = _currentIndex;
List<T>? beforeItems = SnapshotForUndo();
Expand Down
Loading