Skip to content

Commit

Permalink
UI-test collapsing adorned element for watermark. #24.
Browse files Browse the repository at this point in the history
No repro.
  • Loading branch information
JohanLarsson committed Aug 14, 2018
1 parent 9e92368 commit a64438a
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 35 deletions.
18 changes: 14 additions & 4 deletions Gu.Wpf.Adorners.Demo/Windows/WatermarkWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
<UniformGrid Rows="1">
<StackPanel>
<TextBlock Text="TextBox with watermark" />
<TextBox x:Name="TextBoxWithDefaultWatermark" adorners:Watermark.Text="Write something here" />
<TextBox x:Name="TextBoxWithDefaultWatermark"
adorners:Watermark.Text="Write something here"
Visibility="{Binding ElementName=VisibilityCbx, Path=SelectedItem}" />

<TextBlock Text="Bound text" />
<TextBox x:Name="TextBoxWithWatermarkWithBoundText" adorners:Watermark.Text="{Binding Text, ElementName=AdornerText}" />
Expand Down Expand Up @@ -79,7 +81,9 @@

<StackPanel>
<TextBlock Text="PasswordBox with watermark" />
<PasswordBox x:Name="PasswordBoxWithDefaultWatermark" adorners:Watermark.Text="Write something here" />
<PasswordBox x:Name="PasswordBoxWithDefaultWatermark"
adorners:Watermark.Text="Write something here"
Visibility="{Binding ElementName=VisibilityCbx, Path=SelectedItem}" />

<TextBlock Text="Bound text" />
<PasswordBox x:Name="PasswordBoxWithWatermarkWithBoundText" adorners:Watermark.Text="{Binding Text, ElementName=AdornerText}" />
Expand Down Expand Up @@ -124,8 +128,9 @@
<StackPanel>
<TextBlock Text="ComboBox with watermark" />
<ComboBox x:Name="ComboBoxWithDefaultWatermark"
adorners:Watermark.Text="Write something here"
BorderBrush="#FF707070">
adorners:Watermark.Text="Write something here"
BorderBrush="#FF707070"
Visibility="{Binding ElementName=VisibilityCbx, Path=SelectedItem}">
<ComboBoxItem>abc</ComboBoxItem>
<ComboBoxItem>cde</ComboBoxItem>
<ComboBoxItem>fgh</ComboBoxItem>
Expand Down Expand Up @@ -214,6 +219,11 @@
</StackPanel>
</UniformGrid>
<TextBox x:Name="AdornerText" Text="AAA" />
<ComboBox x:Name="VisibilityCbx" SelectedIndex="0">
<Visibility>Visible</Visibility>
<Visibility>Hidden</Visibility>
<Visibility>Collapsed</Visibility>
</ComboBox>
<Button Content="Lose focus" />
</StackPanel>
</Window>
84 changes: 53 additions & 31 deletions Gu.Wpf.Adorners.UiTests/WatermarkWindowTests.ComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public void WithDefaultWatermarkWhenNotFocused()
using (var app = Application.Launch(ExeFileName, WindowName))
{
var window = app.MainWindow;
var passwordBox = window.FindComboBox("ComboBoxWithDefaultWatermark");
ImageAssert.AreEqual(".\\Images\\ComboBoxWithDefaultWatermark_not_focused.png", passwordBox);
var comboBox = window.FindComboBox("ComboBoxWithDefaultWatermark");
ImageAssert.AreEqual(".\\Images\\ComboBoxWithDefaultWatermark_not_focused.png", comboBox);
}
}

Expand All @@ -31,9 +31,9 @@ public void WithDefaultWatermarkWhenFocused()
using (var app = Application.Launch(ExeFileName, WindowName))
{
var window = app.MainWindow;
var passwordBox = window.FindComboBox("ComboBoxWithDefaultWatermark");
passwordBox.Focus();
ImageAssert.AreEqual(".\\Images\\ComboBoxWithDefaultWatermark_focused.png", passwordBox);
var comboBox = window.FindComboBox("ComboBoxWithDefaultWatermark");
comboBox.Focus();
ImageAssert.AreEqual(".\\Images\\ComboBoxWithDefaultWatermark_focused.png", comboBox);
}
}

Expand All @@ -43,10 +43,10 @@ public void WithDefaultWatermarkWhenNotEmpty()
using (var app = Application.Launch(ExeFileName, WindowName))
{
var window = app.MainWindow;
var passwordBox = window.FindComboBox("ComboBoxWithDefaultWatermark");
passwordBox.Select("abc");
var comboBox = window.FindComboBox("ComboBoxWithDefaultWatermark");
comboBox.Select("abc");
window.FindButton("Lose focus").Click();
ImageAssert.AreEqual(".\\Images\\ComboBoxWithDefaultWatermark_not_empty.png", passwordBox);
ImageAssert.AreEqual(".\\Images\\ComboBoxWithDefaultWatermark_not_empty.png", comboBox);
}
}

