Browse Source

Fix unit tests

pull/117/head
JT 1 year ago
parent
commit
fbdb15e8de
  1. 214
      StabilityMatrix.Avalonia/DesignData/DesignData.cs

214
StabilityMatrix.Avalonia/DesignData/DesignData.cs

@ -20,6 +20,7 @@ using StabilityMatrix.Core.Helper.Cache;
using StabilityMatrix.Core.Helper.Factory; using StabilityMatrix.Core.Helper.Factory;
using StabilityMatrix.Core.Models; using StabilityMatrix.Core.Models;
using StabilityMatrix.Core.Models.Api; using StabilityMatrix.Core.Models.Api;
using StabilityMatrix.Core.Models.PackageModification;
using StabilityMatrix.Core.Models.Progress; using StabilityMatrix.Core.Models.Progress;
using StabilityMatrix.Core.Python; using StabilityMatrix.Core.Python;
using StabilityMatrix.Core.Services; using StabilityMatrix.Core.Services;
@ -30,7 +31,8 @@ namespace StabilityMatrix.Avalonia.DesignData;
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static class DesignData public static class DesignData
{ {
[NotNull] public static IServiceProvider? Services { get; set; } [NotNull]
public static IServiceProvider? Services { get; set; }
private static bool isInitialized; private static bool isInitialized;
@ -44,44 +46,49 @@ public static class DesignData
var services = new ServiceCollection(); var services = new ServiceCollection();
var activePackageId = Guid.NewGuid(); var activePackageId = Guid.NewGuid();
services.AddSingleton<ISettingsManager, MockSettingsManager>(_ => new MockSettingsManager services.AddSingleton<ISettingsManager, MockSettingsManager>(
{ _ =>
Settings = new MockSettingsManager
{
InstalledPackages = new List<InstalledPackage>
{ {
new() Settings =
{
Id = activePackageId,
DisplayName = "My Installed Package",
PackageName = "stable-diffusion-webui",
Version = new InstalledPackageVersion
{
InstalledReleaseVersion = "v1.0.0"
},
LibraryPath = $"Packages{Path.DirectorySeparatorChar}example-webui",
LastUpdateCheck = DateTimeOffset.Now
},
new()
{ {
Id = Guid.NewGuid(), InstalledPackages = new List<InstalledPackage>
DisplayName = "Comfy Diffusion WebUI Dev Branch Long Name",
PackageName = "ComfyUI",
Version = new InstalledPackageVersion
{ {
InstalledBranch = "master", new()
InstalledCommitSha = "abc12uwu345568972abaedf7g7e679a98879e879f87ga8" {
Id = activePackageId,
DisplayName = "My Installed Package",
PackageName = "stable-diffusion-webui",
Version = new InstalledPackageVersion
{
InstalledReleaseVersion = "v1.0.0"
},
LibraryPath = $"Packages{Path.DirectorySeparatorChar}example-webui",
LastUpdateCheck = DateTimeOffset.Now
},
new()
{
Id = Guid.NewGuid(),
DisplayName = "Comfy Diffusion WebUI Dev Branch Long Name",
PackageName = "ComfyUI",
Version = new InstalledPackageVersion
{
InstalledBranch = "master",
InstalledCommitSha =
"abc12uwu345568972abaedf7g7e679a98879e879f87ga8"
},
LibraryPath = $"Packages{Path.DirectorySeparatorChar}example-webui",
LastUpdateCheck = DateTimeOffset.Now
}
}, },
LibraryPath = $"Packages{Path.DirectorySeparatorChar}example-webui", ActiveInstalledPackageId = activePackageId
LastUpdateCheck = DateTimeOffset.Now
} }
}, }
ActiveInstalledPackageId = activePackageId );
}
});
// General services // General services
services.AddLogging() services
.AddLogging()
.AddSingleton<INavigationService, NavigationService>() .AddSingleton<INavigationService, NavigationService>()
.AddSingleton<IPackageFactory, PackageFactory>() .AddSingleton<IPackageFactory, PackageFactory>()
.AddSingleton<IUpdateHelper, UpdateHelper>() .AddSingleton<IUpdateHelper, UpdateHelper>()
@ -96,7 +103,8 @@ public static class DesignData
.AddSingleton<IHttpClientFactory, MockHttpClientFactory>() .AddSingleton<IHttpClientFactory, MockHttpClientFactory>()
.AddSingleton<IDiscordRichPresenceService, MockDiscordRichPresenceService>() .AddSingleton<IDiscordRichPresenceService, MockDiscordRichPresenceService>()
.AddSingleton<IModelIndexService, MockModelIndexService>() .AddSingleton<IModelIndexService, MockModelIndexService>()
.AddSingleton<ITrackedDownloadService, MockTrackedDownloadService>(); .AddSingleton<ITrackedDownloadService, MockTrackedDownloadService>()
.AddSingleton<IPackageModificationRunner, PackageModificationRunner>();
// Placeholder services that nobody should need during design time // Placeholder services that nobody should need during design time
services services
@ -128,26 +136,31 @@ public static class DesignData
LaunchOptionsViewModel = Services.GetRequiredService<LaunchOptionsViewModel>(); LaunchOptionsViewModel = Services.GetRequiredService<LaunchOptionsViewModel>();
LaunchOptionsViewModel.Cards = new[] LaunchOptionsViewModel.Cards = new[]
{ {
LaunchOptionCard.FromDefinition(new LaunchOptionDefinition LaunchOptionCard.FromDefinition(
{ new LaunchOptionDefinition
Name = "Host", {
Type = LaunchOptionType.String, Name = "Host",
Description = "The host name for the Web UI", Type = LaunchOptionType.String,
DefaultValue = "localhost", Description = "The host name for the Web UI",
Options = {"--host"} DefaultValue = "localhost",
}), Options = { "--host" }
LaunchOptionCard.FromDefinition(new LaunchOptionDefinition }
{ ),
Name = "API", LaunchOptionCard.FromDefinition(
Type = LaunchOptionType.Bool, new LaunchOptionDefinition
Options = {"--api"} {
}) Name = "API",
Type = LaunchOptionType.Bool,
Options = { "--api" }
}
)
}; };
LaunchOptionsViewModel.UpdateFilterCards(); LaunchOptionsViewModel.UpdateFilterCards();
InstallerViewModel = Services.GetRequiredService<InstallerViewModel>(); InstallerViewModel = Services.GetRequiredService<InstallerViewModel>();
InstallerViewModel.AvailablePackages = InstallerViewModel.AvailablePackages = packageFactory
packageFactory.GetAllAvailablePackages().ToImmutableArray(); .GetAllAvailablePackages()
.ToImmutableArray();
InstallerViewModel.SelectedPackage = InstallerViewModel.AvailablePackages[0]; InstallerViewModel.SelectedPackage = InstallerViewModel.AvailablePackages[0];
InstallerViewModel.ReleaseNotes = "## Release Notes\nThis is a test release note."; InstallerViewModel.ReleaseNotes = "## Release Notes\nThis is a test release note.";
@ -164,8 +177,9 @@ public static class DesignData
{ {
FilePath = "~/Models/StableDiffusion/electricity-light.safetensors", FilePath = "~/Models/StableDiffusion/electricity-light.safetensors",
Title = "Auroral Background", Title = "Auroral Background",
PreviewImagePath = "https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/" + PreviewImagePath =
"78fd2a0a-42b6-42b0-9815-81cb11bb3d05/00009-2423234823.jpeg", "https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/"
+ "78fd2a0a-42b6-42b0-9815-81cb11bb3d05/00009-2423234823.jpeg",
ConnectedModel = new ConnectedModelInfo ConnectedModel = new ConnectedModelInfo
{ {
VersionName = "Lightning Auroral", VersionName = "Lightning Auroral",
@ -180,11 +194,7 @@ public static class DesignData
} }
} }
}, },
new() new() { FilePath = "~/Models/Lora/model.safetensors", Title = "Some model" },
{
FilePath = "~/Models/Lora/model.safetensors",
Title = "Some model"
},
}, },
}, },
new(settingsManager, downloadService, modelFinder) new(settingsManager, downloadService, modelFinder)
@ -206,11 +216,7 @@ public static class DesignData
}, },
CheckpointFiles = new AdvancedObservableList<CheckpointFile> CheckpointFiles = new AdvancedObservableList<CheckpointFile>
{ {
new() new() { FilePath = "~/Models/Lora/lora_v2.pt", Title = "Best Lora v2", }
{
FilePath = "~/Models/Lora/lora_v2.pt",
Title = "Best Lora v2",
}
} }
} }
}; };
@ -220,8 +226,8 @@ public static class DesignData
folder.DisplayedCheckpointFiles = folder.CheckpointFiles; folder.DisplayedCheckpointFiles = folder.CheckpointFiles;
} }
CheckpointBrowserViewModel.ModelCards = new CheckpointBrowserViewModel.ModelCards =
ObservableCollection<CheckpointBrowserCardViewModel> new ObservableCollection<CheckpointBrowserCardViewModel>
{ {
dialogFactory.Get<CheckpointBrowserCardViewModel>(vm => dialogFactory.Get<CheckpointBrowserCardViewModel>(vm =>
{ {
@ -239,8 +245,9 @@ public static class DesignData
{ {
FilePath = "~/Models/StableDiffusion/electricity-light.safetensors", FilePath = "~/Models/StableDiffusion/electricity-light.safetensors",
Title = "Auroral Background", Title = "Auroral Background",
PreviewImagePath = "https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/" + PreviewImagePath =
"78fd2a0a-42b6-42b0-9815-81cb11bb3d05/00009-2423234823.jpeg", "https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/"
+ "78fd2a0a-42b6-42b0-9815-81cb11bb3d05/00009-2423234823.jpeg",
ConnectedModel = new ConnectedModelInfo ConnectedModel = new ConnectedModelInfo
{ {
VersionName = "Lightning Auroral", VersionName = "Lightning Auroral",
@ -255,19 +262,22 @@ public static class DesignData
} }
} }
}, },
new() new() { FilePath = "~/Models/Lora/model.safetensors", Title = "Some model" }
{
FilePath = "~/Models/Lora/model.safetensors",
Title = "Some model"
}
}; };
ProgressManagerViewModel.ProgressItems.AddRange(new ProgressItemViewModelBase[] ProgressManagerViewModel.ProgressItems.AddRange(
{ new ProgressItemViewModelBase[]
new ProgressItemViewModel(new ProgressItem(Guid.NewGuid(), "Test File.exe", {
new ProgressReport(0.5f, "Downloading..."))), new ProgressItemViewModel(
new MockDownloadProgressItemViewModel("Test File 2.exe"), new ProgressItem(
}); Guid.NewGuid(),
"Test File.exe",
new ProgressReport(0.5f, "Downloading...")
)
),
new MockDownloadProgressItemViewModel("Test File 2.exe"),
}
);
UpdateViewModel = Services.GetRequiredService<UpdateViewModel>(); UpdateViewModel = Services.GetRequiredService<UpdateViewModel>();
UpdateViewModel.UpdateText = UpdateViewModel.UpdateText =
@ -278,9 +288,14 @@ public static class DesignData
isInitialized = true; isInitialized = true;
} }
[NotNull] public static InstallerViewModel? InstallerViewModel { get; private set; } [NotNull]
[NotNull] public static LaunchOptionsViewModel? LaunchOptionsViewModel { get; private set; } public static InstallerViewModel? InstallerViewModel { get; private set; }
[NotNull] public static UpdateViewModel? UpdateViewModel { get; private set; }
[NotNull]
public static LaunchOptionsViewModel? LaunchOptionsViewModel { get; private set; }
[NotNull]
public static UpdateViewModel? UpdateViewModel { get; private set; }
public static ServiceManager<ViewModelBase> DialogFactory => public static ServiceManager<ViewModelBase> DialogFactory =>
Services.GetRequiredService<ServiceManager<ViewModelBase>>(); Services.GetRequiredService<ServiceManager<ViewModelBase>>();
@ -302,10 +317,12 @@ public static class DesignData
var vm = Services.GetRequiredService<PackageManagerViewModel>(); var vm = Services.GetRequiredService<PackageManagerViewModel>();
vm.SetPackages(settings.Settings.InstalledPackages); vm.SetPackages(settings.Settings.InstalledPackages);
vm.SetUnknownPackages(new InstalledPackage[] vm.SetUnknownPackages(
{ new InstalledPackage[]
UnknownInstalledPackage.FromDirectoryName("sd-unknown-with-long-name"), {
}); UnknownInstalledPackage.FromDirectoryName("sd-unknown-with-long-name"),
}
);
vm.PackageCards[0].IsUpdateAvailable = true; vm.PackageCards[0].IsUpdateAvailable = true;
@ -334,7 +351,8 @@ public static class DesignData
new() new()
{ {
Name = "BB95 Furry Mix", Name = "BB95 Furry Mix",
Description = @"Introducing SnoutMix Description =
@"Introducing SnoutMix
A Mix of non-Furry and Furry models such as Furtastic and BB95Furry to create a great variety of anthro AI generation options, but bringing out more detail, still giving a lot of freedom to customise the human aspects, and having great backgrounds, with a focus on something more realistic. Works well with realistic character loras. A Mix of non-Furry and Furry models such as Furtastic and BB95Furry to create a great variety of anthro AI generation options, but bringing out more detail, still giving a lot of freedom to customise the human aspects, and having great backgrounds, with a focus on something more realistic. Works well with realistic character loras.
The gallery images are often inpainted, but you will get something very similar if copying their data directly. They are inpainted using the same model, therefore all results are possible without anything custom/hidden-away. Controlnet Tiled is applied to enhance them further afterwards. Gallery images were made with same model but before it was renamed", The gallery images are often inpainted, but you will get something very similar if copying their data directly. They are inpainted using the same model, therefore all results are possible without anything custom/hidden-away. Controlnet Tiled is applied to enhance them further afterwards. Gallery images were made with same model but before it was renamed",
BaseModel = "SD 1.5", BaseModel = "SD 1.5",
@ -361,19 +379,18 @@ The gallery images are often inpainted, but you will get something very similar
Fp = CivitModelFpType.fp32, Fp = CivitModelFpType.fp32,
Size = CivitModelSize.full Size = CivitModelSize.full
}, },
Hashes = new CivitFileHashes Hashes = new CivitFileHashes { BLAKE3 = "ABCD" }
{
BLAKE3 = "ABCD"
}
} }
} }
} }
}; };
var sampleViewModel = var sampleViewModel = new ModelVersionViewModel(
new ModelVersionViewModel(new HashSet<string> {"ABCD"}, sampleCivitVersions[0]); new HashSet<string> { "ABCD" },
sampleCivitVersions[0]
);
// Sample data for dialogs // Sample data for dialogs
vm.Versions = new List<ModelVersionViewModel> {sampleViewModel}; vm.Versions = new List<ModelVersionViewModel> { sampleViewModel };
vm.Title = sampleCivitVersions[0].Name; vm.Title = sampleCivitVersions[0].Name;
vm.Description = sampleCivitVersions[0].Description; vm.Description = sampleCivitVersions[0].Description;
vm.SelectedVersionViewModel = sampleViewModel; vm.SelectedVersionViewModel = sampleViewModel;
@ -409,20 +426,15 @@ The gallery images are often inpainted, but you will get something very similar
} }
}); });
public static EnvVarsViewModel EnvVarsViewModel => DialogFactory.Get<EnvVarsViewModel>( public static EnvVarsViewModel EnvVarsViewModel =>
viewModel => DialogFactory.Get<EnvVarsViewModel>(viewModel =>
{ {
viewModel.EnvVars = new ObservableCollection<EnvVarKeyPair> viewModel.EnvVars = new ObservableCollection<EnvVarKeyPair> { new("UWU", "TRUE"), };
{
new("UWU", "TRUE"),
};
}); });
public static PackageImportViewModel PackageImportViewModel => public static PackageImportViewModel PackageImportViewModel =>
DialogFactory.Get<PackageImportViewModel>(); DialogFactory.Get<PackageImportViewModel>();
public static RefreshBadgeViewModel RefreshBadgeViewModel => new() public static RefreshBadgeViewModel RefreshBadgeViewModel =>
{ new() { State = ProgressState.Success };
State = ProgressState.Success
};
} }

Loading…
Cancel
Save