Skip to content

Commit

Permalink
UITest/BookLib: adapt order of items
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed Nov 30, 2024
1 parent b656a2c commit 118ad80
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
8 changes: 4 additions & 4 deletions src/Samples.UITest/BookLibrary.Test/Tests/AddressBookTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void AddAndRemoveEntriesTest() => Run(() =>
personListView.AddButton.Click();
Assert.Equal(5, personListView.PersonDataGrid.RowCount);
var newRow = personListView.PersonDataGrid.SelectedItem.As<PersonGridRow>();
Assert.Equal(personListView.PersonDataGrid.Rows[0], newRow);
Assert.Equal(personListView.PersonDataGrid.Rows[^1].As<PersonGridRow>().ToTuple(), newRow.ToTuple());

// ItemStatus contains the validation error message or string.Empty if no error exists
AssertEqual("", personView.FirstnameTextBox.Text, newRow.FirstnameCell.Label.Text);
Expand All @@ -77,9 +77,9 @@ public void AddAndRemoveEntriesTest() => Run(() =>
Assert.Equal("ALastname", personView.LastnameTextBox.Text);
AssertEqual("", personView.LastnameTextBox.ItemStatus, newRow.LastnameCell.Label.ItemStatus);

var lastRow = personListView.PersonDataGrid.GetRowByIndex(personListView.PersonDataGrid.RowCount - 1).As<PersonGridRow>();
Assert.False(lastRow.IsOffscreen);
Assert.StartsWith("Ron", lastRow.FirstnameCell.Name);
var secondLastRow = personListView.PersonDataGrid.GetRowByIndex(personListView.PersonDataGrid.RowCount - 2).As<PersonGridRow>();
Assert.False(secondLastRow.IsOffscreen);
Assert.StartsWith("Ron", secondLastRow.FirstnameCell.Name);

var lastNotRemovedRow = personListView.PersonDataGrid.GetRowByIndex(personListView.PersonDataGrid.RowCount - 3);
personListView.PersonDataGrid.Select(personListView.PersonDataGrid.RowCount - 2);
Expand Down
47 changes: 23 additions & 24 deletions src/Samples.UITest/BookLibrary.Test/Tests/BookLibraryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,32 @@ public void SearchBookListAndChangeEntriesTest() => Run(() =>
var firstBook = bookListView.BookDataGrid.GetRowByIndex(0).As<BookGridRow>();
var lastBook = bookListView.BookDataGrid.GetRowByIndex(rowCount - 1).As<BookGridRow>();
// GetRowByIndex scrolls to the item -> let's scroll back to the first book
Assert.True(firstBook.IsOffscreen);
firstBook.ScrollIntoView();
Assert.False(firstBook.IsOffscreen);

bookListView.SearchBox.Text = "Ha";
Assert.Equal(13, bookListView.BookDataGrid.RowCount);
bookListView.SearchBox.Text = "Harr";
Assert.Equal(7, bookListView.BookDataGrid.RowCount);
var bookRow2 = bookListView.BookDataGrid.GetRowByIndex(1).As<BookGridRow>();
bookRow2.Select();
var bookRow1 = bookListView.BookDataGrid.GetRowByIndex(0).As<BookGridRow>();
bookRow1.Select();

AssertEqual("Harry Potter and the Deathly Hallows", bookRow2.TitleCell.Name, bookView.TitleTextBox.Text);
AssertEqual("J.K. Rowling", bookRow2.AuthorCell.Name, bookView.AuthorTextBox.Text);
AssertEqual("Harry Potter and the Deathly Hallows", bookRow1.TitleCell.Name, bookView.TitleTextBox.Text);
AssertEqual("J.K. Rowling", bookRow1.AuthorCell.Name, bookView.AuthorTextBox.Text);
Assert.Equal("Bloomsbury", bookView.PublisherTextBox.Text);
Assert.Equal("1/1/2007", bookRow2.PublishDateCell.Name);
Assert.Equal("1/1/2007", bookRow1.PublishDateCell.Name);
Assert.Equal(new DateTime(2007, 1, 1), bookView.PublishDatePicker.SelectedDate);
Assert.Equal("9780747591054", bookView.IsbnTextBox.Text);
Assert.Equal("English", bookView.LanguageComboBox.SelectedItem.Text);
Assert.Equal("607", bookView.PagesTextBox.Text);
AssertEqual("Ginny Weasley", bookRow2.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text);
AssertEqual("Ginny Weasley", bookRow1.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text);

bookRow2.TitleCell.Text = "Test Title";
bookRow1.TitleCell.Text = "Test Title";
Assert.Equal("Test Title", bookView.TitleTextBox.Text);
bookView.AuthorTextBox.Text = "TAuthor";
Assert.Equal("TAuthor", bookRow2.AuthorCell.Name);
Assert.Equal("TAuthor", bookRow1.AuthorCell.Name);
bookView.PublishDatePicker.SelectedDate = new DateTime(2024, 3, 2);
Assert.Equal("3/2/2024", bookRow2.PublishDateCell.Name);
Assert.Equal("3/2/2024", bookRow1.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
Expand All @@ -67,9 +66,9 @@ public void SearchBookListAndChangeEntriesTest() => Run(() =>
lendToWindow.WasReturnedRadioButton.Click();
Assert.False(lendToWindow.PersonListBox.IsEnabled);
lendToWindow.OkButton.Click();
AssertEqual("", bookRow2.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text);
AssertEqual("", bookRow1.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text);

bookRow2.LendToCell.LendToButton.Click();
bookRow1.LendToCell.LendToButton.Click();
lendToWindow = window.FirstModalWindow().As<LendToWindow>();
Assert.True(lendToWindow.WasReturnedRadioButton.IsChecked);
Assert.False(lendToWindow.LendToRadioButton.IsChecked);
Expand All @@ -80,7 +79,7 @@ public void SearchBookListAndChangeEntriesTest() => Run(() =>
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);
AssertEqual("Harry Potter", bookRow1.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text);

window.Close();
var messageBox = window.FirstModalWindow().As<MessageBox>(); // MessageBox that asks user to save the changes
Expand All @@ -99,7 +98,7 @@ public void AddAndRemoveEntriesTest() => Run(() =>
bookListView.AddButton.Click();
Assert.Equal(42, bookListView.BookDataGrid.RowCount);
var newRow = bookListView.BookDataGrid.SelectedItem.As<BookGridRow>();
Assert.Equal(bookListView.BookDataGrid.Rows[0], newRow);
Assert.Equal(bookListView.BookDataGrid.Rows[^1], newRow);

// ItemStatus contains the validation error message or string.Empty if no error exists
AssertEqual("", bookView.TitleTextBox.Text, newRow.TitleCell.Label.Text);
Expand All @@ -115,9 +114,9 @@ public void AddAndRemoveEntriesTest() => Run(() =>
Assert.Equal("TAuthor", bookView.AuthorTextBox.Text);
AssertEqual("", bookView.AuthorTextBox.ItemStatus, newRow.AuthorCell.Label.ItemStatus);

var lastRow = bookListView.BookDataGrid.GetRowByIndex(bookListView.BookDataGrid.RowCount - 1).As<BookGridRow>();
Assert.False(lastRow.IsOffscreen);
Assert.StartsWith("WPF", lastRow.TitleCell.Name);
var secondLastRow = bookListView.BookDataGrid.GetRowByIndex(bookListView.BookDataGrid.RowCount - 2).As<BookGridRow>();
Assert.False(secondLastRow.IsOffscreen);
Assert.StartsWith("WPF", secondLastRow.TitleCell.Name);

var lastNotRemovedRow = bookListView.BookDataGrid.GetRowByIndex(bookListView.BookDataGrid.RowCount - 3);
bookListView.BookDataGrid.Select(bookListView.BookDataGrid.RowCount - 2);
Expand Down Expand Up @@ -199,10 +198,10 @@ public void RemoveLendToPersonTest() => Run(() =>
var bookView = window.TabControl.BookLibraryTabItem.BookView;

bookListView.SearchBox.Text = "Harr";
var bookRow2 = bookListView.BookDataGrid.GetRowByIndex(1).As<BookGridRow>();
bookRow2.Select();
var bookRow1 = bookListView.BookDataGrid.GetRowByIndex(0).As<BookGridRow>();
bookRow1.Select();

AssertEqual("Ginny Weasley", bookRow2.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text);
AssertEqual("Ginny Weasley", bookRow1.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text);

window.TabControl.AddressBookTabItem.Select();
var personListView = window.TabControl.AddressBookTabItem.PersonListView;
Expand All @@ -212,7 +211,7 @@ public void RemoveLendToPersonTest() => Run(() =>
personListView.RemoveButton.Click();

window.TabControl.BookLibraryTabItem.Select();
AssertEqual("", bookRow2.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text);
AssertEqual("", bookRow1.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text);

window.DataMenu.Click();
window.DataMenu.SaveMenuItem.Click();
Expand All @@ -225,11 +224,11 @@ public void RemoveLendToPersonTest() => Run(() =>
bookView = window.TabControl.BookLibraryTabItem.BookView;

bookListView.SearchBox.Text = "Harr";
bookRow2 = bookListView.BookDataGrid.GetRowByIndex(1).As<BookGridRow>();
bookRow2.Select();
bookRow1 = bookListView.BookDataGrid.GetRowByIndex(1).As<BookGridRow>();
bookRow1.Select();

window.TabControl.BookLibraryTabItem.Select();
AssertEqual("", bookRow2.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text);
AssertEqual("", bookRow1.LendToCell.LendToLabel.Name, bookView.LendToTextBox.Text);

window.Close();
});
Expand Down
2 changes: 2 additions & 0 deletions src/Samples.UITest/BookLibrary.Test/Views/PersonListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public class PersonGridRow(FrameworkAutomationElementBase element) : GridRow(ele
public TextGridCell LastnameCell => Cells[1].As<TextGridCell>();

public HyperlinkGridCell EmailCell => Cells[2].As<HyperlinkGridCell>();

public (string firstname, string lastname, string email) ToTuple() => (FirstnameCell.Text, LastnameCell.Text, EmailCell.Name);
}

0 comments on commit 118ad80

Please sign in to comment.