-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
ShellTests.cs
140 lines (121 loc) · 3.65 KB
/
ShellTests.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Android.Content;
using Android.Support.Design.Widget;
using Android.Views;
using Android.Widget;
using NUnit.Framework;
using Xamarin.Forms;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Platform.Android.UnitTests;
#if __ANDROID_29__
using AndroidX.AppCompat.App;
using AToolbar = AndroidX.AppCompat.Widget.Toolbar;
#else
#endif
[assembly: ExportRenderer(typeof(TestShell), typeof(TestShellRenderer))]
namespace Xamarin.Forms.Platform.Android.UnitTests
{
public class ShellTests : PlatformTestFixture
{
[Test, Category("Shell")]
[Description("Flyout Header Changes When Updated")]
public async Task FlyoutHeaderReactsToChanges()
{
var shell = CreateShell();
var initialHeader = new Label() { Text = "Hello" };
var newHeader = new Label() { Text = "Hello part 2" };
shell.FlyoutHeader = initialHeader;
await Device.InvokeOnMainThreadAsync(async () =>
{
TestActivity testSurface = null;
try
{
testSurface = await TestActivity.GetTestSurface(Context, shell);
var addedView = shell.GetRenderer().View;
Assert.IsNotNull(addedView);
Assert.IsNull(newHeader.GetValue(Platform.RendererProperty));
Assert.IsNotNull(initialHeader.GetValue(Platform.RendererProperty));
await Device.InvokeOnMainThreadAsync(() => shell.FlyoutHeader = newHeader);
Assert.IsNotNull(newHeader.GetValue(Platform.RendererProperty), "New Header Not Set Up");
Assert.IsNull(initialHeader.GetValue(Platform.RendererProperty), "Old Header Still Set Up");
}
finally
{
testSurface?.Finish();
}
});
}
[Test, Category("Shell")]
[Description("Ensure Default Colors are White for BottomNavigationView")]
public async Task ShellTabColorsDefaultToWhite()
{
var shell = CreateShell();
var tracker = new ShellBottomNavViewAppearanceTracker(null, shell.Items[0]);
BottomNavigationView bottomView = new BottomNavigationView(this.Context);
bottomView.Menu.Add("test");
ColorChangeRevealDrawable ccr =
await Device.InvokeOnMainThreadAsync(() =>
{
tracker.SetAppearance(bottomView, new ShellAppearanceTest());
return (ColorChangeRevealDrawable)bottomView.Background;
});
Assert.AreEqual(Color.White.ToAndroid(), ccr.EndColor);
}
public class ShellAppearanceTest : IShellAppearanceElement
{
public Color EffectiveTabBarBackgroundColor { get; set; }
public Color EffectiveTabBarDisabledColor { get; set; }
public Color EffectiveTabBarForegroundColor { get; set; }
public Color EffectiveTabBarTitleColor { get; set; }
public Color EffectiveTabBarUnselectedColor { get; set; }
}
Shell CreateShell()
{
return new Shell()
{
Items =
{
new FlyoutItem()
{
Items =
{
new Tab()
{
Items =
{
new ShellContent()
{
Content = new ContentPage()
}
}
}
}
}
}
};
}
}
public class TestShell : Shell { }
public class ShellAppearanceTest : IShellAppearanceElement
{
public Color EffectiveTabBarBackgroundColor { get; set; }
public Color EffectiveTabBarDisabledColor { get; set; }
public Color EffectiveTabBarForegroundColor { get; set; }
public Color EffectiveTabBarTitleColor { get; set; }
public Color EffectiveTabBarUnselectedColor { get; set; }
}
public class TestShellRenderer : ShellRenderer
{
protected override IShellFlyoutContentRenderer CreateShellFlyoutContentRenderer()
{
return base.CreateShellFlyoutContentRenderer();
}
public TestShellRenderer(Context context) : base(context)
{
}
}
}