-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Verify * Update tests * Use WorkspaceGridState
- Loading branch information
Showing
21 changed files
with
166 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,7 @@ Thumbs.db | |
Desktop.ini | ||
.DS_Store | ||
|
||
coverage.json | ||
coverage.json | ||
|
||
# Verify | ||
*.received.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
src/NexusMods.App.UI/WorkspaceSystem/AddPanelButton/IAddPanelButtonViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
using System.Reactive; | ||
using Avalonia; | ||
using Avalonia.Media; | ||
using ReactiveUI; | ||
|
||
namespace NexusMods.App.UI.WorkspaceSystem; | ||
|
||
public interface IAddPanelButtonViewModel : IViewModelInterface | ||
{ | ||
public IReadOnlyDictionary<PanelId, Rect> NewLayoutState { get; } | ||
public WorkspaceGridState NewLayoutState { get; } | ||
|
||
public IImage ButtonImage { get; } | ||
|
||
public ReactiveCommand<Unit, IReadOnlyDictionary<PanelId, Rect>> AddPanelCommand { get; } | ||
public ReactiveCommand<Unit, WorkspaceGridState> AddPanelCommand { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Runtime.CompilerServices; | ||
using ImageMagick; | ||
|
||
namespace NexusMods.UI.Tests; | ||
|
||
public static class ModuleInitializer | ||
{ | ||
[ModuleInitializer] | ||
public static void Init() | ||
{ | ||
VerifyImageMagick.Initialize(); | ||
VerifyImageMagick.RegisterComparers(threshold: 0.005D, metric: ErrorMetric.Fuzz); | ||
} | ||
|
||
[ModuleInitializer] | ||
public static void InitOther() | ||
{ | ||
VerifierSettings.InitializePlugins(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+1.38 KB
...Tests/WorkspaceSystem/IconUtilsTests.Test_StateToBitmap_FourPanels.verified.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.65 KB
...ystem/IconUtilsTests.Test_StateToBitmap_ThreePanels_OneLargeColumn.verified.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.53 KB
...ceSystem/IconUtilsTests.Test_StateToBitmap_ThreePanels_OneLargeRow.verified.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1012 Bytes
...Tests/WorkspaceSystem/IconUtilsTests.Test_StateToBitmap_TwoColumns.verified.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.42 KB
...UI.Tests/WorkspaceSystem/IconUtilsTests.Test_StateToBitmap_TwoRows.verified.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 73 additions & 10 deletions
83
tests/NexusMods.UI.Tests/WorkspaceSystem/IconUtilsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,86 @@ | ||
using System.Runtime.CompilerServices; | ||
using Avalonia; | ||
using FluentAssertions; | ||
using NexusMods.App.UI.WorkspaceSystem; | ||
|
||
namespace NexusMods.UI.Tests.WorkspaceSystem; | ||
|
||
public class IconUtilsTests : AUiTest | ||
[UsesVerify] | ||
public class IconUtilsTests(IServiceProvider provider) : AUiTest(provider) | ||
{ | ||
public IconUtilsTests(IServiceProvider provider) : base(provider) { } | ||
[Fact] | ||
public Task Test_StateToBitmap_TwoColumns() | ||
{ | ||
var state = WorkspaceGridState.From( | ||
isHorizontal: true, | ||
new PanelGridState(PanelId.NewId(),new Rect(0, 0, 0.5, 1)), | ||
new PanelGridState(PanelId.DefaultValue, new Rect(0.5, 0, 0.5, 1)) | ||
); | ||
|
||
return RunVerify(state); | ||
} | ||
|
||
[Fact] | ||
public Task Test_StateToBitmap_TwoRows() | ||
{ | ||
var state = WorkspaceGridState.From( | ||
isHorizontal: true, | ||
new PanelGridState(PanelId.NewId(), new Rect(0, 0, 1, 0.5)), | ||
new PanelGridState(PanelId.DefaultValue, new Rect(0, 0.5, 1, 0.5)) | ||
); | ||
|
||
return RunVerify(state); | ||
} | ||
|
||
[Fact] | ||
public void Test_StateToBitmap() | ||
public Task Test_StateToBitmap_ThreePanels_OneLargeColumn() | ||
{ | ||
var state = WorkspaceGridState.From( | ||
isHorizontal: true, | ||
new PanelGridState(PanelId.NewId(),new Rect(0, 0, 0.5, 0.5)), | ||
new PanelGridState(PanelId.DefaultValue, new Rect(0.5, 0, 0.5, 1)), | ||
new PanelGridState(PanelId.NewId(), new Rect(0, 0.5, 0.5, 0.5)) | ||
); | ||
|
||
return RunVerify(state); | ||
} | ||
|
||
[Fact] | ||
public Task Test_StateToBitmap_ThreePanels_OneLargeRow() | ||
{ | ||
var state = WorkspaceGridState.From( | ||
isHorizontal: true, | ||
new PanelGridState(PanelId.NewId(), new Rect(0, 0, 0.5, 0.5)), | ||
new PanelGridState(PanelId.NewId(), new Rect(0.5, 0, 0.5, 0.5)), | ||
new PanelGridState(PanelId.DefaultValue,new Rect(0, 0.5, 1, 0.5)) | ||
); | ||
|
||
return RunVerify(state); | ||
} | ||
|
||
[Fact] | ||
public Task Test_StateToBitmap_FourPanels() | ||
{ | ||
var state = WorkspaceGridState.From( | ||
isHorizontal: true, | ||
new PanelGridState(PanelId.NewId(), new Rect(0, 0, 0.5, 0.5)), | ||
new PanelGridState(PanelId.NewId(), new Rect(0, 0.5, 0.5, 0.5)), | ||
new PanelGridState(PanelId.NewId(), new Rect(0.5, 0, 0.5, 0.5)), | ||
new PanelGridState(PanelId.DefaultValue, new Rect(0.5, 0.5, 0.5, 0.5)) | ||
); | ||
|
||
return RunVerify(state); | ||
} | ||
|
||
private static Task RunVerify(WorkspaceGridState state, [CallerFilePath] string sourceFile = "") | ||
{ | ||
var state = new Dictionary<PanelId, Rect> | ||
using var stream = new MemoryStream(); | ||
using (var bitmap = IconUtils.StateToBitmap(state)) | ||
{ | ||
{ PanelId.NewId(), new Rect(0, 0, 0.5, 1) }, | ||
{ PanelId.DefaultValue, new Rect(0.5, 0, 0.5, 1) } | ||
}; | ||
bitmap.Save(stream); | ||
stream.Position = 0; | ||
} | ||
|
||
var bitmap = IconUtils.StateToBitmap(state); | ||
bitmap.Size.Should().Be(new Size(150, 150)); | ||
// ReSharper disable once ExplicitCallerInfoArgument | ||
return Verify(stream, extension: "png", sourceFile: sourceFile).DisableDiff(); | ||
} | ||
} |