-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
146 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
using DemoApp.Models; | ||
using DemoApp.Properties; | ||
using DemoApp.Views; | ||
|
||
namespace DemoApp.ViewModels; | ||
|
||
public partial class FlyoutMenuViewModel : BaseViewModel | ||
{ | ||
#region Properties | ||
|
||
[ObservableProperty] | ||
private List<FlyoutPageItem> menuPages = new List<FlyoutPageItem> | ||
{ | ||
new FlyoutPageItem | ||
{ | ||
Title = Resources.Contacts_Title, | ||
IconSource = "contacts.png", | ||
TargetType = typeof(ContactsPage), | ||
}, | ||
new FlyoutPageItem | ||
{ | ||
Title = Resources.Todo_Title, | ||
IconSource = "todo.png", | ||
TargetType = typeof(TodoPage), | ||
}, | ||
new FlyoutPageItem | ||
{ | ||
Title = Resources.Reminders_Title, | ||
IconSource = "reminders.png", | ||
TargetType = typeof(RemindersPage), | ||
}, | ||
new FlyoutPageItem | ||
{ | ||
Title = Resources.DemoTabs_Title, | ||
IconSource = "tabs.png", | ||
TargetType = typeof(DemoTabsPage), | ||
}, | ||
}; | ||
|
||
#endregion Properties | ||
|
||
#region Constructors | ||
|
||
public FlyoutMenuViewModel( | ||
INavigationService navigationService) | ||
: base(navigationService) | ||
{ | ||
} | ||
|
||
#endregion Constructors | ||
|
||
#region Commands | ||
|
||
/// <summary> | ||
/// Switch the flyout detail to the selected page. | ||
/// </summary> | ||
[RelayCommand] | ||
private void SwitchFlyoutDetailPage(FlyoutPageItem flyoutPageItem) | ||
{ | ||
if (flyoutPageItem != null) | ||
{ | ||
navigationService.SwitchFlyoutDetail(flyoutPageItem.TargetType); | ||
} | ||
} | ||
|
||
#endregion Commands | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,9 @@ | ||
using DemoApp.Models; | ||
|
||
namespace DemoApp.Views; | ||
namespace DemoApp.Views; | ||
|
||
public partial class FlyoutMenuPage : ContentPage | ||
{ | ||
private readonly INavigationService navigationService; | ||
|
||
public FlyoutMenuPage() | ||
{ | ||
navigationService = ServiceResolver.Resolve<INavigationService>(); | ||
|
||
InitializeComponent(); | ||
collectionView.SelectionChanged += OnSelectionChanged; | ||
} | ||
|
||
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e) | ||
{ | ||
var item = collectionView.SelectedItem as FlyoutPageItem; | ||
|
||
if (item != null) | ||
{ | ||
navigationService.SwitchFlyoutDetail(item.TargetType); | ||
collectionView.SelectedItem = null; | ||
} | ||
} | ||
} |
File renamed without changes.
48 changes: 48 additions & 0 deletions
48
tests/DemoApp.UnitTests/ViewModels/Flyouts/FlyoutMenuViewModelTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using DemoApp.Models; | ||
using DemoApp.ViewModels; | ||
using DemoApp.Views; | ||
|
||
namespace DemoApp.UnitTests.ViewModels; | ||
|
||
public class FlyoutMenuViewModelTests | ||
{ | ||
private readonly INavigationService mockNavigationService; | ||
|
||
public FlyoutMenuViewModelTests() | ||
{ | ||
mockNavigationService = Substitute.For<INavigationService>(); | ||
} | ||
|
||
public FlyoutMenuViewModel ViewModel => new FlyoutMenuViewModel( | ||
mockNavigationService); | ||
|
||
[Fact] | ||
public void Constructor_WhenInitialized_SetsMenuPageList() | ||
{ | ||
// Arrange | ||
// Act | ||
var viewModel = ViewModel; | ||
|
||
// Assert | ||
Assert.Equal(4, viewModel.MenuPages.Count); | ||
} | ||
|
||
[Fact] | ||
public void SwitchFlyoutDetailPageCommand_WhenCalled_SwitchesToSelectedDetailPage() | ||
{ | ||
// Arrange | ||
var viewModel = ViewModel; | ||
var selectedItem = new FlyoutPageItem | ||
{ | ||
Title = "MockItem", | ||
IconSource = "test.png", | ||
TargetType = typeof(TodoPage), | ||
}; | ||
|
||
// Act | ||
viewModel.SwitchFlyoutDetailPageCommand.Execute(selectedItem); | ||
|
||
// Assert | ||
mockNavigationService.Received().SwitchFlyoutDetail(typeof(TodoPage)); | ||
} | ||
} |