FilePickerVM tooltip fixes + tests

This commit is contained in:
Justin Swanson 2019-12-14 21:55:16 -06:00
parent d6a819b9b9
commit 705914bd77
3 changed files with 39 additions and 10 deletions

View File

@ -66,6 +66,9 @@ namespace Wabbajack.Lib
public SourceList<CommonFileDialogFilter> Filters { get; } = new SourceList<CommonFileDialogFilter>(); public SourceList<CommonFileDialogFilter> Filters { get; } = new SourceList<CommonFileDialogFilter>();
public const string PathDoesNotExistText = "Path does not exist";
public const string DoesNotPassFiltersText = "Path does not pass designated filters";
public FilePickerVM(object parentVM = null) public FilePickerVM(object parentVM = null)
{ {
Parent = parentVM; Parent = parentVM;
@ -193,23 +196,22 @@ namespace Wabbajack.Lib
.Select(passed => .Select(passed =>
{ {
if (passed) return ErrorResponse.Success; if (passed) return ErrorResponse.Success;
return ErrorResponse.Fail($"Path does not pass designated filters"); return ErrorResponse.Fail(DoesNotPassFiltersText);
}) })
.Publish() .Replay(1)
.RefCount(); .RefCount();
_errorState = Observable.CombineLatest( _errorState = Observable.CombineLatest(
this.WhenAny(x => x.Exists),
Observable.CombineLatest( Observable.CombineLatest(
this.WhenAny(x => x.Exists), this.WhenAny(x => x.Exists),
doExistsCheck, doExistsCheck,
resultSelector: (exists, doExists) => !doExists || exists) resultSelector: (exists, doExists) => !doExists || exists)
.Select(exists => ErrorResponse.Create(successful: exists, exists ? default(string) : "Path does not exist")), .Select(exists => ErrorResponse.Create(successful: exists, exists ? default(string) : PathDoesNotExistText)),
passesFilters, passesFilters,
this.WhenAny(x => x.AdditionalError) this.WhenAny(x => x.AdditionalError)
.Select(x => x ?? Observable.Return<IErrorResponse>(ErrorResponse.Success)) .Select(x => x ?? Observable.Return<IErrorResponse>(ErrorResponse.Success))
.Switch(), .Switch(),
resultSelector: (exists, existCheck, filter, err) => resultSelector: (existCheck, filter, err) =>
{ {
if (existCheck.Failed) return existCheck; if (existCheck.Failed) return existCheck;
if (filter.Failed) return filter; if (filter.Failed) return filter;
@ -224,8 +226,11 @@ namespace Wabbajack.Lib
// Doesn't derive from ErrorState, as we want to bubble non-empty tooltips, // Doesn't derive from ErrorState, as we want to bubble non-empty tooltips,
// which is slightly different logic // which is slightly different logic
_errorTooltip = Observable.CombineLatest( _errorTooltip = Observable.CombineLatest(
this.WhenAny(x => x.Exists) Observable.CombineLatest(
.Select(exists => exists ? default(string) : "Path does not exist"), this.WhenAny(x => x.Exists),
doExistsCheck,
resultSelector: (exists, doExists) => !doExists || exists)
.Select(exists => exists ? default(string) : PathDoesNotExistText),
passesFilters passesFilters
.Select(x => x.Reason), .Select(x => x.Reason),
this.WhenAny(x => x.AdditionalError) this.WhenAny(x => x.AdditionalError)

View File

@ -41,6 +41,7 @@ namespace Wabbajack.Test
Assert.IsFalse(vm.Exists); Assert.IsFalse(vm.Exists);
Assert.IsTrue(vm.ErrorState.Succeeded); Assert.IsTrue(vm.ErrorState.Succeeded);
Assert.IsFalse(vm.InError); Assert.IsFalse(vm.InError);
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
} }
[TestMethod] [TestMethod]
@ -53,6 +54,7 @@ namespace Wabbajack.Test
Assert.IsFalse(vm.Exists); Assert.IsFalse(vm.Exists);
Assert.IsTrue(vm.ErrorState.Succeeded); Assert.IsTrue(vm.ErrorState.Succeeded);
Assert.IsFalse(vm.InError); Assert.IsFalse(vm.InError);
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
} }
[TestMethod] [TestMethod]
@ -67,6 +69,7 @@ namespace Wabbajack.Test
Assert.IsFalse(vm.Exists); Assert.IsFalse(vm.Exists);
Assert.IsTrue(vm.ErrorState.Succeeded); Assert.IsTrue(vm.ErrorState.Succeeded);
Assert.IsFalse(vm.InError); Assert.IsFalse(vm.InError);
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
} }
} }
@ -80,6 +83,7 @@ namespace Wabbajack.Test
Assert.IsFalse(vm.Exists); Assert.IsFalse(vm.Exists);
Assert.IsTrue(vm.ErrorState.Succeeded); Assert.IsTrue(vm.ErrorState.Succeeded);
Assert.IsFalse(vm.InError); Assert.IsFalse(vm.InError);
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
} }
[TestMethod] [TestMethod]
@ -94,6 +98,7 @@ namespace Wabbajack.Test
Assert.IsFalse(vm.Exists); Assert.IsFalse(vm.Exists);
Assert.IsTrue(vm.ErrorState.Succeeded); Assert.IsTrue(vm.ErrorState.Succeeded);
Assert.IsFalse(vm.InError); Assert.IsFalse(vm.InError);
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
} }
} }
@ -107,6 +112,7 @@ namespace Wabbajack.Test
Assert.IsFalse(vm.Exists); Assert.IsFalse(vm.Exists);
Assert.IsTrue(vm.ErrorState.Succeeded); Assert.IsTrue(vm.ErrorState.Succeeded);
Assert.IsFalse(vm.InError); Assert.IsFalse(vm.InError);
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
} }
[TestMethod] [TestMethod]
@ -120,6 +126,7 @@ namespace Wabbajack.Test
Assert.IsFalse(vm.Exists); Assert.IsFalse(vm.Exists);
Assert.IsFalse(vm.ErrorState.Succeeded); Assert.IsFalse(vm.ErrorState.Succeeded);
Assert.IsTrue(vm.InError); Assert.IsTrue(vm.InError);
Assert.AreEqual(FilePickerVM.PathDoesNotExistText, vm.ErrorTooltip);
} }
[TestMethod] [TestMethod]
@ -134,6 +141,7 @@ namespace Wabbajack.Test
Assert.IsTrue(vm.Exists); Assert.IsTrue(vm.Exists);
Assert.IsTrue(vm.ErrorState.Succeeded); Assert.IsTrue(vm.ErrorState.Succeeded);
Assert.IsFalse(vm.InError); Assert.IsFalse(vm.InError);
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
} }
} }
@ -147,6 +155,7 @@ namespace Wabbajack.Test
Assert.IsFalse(vm.Exists); Assert.IsFalse(vm.Exists);
Assert.IsFalse(vm.ErrorState.Succeeded); Assert.IsFalse(vm.ErrorState.Succeeded);
Assert.IsTrue(vm.InError); Assert.IsTrue(vm.InError);
Assert.AreEqual(FilePickerVM.PathDoesNotExistText, vm.ErrorTooltip);
} }
[TestMethod] [TestMethod]
@ -161,6 +170,7 @@ namespace Wabbajack.Test
Assert.IsTrue(vm.Exists); Assert.IsTrue(vm.Exists);
Assert.IsTrue(vm.ErrorState.Succeeded); Assert.IsTrue(vm.ErrorState.Succeeded);
Assert.IsFalse(vm.InError); Assert.IsFalse(vm.InError);
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
} }
} }
@ -174,6 +184,7 @@ namespace Wabbajack.Test
Assert.IsFalse(vm.Exists); Assert.IsFalse(vm.Exists);
Assert.IsTrue(vm.ErrorState.Succeeded); Assert.IsTrue(vm.ErrorState.Succeeded);
Assert.IsFalse(vm.InError); Assert.IsFalse(vm.InError);
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
} }
[TestMethod] [TestMethod]
@ -187,6 +198,7 @@ namespace Wabbajack.Test
Assert.IsFalse(vm.Exists); Assert.IsFalse(vm.Exists);
Assert.IsFalse(vm.ErrorState.Succeeded); Assert.IsFalse(vm.ErrorState.Succeeded);
Assert.IsTrue(vm.InError); Assert.IsTrue(vm.InError);
Assert.AreEqual(FilePickerVM.PathDoesNotExistText, vm.ErrorTooltip);
} }
[TestMethod] [TestMethod]
@ -201,6 +213,7 @@ namespace Wabbajack.Test
Assert.IsTrue(vm.Exists); Assert.IsTrue(vm.Exists);
Assert.IsTrue(vm.ErrorState.Succeeded); Assert.IsTrue(vm.ErrorState.Succeeded);
Assert.IsFalse(vm.InError); Assert.IsFalse(vm.InError);
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
} }
} }
@ -214,6 +227,7 @@ namespace Wabbajack.Test
Assert.IsFalse(vm.Exists); Assert.IsFalse(vm.Exists);
Assert.IsFalse(vm.ErrorState.Succeeded); Assert.IsFalse(vm.ErrorState.Succeeded);
Assert.IsTrue(vm.InError); Assert.IsTrue(vm.InError);
Assert.AreEqual(FilePickerVM.PathDoesNotExistText, vm.ErrorTooltip);
} }
[TestMethod] [TestMethod]
@ -228,6 +242,7 @@ namespace Wabbajack.Test
Assert.IsTrue(vm.Exists); Assert.IsTrue(vm.Exists);
Assert.IsTrue(vm.ErrorState.Succeeded); Assert.IsTrue(vm.ErrorState.Succeeded);
Assert.IsFalse(vm.InError); Assert.IsFalse(vm.InError);
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
} }
} }
@ -239,16 +254,19 @@ namespace Wabbajack.Test
await Task.Delay(250); await Task.Delay(250);
Assert.IsTrue(vm.ErrorState.Succeeded); Assert.IsTrue(vm.ErrorState.Succeeded);
Assert.IsFalse(vm.InError); Assert.IsFalse(vm.InError);
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
} }
[TestMethod] [TestMethod]
public async Task AdditionalError_Fail() public async Task AdditionalError_Fail()
{ {
var vm = new FilePickerVM(); var vm = new FilePickerVM();
vm.AdditionalError = Observable.Return<IErrorResponse>(ErrorResponse.Fail()); string errText = "An error";
vm.AdditionalError = Observable.Return<IErrorResponse>(ErrorResponse.Fail(errText));
await Task.Delay(250); await Task.Delay(250);
Assert.IsFalse(vm.ErrorState.Succeeded); Assert.IsFalse(vm.ErrorState.Succeeded);
Assert.IsTrue(vm.InError); Assert.IsTrue(vm.InError);
Assert.AreEqual(errText, vm.ErrorTooltip);
} }
[TestMethod] [TestMethod]
@ -263,6 +281,7 @@ namespace Wabbajack.Test
Assert.IsFalse(vm.Exists); Assert.IsFalse(vm.Exists);
Assert.IsFalse(vm.ErrorState.Succeeded); Assert.IsFalse(vm.ErrorState.Succeeded);
Assert.IsTrue(vm.InError); Assert.IsTrue(vm.InError);
Assert.AreEqual(FilePickerVM.PathDoesNotExistText, vm.ErrorTooltip);
} }
} }
@ -278,6 +297,7 @@ namespace Wabbajack.Test
Assert.IsFalse(vm.Exists); Assert.IsFalse(vm.Exists);
Assert.IsFalse(vm.ErrorState.Succeeded); Assert.IsFalse(vm.ErrorState.Succeeded);
Assert.IsTrue(vm.InError); Assert.IsTrue(vm.InError);
Assert.AreEqual(FilePickerVM.PathDoesNotExistText, vm.ErrorTooltip);
} }
} }
@ -294,6 +314,7 @@ namespace Wabbajack.Test
Assert.IsFalse(vm.Exists); Assert.IsFalse(vm.Exists);
Assert.IsTrue(vm.ErrorState.Succeeded); Assert.IsTrue(vm.ErrorState.Succeeded);
Assert.IsFalse(vm.InError); Assert.IsFalse(vm.InError);
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
} }
} }
@ -310,6 +331,7 @@ namespace Wabbajack.Test
Assert.IsFalse(vm.Exists); Assert.IsFalse(vm.Exists);
Assert.IsFalse(vm.ErrorState.Succeeded); Assert.IsFalse(vm.ErrorState.Succeeded);
Assert.IsTrue(vm.InError); Assert.IsTrue(vm.InError);
Assert.AreEqual(FilePickerVM.DoesNotPassFiltersText, vm.ErrorTooltip);
} }
} }
@ -325,6 +347,7 @@ namespace Wabbajack.Test
Assert.IsFalse(vm.Exists); Assert.IsFalse(vm.Exists);
Assert.IsTrue(vm.ErrorState.Succeeded); Assert.IsTrue(vm.ErrorState.Succeeded);
Assert.IsFalse(vm.InError); Assert.IsFalse(vm.InError);
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
} }
[TestMethod] [TestMethod]
@ -339,6 +362,7 @@ namespace Wabbajack.Test
Assert.IsFalse(vm.Exists); Assert.IsFalse(vm.Exists);
Assert.IsTrue(vm.ErrorState.Succeeded); Assert.IsTrue(vm.ErrorState.Succeeded);
Assert.IsFalse(vm.InError); Assert.IsFalse(vm.InError);
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
} }
} }
} }

View File

@ -103,7 +103,7 @@
FontSize="14" FontSize="14"
Text="Download Location" Text="Download Location"
TextAlignment="Center" TextAlignment="Center"
ToolTip="The folder to downloads your mods" /> ToolTip="The folder to download your mods" />
<local:FilePicker <local:FilePicker
Grid.Row="0" Grid.Row="0"
Grid.Column="6" Grid.Column="6"
@ -111,7 +111,7 @@
VerticalAlignment="Center" VerticalAlignment="Center"
DataContext="{Binding DownloadsLocation}" DataContext="{Binding DownloadsLocation}"
FontSize="14" FontSize="14"
ToolTip="The folder to downloads your mods" /> ToolTip="The folder to download your mods" />
<TextBlock <TextBlock
Grid.Row="1" Grid.Row="1"
Grid.Column="4" Grid.Column="4"