added unit test
This commit is contained in:
Родитель
140371329a
Коммит
598d75063d
|
@ -9,6 +9,8 @@ namespace Xamarin.Forms.Core.UnitTests
|
|||
{
|
||||
const string NormalStateName = "Normal";
|
||||
const string InvalidStateName = "Invalid";
|
||||
const string FocusedStateName = "Focused";
|
||||
const string DisabledStateName = "Disabled";
|
||||
const string CommonStatesName = "CommonStates";
|
||||
|
||||
static VisualStateGroupList CreateTestStateGroups()
|
||||
|
@ -17,9 +19,13 @@ namespace Xamarin.Forms.Core.UnitTests
|
|||
var visualStateGroup = new VisualStateGroup { Name = CommonStatesName };
|
||||
var normalState = new VisualState { Name = NormalStateName };
|
||||
var invalidState = new VisualState { Name = InvalidStateName };
|
||||
var focusedState = new VisualState { Name = FocusedStateName };
|
||||
var disabledState = new VisualState { Name = DisabledStateName };
|
||||
|
||||
visualStateGroup.States.Add(normalState);
|
||||
visualStateGroup.States.Add(invalidState);
|
||||
visualStateGroup.States.Add(focusedState);
|
||||
visualStateGroup.States.Add(disabledState);
|
||||
|
||||
stateGroups.Add(visualStateGroup);
|
||||
|
||||
|
@ -172,9 +178,39 @@ namespace Xamarin.Forms.Core.UnitTests
|
|||
{
|
||||
IList<VisualStateGroup> vsgs = CreateTestStateGroups();
|
||||
|
||||
var emptyStateName = new VisualState{Name = ""};
|
||||
var emptyStateName = new VisualState { Name = "" };
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => vsgs[0].States.Add(emptyStateName));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void VerifyVisualStateChanges()
|
||||
{
|
||||
var label1 = new Label();
|
||||
VisualStateManager.SetVisualStateGroups(label1, CreateTestStateGroups());
|
||||
|
||||
var groups1 = VisualStateManager.GetVisualStateGroups(label1);
|
||||
Assert.That(groups1[0].CurrentState.Name, Is.EqualTo(NormalStateName));
|
||||
|
||||
label1.IsEnabled = false;
|
||||
|
||||
groups1 = VisualStateManager.GetVisualStateGroups(label1);
|
||||
Assert.That(groups1[0].CurrentState.Name, Is.EqualTo(DisabledStateName));
|
||||
|
||||
|
||||
label1.SetValue(VisualElement.IsFocusedPropertyKey, true);
|
||||
groups1 = VisualStateManager.GetVisualStateGroups(label1);
|
||||
Assert.That(groups1[0].CurrentState.Name, Is.EqualTo(DisabledStateName));
|
||||
|
||||
label1.IsEnabled = true;
|
||||
groups1 = VisualStateManager.GetVisualStateGroups(label1);
|
||||
Assert.That(groups1[0].CurrentState.Name, Is.EqualTo(FocusedStateName));
|
||||
|
||||
|
||||
label1.SetValue(VisualElement.IsFocusedPropertyKey, false);
|
||||
groups1 = VisualStateManager.GetVisualStateGroups(label1);
|
||||
Assert.That(groups1[0].CurrentState.Name, Is.EqualTo(NormalStateName));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче