Add unit tests for Hosts ValidationHelper and ColorPicker format conversions#46679
Add unit tests for Hosts ValidationHelper and ColorPicker format conversions#46679
Conversation
…ersions Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/25304f7c-b1e2-41d9-a5ac-b17525e996b5 Co-authored-by: crutkas <1462282+crutkas@users.noreply.github.com>
…g statement Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/25304f7c-b1e2-41d9-a5ac-b17525e996b5 Co-authored-by: crutkas <1462282+crutkas@users.noreply.github.com>
src/modules/colorPicker/ColorPickerUI.UnitTests/Helpers/ColorFormatConversionTest.cs
Fixed
Show fixed
Hide fixed
src/modules/colorPicker/ColorPickerUI.UnitTests/Helpers/ColorFormatConversionTest.cs
Fixed
Show fixed
Hide fixed
src/modules/colorPicker/ColorPickerUI.UnitTests/Helpers/ColorFormatConversionTest.cs
Fixed
Show fixed
Hide fixed
src/modules/colorPicker/ColorPickerUI.UnitTests/Helpers/ColorFormatConversionTest.cs
Fixed
Show fixed
Hide fixed
src/modules/colorPicker/ColorPickerUI.UnitTests/Helpers/ColorFormatConversionTest.cs
Fixed
Show fixed
Hide fixed
This comment has been minimized.
This comment has been minimized.
Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/3d350c40-0ab2-4f38-9228-17ad2a0a642d Co-authored-by: crutkas <1462282+crutkas@users.noreply.github.com>
Added |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
there are a host of failures in CI. please fix @copilot |
…r StartsWith (CA1866/CA1310) Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/ae061166-2823-41cb-ba13-61a1b8317756 Co-authored-by: crutkas <1462282+crutkas@users.noreply.github.com>
Fixed all CI failures in commit fe081df:
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@copilot There are SA1515 errors |
…ch_White test Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/07f28620-f2fc-4ae7-b7fc-c9fc34247d8d Co-authored-by: crutkas <1462282+crutkas@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@copilot two test failures. @azure-pipelines src\modules\colorPicker\ColorPickerUI.UnitTests\Helpers\ColorFormatConversionTest.cs(418,0): Error test failed: GetStringRepresentation_Blue ("Decimal","255") (0ms): Assert.AreEqual failed. Expected:<255>. Actual:<16711680>. |
…esentation tests Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/9969dd7a-6e3c-4beb-9082-8f65e0fa92b2 Co-authored-by: crutkas <1462282+crutkas@users.noreply.github.com>
Fixed in commit a0e8a20. The Decimal expected values for Red and Blue were swapped — the default Decimal format uses |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Adds new MSTest coverage for two previously untested areas: Hosts ValidationHelper input validation and ColorPicker/ManagedCommon color format conversions + string representations, along with a spell-check allow-list update for a new identifier.
Changes:
- Add unit tests for
HostsUILib.Helpers.ValidationHelper(ValidIPv4,ValidIPv6,ValidHosts) including boundary coverage aroundConsts.MaxHostsCount. - Add unit tests for
ManagedCommon.ColorFormatHelperconversions (CMYK/HSB/HSI/HWB/CIE XYZ/LAB/Oklab/Oklch/sRGB-linear/NCol) andColorRepresentationHelper.GetStringRepresentationacross multiple formats. - Add
SRGBToto the spell-check allow list.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/modules/Hosts/Hosts.Tests/ValidationHelperTest.cs | New unit tests for IPv4/IPv6/hosts validation and max-host-count boundary behavior. |
| src/modules/colorPicker/ColorPickerUI.UnitTests/Helpers/ColorFormatConversionTest.cs | New unit tests for multiple color-space conversions and formatted string outputs. |
| .github/actions/spell-check/allow/code.txt | Allow-list update for SRGBTo token used in code/tests. |
src/modules/colorPicker/ColorPickerUI.UnitTests/Helpers/ColorFormatConversionTest.cs
Outdated
Show resolved
Hide resolved
src/modules/colorPicker/ColorPickerUI.UnitTests/Helpers/ColorFormatConversionTest.cs
Outdated
Show resolved
Hide resolved
| [TestMethod] | ||
| public void ConvertToNaturalColor_Blue_ReturnsB0() | ||
| { | ||
| var result = ColorFormatHelper.ConvertToNaturalColor(Color.FromArgb(255, 0, 0, 255)); | ||
| Assert.IsTrue(result.Hue.StartsWith('B'), $"Blue should start with B, got {result.Hue}"); | ||
| } |
There was a problem hiding this comment.
Test name says ConvertToNaturalColor_Blue_ReturnsB0, but the assertion only checks that the hue starts with 'B'. Either assert the full expected value (e.g., B0) for the chosen input color, or rename the test to reflect the weaker expectation.
|
@copilot apply fixes based on code review |
…c host count Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/d51c018e-c826-431c-a66c-f56769e215aa Co-authored-by: crutkas <1462282+crutkas@users.noreply.github.com>
Applied all 4 code review fixes in commit db73018:
|
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Summary of the Pull Request
Adds comprehensive unit tests for two previously untested areas to improve test coverage and prevent regressions:
ValidationHelperTest.cs) — 25+ test cases coveringValidIPv4,ValidIPv6, andValidHostsmethodsColorFormatConversionTest.cs) — 50+ test cases covering CMYK, HSB, HSI, HWB, CIE XYZ, CIE LAB, Oklab, Oklch, sRGB-to-linear, NCol conversions, plus expandedGetStringRepresentationtests for Red, White, Green, and Blue colors across all supported formatsPR Checklist
Detailed Description of the Pull Request / Additional comments
Hosts ValidationHelper (
src/modules/Hosts/Hosts.Tests/ValidationHelperTest.cs)ValidIPv4with valid addresses (loopback, private ranges, broadcast), invalid addresses (out of range octets, wrong format, CIDR notation), and null/whitespace inputsValidIPv6with valid addresses (loopback, full/compressed notation, link-local, IPv4-mapped), invalid addresses (extra groups, invalid hex digits), and null/whitespace inputsValidHostswith valid hostnames, FQDNs, max host count boundary (usingConsts.MaxHostsCountdynamically for both exact-boundary and exceeds-boundary tests), and invalid hostnamesColorPicker Format Conversions (
src/modules/colorPicker/ColorPickerUI.UnitTests/Helpers/ColorFormatConversionTest.cs)ConvertToCMYKColorfor Black, White, Red, Green, Blue, and Mid GrayConvertToHSBColor,ConvertToHSIColor,ConvertToHWBColorfor primary colorsConvertToCIEXYZColorandConvertToCIELABColorincluding D65 illuminant verification and negative b* assertion for BlueConvertToOklabColorandConvertToOklchColorincluding chroma non-negativityConvertSRGBToLinearRGBfor linear and gamma pathsConvertToNaturalColorfor hue letter mapping (R exact match, G and B prefix assertions)GetStringRepresentationwith Red, White, Green, Blue across all 11+ format types (Decimal values use BGR byte order via%Dvformat: Red → "255", Blue → "16711680")GetDefaultFormatreturns non-empty strings for all known format namesSpell-check allow list
SRGBToto.github/actions/spell-check/allow/code.txtto resolve unrecognized-spelling alertsStyleCop / code analysis fixes
Code review fixes
ConvertToCIELAB_Blue_HasNegativeA→ConvertToCIELAB_Blue_HasNegativeBwith corrected comment to match the actual b* axis assertionConsts.MaxHostsCount + 1in the exceeds-max-count boundary testConvertToNaturalColor_Green_ReturnsG0→ConvertToNaturalColor_Green_HueStartsWithGandConvertToNaturalColor_Blue_ReturnsB0→ConvertToNaturalColor_Blue_HueStartsWithBto accurately reflect prefix-only assertionsValidation Steps Performed
[TestClass],[TestMethod],[DataTestMethod],[DataRow])Consts.MaxHostsCountrather than hardcoded values for all boundary tests%Dv(BGR order) implementation:R + G*256 + B*65536