From 9ea072693d6709deeace855629636be19030c32b Mon Sep 17 00:00:00 2001 From: haven1433 Date: Sat, 12 Aug 2023 21:42:07 -0500 Subject: [PATCH] test that save status updates correctly for data/non-data changes --- .../ViewModels/ChangeHistory.cs | 5 ++-- .../Before_Baseclass/ChangeHistoryTests.cs | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/HexManiac.Core/ViewModels/ChangeHistory.cs b/src/HexManiac.Core/ViewModels/ChangeHistory.cs index 1b3dc860..fd42afa9 100644 --- a/src/HexManiac.Core/ViewModels/ChangeHistory.cs +++ b/src/HexManiac.Core/ViewModels/ChangeHistory.cs @@ -160,9 +160,10 @@ namespace HavenSoft.HexManiac.Core.ViewModels { var hasDataChange = HasDataChange; if (hasDataChange != hasDataChangeCache) { hasDataChangeCache = hasDataChange; - NotifyPropertyChanged(nameof(HasDataChange), nameof(IsSaved)); + NotifyPropertiesChanged(nameof(HasDataChange), nameof(IsSaved)); + } else if (!hasDataChange && currentChange.HasAnyChange) { + NotifyPropertyChanged(nameof(IsSaved)); } - if (!hasDataChange && currentChange.HasAnyChange) NotifyPropertyChanged(nameof(IsSaved)); } private void UndoExecuted() { diff --git a/src/HexManiac.Tests/Before_Baseclass/ChangeHistoryTests.cs b/src/HexManiac.Tests/Before_Baseclass/ChangeHistoryTests.cs index f475430b..8064ded9 100644 --- a/src/HexManiac.Tests/Before_Baseclass/ChangeHistoryTests.cs +++ b/src/HexManiac.Tests/Before_Baseclass/ChangeHistoryTests.cs @@ -496,5 +496,28 @@ namespace HavenSoft.HexManiac.Tests { Assert.Equal(3, recentChanges.Count); } + + [Fact] + public void DataChange_Name_ContainsAstrisk() { + var view = new StubView(ViewPort); + + ViewPort.Edit("03"); + + Assert.EndsWith("*", ViewPort.Name); + Assert.True(ViewPort.ChangeHistory.HasDataChange); + Assert.Contains(nameof(ViewPort.Name), view.PropertyNotifications); + Assert.Contains(nameof(ViewPort.Save), view.CommandCanExecuteChangedNotifications); + } + + [Fact] + public void NonDataChange_Name_NoAstrisk() { + var view = new StubView(ViewPort); + + ViewPort.Edit("^test "); + + Assert.False(ViewPort.Name.EndsWith("*")); + Assert.False(ViewPort.ChangeHistory.HasDataChange); + Assert.Contains(nameof(ViewPort.Save), view.CommandCanExecuteChangedNotifications); + } } }