-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UITest/InfoMan: AddAndRemoveEntriesTest
- Loading branch information
Showing
3 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
|
@@ -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", "[email protected]", "(222) 555-0105"); | ||
var item = contactListView.ContactList.SelectedItem.As<ContactListItem>(); | ||
AssertContactItem(item, contactView, "Michael", "Pfeiffer", "[email protected]", "(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 = "[email protected]"; | ||
contactView.PhoneBox.Text = "1234"; | ||
AssertContactItem(newItem, contactView, "AFirstname", "ALastname", "[email protected]", "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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters