Skip to content

Add built-in theme tests and fix several bugs found by them - #22216

Open
maxkatz6 wants to merge 19 commits into
mainfrom
fixes/add-fluent-theme-tests-and-several-fixes
Open

maxkatz6 wants to merge 19 commits into
mainfrom
fixes/add-fluent-theme-tests-and-several-fixes

Conversation

@maxkatz6

@maxkatz6 maxkatz6 commented Sep 11, 2026

Copy link
Copy Markdown
Member

What does the pull request do?

Adds a new Avalonia.Themes.UnitTests project that validates the built-in Fluent and Simple themes, and fixes the theme issues these tests found.

What is the current behavior?

Before this PR, built-in themes were not covered by any tests. Several types of issues existed unnoticed:

  • DynamicResource targetting undefined resources
  • Brushes/colors being hardcoded in the setter or template parts
  • Several XAML files were compiled as public (doubling IL output, as we merge XAML files)
  • StringCalendarWeekNumberHeader apparently was still ignored as a resource

What is the updated/expected behavior with this PR?

New tests:

  • Theme class has a ctor(IServiceProvider) and can be reached via avares: (which we technically always supported).
  • All XAML files should be internal (except entry point).
  • Every theme dictionary defines the same resources.
  • No global styles are defined, only ControlTheme with nested styles.
  • Every built-in templated control has a ControlTheme (with some known exceptions).
  • Every [TemplatePart] is defined in the template.
  • Every {DynamicResource} references a defined key.
  • No brush, color or box shadow is hardcoded in a setter or a template

How was the solution implemented (if it's not obvious)?

All tests are defined in abstract classes with specific implementations per each theme:

[Trait("Category", "FluentTheme")]
public class FluentControlThemeTests() : ControlThemeTests(typeof(FluentTheme));
[Trait("Category", "SimpleTheme")]
public class SimpleControlThemeTests() : ControlThemeTests(typeof(SimpleTheme));

public abstract class ControlThemeTests(Type typeEntryPoint) : ThemeTestBase(typeEntryPoint)
{
}

With an idea to later add Fluent2 to the same test project.

Breaking changes

None

Disclamer: This PR was written by hand, without an AI. Code might be better or worse depending on who reads.
But it still was reviewed by Opus.

@maxkatz6
maxkatz6 requested a review from MrJul September 11, 2026 10:50
@maxkatz6 maxkatz6 added enhancement area-theme Related to the simple or fluent theme. labels Sep 11, 2026
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0069865-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good set of tests!
A small nitpick, otherwise LGTM.

Comment thread src/Avalonia.Base/Avalonia.Base.csproj
.Select(r => (Type)r.Key)
.ToHashSet();

Assert.All(templatedControls, c => Assert.Contains(c, defaultControlThemes));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: add an Assert.NotEmpty(templatedControls) before, to make sure the test doesn't pass for the wrong reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-theme Related to the simple or fluent theme. enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants