Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Book lib show first UI #59

Merged
merged 2 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void SelectionTest()
entityService.Books.Add(new() { Title = "The Two Towers" });
var bookController = Get<BookController>();
bookController.Initialize();
bookController.Run();

// Check that Initialize shows the BookListView and BookView
var shellService = Get<ShellService>();
Expand Down Expand Up @@ -60,6 +61,7 @@ public void AddAndRemoveTest()
entityService.Books.Add(twoTowers);
var bookController = Get<BookController>();
bookController.Initialize();
bookController.Run();
var bookListView = Get<MockBookListView>();
var bookListViewModel = bookListView.ViewModel;
var bookView = Get<MockBookView>();
Expand Down Expand Up @@ -107,6 +109,7 @@ public void AddAndRemoveDisableTest()
entityService.Books.Add(fellowship);
var bookController = Get<BookController>();
bookController.Initialize();
bookController.Run();
var bookListViewModel = Get<BookListViewModel>();
bookListViewModel.AddSelectedBook(bookListViewModel.Books!.Single());
var bookViewModel = Get<BookViewModel>();
Expand Down Expand Up @@ -140,6 +143,7 @@ public void RemoveAndSelection1Test()
entityService.Books.Add(returnKing);
var bookController = Get<BookController>();
bookController.Initialize();
bookController.Run();
var bookListView = Get<MockBookListView>();
var bookListViewModel = bookListView.ViewModel;
// Set the sorting to: "The Fell...", "The Retu...", "The Two..."
Expand All @@ -165,6 +169,7 @@ public void RemoveAndSelection2Test()
entityService.Books.Add(returnKing);
var bookController = Get<BookController>();
bookController.Initialize();
bookController.Run();
var bookListView = Get<MockBookListView>();
var bookListViewModel = bookListView.ViewModel;
// Set the sorting to: "The Fell...", "The Retu...", "The Two..."
Expand All @@ -190,6 +195,7 @@ public void RemoveAndSelection3Test()
entityService.Books.Add(returnKing);
var bookController = Get<BookController>();
bookController.Initialize();
bookController.Run();
var bookListView = Get<MockBookListView>();
var bookListViewModel = bookListView.ViewModel;

Expand Down Expand Up @@ -219,6 +225,7 @@ public void LendToTest()
shellService.ShellView = Get<IShellView>();
var bookController = Get<BookController>();
bookController.Initialize();
bookController.Run();
var bookListView = Get<MockBookListView>();
var bookListViewModel = bookListView.ViewModel;
var bookView = Get<MockBookView>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void SelectionTest()
entityService.Persons.Add(new() { Firstname = "Ron" });
var personController = Get<PersonController>();
personController.Initialize();
personController.Run();

