Skip to content

Commit

Permalink
UITest/InfoMan: Extend AddressBookTest; add EmailTest
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed Oct 29, 2024
1 parent bf9fb5b commit 1b49b4c
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "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);
Expand Down
78 changes: 78 additions & 0 deletions src/Samples.UITest/InformationManager.Test/Tests/EmailTest.cs
Original file line number Diff line number Diff line change
@@ -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, "[email protected]", "[email protected]", "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<EmailListItem>();
AssertEmail(true, item, emailView, "[email protected]", "[email protected]", "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<EmailListItem>(), emailView, "[email protected]", "[email protected]", "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<EmailListItem>(), emailView, "[email protected]", "", "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)); }
}
}
Original file line number Diff line number Diff line change
@@ -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<EmailListView>();

public EmailView EmailView => this.Find("EmailView").As<EmailView>();
}
29 changes: 29 additions & 0 deletions src/Samples.UITest/InformationManager.Test/Views/EmailListView.cs
Original file line number Diff line number Diff line change
@@ -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<SearchBox>();

public ListBox EmailList => this.Find("EmailList").AsListBox();

public IReadOnlyList<EmailListItem> EmailItems => EmailList.Items.Select(x => x.As<EmailListItem>()).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);
}
19 changes: 19 additions & 0 deletions src/Samples.UITest/InformationManager.Test/Views/EmailView.cs
Original file line number Diff line number Diff line change
@@ -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();
}
12 changes: 12 additions & 0 deletions src/Samples.UITest/InformationManager.Test/Views/ShellWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class ShellWindow(FrameworkAutomationElementBase element) : Window(elemen

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

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

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


Expand All @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,12 @@ public class Email : ValidatableModel, IValidatableObject
[DataMember] private EmailType emailType;
[DataMember] private string title = "";
[DataMember] private string from = "";
[DataMember] private IEnumerable<string> to;
[DataMember] private IEnumerable<string> cc;
[DataMember] private IEnumerable<string> bcc;
[DataMember] private IEnumerable<string> to = [];
[DataMember] private IEnumerable<string> cc = [];
[DataMember] private IEnumerable<string> bcc = [];
[DataMember] private DateTime sent;
[DataMember] private string? message;

public Email()
{
to = Array.Empty<string>();
cc = Array.Empty<string>();
bcc = Array.Empty<string>();
}

public EmailType EmailType
{
get => emailType;
Expand Down Expand Up @@ -105,7 +98,7 @@ public IEnumerable<ValidationResult> 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;
}
Expand All @@ -114,7 +107,7 @@ private static void ValidateEmail(ICollection<ValidationResult> 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]));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}">
<Grid>
<Grid.ColumnDefinitions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}">
<UserControl.Resources>
<s:EmailItemTemplateSelector x:Key="EmailItemTemplateSelector"/>
Expand All @@ -24,11 +24,11 @@
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<TextBlock Text="{Binding From, ValidatesOnNotifyDataErrors=False}" Margin="7"/>
<TextBlock Text="{Binding From, ValidatesOnNotifyDataErrors=False}" Margin="7" AutomationProperties.AutomationId="FromLabel"/>

<TextBlock Text="{Binding Sent, ValidatesOnNotifyDataErrors=False, StringFormat=d}" Grid.Column="1" Margin="7"/>
<TextBlock Text="{Binding Sent, ValidatesOnNotifyDataErrors=False, StringFormat=d}" Grid.Column="1" Margin="7" AutomationProperties.AutomationId="SentLabel"/>

<TextBlock Text="{Binding Title, ValidatesOnNotifyDataErrors=False}" Grid.Row="1" Grid.ColumnSpan="2" Margin="7,0,7,7"/>
<TextBlock Text="{Binding Title, ValidatesOnNotifyDataErrors=False}" Grid.Row="1" Grid.ColumnSpan="2" Margin="7,0,7,7" AutomationProperties.AutomationId="TitleLabel"/>
</Grid>
</DataTemplate>

Expand All @@ -44,11 +44,11 @@
</Grid.RowDefinitions>

<TextBlock Text="{Binding To, ValidatesOnNotifyDataErrors=False, Converter={x:Static c:StringCollectionToStringConverter.Default}}"
Margin="7" TextTrimming="CharacterEllipsis" />
Margin="7" TextTrimming="CharacterEllipsis" AutomationProperties.AutomationId="ToLabel"/>

