This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
059f050
commit cf16698
Showing
3 changed files
with
33 additions
and
43 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
tests/Avalonia.Xaml.Interactions.UnitTests/Core/ChangePropertyAction001.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Window xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
x:Class="Avalonia.Xaml.Interactions.UnitTests.Core.ChangePropertyAction001" | ||
Title="ChangePropertyAction001"> | ||
<StackPanel> | ||
<TextBox Name="TargetTextBox" Text="Initial Text" /> | ||
<Button Name="TargetButton"> | ||
<Interaction.Behaviors> | ||
<EventTriggerBehavior EventName="Click"> | ||
<ChangePropertyAction TargetObject="TargetTextBox" | ||
PropertyName="Text" | ||
Value="Updated Text" /> | ||
</EventTriggerBehavior> | ||
</Interaction.Behaviors> | ||
</Button> | ||
</StackPanel> | ||
</Window> |
11 changes: 11 additions & 0 deletions
11
tests/Avalonia.Xaml.Interactions.UnitTests/Core/ChangePropertyAction001.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Avalonia.Controls; | ||
|
||
namespace Avalonia.Xaml.Interactions.UnitTests.Core; | ||
|
||
public partial class ChangePropertyAction001 : Window | ||
{ | ||
public ChangePropertyAction001() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |
48 changes: 5 additions & 43 deletions
48
tests/Avalonia.Xaml.Interactions.UnitTests/Core/ChangePropertyActionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,23 @@ | ||
using Avalonia.Controls; | ||
using Avalonia.Headless; | ||
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() | ||
public void ChangePropertyAction_001() | ||
{ | ||
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 | ||
} | ||
} | ||
}; | ||
var window = new ChangePropertyAction001(); | ||
|
||
window.Show(); | ||
|
||
// Click | ||
button.Focus(); | ||
window.TargetButton.Focus(); | ||
window.KeyPress(Key.Enter, RawInputModifiers.None); | ||
|
||
Assert.Equal("Updated Text", textBox.Text); | ||
Assert.Equal("Updated Text", window.TargetTextBox.Text); | ||
} | ||
} |