// Check that Initialize shows the PersonListView and PersonView
var shellService = Get<ShellService>();
Expand Down Expand Up @@ -57,6 +58,7 @@ public void AddAndRemoveTest()
entityService.Persons.Add(ron);
var personController = Get<PersonController>();
personController.Initialize();
personController.Run();
var personListView = Get<MockPersonListView>();
var personListViewModel = personListView.ViewModel;
var personView = Get<MockPersonView>();
Expand Down Expand Up @@ -106,6 +108,7 @@ public void CreateNewEmailTest()
entityService.Persons.Add(ron);
var personController = Get<PersonController>();
personController.Initialize();
personController.Run();
var personListView = Get<MockPersonListView>();
var personListViewModel = personListView.ViewModel;
var personView = Get<MockPersonView>();
Expand Down Expand Up @@ -147,6 +150,7 @@ public void AddAndRemoveDisableTest()
entityService.Persons.Add(harry);
var personController = Get<PersonController>();
personController.Initialize();
personController.Run();
var personListViewModel = Get<PersonListViewModel>();
personListViewModel.AddSelectedPerson(personListViewModel.Persons!.Single());
var personViewModel = Get<PersonViewModel>();
Expand Down Expand Up @@ -180,6 +184,7 @@ public void RemoveAndSelection1Test()
entityService.Persons.Add(ginny);
var personController = Get<PersonController>();
personController.Initialize();
personController.Run();
var personListView = Get<MockPersonListView>();
var personListViewModel = personListView.ViewModel;
// Set the sorting to: "Ginny", "Harry", "Ron"
Expand All @@ -205,6 +210,7 @@ public void RemoveAndSelection2Test()
entityService.Persons.Add(ginny);
var personController = Get<PersonController>();
personController.Initialize();
personController.Run();
var personListView = Get<MockPersonListView>();
var personListViewModel = personListView.ViewModel;
// Set the sorting to: "Ginny", "Harry", "Ron"
Expand All @@ -230,6 +236,7 @@ public void RemoveAndSelection3Test()
entityService.Persons.Add(ginny);
var personController = Get<PersonController>();
personController.Initialize();
personController.Run();
var personListView = Get<MockPersonListView>();
var personListViewModel = personListView.ViewModel;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public BookController(IMessageService messageService, IShellService shellService

internal ObservableListViewCore<BookDataModel>? BooksView { get; private set; }

public async void Initialize()
public void Initialize()
{
bookViewModel.LendToCommand = lendToCommand;
bookViewModel.PropertyChanged += BookViewModelPropertyChanged;
Expand All @@ -55,7 +55,10 @@ public async void Initialize()

shellService.BookListView = bookListViewModel.View;
shellService.BookView = bookViewModel.View;
}

public async void Run()
{
try
{
await entityService.LoadBooks();
Expand All @@ -65,7 +68,7 @@ public async void Initialize()
Log.Default.Error(ex, "LoadBooks");
messageService.ShowError(shellService.ShellView, Resources.LoadErrorBooks);
}
bookListViewModel.SelectedBook = bookListViewModel.Books.FirstOrDefault();
bookListViewModel.SelectedBook = bookListViewModel.Books?.FirstOrDefault();
}

private bool CanAddNewBook() => bookListViewModel.IsValid && bookViewModel.IsValid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ public void Initialize()
personController.Initialize();
}

public void Run() => ShellViewModel.Show();
public void Run()
{
ShellViewModel.Show();
bookController.Run();
personController.Run();
}

public void Shutdown() => entityController.Shutdown();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public PersonController(IMessageService messageService, IShellService shellServi

internal ObservableListViewCore<Person>? PersonsView { get; private set; }

public async void Initialize()
public void Initialize()
{
personViewModel.CreateNewEmailCommand = createNewEmailCommand;
personViewModel.PropertyChanged += PersonViewModelPropertyChanged;
Expand All @@ -53,7 +53,10 @@ public async void Initialize()

shellService.PersonListView = personListViewModel.View;
shellService.PersonView = personViewModel.View;
}

public async void Run()
{
try
{
await entityService.LoadPersons();
Expand All @@ -63,7 +66,7 @@ public async void Initialize()
Log.Default.Error(ex, "LoadPersons");
messageService.ShowError(shellService.ShellView, Resources.LoadErrorPersons);
}
personListViewModel.SelectedPerson = personListViewModel.Persons.FirstOrDefault();
personListViewModel.SelectedPerson = personListViewModel.Persons?.FirstOrDefault();
}

private bool CanAddPerson() => personListViewModel.IsValid && personViewModel.IsValid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
[assembly: SuppressMessage("Performance", "CA1826:Do not use Enumerable methods on indexable collections", Justification = "<Pending>", Scope = "member", Target = "~M:Waf.BookLibrary.Library.Applications.Controllers.PersonController.RemovePerson")]
[assembly: SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "<Pending>", Scope = "member", Target = "~M:Waf.BookLibrary.Library.Applications.ViewModels.ShellViewModel.#ctor(Waf.BookLibrary.Library.Applications.Views.IShellView,System.Waf.Applications.Services.IMessageService,Waf.BookLibrary.Library.Applications.Services.IShellService,System.Waf.Applications.Services.ISettingsService)")]
[assembly: SuppressMessage("Globalization", "CA1305:Specify IFormatProvider", Justification = "<Pending>", Scope = "member", Target = "~M:Waf.BookLibrary.Library.Applications.Controllers.EntityController.Save~System.Threading.Tasks.Task")]
[assembly: SuppressMessage("Performance", "CA1826:Do not use Enumerable methods on indexable collections", Justification = "<Pending>", Scope = "member", Target = "~M:Waf.BookLibrary.Library.Applications.Controllers.PersonController.Run")]
[assembly: SuppressMessage("Performance", "CA1826:Do not use Enumerable methods on indexable collections", Justification = "<Pending>", Scope = "member", Target = "~M:Waf.BookLibrary.Library.Applications.Controllers.BookController.Run")]