|
4 | 4 | using System.Windows.Input;
|
5 | 5 | using UraniumUI.Material.Controls;
|
6 | 6 | using UraniumUI.Tests.Core;
|
| 7 | +using UraniumUI.ViewExtensions; |
| 8 | +using UraniumUI.Views; |
7 | 9 |
|
8 | 10 | namespace UraniumUI.Material.Tests.Controls;
|
9 | 11 | public class TextField_Test
|
@@ -40,23 +42,23 @@ public void Text_Binding_FromSource()
|
40 | 42 | control.Text.ShouldBe(viewModel.Text);
|
41 | 43 | }
|
42 | 44 |
|
43 |
| - [Fact] |
44 |
| - public void Text_Binding_RaisesPropertyChangedEvent_ExactlyOnce() |
45 |
| - { |
46 |
| - var control = AnimationReadyHandler.Prepare(new TextField()); |
47 |
| - var viewModel = new TestViewModel { Text = "Text Initial Value" }; |
48 |
| - control.BindingContext = viewModel; |
49 |
| - control.SetBinding(TextField.TextProperty, new Binding(nameof(TestViewModel.Text))); |
| 45 | + [Fact] |
| 46 | + public void Text_Binding_RaisesPropertyChangedEvent_ExactlyOnce() |
| 47 | + { |
| 48 | + var control = AnimationReadyHandler.Prepare(new TextField()); |
| 49 | + var viewModel = new TestViewModel { Text = "Text Initial Value" }; |
| 50 | + control.BindingContext = viewModel; |
| 51 | + control.SetBinding(TextField.TextProperty, new Binding(nameof(TestViewModel.Text))); |
50 | 52 |
|
51 |
| - var monitoredSubject = control.Monitor(); |
52 |
| - // Act |
53 |
| - viewModel.Text = "Changed Value"; |
| 53 | + var monitoredSubject = control.Monitor(); |
| 54 | + // Act |
| 55 | + viewModel.Text = "Changed Value"; |
54 | 56 |
|
55 |
| - // Assert |
56 |
| - monitoredSubject.Should().RaisePropertyChangeFor(x => x.Text).ShouldHaveSingleItem(); |
57 |
| - } |
| 57 | + // Assert |
| 58 | + monitoredSubject.Should().RaisePropertyChangeFor(x => x.Text).ShouldHaveSingleItem(); |
| 59 | + } |
58 | 60 |
|
59 |
| - [Fact] |
| 61 | + [Fact] |
60 | 62 | public void Text_Binding_ToSource()
|
61 | 63 | {
|
62 | 64 | var control = AnimationReadyHandler.Prepare(new TextField());
|
@@ -91,6 +93,23 @@ public void TextProperty_Parent_ShouldTwoWayBind_Child()
|
91 | 93 | control.Text.ShouldBe(control.EntryView.Text);
|
92 | 94 | }
|
93 | 95 |
|
| 96 | + [Fact] |
| 97 | + public void TextChanges_ShouldShouldCorrectlyUpdateClearButtonVisibility() |
| 98 | + { |
| 99 | + var control = AnimationReadyHandler.Prepare(new TextField() { AllowClear = true }); |
| 100 | + // Currently no easier way provided by TextField/InputField to access this control |
| 101 | + var clearIcon = control.FindByViewQueryIdInVisualTreeDescendants<StatefulContentView>("ClearIcon"); |
| 102 | + |
| 103 | + // Since we initialized with AllowClear = true |
| 104 | + clearIcon.Should().NotBeNull(); |
| 105 | + // TextField initialized without text -> clear icon should be initially hidden |
| 106 | + clearIcon.IsVisible.ShouldBeFalse(); |
| 107 | + control.Text = "Test"; |
| 108 | + clearIcon.IsVisible.ShouldBeTrue(); |
| 109 | + control.Text = ""; |
| 110 | + clearIcon.IsVisible.ShouldBeFalse(); |
| 111 | + } |
| 112 | + |
94 | 113 | [Fact]
|
95 | 114 | public void SelectionLength_ShouldBeSent_ToViewModel()
|
96 | 115 | {
|
|
0 commit comments