diff --git a/src/Samples.UITest/InformationManager.Test/Tests/AddressBookTest.cs b/src/Samples.UITest/InformationManager.Test/Tests/AddressBookTest.cs index 3f9d876b..1e0f3d57 100644 --- a/src/Samples.UITest/InformationManager.Test/Tests/AddressBookTest.cs +++ b/src/Samples.UITest/InformationManager.Test/Tests/AddressBookTest.cs @@ -85,15 +85,34 @@ public void AddAndRemoveEntriesTest() => Run(() => window.ExitCommand.Click(); - + // Restart application and assert that new contact was saved Launch(resetSettings: false, resetContainer: false); window = GetShellWindow(); Assert.Equal(WindowVisualState.Maximized, window.WindowState); window.RootTreeItem.ContactsNode.Click(); contactListView = window.ContactLayoutView.ContactListView; + contactView = window.ContactLayoutView.ContactView; Assert.Equal(5, contactListView.ContactItems.Count); - Assert.Equal("AFirstname", contactListView.ContactItems[^1].FirstnameLabel.Text); + newItem = contactListView.ContactItems[^1]; + Assert.Equal("AFirstname", newItem.FirstnameLabel.Text); + contactListView.ContactList.Select(contactListView.ContactItems.Count - 1); + AssertContactItem(newItem, contactView, "AFirstname", "ALastname", "AEmail@mail.com", "1234"); + + // Invalid Firstname > Save > Restart > Validation error should be here again + contactView.FirstnameBox.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; + contactView = window.ContactLayoutView.ContactView; + newItem = contactListView.ContactItems[^1]; + contactListView.ContactList.Select(contactListView.ContactItems.Count - 1); + Assert.Equal("The Firstname field is required.", contactView.FirstnameBox.ItemStatus); + // Remove all contact items var count = contactListView.ContactItems.Count; for (int i = 0; i < count; i++) window.DeleteCommand.Click(); Assert.False(window.DeleteCommand.IsEnabled); diff --git a/src/Samples.UITest/InformationManager.Test/Tests/EmailTest.cs b/src/Samples.UITest/InformationManager.Test/Tests/EmailTest.cs new file mode 100644 index 00000000..e5ba28b8 --- /dev/null +++ b/src/Samples.UITest/InformationManager.Test/Tests/EmailTest.cs @@ -0,0 +1,78 @@ +using FlaUI.Core.AutomationElements; +using UITest.InformationManager.Views; +using Xunit; +using Xunit.Abstractions; + +namespace UITest.InformationManager.Tests; +public class EmailTest(ITestOutputHelper log) : UITest(log) +{ + [Fact] + public void SearchEmailsAndAssertLists() => Run(() => + { + Launch(); + var window = GetShellWindow(); + Assert.True(window.RootTreeItem.InboxNode.IsSelected); + + var emailListView = window.EmailLayoutView.EmailListView; + var emailView = window.EmailLayoutView.EmailView; + var count = emailListView.EmailItems.Count; + Assert.Equal(10, count); + Log.WriteLine($"List of Contacts ({count})"); + for (int i = 0; i < count; i++) Log.WriteLine($"{i:00}: {emailListView.EmailItems[i].ToReceivedTuple()}"); + + AssertEmail(true, emailListView.EmailItems[0], emailView, "user-2@fabrikam.com", "harry@example.com", "8/9/2012", "5:58:21 AM", "Nunc sed dis suscipit"); + + Assert.Equal("Search", emailListView.SearchBox.SearchHintLabel.Text); + emailListView.SearchBox.SearchTextBox.Text = "!"; + Assert.Empty(emailListView.EmailItems); + + emailListView.SearchBox.SearchTextBox.Text = "someone"; + Assert.Equal(3, emailListView.EmailItems.Count); + Assert.Null(emailListView.EmailList.SelectedItem); + emailListView.EmailList.Select(1); + var item = emailListView.EmailList.SelectedItem.As(); + AssertEmail(true, item, emailView, "someone-2@adventure-works.com", "harry@example.com", "9/5/2005", "4:34:45 PM", "Taciti enim"); + + + window.RootTreeItem.OutboxNode.Select(); + emailListView = window.EmailLayoutView.EmailListView; + emailView = window.EmailLayoutView.EmailView; + Assert.Empty(emailListView.EmailItems); + Assert.Empty(emailView.TitleLabel.Text); + + + window.RootTreeItem.SentNode.Select(); + emailListView = window.EmailLayoutView.EmailListView; + emailView = window.EmailLayoutView.EmailView; + Assert.Equal(5, emailListView.EmailItems.Count); + AssertEmail(false, emailListView.EmailList.SelectedItem.As(), emailView, "harry@example.com", "user-2@fabrikam.com", "4/7/2012", "10:07:05 AM", "Massa sed"); + + + window.RootTreeItem.DraftsNode.Select(); + emailListView = window.EmailLayoutView.EmailListView; + emailView = window.EmailLayoutView.EmailView; + Assert.Single(emailListView.EmailItems); + AssertEmail(false, emailListView.EmailList.SelectedItem.As(), emailView, "harry@example.com", "", "7/1/2006", "3:40:49 AM", "Sociis nunc vivamus sagittis"); + + + window.RootTreeItem.DeletedNode.Select(); + emailListView = window.EmailLayoutView.EmailListView; + emailView = window.EmailLayoutView.EmailView; + Assert.Empty(emailListView.EmailItems); + Assert.Empty(emailView.TitleLabel.Text); + + window.ExitCommand.Click(); + }); + + private static void AssertEmail(bool received, EmailListItem? emailItem, EmailView? emailView, string from, string to, string sentDate, string sentTime, string title) + { + if (emailItem is not null) + { + if (received) Assert.Equal((from, sentDate, title), emailItem.ToReceivedTuple()); + else Assert.Equal((to, sentDate, title), emailItem.ToSendTuple()); + } + if (emailView is not null) + { + Assert.Equal((from, to, sentDate + " " + sentTime, title), (emailView.FromLabel.Text, emailView.ToLabel.Text, emailView.SentLabel.Text, emailView.TitleLabel.Text)); } + } +} diff --git a/src/Samples.UITest/InformationManager.Test/Views/EmailLayoutView.cs b/src/Samples.UITest/InformationManager.Test/Views/EmailLayoutView.cs new file mode 100644 index 00000000..8956745a --- /dev/null +++ b/src/Samples.UITest/InformationManager.Test/Views/EmailLayoutView.cs @@ -0,0 +1,11 @@ +using FlaUI.Core.AutomationElements; +using FlaUI.Core; + +namespace UITest.InformationManager.Views; + +public class EmailLayoutView(FrameworkAutomationElementBase element) : AutomationElement(element) +{ + public EmailListView EmailListView => this.Find("EmailListView").As(); + + public EmailView EmailView => this.Find("EmailView").As(); +} diff --git a/src/Samples.UITest/InformationManager.Test/Views/EmailListView.cs b/src/Samples.UITest/InformationManager.Test/Views/EmailListView.cs new file mode 100644 index 00000000..42151790 --- /dev/null +++ b/src/Samples.UITest/InformationManager.Test/Views/EmailListView.cs @@ -0,0 +1,29 @@ +using FlaUI.Core; +using FlaUI.Core.AutomationElements; +using UITest.InformationManager.Controls; + +namespace UITest.InformationManager.Views; + +public class EmailListView(FrameworkAutomationElementBase element) : AutomationElement(element) +{ + public SearchBox SearchBox => this.Find("SearchBox").As(); + + public ListBox EmailList => this.Find("EmailList").AsListBox(); + + public IReadOnlyList EmailItems => EmailList.Items.Select(x => x.As()).ToArray(); +} + +public class EmailListItem(FrameworkAutomationElementBase element) : ListBoxItem(element) +{ + public Label ToLabel => this.Find("ToLabel").AsLabel(); + + public Label FromLabel => this.Find("FromLabel").AsLabel(); + + public Label SentLabel => this.Find("SentLabel").AsLabel(); + + public Label TitleLabel => this.Find("TitleLabel").AsLabel(); + + public (string to, string sent, string title) ToReceivedTuple() => (FromLabel.Text, SentLabel.Text, TitleLabel.Text); + + public (string to, string sent, string title) ToSendTuple() => (ToLabel.Text, SentLabel.Text, TitleLabel.Text); +} \ No newline at end of file diff --git a/src/Samples.UITest/InformationManager.Test/Views/EmailView.cs b/src/Samples.UITest/InformationManager.Test/Views/EmailView.cs new file mode 100644 index 00000000..789e73e6 --- /dev/null +++ b/src/Samples.UITest/InformationManager.Test/Views/EmailView.cs @@ -0,0 +1,19 @@ +using FlaUI.Core.AutomationElements; +using FlaUI.Core; + +namespace UITest.InformationManager.Views; + +public class EmailView(FrameworkAutomationElementBase element) : AutomationElement(element) +{ + public Label TitleLabel => this.Find("TitleLabel").AsLabel(); + + public Label FromLabel => this.Find("FromLabel").AsLabel(); + + public Label ToLabel => this.Find("ToLabel").AsLabel(); + + public Label CCLabel => this.Find("CCLabel").AsLabel(); + + public Label BccLabel => this.Find("BccLabel").AsLabel(); + + public Label SentLabel => this.Find("SentLabel").AsLabel(); +} diff --git a/src/Samples.UITest/InformationManager.Test/Views/ShellWindow.cs b/src/Samples.UITest/InformationManager.Test/Views/ShellWindow.cs index 062d4e11..42c797ea 100644 --- a/src/Samples.UITest/InformationManager.Test/Views/ShellWindow.cs +++ b/src/Samples.UITest/InformationManager.Test/Views/ShellWindow.cs @@ -23,6 +23,8 @@ public class ShellWindow(FrameworkAutomationElementBase element) : Window(elemen public NavigationRootTreeItem RootTreeItem => this.Find("RootTreeItem").As(); + public EmailLayoutView EmailLayoutView => this.Find("EmailLayoutView").As(); + public ContactLayoutView ContactLayoutView => this.Find("ContactLayoutView").As(); @@ -35,5 +37,15 @@ public WindowVisualState WindowState public class NavigationRootTreeItem(FrameworkAutomationElementBase element) : TreeItem(element) { + public TreeItem InboxNode => this.Find("InboxNode").AsTreeItem(); + + public TreeItem OutboxNode => this.Find("OutboxNode").AsTreeItem(); + + public TreeItem SentNode => this.Find("SentNode").AsTreeItem(); + + public TreeItem DraftsNode => this.Find("DraftsNode").AsTreeItem(); + + public TreeItem DeletedNode => this.Find("DeletedNode").AsTreeItem(); + public TreeItem ContactsNode => this.Find("ContactsNode").AsTreeItem(); } \ No newline at end of file diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Domain/Emails/Email.cs b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Domain/Emails/Email.cs index c92d4b11..277b81ba 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Domain/Emails/Email.cs +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Domain/Emails/Email.cs @@ -13,19 +13,12 @@ public class Email : ValidatableModel, IValidatableObject [DataMember] private EmailType emailType; [DataMember] private string title = ""; [DataMember] private string from = ""; - [DataMember] private IEnumerable to; - [DataMember] private IEnumerable cc; - [DataMember] private IEnumerable bcc; + [DataMember] private IEnumerable to = []; + [DataMember] private IEnumerable cc = []; + [DataMember] private IEnumerable bcc = []; [DataMember] private DateTime sent; [DataMember] private string? message; - public Email() - { - to = Array.Empty(); - cc = Array.Empty(); - bcc = Array.Empty(); - } - public EmailType EmailType { get => emailType; @@ -105,7 +98,7 @@ public IEnumerable Validate(ValidationContext validationContex foreach (var email in Bcc) { ValidateEmail(validationResults, email, nameof(Bcc), "BCC"); } if (!To.Any() && !CC.Any() && !Bcc.Any()) { - validationResults.Add(new ValidationResult("This email doesn't define a recipient.", new[] { nameof(To) })); + validationResults.Add(new ValidationResult("This email doesn't define a recipient.", [nameof(To)])); } return validationResults; } @@ -114,7 +107,7 @@ private static void ValidateEmail(ICollection validationResult { if (!emailAddress.IsValid(email)) { - validationResults.Add(new ValidationResult(string.Format(CultureInfo.CurrentCulture, "The email {0} in the {1} field is not valid.", email, displayName), new[] { field })); + validationResults.Add(new ValidationResult(string.Format(CultureInfo.CurrentCulture, "The email {0} in the {1} field is not valid.", email, displayName), [field])); } } diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailLayoutView.xaml b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailLayoutView.xaml index 3ff168e7..56df63a9 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailLayoutView.xaml +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailLayoutView.xaml @@ -4,7 +4,7 @@ xmlns:dd="clr-namespace:Waf.InformationManager.EmailClient.Modules.Presentation.DesignData" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - mc:Ignorable="d" d:DesignHeight="400" d:DesignWidth="600" + mc:Ignorable="d" d:DesignHeight="400" d:DesignWidth="600" AutomationProperties.AutomationId="EmailLayoutView" d:DataContext="{d:DesignInstance dd:SampleEmailLayoutViewModel, IsDesignTimeCreatable=True}"> diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailListView.xaml b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailListView.xaml index 9d644ea2..e832bab5 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailListView.xaml +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailListView.xaml @@ -8,7 +8,7 @@ xmlns:domain="clr-namespace:Waf.InformationManager.EmailClient.Modules.Domain.Emails;assembly=Waf.InformationManager.EmailClient.Modules.Domain" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" + mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" AutomationProperties.AutomationId="EmailListView" d:DataContext="{d:DesignInstance dd:SampleEmailListViewModel, IsDesignTimeCreatable=True}"> @@ -24,11 +24,11 @@ - + - + - + @@ -44,11 +44,11 @@ + Margin="7" TextTrimming="CharacterEllipsis" AutomationProperties.AutomationId="ToLabel"/> - + - + @@ -57,14 +57,14 @@ - - - + + + + ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Disabled" AutomationProperties.AutomationId="EmailList"> diff --git a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailView.xaml b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailView.xaml index ad36c6b4..a09faa97 100644 --- a/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailView.xaml +++ b/src/System.Waf/Samples/InformationManager/EmailClient.Modules.Presentation/Views/EmailView.xaml @@ -4,7 +4,7 @@ xmlns:c="clr-namespace:Waf.InformationManager.EmailClient.Modules.Presentation.Converters" xmlns:dd="clr-namespace:Waf.InformationManager.EmailClient.Modules.Presentation.DesignData" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" AutomationProperties.AutomationId="EmailView" mc:Ignorable="d" d:DataContext="{d:DesignInstance dd:SampleEmailViewModel, IsDesignTimeCreatable=True}" d:DesignHeight="300" d:DesignWidth="400"> @@ -59,28 +59,28 @@