Expand All @@ -56,12 +56,12 @@ public void WithWatermarkWithBoundText()
using (var app = Application.Launch(ExeFileName, WindowName))
{
var window = app.MainWindow;
var passwordBox = window.FindComboBox("ComboBoxWithWatermarkWithBoundText");
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkWithBoundText_AAA.png", passwordBox);
var comboBox = window.FindComboBox("ComboBoxWithWatermarkWithBoundText");
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkWithBoundText_AAA.png", comboBox);
window.FindTextBox("AdornerText").Text = "abc";
window.FindButton("Lose focus").Invoke();
Wait.For(TimeSpan.FromMilliseconds(50));
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkWithBoundText_abc.png", passwordBox);
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkWithBoundText_abc.png", comboBox);
}
}

Expand All @@ -71,8 +71,8 @@ public void WithWatermarkWithInheritedFontSize()
using (var app = Application.Launch(ExeFileName, WindowName))
{
var window = app.MainWindow;
var passwordBox = window.FindComboBox("ComboBoxWithWatermarkWithInheritedFontSize");
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkWithInheritedFontSize.png", passwordBox);
var comboBox = window.FindComboBox("ComboBoxWithWatermarkWithInheritedFontSize");
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkWithInheritedFontSize.png", comboBox);
}
}

Expand All @@ -82,8 +82,8 @@ public void WithWatermarkWithExplicitTextStyle()
using (var app = Application.Launch(ExeFileName, WindowName))
{
var window = app.MainWindow;
var passwordBox = window.FindComboBox("ComboBoxWithWatermarkWithExplicitTextStyle");
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkWithExplicitTextStyle.png", passwordBox);
var comboBox = window.FindComboBox("ComboBoxWithWatermarkWithExplicitTextStyle");
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkWithExplicitTextStyle.png", comboBox);
}
}

Expand All @@ -104,8 +104,8 @@ public void WithWatermarkVisibleWhenEmpty()
using (var app = Application.Launch(ExeFileName, WindowName))
{
var window = app.MainWindow;
var passwordBox = window.FindComboBox("ComboBoxWithWatermarkVisibleWhenEmpty");
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkVisibleWhenEmpty_not_focused.png", passwordBox);
var comboBox = window.FindComboBox("ComboBoxWithWatermarkVisibleWhenEmpty");
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkVisibleWhenEmpty_not_focused.png", comboBox);
}
}

Expand All @@ -115,9 +115,9 @@ public void WithWatermarkVisibleWhenEmptyWhenFocused()
using (var app = Application.Launch(ExeFileName, WindowName))
{
var window = app.MainWindow;
var passwordBox = window.FindComboBox("ComboBoxWithWatermarkVisibleWhenEmpty");
passwordBox.Focus();
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkVisibleWhenEmpty_focused.png", passwordBox);
var comboBox = window.FindComboBox("ComboBoxWithWatermarkVisibleWhenEmpty");
comboBox.Focus();
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkVisibleWhenEmpty_focused.png", comboBox);
}
}

Expand All @@ -127,10 +127,10 @@ public void WithWatermarkVisibleWhenEmptyWhenNotEmpty()
using (var app = Application.Launch(ExeFileName, WindowName))
{
var window = app.MainWindow;
var passwordBox = window.FindComboBox("ComboBoxWithWatermarkVisibleWhenEmpty");
passwordBox.Select("abc");
var comboBox = window.FindComboBox("ComboBoxWithWatermarkVisibleWhenEmpty");
comboBox.Select("abc");
window.FindButton("Lose focus").Click();
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkVisibleWhenEmpty_not_empty.png", passwordBox);
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkVisibleWhenEmpty_not_empty.png", comboBox);
}
}

Expand All @@ -140,8 +140,8 @@ public void WithWatermarkVisibleWhenEmptyAndNotFocused()
using (var app = Application.Launch(ExeFileName, WindowName))
{
var window = app.MainWindow;
var passwordBox = window.FindComboBox("ComboBoxWithWatermarkVisibleWhenEmptyAndNotFocused");
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkVisibleWhenEmptyAndNotFocused_not_focused.png", passwordBox);
var comboBox = window.FindComboBox("ComboBoxWithWatermarkVisibleWhenEmptyAndNotFocused");
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkVisibleWhenEmptyAndNotFocused_not_focused.png", comboBox);
}
}

Expand All @@ -151,9 +151,9 @@ public void WithWatermarkVisibleWhenEmptyAndNotFocusedWhenFocused()
using (var app = Application.Launch(ExeFileName, WindowName))
{
var window = app.MainWindow;
var passwordBox = window.FindComboBox("ComboBoxWithWatermarkVisibleWhenEmptyAndNotFocused");
passwordBox.Focus();
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkVisibleWhenEmptyAndNotFocused_focused.png", passwordBox);
var comboBox = window.FindComboBox("ComboBoxWithWatermarkVisibleWhenEmptyAndNotFocused");
comboBox.Focus();
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkVisibleWhenEmptyAndNotFocused_focused.png", comboBox);
}
}

Expand All @@ -163,10 +163,32 @@ public void WithWatermarkVisibleWhenEmptyAndNotFocusedWhenNotEmpty()
using (var app = Application.Launch(ExeFileName, WindowName))
{
var window = app.MainWindow;
var passwordBox = window.FindComboBox("ComboBoxWithWatermarkVisibleWhenEmptyAndNotFocused");
passwordBox.Select("abc");
var comboBox = window.FindComboBox("ComboBoxWithWatermarkVisibleWhenEmptyAndNotFocused");
comboBox.Select("abc");
window.FindButton("Lose focus").Click();
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkVisibleWhenEmptyAndNotFocused_not_empty.png", passwordBox);
ImageAssert.AreEqual(".\\Images\\ComboBoxWithWatermarkVisibleWhenEmptyAndNotFocused_not_empty.png", comboBox);
}
}

[TestCase("Collapsed")]
[TestCase("Hidden")]
public void WhenAdornedElementIs(string visibility)
{
using (var app = Application.Launch(ExeFileName, WindowName))
{
var window = app.MainWindow;
Wait.For(TimeSpan.FromMilliseconds(200));
var button = window.FindComboBox("ComboBoxWithDefaultWatermark");
ImageAssert.AreEqual(".\\Images\\ComboBoxWithDefaultWatermark_not_focused.png", button);

var comboBox = window.FindComboBox("VisibilityCbx");
comboBox.Select(visibility);
Wait.For(TimeSpan.FromMilliseconds(200));

// Checking that we don't crash here. See issue #24
comboBox.Select("Visible");
Wait.For(TimeSpan.FromMilliseconds(200));
ImageAssert.AreEqual(".\\Images\\ComboBoxWithDefaultWatermark_not_focused.png", button);
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions Gu.Wpf.Adorners.UiTests/WatermarkWindowTests.PasswordBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,28 @@ public void WithWatermarkVisibleWhenEmptyAndNotFocusedWhenNotEmpty()
ImageAssert.AreEqual(".\\Images\\PasswordBoxWithWatermarkVisibleWhenEmptyAndNotFocused_not_empty.png", passwordBox);
}
}

[TestCase("Collapsed")]
[TestCase("Hidden")]
public void WhenAdornedElementIs(string visibility)
{
using (var app = Application.Launch(ExeFileName, WindowName))
{
var window = app.MainWindow;
Wait.For(TimeSpan.FromMilliseconds(200));
var button = window.FindPasswordBox("PasswordBoxWithDefaultWatermark");
ImageAssert.AreEqual(".\\Images\\PasswordBoxWithDefaultWatermark_not_focused.png", button);

var comboBox = window.FindComboBox("VisibilityCbx");
comboBox.Select(visibility);
Wait.For(TimeSpan.FromMilliseconds(200));

// Checking that we don't crash here. See issue #24
comboBox.Select("Visible");
Wait.For(TimeSpan.FromMilliseconds(200));
ImageAssert.AreEqual(".\\Images\\PasswordBoxWithDefaultWatermark_not_focused.png", button);
}
}
}
}
}
22 changes: 22 additions & 0 deletions Gu.Wpf.Adorners.UiTests/WatermarkWindowTests.TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,28 @@ public void WithWatermarkVisibleWhenEmptyAndNotFocusedWhenNotEmpty()
ImageAssert.AreEqual(".\\Images\\TextBoxWithWatermarkVisibleWhenEmptyAndNotFocused_not_empty.png", textBox);
}
}

[TestCase("Collapsed")]
[TestCase("Hidden")]
public void WhenAdornedElementIs(string visibility)
{
using (var app = Application.Launch(ExeFileName, WindowName))
{
var window = app.MainWindow;
Wait.For(TimeSpan.FromMilliseconds(200));
var button = window.FindTextBox("TextBoxWithDefaultWatermark");
ImageAssert.AreEqual(".\\Images\\TextBoxWithDefaultWatermark_not_focused.png", button);

var comboBox = window.FindComboBox("VisibilityCbx");
comboBox.Select(visibility);
Wait.For(TimeSpan.FromMilliseconds(200));

// Checking that we don't crash here. See issue #24
comboBox.Select("Visible");
Wait.For(TimeSpan.FromMilliseconds(200));
ImageAssert.AreEqual(".\\Images\\TextBoxWithDefaultWatermark_not_focused.png", button);
}
}
}
}
}

0 comments on commit a64438a

Please sign in to comment.