Skip to content

Add unit test for ButtonBaseAdapter.ColorOptions.cs file #13458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Philip-Wang01
Copy link
Contributor

@Philip-Wang01 Philip-Wang01 commented May 14, 2025

Related #13442

Proposed changes

  • Add unit test file: ButtonBaseAdapterTests.cs for ButtonStandardAdapter.cs file.
Microsoft Reviewers: Open in CodeFlow

Copy link

codecov bot commented May 14, 2025

Codecov Report

Attention: Patch coverage is 61.90476% with 40 lines in your changes missing coverage. Please review.

Project coverage is 76.64619%. Comparing base (5821493) to head (b74227e).
Report is 5 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                  @@
##                main      #13458          +/-   ##
====================================================
+ Coverage   62.21083%   76.64619%   +14.43536%     
====================================================
  Files           3213        3231          +18     
  Lines         638302      639202         +900     
  Branches       47201       47294          +93     
====================================================
+ Hits          397093      489924       +92831     
+ Misses        234153      145708       -88445     
+ Partials        7056        3570        -3486     
Flag Coverage Δ
Debug 76.64619% <61.90476%> (+14.43536%) ⬆️
integration 18.88397% <ø> (+0.09519%) ⬆️
production 51.11119% <ø> (+32.32241%) ⬆️
test 97.39354% <61.90476%> (-0.01058%) ⬇️
unit 48.40162% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

[WinFormsFact]
public void Button_Calculate_BackColorIsSystemControl()
{
using Bitmap bmp = new Bitmap(1, 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Bitmap can be removed, the same problem exists elsewhere
using Bitmap bmp = new(1, 1);

{
using Bitmap bmp = new Bitmap(1, 1);
using Graphics g = Graphics.FromImage(bmp);
ColorOptions options = new ColorOptions(g, Color.Black, SystemColors.Control)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use fully name
using Graphics graphics = Graphics.FromImage(image);

data.ButtonShadowDark.Should().Be(SystemColors.ControlDarkDark);
data.Highlight.Should().Be(SystemColors.ControlLightLight);
data.WindowText.Should().Be(data.WindowFrame);
data.WindowDisabled.Should().Be(data.ButtonShadow);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When HighContrast is True, this assertion will fail, so it is necessary to add a conditional judgment here. The other tests also have this problem.

@LeafShi1 LeafShi1 requested a review from Copilot May 16, 2025 08:52
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new unit test file, ButtonBaseAdapterTests.cs, to improve test coverage for the ButtonStandardAdapter.cs file.

  • Added multiple tests to validate ColorOptions behavior under different modes (default, non-SystemControl colors with high contrast on/off, and disabled states).
  • Consolidates assertions for computed color values based on brightness and high contrast conditions.

data.ButtonFace.Should().Be(backColor);
data.ButtonShadow.Should().Be(ControlPaint.Dark(backColor));
data.ButtonShadowDark.Should().Be(ControlPaint.LightLight(backColor));
data.Highlight.Should().Be(ControlPaint.LightLight(backColor));
Copy link
Preview

Copilot AI May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test 'Button_Calculate_BackColorNotSystemControl_HighContrastTrue' asserts data.Highlight twice with different expectations (line 86 asserting ControlPaint.LightLight(backColor) and line 89 asserting data.LowHighlight). Consider consolidating these assertions or clarifying the expected behavior to eliminate potential ambiguity.

Suggested change
data.Highlight.Should().Be(ControlPaint.LightLight(backColor));
// data.Highlight is expected to match data.LowHighlight in high contrast mode.

Copilot uses AI. Check for mistakes.


data.ButtonFace.Should().Be(backColor);
data.ButtonShadow.Should().Be(ControlPaint.Dark(backColor));
data.ButtonShadowDark.Should().Be(ControlPaint.LightLight(backColor));
Copy link
Preview

Copilot AI May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] In high contrast mode, ButtonShadowDark is expected to be ControlPaint.LightLight(backColor) instead of the usual DarkDark. Adding a comment to explain this deviation would improve clarity for future maintainers.

Copilot uses AI. Check for mistakes.

@Olina-Zhang Olina-Zhang added the waiting-author-feedback The team requires more information from the author label May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-test coverage waiting-author-feedback The team requires more information from the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants