-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Issue1747.xaml.cs
98 lines (84 loc) · 2.35 KB
/
Issue1747.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 1747, "Binding to Switch.IsEnabled has no effect", PlatformAffected.WinPhone)]
#if UITEST
[NUnit.Framework.Category(UITestCategories.Switch)]
[NUnit.Framework.Category(Core.UITests.UITestCategories.Github5000)]
#endif
public partial class Issue1747 : TestContentPage
{
const string ToggleButtonAutomationId = nameof(ToggleButtonAutomationId);
const string ToggleSwitchAutomationId = nameof(ToggleSwitchAutomationId);
#if APP
public Issue1747()
{
InitializeComponent();
ToggleButton.AutomationId = ToggleButtonAutomationId;
ToggleSwitch.AutomationId = ToggleSwitchAutomationId;
}
#endif
protected override void Init()
{
BindingContext = new ToggleViewModel();
}
public void Button_OnClick(object sender, EventArgs args)
{
var button = sender as Button;
if (!(button?.BindingContext is ToggleViewModel viewModel))
{
return;
}
viewModel.ShouldBeToggled = !viewModel.ShouldBeToggled;
viewModel.ShouldBeEnabled = !viewModel.ShouldBeEnabled;
}
class ToggleViewModel : ViewModel
{
bool _shouldBeToggled;
public bool ShouldBeToggled
{
get => _shouldBeToggled;
set
{
_shouldBeToggled = value;
OnPropertyChanged();
}
}
bool _shouldBeEnabled;
public bool ShouldBeEnabled
{
get => _shouldBeEnabled;
set
{
_shouldBeEnabled = value;
OnPropertyChanged();
}
}
}
#if UITEST
[Test]
public void Issue1747Test()
{
RunningApp.WaitForElement(q => q.Marked(ToggleButtonAutomationId));
RunningApp.WaitForElement(q => q.Marked(ToggleSwitchAutomationId));
var toggleSwitch = RunningApp.Query(q => q.Marked(ToggleSwitchAutomationId))?.FirstOrDefault();
Assert.AreNotEqual(toggleSwitch, null);
Assert.AreEqual(toggleSwitch?.Enabled, false);
RunningApp.Tap(q => q.Marked(ToggleButtonAutomationId));
toggleSwitch = RunningApp.Query(q => q.Marked(ToggleSwitchAutomationId))?.FirstOrDefault();
Assert.AreNotEqual(toggleSwitch, null);
Assert.AreEqual(toggleSwitch?.Enabled, true);
}
#endif
}
}