Compare commits

...

2 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
3d541e52d8 Fix ImageSize unit switching to Percent - set width/height to 100%
Co-authored-by: yeelam-gordon <73506701+yeelam-gordon@users.noreply.github.com>
2025-08-29 07:13:09 +00:00
copilot-swe-agent[bot]
26e250b6f4 Initial plan 2025-08-29 07:03:30 +00:00
2 changed files with 81 additions and 6 deletions

View File

@@ -32,12 +32,12 @@ public partial class ImageSize : INotifyPropertyChanged, IHasId
public ImageSize(int id = 0, string name = "", ResizeFit fit = ResizeFit.Fit, double width = 0, double height = 0, ResizeUnit unit = ResizeUnit.Pixel)
{
Id = id;
Name = name;
Fit = fit;
Width = width;
Height = height;
Unit = unit;
_id = id;
_name = name;
_fit = fit;
_width = width < 0 || double.IsNaN(width) ? 0 : width;
_height = height < 0 || double.IsNaN(height) ? 0 : height;
_unit = unit;
}
private int _id;
@@ -105,8 +105,16 @@ public partial class ImageSize : INotifyPropertyChanged, IHasId
get => _unit;
set
{
var previousUnit = _unit;
if (SetProperty(ref _unit, value))
{
// When switching to Percent unit, set width and height to 100 (representing 100%)
if (value == ResizeUnit.Percent && previousUnit != ResizeUnit.Percent)
{
Width = 100.0;
Height = 100.0;
}
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsHeightUsed)));
}
}

View File

@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.PowerToys.Settings.UI.UnitTests.ModelsTests
{
[TestClass]
public class ImageSizeTests
{
[TestMethod]
public void WhenUnitChangesToPercent_WidthShouldBeSetTo100()
{
// Arrange
var imageSize = new ImageSize(1, "Test", ResizeFit.Fit, 854, 480, ResizeUnit.Pixel);
// Act
imageSize.Unit = ResizeUnit.Percent;
// Assert
Assert.AreEqual(100.0, imageSize.Width, "Width should be set to 100 when switching to Percent unit");
}
[TestMethod]
public void WhenUnitChangesToPercent_HeightShouldBeSetTo100()
{
// Arrange
var imageSize = new ImageSize(1, "Test", ResizeFit.Stretch, 854, 480, ResizeUnit.Pixel);
// Act
imageSize.Unit = ResizeUnit.Percent;
// Assert
Assert.AreEqual(100.0, imageSize.Height, "Height should be set to 100 when switching to Percent unit");
}
[TestMethod]
public void WhenUnitChangesFromPercentToPixel_ValuesShouldNotChange()
{
// Arrange
var imageSize = new ImageSize(1, "Test", ResizeFit.Fit, 50, 75, ResizeUnit.Percent);
// Act
imageSize.Unit = ResizeUnit.Pixel;
// Assert
Assert.AreEqual(50.0, imageSize.Width, "Width should remain unchanged when switching from Percent to other units");
Assert.AreEqual(75.0, imageSize.Height, "Height should remain unchanged when switching from Percent to other units");
}
[TestMethod]
public void WhenUnitRemainsPercent_ValuesShouldNotChange()
{
// Arrange
var imageSize = new ImageSize(1, "Test", ResizeFit.Fit, 75, 60, ResizeUnit.Percent);
// Act
imageSize.Unit = ResizeUnit.Percent;
// Assert
Assert.AreEqual(75.0, imageSize.Width, "Width should remain unchanged when unit stays as Percent");
Assert.AreEqual(60.0, imageSize.Height, "Height should remain unchanged when unit stays as Percent");
}
}
}