Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 16, 2025

Overview

This PR adds comprehensive unit tests for the VisualState transition selection logic as requested in issue #17436. The tests validate the FindTransition method in VisualStateGroup.cs which determines which transition to apply when changing between visual states.

Changes

Added 9 new test methods to src/Uno.UI.Tests/Windows_UI_Xaml/VisualStateManagerTests/Given_VisualStateManager.cs that comprehensively cover the transition selection algorithm.

Transition Selection Algorithm

The FindTransition method implements a priority-based selection algorithm:

  1. Perfect Match (highest priority): Transition with both From and To matching the state change
  2. From Match: Transition with only From matching (and To is null/empty)
  3. To Match (lowest priority): Transition with only To matching (and From is null/empty)
  4. No Match: Returns null if no transition matches

When multiple transitions match at the same priority level, the first declared transition wins.

Test Coverage

Basic Matching Scenarios

  • When_Transition_With_Both_From_And_To_Matches - Validates perfect match selection
  • When_Transition_With_Only_From_Matches - Validates From-only matching
  • When_Transition_With_Only_To_Matches - Validates To-only matching

Precedence Rules

  • When_Multiple_Transitions_PerfectMatch_Takes_Precedence - Validates that perfect match has highest priority
  • When_Multiple_Transitions_From_Takes_Precedence_Over_To - Validates that From-only beats To-only
  • When_First_Matching_Transition_Is_Selected - Validates first-declared wins when multiple match

Edge Cases

  • When_No_Transition_Matches - Validates behavior when no transition matches
  • When_Transition_From_Initial_To_State1 - Validates transitions from initial state
  • When_UseTransitions_False_No_Transition_Applied - Validates the useTransitions flag

Implementation Details

All tests follow the existing patterns in the file:

  • Use existing helper methods (Setup(), Transition(), AnimateTag())
  • Validate behavior by tracking Control.Tag property changes through RegisterPropertyChangedCallback
  • Use SequenceEqual to verify the exact sequence of state changes
  • Maintain consistency with existing test style and conventions

Example Test

[TestMethod]
public void When_Multiple_Transitions_PerfectMatch_Takes_Precedence()
{
    var (control, group) = Setup();
    // Add transitions in specific order to test precedence
    var transitionFrom = Transition(control, from: 1, to: null, frames: 10);
    var transitionTo = Transition(control, from: null, to: 2, frames: 20);
    var transitionPerfect = Transition(control, from: 1, to: 2, frames: 0);

    group.Transitions.Add(transitionFrom);
    group.Transitions.Add(transitionTo);
    group.Transitions.Add(transitionPerfect);

    var tags = new List<string> { (string)control.Tag };
    control.RegisterPropertyChangedCallback(Control.TagProperty, (_, __) => tags.Add((string)control.Tag));

    VisualStateManager.GoToState(control, "state1", true);
    VisualStateManager.GoToState(control, "state2", true);

    // Perfect match (both from and to) should be selected
    Assert.IsTrue(new[] { "initial", "state1", "transition_from_state1_to_state2_frame_0", "state2" }.SequenceEqual(tags));
}

Related

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:

  • aka.ms
    • Triggering command: curl -I -sSL --retry 5 --retry-delay 2 --connect-timeout 15 REDACTED (dns block)
  • crl.godaddy.com
    • Triggering command: /home/REDACTED/.dotnet/dotnet restore Uno.UI-UnitTests-only.slnf (dns block)
    • Triggering command: /home/REDACTED/.dotnet/dotnet restore Uno.UI-UnitTests-only.slnf --force (dns block)
  • imzvsblobprodcus368.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/.dotnet/dotnet restore Uno.UI-UnitTests-only.slnf (dns block)
    • Triggering command: /home/REDACTED/.dotnet/dotnet restore Uno.UI-UnitTests-only.slnf --force (dns block)
  • m8dvsblobprodcus37.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/.dotnet/dotnet restore Uno.UI-UnitTests-only.slnf (dns block)
  • ocsp.godaddy.com
    • Triggering command: /home/REDACTED/.dotnet/dotnet restore Uno.UI-UnitTests-only.slnf (dns block)
    • Triggering command: /home/REDACTED/.dotnet/dotnet restore Uno.UI-UnitTests-only.slnf --force (dns block)
  • u3hvsblobprodcus371.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/.dotnet/dotnet restore Uno.UI-UnitTests-only.slnf (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Add tests for VIsualState transition selection</issue_title>
<issue_description>### Current behavior

No response

Expected behavior

Add tests for #17436

How to reproduce it (as minimally and precisely as possible)

No response

Workaround

No response

Works on UWP/WinUI

None

Environment

No response

NuGet package version(s)

No response

Affected platforms

No response

IDE

No response

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #17564


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Add tests for VisualState transition selection test: Add comprehensive tests for VisualState transition selection Oct 16, 2025
Copilot AI requested a review from MartinZikmund October 16, 2025 12:01
Copilot finished work on behalf of MartinZikmund October 16, 2025 12:01
@unodevops
Copy link
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21614/wasm-skia-net9/index.html

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@unodevops
Copy link
Contributor

⚠️⚠️ The build 178632 has failed on Uno.UI - CI.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for VIsualState transition selection

4 participants