Skip to content

Commit

Permalink
UITest: BookLib: SearchBookListAndChangeEntriesTest
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed May 16, 2024
1 parent cd54b24 commit 60acd38
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
22 changes: 21 additions & 1 deletion src/Samples.UITest/BookLibrary.Test/Tests/BookLibraryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void AboutTest()
}

[Fact]
public void SearchBookListTest()
public void SearchBookListAndChangeEntriesTest()
{
Launch();
var window = GetShellWindow();
Expand All @@ -59,6 +59,26 @@ public void SearchBookListTest()

bookView.TitleTextBox.Text = "Test Title";
Assert.Equal("Test Title", bookRow2.TitleCell.Name);
bookView.AuthorTextBox.Text = "TAuthor";
Assert.Equal("TAuthor", bookRow2.AuthorCell.Name);
bookView.PublishDatePicker.SelectedDate = new DateTime(2024, 3, 2);
Assert.Equal("2/3/2024", bookRow2.PublishDateCell.Name);
Assert.Equal(["Undefined", "English", "German", "French", "Spanish", "Chinese", "Japanese"], bookView.LanguageComboBox.Items.Select(x => x.Name));
bookView.LanguageComboBox.Select(2);
bookView.LanguageComboBox.Click(); // To close the combo box popup
Assert.Equal("German", bookView.LanguageComboBox.SelectedItem.Text);

bookView.LendToButton.Click();
var lendToWindow = window.FirstModalWindow().As<LendToWindow>();
Assert.True(lendToWindow.WasReturnedRadioButton.IsChecked);
Assert.False(lendToWindow.LendToRadioButton.IsChecked);
Assert.False(lendToWindow.PersonListBox.IsEnabled);
lendToWindow.LendToRadioButton.Click();
Assert.True(lendToWindow.PersonListBox.IsEnabled);
Assert.Equal(["Ginny", "Hermione", "Harry", "Ron"], lendToWindow.PersonListBox.Items.Select(x => x.Text));
lendToWindow.PersonListBox.Items[2].Select();
lendToWindow.OkButton.Click();
AssertEqual("Harry Potter", bookRow2.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text);

window.Close();
var messageBox = window.FirstModalWindow().As<MessageBox>(); // MessageBox that asks user to save the changes
Expand Down
17 changes: 17 additions & 0 deletions src/Samples.UITest/BookLibrary.Test/Views/LendToWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using FlaUI.Core;
using FlaUI.Core.AutomationElements;

namespace UITest.BookLibrary.Views;

public class LendToWindow(FrameworkAutomationElementBase element) : Window(element)
{
public RadioButton WasReturnedRadioButton => this.Find("WasReturnedRadioButton").AsRadioButton();

public RadioButton LendToRadioButton => this.Find("LendToRadioButton").AsRadioButton();

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

public Button OkButton => this.Find("OkButton").AsButton();

public Button CancelButton => this.Find("CancelButton").AsButton();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@

<DockPanel Margin="11,7,11,11">
<Label Content="{Binding Book.Title, ValidatesOnNotifyDataErrors=False}" ContentStringFormat="{x:Static p:Resources.BookTitle}"
Padding="0" DockPanel.Dock="Top" Style="{StaticResource HeaderLabel}"/>
<RadioButton IsChecked="{Binding IsWasReturned}" Content="{x:Static p:Resources.WasReturnedCheck}" TabIndex="0" DockPanel.Dock="Top" Margin="0,11,0,0"/>
<RadioButton IsChecked="{Binding IsLendTo}" Content="{x:Static p:Resources.LendToCheck}" TabIndex="1" DockPanel.Dock="Top" Margin="0,7,0,0"/>
Padding="0" DockPanel.Dock="Top" Style="{StaticResource HeaderLabel}"/>
<RadioButton IsChecked="{Binding IsWasReturned}" Content="{x:Static p:Resources.WasReturnedCheck}" TabIndex="0" DockPanel.Dock="Top" Margin="0,11,0,0"
AutomationProperties.AutomationId="WasReturnedRadioButton"/>
<RadioButton IsChecked="{Binding IsLendTo}" Content="{x:Static p:Resources.LendToCheck}" TabIndex="1" DockPanel.Dock="Top" Margin="0,7,0,0"
AutomationProperties.AutomationId="LendToRadioButton"/>

<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" DockPanel.Dock="Bottom" Margin="0,11,0,0">
<Button Command="{Binding OkCommand}" Content="{x:Static p:Resources.Ok}" IsDefault="True" TabIndex="3"
Style="{StaticResource DialogButton}"/>
Style="{StaticResource DialogButton}" AutomationProperties.AutomationId="OkButton"/>
<Button Content="{x:Static p:Resources.Cancel}" IsCancel="True" TabIndex="4"
Style="{StaticResource DialogButton}" Margin="11,0,0,0"/>
Style="{StaticResource DialogButton}" Margin="11,0,0,0" AutomationProperties.AutomationId="CancelButton"/>
</StackPanel>

<ListView ItemsSource="{Binding Persons}" SelectedItem="{Binding SelectedPerson, ValidatesOnNotifyDataErrors=False}" IsEnabled="{Binding IsLendTo}"
MouseDoubleClick="PersonsListMouseDoubleClick" TabIndex="2" Margin="0,11,0,0">
MouseDoubleClick="PersonsListMouseDoubleClick" TabIndex="2" Margin="0,11,0,0" AutomationProperties.AutomationId="PersonListBox">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Firstname, ValidatesOnNotifyDataErrors=False}" Header="{x:Static p:Resources.Firstname}" Width="125"/>
Expand Down

0 comments on commit 60acd38

Please sign in to comment.