<TextBlock Text="{Binding Sent, ValidatesOnNotifyDataErrors=False, StringFormat=d}" Grid.Column="1" Margin="7"/>
<TextBlock Text="{Binding Sent, ValidatesOnNotifyDataErrors=False, StringFormat=d}" Grid.Column="1" Margin="7" AutomationProperties.AutomationId="SentLabel"/>

<TextBlock Text="{Binding Title, ValidatesOnNotifyDataErrors=False}" Grid.Row="1" Grid.ColumnSpan="2" Margin="7,0,7,7"/>
<TextBlock Text="{Binding Title, ValidatesOnNotifyDataErrors=False}" Grid.Row="1" Grid.ColumnSpan="2" Margin="7,0,7,7" AutomationProperties.AutomationId="TitleLabel"/>
</Grid>
</DataTemplate>
</UserControl.Resources>
Expand All @@ -57,14 +57,14 @@
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<ctrl:SearchBox SearchText="{Binding FilterText}"/>
</Grid.RowDefinitions>

<ctrl:SearchBox SearchText="{Binding FilterText}" AutomationProperties.AutomationId="SearchBox"/>

<ListBox x:Name="emailsBox" ItemsSource="{Binding Emails}" SelectedItem="{Binding SelectedEmail}" Grid.Row="1" HorizontalContentAlignment="Stretch"
ItemTemplateSelector="{StaticResource EmailItemTemplateSelector}"
BorderThickness="0,1,0,0" BorderBrush="{x:Static SystemColors.ActiveBorderBrush}"
ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Disabled" AutomationProperties.AutomationId="EmailList">
<ListBox.InputBindings>
<KeyBinding Command="{Binding DeleteEmailCommand}" Key="Del"/>
</ListBox.InputBindings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<UserControl.Resources>
Expand Down Expand Up @@ -59,28 +59,28 @@
</Grid.Resources>

<Label Content="Title:" Grid.Row="0" Grid.Column="0" Margin="11,0,0,0"/>
<Label Content="{Binding Title}" FontWeight="SemiBold" Grid.Row="0" Grid.Column="1"/>
<Label Content="{Binding Title}" FontWeight="SemiBold" Grid.Row="0" Grid.Column="1" AutomationProperties.AutomationId="TitleLabel"/>

<Label Content="From:" Grid.Row="1" Grid.Column="0" Margin="11,0,0,0"/>
<Label Content="{Binding From}" Grid.Row="1" Grid.Column="1"/>
<Label Content="{Binding From}" Grid.Row="1" Grid.Column="1" AutomationProperties.AutomationId="FromLabel"/>

<Label Content="To:" Grid.Row="2" Grid.Column="0" Margin="11,0,0,0"/>
<Label Grid.Row="2" Grid.Column="1">
<TextBlock Text="{Binding To, Converter={x:Static c:StringCollectionToStringConverter.Default}}" TextTrimming="CharacterEllipsis" />
<Label Grid.Row="2" Grid.Column="1" AutomationProperties.AutomationId="ToLabel">
<TextBlock Text="{Binding To, Converter={x:Static c:StringCollectionToStringConverter.Default}}" TextTrimming="CharacterEllipsis"/>
</Label>

<Label Content="CC:" Grid.Row="3" Grid.Column="0" Margin="11,0,0,0"/>
<Label Grid.Row="3" Grid.Column="1">
<Label Grid.Row="3" Grid.Column="1" AutomationProperties.AutomationId="CCLabel">
<TextBlock Text="{Binding CC, Converter={x:Static c:StringCollectionToStringConverter.Default}}" TextTrimming="CharacterEllipsis"/>
</Label>

<Label Content="BCC:" Grid.Row="4" Grid.Column="0" Margin="11,0,0,0"/>
<Label Grid.Row="4" Grid.Column="1">
<Label Grid.Row="4" Grid.Column="1" AutomationProperties.AutomationId="BccLabel">
<TextBlock Text="{Binding Bcc, Converter={x:Static c:StringCollectionToStringConverter.Default}}" TextTrimming="CharacterEllipsis"/>
</Label>

<Label Content="Sent:" Grid.Row="5" Grid.Column="0" Margin="11,0,0,0"/>
<Label Content="{Binding Sent}" Grid.Row="5" Grid.Column="1"/>
<Label Content="{Binding Sent}" Grid.Row="5" Grid.Column="1" AutomationProperties.AutomationId="SentLabel"/>
</Grid>
</DataTemplate>
</ContentControl.ContentTemplate>
Expand Down

0 comments on commit 1b49b4c

Please sign in to comment.