mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
FilePickerVM tooltip fixes + tests
This commit is contained in:
parent
d6a819b9b9
commit
705914bd77
@ -66,6 +66,9 @@ namespace Wabbajack.Lib
|
||||
|
||||
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)
|
||||
{
|
||||
Parent = parentVM;
|
||||
@ -193,23 +196,22 @@ namespace Wabbajack.Lib
|
||||
.Select(passed =>
|
||||
{
|
||||
if (passed) return ErrorResponse.Success;
|
||||
return ErrorResponse.Fail($"Path does not pass designated filters");
|
||||
return ErrorResponse.Fail(DoesNotPassFiltersText);
|
||||
})
|
||||
.Publish()
|
||||
.Replay(1)
|
||||
.RefCount();
|
||||
|
||||
_errorState = Observable.CombineLatest(
|
||||
this.WhenAny(x => x.Exists),
|
||||
Observable.CombineLatest(
|
||||
this.WhenAny(x => x.Exists),
|
||||
doExistsCheck,
|
||||
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,
|
||||
this.WhenAny(x => x.AdditionalError)
|
||||
.Select(x => x ?? Observable.Return<IErrorResponse>(ErrorResponse.Success))
|
||||
.Switch(),
|
||||
resultSelector: (exists, existCheck, filter, err) =>
|
||||
resultSelector: (existCheck, filter, err) =>
|
||||
{
|
||||
if (existCheck.Failed) return existCheck;
|
||||
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,
|
||||
// which is slightly different logic
|
||||
_errorTooltip = Observable.CombineLatest(
|
||||
this.WhenAny(x => x.Exists)
|
||||
.Select(exists => exists ? default(string) : "Path does not exist"),
|
||||
Observable.CombineLatest(
|
||||
this.WhenAny(x => x.Exists),
|
||||
doExistsCheck,
|
||||
resultSelector: (exists, doExists) => !doExists || exists)
|
||||
.Select(exists => exists ? default(string) : PathDoesNotExistText),
|
||||
passesFilters
|
||||
.Select(x => x.Reason),
|
||||
this.WhenAny(x => x.AdditionalError)
|
||||
|
@ -41,6 +41,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsFalse(vm.Exists);
|
||||
Assert.IsTrue(vm.ErrorState.Succeeded);
|
||||
Assert.IsFalse(vm.InError);
|
||||
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -53,6 +54,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsFalse(vm.Exists);
|
||||
Assert.IsTrue(vm.ErrorState.Succeeded);
|
||||
Assert.IsFalse(vm.InError);
|
||||
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -67,6 +69,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsFalse(vm.Exists);
|
||||
Assert.IsTrue(vm.ErrorState.Succeeded);
|
||||
Assert.IsFalse(vm.InError);
|
||||
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,6 +83,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsFalse(vm.Exists);
|
||||
Assert.IsTrue(vm.ErrorState.Succeeded);
|
||||
Assert.IsFalse(vm.InError);
|
||||
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -94,6 +98,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsFalse(vm.Exists);
|
||||
Assert.IsTrue(vm.ErrorState.Succeeded);
|
||||
Assert.IsFalse(vm.InError);
|
||||
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,6 +112,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsFalse(vm.Exists);
|
||||
Assert.IsTrue(vm.ErrorState.Succeeded);
|
||||
Assert.IsFalse(vm.InError);
|
||||
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -120,6 +126,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsFalse(vm.Exists);
|
||||
Assert.IsFalse(vm.ErrorState.Succeeded);
|
||||
Assert.IsTrue(vm.InError);
|
||||
Assert.AreEqual(FilePickerVM.PathDoesNotExistText, vm.ErrorTooltip);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -134,6 +141,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsTrue(vm.Exists);
|
||||
Assert.IsTrue(vm.ErrorState.Succeeded);
|
||||
Assert.IsFalse(vm.InError);
|
||||
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,6 +155,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsFalse(vm.Exists);
|
||||
Assert.IsFalse(vm.ErrorState.Succeeded);
|
||||
Assert.IsTrue(vm.InError);
|
||||
Assert.AreEqual(FilePickerVM.PathDoesNotExistText, vm.ErrorTooltip);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -161,6 +170,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsTrue(vm.Exists);
|
||||
Assert.IsTrue(vm.ErrorState.Succeeded);
|
||||
Assert.IsFalse(vm.InError);
|
||||
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,6 +184,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsFalse(vm.Exists);
|
||||
Assert.IsTrue(vm.ErrorState.Succeeded);
|
||||
Assert.IsFalse(vm.InError);
|
||||
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -187,6 +198,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsFalse(vm.Exists);
|
||||
Assert.IsFalse(vm.ErrorState.Succeeded);
|
||||
Assert.IsTrue(vm.InError);
|
||||
Assert.AreEqual(FilePickerVM.PathDoesNotExistText, vm.ErrorTooltip);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -201,6 +213,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsTrue(vm.Exists);
|
||||
Assert.IsTrue(vm.ErrorState.Succeeded);
|
||||
Assert.IsFalse(vm.InError);
|
||||
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,6 +227,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsFalse(vm.Exists);
|
||||
Assert.IsFalse(vm.ErrorState.Succeeded);
|
||||
Assert.IsTrue(vm.InError);
|
||||
Assert.AreEqual(FilePickerVM.PathDoesNotExistText, vm.ErrorTooltip);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -228,6 +242,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsTrue(vm.Exists);
|
||||
Assert.IsTrue(vm.ErrorState.Succeeded);
|
||||
Assert.IsFalse(vm.InError);
|
||||
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
|
||||
}
|
||||
}
|
||||
|
||||
@ -239,16 +254,19 @@ namespace Wabbajack.Test
|
||||
await Task.Delay(250);
|
||||
Assert.IsTrue(vm.ErrorState.Succeeded);
|
||||
Assert.IsFalse(vm.InError);
|
||||
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AdditionalError_Fail()
|
||||
{
|
||||
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);
|
||||
Assert.IsFalse(vm.ErrorState.Succeeded);
|
||||
Assert.IsTrue(vm.InError);
|
||||
Assert.AreEqual(errText, vm.ErrorTooltip);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -263,6 +281,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsFalse(vm.Exists);
|
||||
Assert.IsFalse(vm.ErrorState.Succeeded);
|
||||
Assert.IsTrue(vm.InError);
|
||||
Assert.AreEqual(FilePickerVM.PathDoesNotExistText, vm.ErrorTooltip);
|
||||
}
|
||||
}
|
||||
|
||||
@ -278,6 +297,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsFalse(vm.Exists);
|
||||
Assert.IsFalse(vm.ErrorState.Succeeded);
|
||||
Assert.IsTrue(vm.InError);
|
||||
Assert.AreEqual(FilePickerVM.PathDoesNotExistText, vm.ErrorTooltip);
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,6 +314,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsFalse(vm.Exists);
|
||||
Assert.IsTrue(vm.ErrorState.Succeeded);
|
||||
Assert.IsFalse(vm.InError);
|
||||
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
|
||||
}
|
||||
}
|
||||
|
||||
@ -310,6 +331,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsFalse(vm.Exists);
|
||||
Assert.IsFalse(vm.ErrorState.Succeeded);
|
||||
Assert.IsTrue(vm.InError);
|
||||
Assert.AreEqual(FilePickerVM.DoesNotPassFiltersText, vm.ErrorTooltip);
|
||||
}
|
||||
}
|
||||
|
||||
@ -325,6 +347,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsFalse(vm.Exists);
|
||||
Assert.IsTrue(vm.ErrorState.Succeeded);
|
||||
Assert.IsFalse(vm.InError);
|
||||
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -339,6 +362,7 @@ namespace Wabbajack.Test
|
||||
Assert.IsFalse(vm.Exists);
|
||||
Assert.IsTrue(vm.ErrorState.Succeeded);
|
||||
Assert.IsFalse(vm.InError);
|
||||
Assert.IsTrue(string.IsNullOrEmpty(vm.ErrorTooltip));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -103,7 +103,7 @@
|
||||
FontSize="14"
|
||||
Text="Download Location"
|
||||
TextAlignment="Center"
|
||||
ToolTip="The folder to downloads your mods" />
|
||||
ToolTip="The folder to download your mods" />
|
||||
<local:FilePicker
|
||||
Grid.Row="0"
|
||||
Grid.Column="6"
|
||||
@ -111,7 +111,7 @@
|
||||
VerticalAlignment="Center"
|
||||
DataContext="{Binding DownloadsLocation}"
|
||||
FontSize="14"
|
||||
ToolTip="The folder to downloads your mods" />
|
||||
ToolTip="The folder to download your mods" />
|
||||
<TextBlock
|
||||
Grid.Row="1"
|
||||
Grid.Column="4"
|
||||
|
Loading…
Reference in New Issue
Block a user