Files
OpenNest/OpenNest.WinForms.Tests/Forms/MainWindowSettingsTests.cs
T
aj d69fc936e7 fix(desktop): stop the main window opening at its minimum size
With no saved size, Load applied the 0, 0 default, which Windows raised to
the window's minimum (588 x 381); the next normal close saved that minimum,
and from then on the window always opened at it. Before settings survived
updates (v0.7.0) every update started from the default, and the settings
migration then carried the saved minimum into user-settings.json.

Load now ignores a saved size that is empty or no larger than the minimum
and keeps the designer start, maximized, so existing settings recover.
Save keeps the restored bounds of a maximized or minimized window and never
saves the minimized state, as the Drawing Sets window already does.
2026-11-26 11:17:43 -05:00

64 lines
2.1 KiB
C#

using System.Drawing;
using System.Windows.Forms;
using OpenNest.Forms;
namespace OpenNest.WinForms.Tests.Forms;
public class MainWindowSettingsTests
{
private static readonly Size Minimum = new(588, 381);
private static readonly Size ScreenSize = new(1920, 1080);
[Theory]
[InlineData(0, 0)] // The default: no size was ever saved.
[InlineData(588, 381)] // The minimum the default shrank to, saved on a later close.
[InlineData(500, 300)]
[InlineData(1921, 800)] // Wider than the screen.
[InlineData(1200, 1081)] // Taller than the screen.
public void SizesNotWorthRestoringAreIgnored(int width, int height) =>
Assert.False(
MainWindowSettings.IsRestorableSize(new Size(width, height), Minimum, ScreenSize));
[Theory]
[InlineData(1281, 654)]
[InlineData(589, 381)]
[InlineData(588, 382)]
[InlineData(1920, 1080)]
public void SizesAboveTheMinimumThatFitAreRestored(int width, int height) =>
Assert.True(
MainWindowSettings.IsRestorableSize(new Size(width, height), Minimum, ScreenSize));
[Fact]
public void ANormalWindowSavesItsBounds()
{
var bounds = new Rectangle(100, 50, 1200, 800);
var saved = MainWindowSettings.SavedPlacement(
FormWindowState.Normal, bounds, Rectangle.Empty);
Assert.Equal((bounds, FormWindowState.Normal), saved);
}
[Fact]
public void AMaximizedWindowSavesTheBoundsItRestoresTo()
{
var restore = new Rectangle(100, 50, 1200, 800);
var saved = MainWindowSettings.SavedPlacement(
FormWindowState.Maximized, new Rectangle(-8, -8, 1936, 1056), restore);
Assert.Equal((restore, FormWindowState.Maximized), saved);
}
[Fact]
public void AMinimizedWindowSavesItsRestoreBoundsAsNormal()
{
var restore = new Rectangle(100, 50, 1200, 800);
var saved = MainWindowSettings.SavedPlacement(
FormWindowState.Minimized, new Rectangle(-32000, -32000, 160, 28), restore);
Assert.Equal((restore, FormWindowState.Normal), saved);
}
}