Skip to content

Commit

Permalink
UITest/InfoMan: AddAndRemoveEntriesTest
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed Oct 5, 2024
1 parent 4af3119 commit f490784
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
using Xunit.Abstractions;
using Xunit;
using UITest.InformationManager.Views;
using FlaUI.Core.Definitions;

namespace UITest.InformationManager.Tests;

public class AddressBookTest(ITestOutputHelper log) : UITest(log)
{
[Fact]
public void ShowContactsTest() => Run(() =>
public void SearchContactsAndChangeEntriesTest() => Run(() =>
{
Launch();
var window = GetShellWindow();
Expand Down Expand Up @@ -38,17 +39,79 @@ public void ShowContactsTest() => Run(() =>
Assert.Equal(2, contactListView.ContactItems.Count);
Assert.Null(contactListView.ContactList.SelectedItem);
contactListView.ContactList.Select(0);
AssertContactItem(contactListView.ContactList.SelectedItem.As<ContactListItem>(), contactView, "Michael", "Pfeiffer", "michael.pfeiffer@fabrikam.com", "(222) 555-0105");
var item = contactListView.ContactList.SelectedItem.As<ContactListItem>();
AssertContactItem(item, contactView, "Michael", "Pfeiffer", "michael.pfeiffer@fabrikam.com", "(222) 555-0105");
contactView.FirstnameBox.Text = "TFirstname";
Assert.Equal("TFirstname", item.FirstnameLabel.Text);
contactView.PhoneBox.Text = "TPhone";
Assert.Equal("TPhone", item.PhoneLabel.Text);
window.ExitCommand.Click();
});

private static void AssertContactItem(ContactListItem contactItem, ContactView? contactView, string firstName, string lastName, string email, string phone)
[Fact]
public void AddAndRemoveEntriesTest() => Run(() =>
{
SkipAppClose = true;
Launch();
var window = GetShellWindow();
window.WindowState = WindowVisualState.Maximized;
window.RootTreeItem.ContactsNode.Click();
var contactListView = window.ContactLayoutView.ContactListView;
var contactView = window.ContactLayoutView.ContactView;
Assert.Equal(5, contactListView.ContactItems.Count);
window.NewContactCommand.Click();
Assert.Equal(6, contactListView.ContactItems.Count);
var newItem = contactListView.ContactList.SelectedItem.As<ContactListItem>();
// ItemStatus contains the validation error message or string.Empty if no error exists
AssertContactItem(null, contactView, "", "", "", "");
AssertContactItem(newItem, null, "(none)", "(none)", "(none)", "(none)");
Assert.Equal("The Firstname field is required.", contactView.FirstnameBox.ItemStatus);
contactView.FirstnameBox.Text = "AFirstname";
Assert.Equal("AFirstname", newItem.FirstnameLabel.Text);
Assert.Equal("", contactView.FirstnameBox.ItemStatus);
contactView.LastnameBox.Text = "ALastname";
contactView.EmailBox.Text = "AEmail@mail.com";
contactView.PhoneBox.Text = "1234";
AssertContactItem(newItem, contactView, "AFirstname", "ALastname", "AEmail@mail.com", "1234");
var secondItem = contactListView.ContactItems[1];
contactListView.ContactList.Select(0);
window.DeleteCommand.Click();
Assert.Equal(5, contactListView.ContactItems.Count);
Assert.Equal(secondItem.FirstnameLabel.Text, contactListView.ContactList.SelectedItem.As<ContactListItem>().FirstnameLabel.Text);
window.ExitCommand.Click();
Launch(resetSettings: false, resetContainer: false);
window = GetShellWindow();
Assert.Equal(WindowVisualState.Maximized, window.WindowState);
window.RootTreeItem.ContactsNode.Click();
contactListView = window.ContactLayoutView.ContactListView;
Assert.Equal(5, contactListView.ContactItems.Count);
Assert.Equal("AFirstname", contactListView.ContactItems[^1].FirstnameLabel.Text);
var count = contactListView.ContactItems.Count;
for (int i = 0; i < count; i++) window.DeleteCommand.Click();
Assert.False(window.DeleteCommand.IsEnabled);
Assert.Null(contactListView.ContactList.SelectedItem);
window.Close();
});

private static void AssertContactItem(ContactListItem? contactItem, ContactView? contactView, string firstName, string lastName, string email, string phone)
{
Assert.Equal((firstName, lastName, email, phone), contactItem.ToTuple());
if (contactItem is not null)
{
Assert.Equal((firstName, lastName, email, phone), contactItem.ToTuple());
}
if (contactView is not null)
{
Assert.Equal(contactItem.ToTuple(), (contactView.FirstnameBox.Text, contactView.LastnameBox.Text, contactView.EmailBox.Text, contactView.PhoneBox.Text));
Assert.Equal((firstName, lastName, email, phone), (contactView.FirstnameBox.Text, contactView.LastnameBox.Text, contactView.EmailBox.Text, contactView.PhoneBox.Text));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FlaUI.Core;
using FlaUI.Core.AutomationElements;
using FlaUI.Core.Definitions;

namespace UITest.InformationManager.Views;

Expand All @@ -23,6 +24,13 @@ public class ShellWindow(FrameworkAutomationElementBase element) : Window(elemen
public NavigationRootTreeItem RootTreeItem => this.Find("RootTreeItem").As<NavigationRootTreeItem>();

public ContactLayoutView ContactLayoutView => this.Find("ContactLayoutView").As<ContactLayoutView>();


public WindowVisualState WindowState
{
get => Patterns.Window.Pattern.WindowVisualState;
set => Patterns.Window.Pattern.SetWindowVisualState(value);
}
}

public class NavigationRootTreeItem(FrameworkAutomationElementBase element) : TreeItem(element)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
<Style TargetType="TextBox">
<Setter Property="Padding" Value="1,3"/>
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource ErrorTemplate}"/>
<Setter Property="AutomationProperties.ItemStatus">
<Setter.Value>
<MultiBinding Converter="{x:Static waf:ValidationErrorsConverter.Default}">
<Binding Path="(Validation.Errors)" RelativeSource="{RelativeSource Self}"/>
<Binding Path="(Validation.Errors).Count" RelativeSource="{RelativeSource Self}"/>
</MultiBinding>
</Setter.Value>
</Setter>
</Style>

<Style TargetType="PasswordBox">
Expand Down

0 comments on commit f490784

Please sign in to comment.