Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Add ChangePropertyAction unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed Jul 26, 2023
1 parent 4de728e commit 059f050
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Avalonia.Controls;
using Avalonia.Headless;
using Avalonia.Headless.XUnit;
using Avalonia.Input;
using Avalonia.Xaml.Interactions.Core;
using Avalonia.Xaml.Interactivity;
using Xunit;

namespace Avalonia.Xaml.Interactions.UnitTests.Core;

public class ChangePropertyActionTests
{
[AvaloniaFact]
public void Should_Update_Text_Property_On_Click_Event()
{
var textBox = new TextBox
{
Text = "Initial Text"
};

var button = new Button
{
[Interaction.BehaviorsProperty] = new BehaviorCollection
{
new EventTriggerBehavior
{
EventName = "Click",
Actions =
{
new ChangePropertyAction
{
TargetObject = textBox,
PropertyName = "Text",
Value = "Updated Text"
}
}
}
}
};

var window = new Window
{
Content = new StackPanel
{
Children =
{
textBox,
button
}
}
};

window.Show();

// Click
button.Focus();
window.KeyPress(Key.Enter, RawInputModifiers.None);

Assert.Equal("Updated Text", textBox.Text);
}
}

0 comments on commit 059f050

Please sign in to comment.