Skip to content

Commit

Permalink
test(ComboBox): added tests for PlaceholderText
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoy312 committed Aug 25, 2020
1 parent c4c1109 commit bbe5e47
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,67 @@ public void ComboBoxTests_ToggleDisabled()

TakeScreenshot("ComboBox Disabled");
}

[Test]
[AutoRetry]
[ActivePlatforms(Platform.Android)]
public void ComboBoxTests_PlaceholderText() => ComboBoxTests_PlaceholderText_Impl("TestBox", 4, combo =>
{
var implicitTextBlock = combo.Descendant().Marked("ContentPresenter").Child;
var text = implicitTextBlock.GetDependencyPropertyValue<string>("Text");
Assert.AreEqual("5", text, "item #4 (text: 5) should be now selected");
});

[Test]
[AutoRetry]
[ActivePlatforms(Platform.Android)]
public void ComboBoxTests_PlaceholderText_With_ItemTemplate() => ComboBoxTests_PlaceholderText_Impl("TestBox2", 4, combo =>
{
var descendants = combo.Descendant().Marked("ContentPresenter").Descendant();
//<StackPanel Orientation="Horizontal"><!-- templateRoot -->
// <Rectangle ... />
// <TextBlock Text="Item:" />
// <TextBlock Text="{Binding}" />
//</StackPanel>
var offset = 2; // skipping the ContentPresenter#0 and the StackPanel#1
var text1 = descendants.AtIndex(offset + 1).GetDependencyPropertyValue<string>("Text");
var text2 = descendants.AtIndex(offset + 2).GetDependencyPropertyValue<string>("Text");
Assert.AreEqual("Item:", text1, "item #4 should be now selected with ItemTemplate");
Assert.AreEqual("5", text2, "item #4 (value: 5) should be now selected with ItemTemplate");
});

public void ComboBoxTests_PlaceholderText_Impl(string targetName, int selectionIndex, Action<QueryEx> selectionValidation)
{
Run("SamplesApp.Wasm.Windows_UI_Xaml_Controls.ComboBox.ComboBox_PlaceholderText");
_app.WaitForElement("sampleControl");

var testComboBox = _app.Marked(targetName);
var resetButton = _app.Marked("ResetButton");

// check initial value
var placeholderTextBlock = testComboBox.Descendant().Marked("PlaceholderTextBlock");
var expectedPlaceholderText = testComboBox.GetDependencyPropertyValue<string>("PlaceholderText");
var actualPlaceholderText = placeholderTextBlock.GetDependencyPropertyValue<string>("Text");
Assert.AreEqual(expectedPlaceholderText, actualPlaceholderText, "PlaceholderText should be shown prior to selection");

// open combobox flyout
testComboBox.FastTap();
var popupBorder = _app.Marked("PopupBorder");
_app.WaitForElement(popupBorder);

// select item at {selectionIndex}
var item5 = popupBorder.Descendant().WithClass("ComboBoxItem").AtIndex(selectionIndex);
item5.FastTap();
_app.WaitForDependencyPropertyValue<int>(testComboBox, "SelectedIndex", selectionIndex);
selectionValidation(testComboBox);

// clear selection
resetButton.FastTap();
_app.WaitForDependencyPropertyValue<int>(testComboBox, "SelectedIndex", -1);
actualPlaceholderText = placeholderTextBlock.GetDependencyPropertyValue<string>("Text");
Assert.AreEqual(expectedPlaceholderText, actualPlaceholderText, "PlaceholderText should be shown again when the selection is cleared");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,29 @@
d:DesignHeight="300"
d:DesignWidth="400">

<controls:SampleControl SampleDescription="ComboBox with PlaceholderText">
<controls:SampleControl.SampleContent>
<DataTemplate>
<StackPanel>
<ComboBox x:Name="TestBox"
PlaceholderText="PlaceholderText"
ItemsSource="{Binding [SampleItems]}" />
<ComboBox x:Name="TestBox2"
PlaceholderText="PlaceholderText + ItemTemplate"
ItemsSource="{Binding [SampleItems]}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Rectangle Height="12"
Width="12"
Fill="Pink" />
<TextBlock Text="Item:" />
<TextBlock Text="{Binding}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>

<ComboBox PlaceholderText="PlaceholderText"
ItemsSource="{Binding [SampleItems]}" />
<Button x:Name="ResetButton"
Content="Reset Selection"
Click="ResetSelection" />
</StackPanel>

</DataTemplate>
</controls:SampleControl.SampleContent>
</controls:SampleControl>
</UserControl>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Windows.UI.Xaml.Controls;
using SamplesApp.Windows_UI_Xaml_Controls.Models;
using Uno.UI.Samples.Controls;
using Windows.UI.Xaml;

namespace SamplesApp.Wasm.Windows_UI_Xaml_Controls.ComboBox
{
Expand All @@ -11,5 +12,11 @@ public ComboBox_PlaceholderText()
{
this.InitializeComponent();
}

void ResetSelection(object sender, RoutedEventArgs e)
{
TestBox.SelectedItem = null;
TestBox2.SelectedItem = null;
}
}
}

0 comments on commit bbe5e47

Please sign in to comment.