Skip to content

Commit 853123c

Browse files
Adopt new SmartHint in PasswordBox styles (#3528)
* Move resources beneath the styles * Rename "border" to OuterBorder to align with TextBox * PasswordBox (non-reveal) style adjusted to new SmartHint * Update tests so. Reveal style expected to fail for now. * Getting close to having PasswordBox adopting new SmartHint * Jumpy UI and wrong hint color when validation error fixed * Fix helper text alignment in PasswordBox * Adjustments after rebase * Remove remote process attachment in test * Fix minor hint misalignment (rounding error) * Reset launchSettings.json back to default values * Post-merge fix and cleanup in test class * Include outline border tweak from TimePicker adoption * Fix reveal icon - missing from initial adoption.
1 parent e1f5b5a commit 853123c

File tree

2 files changed

+675
-671
lines changed

2 files changed

+675
-671
lines changed

MaterialDesignThemes.UITests/WPF/TextFieldDefaultHeightTests.cs

Lines changed: 84 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
namespace MaterialDesignThemes.UITests.WPF;
22

3-
public class TextFieldDefaultHeightTests : TestBase
3+
public class TextFieldDefaultHeightTests(ITestOutputHelper output) : TestBase(output)
44
{
5-
public TextFieldDefaultHeightTests(ITestOutputHelper output) : base(output) { }
6-
75
private const int Precision = 3;
86

97
[Fact]
@@ -12,14 +10,13 @@ public async Task SameHeightWithDefaultStyle()
1210
await using var recorder = new TestRecorder(App);
1311

1412
// TODO: Remove controls from here as they adopt the new SmartHint approach
15-
var stackPanel = await LoadXaml<StackPanel>(@"
16-
<StackPanel>
17-
<PasswordBox />
18-
<DatePicker />
19-
</StackPanel>");
13+
var stackPanel = await LoadXaml<StackPanel>("""
14+
<StackPanel>
15+
<DatePicker />
16+
</StackPanel>
17+
""");
2018

21-
var height = await GetHeight(stackPanel, "PasswordBox");
22-
Assert.Equal(height, await GetHeight(stackPanel, "DatePicker"), Precision);
19+
await GetHeight(stackPanel, "DatePicker");
2320

2421
recorder.Success();
2522
}
@@ -30,14 +27,17 @@ public async Task SameHeightWithDefaultStyle_PostSmartHintRefactor()
3027
await using var recorder = new TestRecorder(App);
3128

3229
// TODO: Add controls here as they adopt the new SmartHint approach. Once all controls have migrated, collapse into a single test with the old name.
33-
var stackPanel = await LoadXaml<StackPanel>(@"
34-
<StackPanel>
35-
<TextBox />
36-
<ComboBox IsEditable=""True"" />
37-
<materialDesign:TimePicker />
38-
</StackPanel>");
39-
40-
var height = await GetHeight(stackPanel, "TextBox");
30+
var stackPanel = await LoadXaml<StackPanel>("""
31+
<StackPanel>
32+
<TextBox />
33+
<PasswordBox />
34+
<ComboBox IsEditable="True" />
35+
<materialDesign:TimePicker />
36+
</StackPanel>
37+
""");
38+
39+
double height = await GetHeight(stackPanel, "TextBox");
40+
Assert.Equal(height, await GetHeight(stackPanel, "PasswordBox"), Precision);
4141
Assert.Equal(height, await GetHeight(stackPanel, "ComboBox"), Precision);
4242
Assert.Equal(height, await GetHeight(stackPanel, "TimePicker"), Precision);
4343

@@ -50,16 +50,14 @@ public async Task SameHeightWithFloatingHintStyle()
5050
await using var recorder = new TestRecorder(App);
5151

5252
// TODO: Remove controls from here as they adopt the new SmartHint approach
53-
var stackPanel = await LoadXaml<StackPanel>(@"
54-
<StackPanel>
55-
<PasswordBox Style=""{StaticResource MaterialDesignFloatingHintPasswordBox}"" materialDesign:HintAssist.Hint=""Hint"" />
56-
<DatePicker Style=""{StaticResource MaterialDesignFloatingHintDatePicker}"" materialDesign:HintAssist.Hint=""Hint"" />
57-
</StackPanel>");
58-
59-
var height = await GetHeight(stackPanel, "PasswordBox");
60-
Assert.True(height > 0);
61-
Assert.Equal(height, await GetHeight(stackPanel, "DatePicker"), Precision);
62-
53+
var stackPanel = await LoadXaml<StackPanel>("""
54+
<StackPanel>
55+
<DatePicker Style="{StaticResource MaterialDesignFloatingHintDatePicker}" materialDesign:HintAssist.Hint="Hint" />
56+
</StackPanel>
57+
""");
58+
59+
await GetHeight(stackPanel, "DatePicker");
60+
6361
recorder.Success();
6462
}
6563

@@ -69,15 +67,19 @@ public async Task SameHeightWithFloatingHintStyle_PostSmartHintRefactor()
6967
await using var recorder = new TestRecorder(App);
7068

7169
// TODO: Add controls here as they adopt the new SmartHint approach. Once all controls have migrated, collapse into a single test with the old name.
72-
var stackPanel = await LoadXaml<StackPanel>(@"
73-
<StackPanel>
74-
<TextBox Style=""{StaticResource MaterialDesignFloatingHintTextBox}"" materialDesign:HintAssist.Hint=""Hint"" />
75-
<ComboBox IsEditable=""True"" Style=""{StaticResource MaterialDesignFloatingHintComboBox}"" materialDesign:HintAssist.Hint=""Hint"" />
76-
<materialDesign:TimePicker Style=""{StaticResource MaterialDesignFloatingHintTimePicker}"" materialDesign:HintAssist.Hint=""Hint"" />
77-
</StackPanel>");
78-
79-
var height = await GetHeight(stackPanel, "TextBox");
80-
Assert.True(height > 0);
70+
var stackPanel = await LoadXaml<StackPanel>("""
71+
<StackPanel>
72+
<TextBox Style="{StaticResource MaterialDesignFloatingHintTextBox}" materialDesign:HintAssist.Hint="Hint" />
73+
<PasswordBox Style="{StaticResource MaterialDesignFloatingHintPasswordBox}" materialDesign:HintAssist.Hint="Hint" />
74+
<PasswordBox x:Name="RevealPasswordBox" Style="{StaticResource MaterialDesignFloatingHintRevealPasswordBox}" materialDesign:HintAssist.Hint="Hint" />
75+
<ComboBox IsEditable="True" Style="{StaticResource MaterialDesignFloatingHintComboBox}" materialDesign:HintAssist.Hint="Hint" />
76+
<materialDesign:TimePicker Style="{StaticResource MaterialDesignFloatingHintTimePicker}" materialDesign:HintAssist.Hint="Hint" />
77+
</StackPanel>
78+
""");
79+
80+
double height = await GetHeight(stackPanel, "TextBox");
81+
Assert.Equal(height, await GetHeight(stackPanel, "PasswordBox"), Precision);
82+
Assert.Equal(height, await GetHeight(stackPanel, "PasswordBox", "RevealPasswordBox"), Precision);
8183
Assert.Equal(height, await GetHeight(stackPanel, "ComboBox"), Precision);
8284
Assert.Equal(height, await GetHeight(stackPanel, "TimePicker"), Precision);
8385

@@ -90,16 +92,14 @@ public async Task SameHeightWithFilledStyle()
9092
await using var recorder = new TestRecorder(App);
9193

9294
// TODO: Remove controls from here as they adopt the new SmartHint approach
93-
var stackPanel = await LoadXaml<StackPanel>(@"
94-
<StackPanel>
95-
<PasswordBox Style=""{StaticResource MaterialDesignFilledPasswordBox}"" materialDesign:HintAssist.Hint=""Hint"" />
96-
<DatePicker Style=""{StaticResource MaterialDesignFilledDatePicker}"" materialDesign:HintAssist.Hint=""Hint"" />
97-
</StackPanel>");
98-
99-
var height = await GetHeight(stackPanel, "PasswordBox");
100-
Assert.True(height > 0);
101-
Assert.Equal(height, await GetHeight(stackPanel, "DatePicker"), Precision);
102-
95+
var stackPanel = await LoadXaml<StackPanel>("""
96+
<StackPanel>
97+
<DatePicker Style="{StaticResource MaterialDesignFilledDatePicker}" materialDesign:HintAssist.Hint="Hint" />
98+
</StackPanel>
99+
""");
100+
101+
await GetHeight(stackPanel, "DatePicker");
102+
103103
recorder.Success();
104104
}
105105

@@ -109,15 +109,19 @@ public async Task SameHeightWithFilledStyle_PostSmartHintRefactor()
109109
await using var recorder = new TestRecorder(App);
110110

111111
// TODO: Add controls here as they adopt the new SmartHint approach. Once all controls have migrated, collapse into a single test with the old name.
112-
var stackPanel = await LoadXaml<StackPanel>(@"
113-
<StackPanel>
114-
<TextBox Style=""{StaticResource MaterialDesignFilledTextBox}"" materialDesign:HintAssist.Hint=""Hint"" />
115-
<ComboBox IsEditable=""True"" Style=""{StaticResource MaterialDesignFilledComboBox}"" materialDesign:HintAssist.Hint=""Hint"" />
116-
<materialDesign:TimePicker Style=""{StaticResource MaterialDesignFilledTimePicker}"" materialDesign:HintAssist.Hint=""Hint"" />
117-
</StackPanel>");
118-
119-
var height = await GetHeight(stackPanel, "TextBox");
120-
Assert.True(height > 0);
112+
var stackPanel = await LoadXaml<StackPanel>("""
113+
<StackPanel>
114+
<TextBox Style="{StaticResource MaterialDesignFilledTextBox}" materialDesign:HintAssist.Hint="Hint" />
115+
<PasswordBox Style="{StaticResource MaterialDesignFilledPasswordBox}" materialDesign:HintAssist.Hint="Hint" />
116+
<PasswordBox x:Name="RevealPasswordBox" Style="{StaticResource MaterialDesignFilledRevealPasswordBox}" materialDesign:HintAssist.Hint="Hint" />
117+
<ComboBox IsEditable="True" Style="{StaticResource MaterialDesignFilledComboBox}" materialDesign:HintAssist.Hint="Hint" />
118+
<materialDesign:TimePicker Style="{StaticResource MaterialDesignFilledTimePicker}" materialDesign:HintAssist.Hint="Hint" />
119+
</StackPanel>
120+
""");
121+
122+
double height = await GetHeight(stackPanel, "TextBox");
123+
Assert.Equal(height, await GetHeight(stackPanel, "PasswordBox"), Precision);
124+
Assert.Equal(height, await GetHeight(stackPanel, "PasswordBox", "RevealPasswordBox"), Precision);
121125
Assert.Equal(height, await GetHeight(stackPanel, "ComboBox"), Precision);
122126
Assert.Equal(height, await GetHeight(stackPanel, "TimePicker"), Precision);
123127

@@ -130,16 +134,14 @@ public async Task SameHeightWithOutlinedStyle()
130134
await using var recorder = new TestRecorder(App);
131135

132136
// TODO: Remove controls from here as they adopt the new SmartHint approach
133-
var stackPanel = await LoadXaml<StackPanel>(@"
134-
<StackPanel>
135-
<PasswordBox Style=""{StaticResource MaterialDesignOutlinedPasswordBox}"" materialDesign:HintAssist.Hint=""Hint"" />
136-
<DatePicker Style=""{StaticResource MaterialDesignOutlinedDatePicker}"" materialDesign:HintAssist.Hint=""Hint"" />
137-
</StackPanel>");
138-
139-
var height = await GetHeight(stackPanel, "PasswordBox");
140-
Assert.True(height > 0);
141-
Assert.Equal(height, await GetHeight(stackPanel, "DatePicker"), Precision);
142-
137+
var stackPanel = await LoadXaml<StackPanel>("""
138+
<StackPanel>
139+
<DatePicker Style="{StaticResource MaterialDesignOutlinedDatePicker}" materialDesign:HintAssist.Hint="Hint" />
140+
</StackPanel>
141+
""");
142+
143+
await GetHeight(stackPanel, "DatePicker");
144+
143145
recorder.Success();
144146
}
145147

@@ -149,25 +151,29 @@ public async Task SameHeightWithOutlinedStyle_PostSmartHintRefactor()
149151
await using var recorder = new TestRecorder(App);
150152

151153
// TODO: Add controls here as they adopt the new SmartHint approach. Once all controls have migrated, collapse into a single test with the old name.
152-
var stackPanel = await LoadXaml<StackPanel>(@"
153-
<StackPanel>
154-
<TextBox Style=""{StaticResource MaterialDesignOutlinedTextBox}"" materialDesign:HintAssist.Hint=""Hint"" />
155-
<ComboBox IsEditable=""True"" Style=""{StaticResource MaterialDesignOutlinedComboBox}"" />
156-
<materialDesign:TimePicker Style=""{StaticResource MaterialDesignOutlinedTimePicker}"" materialDesign:HintAssist.Hint=""Hint"" />
157-
</StackPanel>");
158-
159-
var height = await GetHeight(stackPanel, "TextBox");
160-
Assert.True(height > 0);
154+
var stackPanel = await LoadXaml<StackPanel>("""
155+
<StackPanel>
156+
<TextBox Style="{StaticResource MaterialDesignOutlinedTextBox}" materialDesign:HintAssist.Hint="Hint" />
157+
<PasswordBox Style="{StaticResource MaterialDesignOutlinedPasswordBox}" materialDesign:HintAssist.Hint="Hint" />
158+
<PasswordBox x:Name="RevealPasswordBox" Style="{StaticResource MaterialDesignOutlinedRevealPasswordBox}" materialDesign:HintAssist.Hint="Hint" />
159+
<ComboBox IsEditable="True" Style="{StaticResource MaterialDesignOutlinedComboBox}" />
160+
<materialDesign:TimePicker Style="{StaticResource MaterialDesignOutlinedTimePicker}" materialDesign:HintAssist.Hint="Hint" />
161+
</StackPanel>
162+
""");
163+
164+
double height = await GetHeight(stackPanel, "TextBox");
165+
Assert.Equal(height, await GetHeight(stackPanel, "PasswordBox"), Precision);
166+
Assert.Equal(height, await GetHeight(stackPanel, "PasswordBox", "RevealPasswordBox"), Precision);
161167
Assert.Equal(height, await GetHeight(stackPanel, "ComboBox"), Precision);
162168
Assert.Equal(height, await GetHeight(stackPanel, "TimePicker"), Precision);
163169

164170
recorder.Success();
165171
}
166172

167-
private static async Task<double> GetHeight(IVisualElement container, string type)
173+
private static async Task<double> GetHeight(IVisualElement container, string type, string? optionalName = null)
168174
{
169-
var element = await container.GetElement<FrameworkElement>("/" + type);
170-
var height = await element.GetActualHeight();
175+
var element = await container.GetElement<FrameworkElement>(optionalName ?? "/" + type);
176+
double height = await element.GetActualHeight();
171177
Assert.True(height > 0);
172178
return height;
173179
}

0 commit comments

Comments
 (0)