feat/files-control #52

Open
notazof wants to merge 32 commits from feat/files-control into main
5 changed files with 45 additions and 26 deletions
Showing only changes of commit ddff760c41 - Show all commits

fixes the tests
Some checks failed
Dotnet build and test / build (pull_request) Failing after 8m6s

Paul Schneider 2026-09-11 18:37:14 +01:00
Signed by: notazof
GPG key ID: 1DD5D838E5343B06

View file

@ -9,6 +9,7 @@ using PostIt.Services;
using PostIt.ViewModels; using PostIt.ViewModels;
using PostIt.Views; using PostIt.Views;
using PostIt.Views.Blogs; using PostIt.Views.Blogs;
using PostIt.Helpers;
namespace PostIt.Tests; namespace PostIt.Tests;
@ -117,7 +118,10 @@ public class MainPageButtonsTests
var app = (PostIt.App)Application.Current!; var app = (PostIt.App)Application.Current!;
app.AttachMainWindow(window); app.AttachMainWindow(window);
window.NavRoot.PushAsync(page).GetAwaiter().GetResult(); window.NavRoot.PushAsync(page).GetAwaiter().GetResult();
var mainWindow = new Window { Content = window };
mainWindow.Show();
return (window, page); return (window, page);
} }
@ -147,7 +151,7 @@ public class MainPageButtonsTests
} }
[AvaloniaFact] [AvaloniaFact]
public void Acl_button_click_pushes_a_page_onto_nav_stack() public async Task Acl_button_click_pushes_a_page_onto_nav_stack()
{ {
// Arrange: a VM whose SelectedPost is non-null so // Arrange: a VM whose SelectedPost is non-null so
// CanManageAcl evaluates to true and the button is // CanManageAcl evaluates to true and the button is
@ -180,7 +184,7 @@ public class MainPageButtonsTests
} }
[AvaloniaFact] [AvaloniaFact]
public void Circles_button_click_pushes_a_page_onto_nav_stack() public async Task Circles_button_click_pushes_a_page_onto_nav_stack()
{ {
// Arrange: OpenCircles has no CanExecute guard today — // Arrange: OpenCircles has no CanExecute guard today —
// any click should fire it and push the page. // any click should fire it and push the page.

View file

@ -64,9 +64,7 @@ public class MainPageSaveTests
const string typed = "Mon premier billet"; const string typed = "Mon premier billet";
titleBox.Text = typed; titleBox.Text = typed;
var saveButton = window.GetVisualDescendants() var saveButton = page.SaveButton;
.OfType<Button>()
.Single(b => b.Content as string == "Save");
saveButton.Command!.Execute(null); saveButton.Command!.Execute(null);
// The Save command is async (RelayCommand over Task) but // The Save command is async (RelayCommand over Task) but

View file

@ -46,35 +46,48 @@ public partial class App : Application
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{ {
var window = ServiceProvider.GetRequiredService<MainWindow>(); InitializeClassicDesktopLifetime(settings, desktop);
desktop.MainWindow = window;
View = window.MainView;
this.ConfigureRootView(window.MainView);
ApplyDarkMode(settings);
} }
else if (ApplicationLifetime is IActivityApplicationLifetime singleViewFactoryApplicationLifetime) else if (ApplicationLifetime is IActivityApplicationLifetime singleViewFactoryApplicationLifetime)
{ {
singleViewFactoryApplicationLifetime.MainViewFactory = InitializeActivityLifetime(settings, singleViewFactoryApplicationLifetime);
() =>
{
View = ServiceProvider.GetRequiredService<MainView>();
this.ConfigureRootView(View);
ApplyDarkMode(settings);
return View;
};
} }
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform) else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
{ {
singleViewPlatform.MainView = View = ServiceProvider.GetRequiredService<MainView>(); InitializeSingleViewLifetime(settings, singleViewPlatform);
ConfigureRootView(View);
ApplyDarkMode(settings);
} }
base.OnFrameworkInitializationCompleted(); base.OnFrameworkInitializationCompleted();
} }
private void ConfigureRootView(MainView rootView) public void InitializeSingleViewLifetime(Settings settings, ISingleViewApplicationLifetime singleViewPlatform)
{
singleViewPlatform.MainView = View = ServiceProvider!.GetRequiredService<MainView>();
ConfigureRootView(View);
ApplyDarkMode(settings);
}
public void InitializeActivityLifetime(Settings settings, IActivityApplicationLifetime singleViewFactoryApplicationLifetime)
{
singleViewFactoryApplicationLifetime.MainViewFactory =
() =>
{
this.ConfigureRootView(ServiceProvider!.GetRequiredService<MainView>());
ApplyDarkMode(settings);
return View!;
};
}
public void InitializeClassicDesktopLifetime(Settings settings, IClassicDesktopStyleApplicationLifetime desktop)
{
var window = ServiceProvider!.GetRequiredService<MainWindow>();
desktop.MainWindow = window;
this.ConfigureRootView(window.MainView);
ApplyDarkMode(settings);
}
public void ConfigureRootView(MainView rootView)
{ {
// Déclencher le Boot une seule fois lors du chargement du contrôle à l'écran. // Déclencher le Boot une seule fois lors du chargement du contrôle à l'écran.
rootView.AttachedToVisualTree += async (_, _) => await BootOnceAsync(); rootView.AttachedToVisualTree += async (_, _) => await BootOnceAsync();
@ -87,6 +100,7 @@ private void ConfigureRootView(MainView rootView)
}; };
rootView.SessionBanner.DataContext = sessionStatus; rootView.SessionBanner.DataContext = sessionStatus;
this.View = rootView;
} }
private async Task BootOnceAsync() private async Task BootOnceAsync()

View file

@ -8,7 +8,7 @@ namespace PostIt.Helpers;
public static class ViewModelBaseHelpers public static class ViewModelBaseHelpers
{ {
public static async Task PushPageAsync(this App app, ViewModelBase vm) public static async Task<Page> PushPageAsync(this App app, ViewModelBase vm)
{ {
var window = app.View; var window = app.View;
if (window is null) if (window is null)
@ -43,9 +43,11 @@ public static class ViewModelBaseHelpers
var stack = window.NavRoot.NavigationStack; var stack = window.NavRoot.NavigationStack;
if (stack.Count > 0 && ReferenceEquals(stack[stack.Count - 1], page)) if (stack.Count > 0 && ReferenceEquals(stack[stack.Count - 1], page))
{ {
return; return page;
} }
await window.NavRoot.PushAsync(page); await window.NavRoot.PushAsync(page);
return page;
} }
} }

View file

@ -31,8 +31,9 @@ public class HomePageViewModel : ViewModelBase
OpenActivities = new AsyncRelayCommand(OpenActivitiesAsync); OpenActivities = new AsyncRelayCommand(OpenActivitiesAsync);
OpenProviderRequests = new AsyncRelayCommand(OpenProviderRequestsAsync); OpenProviderRequests = new AsyncRelayCommand(OpenProviderRequestsAsync);
OpenBlogs = new AsyncRelayCommand(App.PushBlogsPageAsync);
} }
public IAsyncRelayCommand OpenBlogs { get; } = new AsyncRelayCommand(App.PushBlogsPageAsync); public IAsyncRelayCommand OpenBlogs { get; }
public IAsyncRelayCommand OpenActivities { get; } public IAsyncRelayCommand OpenActivities { get; }
public IAsyncRelayCommand OpenProviderRequests { get; } public IAsyncRelayCommand OpenProviderRequests { get; }