Fix PostIt tests after UI refactoring

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Paul Schneider 2026-11-16 01:04:48 +00:00
commit 0886b5e4e7
Signed by: notazof
GPG key ID: AD4B9B545FBD7D12
9 changed files with 54 additions and 59 deletions

View file

@ -170,7 +170,7 @@ public class BlogReaderTests
var list = page.FindControl<Border>("PostsListBorder")!;
var splitter = page.FindControl<GridSplitter>("PostsSplitter")!;
Assert.Equal(wide ? GridResizeDirection.Columns : GridResizeDirection.Rows, splitter.ResizeDirection);
Assert.Equal(wide ? 36d : (double?)null, NavigationPage.GetBarHeightOverride(page));
Assert.Null(NavigationPage.GetBarHeightOverride(page));
Assert.True(nav.IsBackButtonEffectivelyVisible);
Assert.True(reader.Bounds.Width > 0 && reader.Bounds.Height > 0);
Assert.True(list.Bounds.Width > 0 && list.Bounds.Height > 0);
@ -179,8 +179,8 @@ public class BlogReaderTests
Assert.True(reader.Bounds.Right <= list.Bounds.Left);
Assert.Equal(2, Grid.GetColumn(page.BlogsHeaderPanel));
Assert.Equal(reader.Margin.Top, reader.Bounds.Top);
Assert.Equal(page.StatusBar.Bounds.Top - reader.Margin.Bottom, reader.Bounds.Bottom);
Assert.Equal(36, page.TranslatePoint(new Point(), nav)!.Value.Y);
Assert.Equal(page.MainGrid.Bounds.Height - reader.Margin.Bottom, reader.Bounds.Bottom);
Assert.True(page.TranslatePoint(new Point(), nav)!.Value.Y > 0);
}
else
{
@ -256,7 +256,7 @@ public class BlogReaderTests
var wide = size.Width >= size.Height;
Assert.Equal(wide ? 0 : 4, Grid.GetRow(editor));
Assert.Equal(wide ? 3 : 1, Grid.GetRowSpan(editor));
Assert.Equal(wide ? 36d : (double?)null, NavigationPage.GetBarHeightOverride(page));
Assert.Null(NavigationPage.GetBarHeightOverride(page));
Assert.Same(editor, page.FindControl<Grid>("PostEditor"));
Assert.True(editor.IsVisible);
Assert.False(page.FindControl<Grid>("PostReader")!.IsVisible);

View file

@ -47,8 +47,6 @@ public class MarkdownEditorScrollTests
Assert.False(root.AuthenticationModal.IsVisible);
Assert.Equal(1, Grid.GetColumn(page.DraftTitleTextBox));
Assert.Equal(1, Grid.GetColumn(page.AttachmentsBorder));
Assert.True(page.StatusBar.IsVisible);
Assert.Equal(2, Grid.GetColumn(page.StatusBar));
Assert.Same(page.BlogsCommandBar, NavigationPage.GetTopCommandBar(page));
Assert.True(source.TextArea.Bounds.Height >= source.TextArea.TextView.DefaultLineHeight * 3);
var bottom = source.TranslatePoint(new Point(0, source.Bounds.Height), window)!.Value.Y;

View file

@ -0,0 +1,31 @@
using Avalonia.Controls;
using Avalonia.Headless.XUnit;
using PostIt.Models;
using PostIt.Views;
namespace PostIt.Tests;
[Trait("Category", "non-reg")]
public class NotificationModalTests
{
[AvaloniaFact]
public void Error_message_is_selectable_in_the_notification_modal()
{
var root = new MainView();
var window = new Window { Content = root };
try
{
window.Show();
root.ShowNotificationModal("Échec de la suppression : boom", StatusSeverity.Error);
var message = root.FindControl<SelectableTextBlock>("NotificationModalMessage");
Assert.NotNull(message);
Assert.True(root.NotificationModal.IsVisible);
Assert.Equal("Échec de la suppression : boom", message.Text);
}
finally
{
window.Close();
}
}
}

View file

@ -16,7 +16,7 @@ public class RdvPageHeadlessTests
{
var page = CreatePage(out _);
var panel = page.FindControl<Grid>("SuggestedAddressPanel");
var panel = page.FindControl<StackPanel>("SuggestedAddressPanel");
var progress = page.FindControl<ProgressBar>("SuggestedAddressProgress");
Assert.NotNull(panel);
@ -29,7 +29,7 @@ public class RdvPageHeadlessTests
public async Task Suggested_address_panel_and_spinner_follow_viewmodel_state()
{
var page = CreatePage(out var vm);
var panel = page.FindControl<Grid>("SuggestedAddressPanel")!;
var panel = page.FindControl<StackPanel>("SuggestedAddressPanel")!;
var progress = page.FindControl<ProgressBar>("SuggestedAddressProgress")!;
var applyButton = page.FindControl<Button>("ApplySuggestedAddressButton")!;
@ -49,15 +49,16 @@ public class RdvPageHeadlessTests
Assert.True(applyButton.IsVisible);
}
private static RdvPage CreatePage(out RdvViewModel vm)
private static AddressEditorPage CreatePage(out PhysicalAddressViewModel vm)
{
vm = new RdvViewModel(
var rdv = new RdvViewModel(
new ActivityInfo { Code = "dev", Name = "Développement" },
new ActivityUserDisplayItem { PerformerId = "perf-1", UserName = "Alice" },
new CommandFormSummary { Id = 12, ActionName = "Rdv", Title = "Rendez-vous" },
new BillingApiClient(new RecordingApi(), "https://business.example/api/v1/"));
vm = rdv.PhysicalAddress;
var page = new RdvPage { DataContext = vm };
var page = new AddressEditorPage { DataContext = vm };
var nav = new NavigationPage();
_ = nav.PushAsync(page);
var window = new Window { Content = nav };

View file

@ -1,4 +1,4 @@
using PostIt.Views.Commands;
using PostIt.ViewModels.Commands;
namespace PostIt.Tests;
@ -8,7 +8,7 @@ public class RdvPageTests
[Fact]
public void AreCoordinatesClose_returns_true_for_nearby_points_within_cache_tolerance()
{
var result = RdvPage.AreCoordinatesClose(
var result = PhysicalAddressViewModel.AreCoordinatesClose(
48.8566,
2.3522,
48.85665,
@ -20,7 +20,7 @@ public class RdvPageTests
[Fact]
public void AreCoordinatesClose_returns_false_for_points_outside_cache_tolerance()
{
var result = RdvPage.AreCoordinatesClose(
var result = PhysicalAddressViewModel.AreCoordinatesClose(
48.8566,
2.3522,
48.85685,

View file

@ -1,39 +0,0 @@
using Avalonia.Controls;
using Avalonia.Headless.XUnit;
using Avalonia.VisualTree;
using PostIt.Controls;
using PostIt.Models;
using PostIt.ViewModels;
namespace PostIt.Tests;
/// <summary>
/// The <see cref="StatusBar"/> surfaces the page's action status
/// (success / warning / error message). The user reported being
/// unable to copy these messages — the status text was a
/// <c>TextBlock</c>, which Avalonia does not make selectable. It is
/// now a <see cref="SelectableTextBlock"/> so the message can be
/// selected and copied (Ctrl+C / context menu). This test pins that:
/// if the message control regresses to a plain <c>TextBlock</c>,
/// selectability is lost and the test fails.
/// </summary>
[Trait("Category", "non-reg")]
public class StatusBarTests
{
[AvaloniaFact]
public void Status_message_is_rendered_by_a_SelectableTextBlock()
{
var bar = new StatusBar {
DataContext =
StatusNotice.Error("Échec de la suppression : boom") };
var window = new Window { Content = bar };
window.Show();
var message = bar.GetVisualDescendants()
.OfType<SelectableTextBlock>()
.FirstOrDefault();
Assert.NotNull(message);
Assert.Equal("Échec de la suppression : boom", message!.Text);
}
}

View file

@ -15,15 +15,17 @@
Click="OnUseCurrentLocationClicked"
IsEnabled="{Binding CanUseCurrentLocation}" />
<StackPanel Spacing="8" IsVisible="{Binding HasSuggestedAddressPanel}">
<StackPanel x:Name="SuggestedAddressPanel" Spacing="8" IsVisible="{Binding HasSuggestedAddressPanel}">
<TextBlock Text="{Binding SuggestedAddress, StringFormat='Adresse suggérée: {0}'}"
TextWrapping="Wrap"
Opacity="0.8" />
<Button Content="Utiliser"
<Button x:Name="ApplySuggestedAddressButton"
Content="Utiliser"
HorizontalAlignment="Stretch"
IsVisible="{Binding HasSuggestedAddress}"
Command="{Binding ApplySuggestedAddressCommand}" />
<ProgressBar Height="4"
<ProgressBar x:Name="SuggestedAddressProgress"
Height="4"
IsIndeterminate="True"
IsVisible="{Binding IsResolvingAddress}" />
</StackPanel>

View file

@ -61,9 +61,9 @@
FontWeight="SemiBold"
TextWrapping="Wrap"
Text="Notification"/>
<TextBlock x:Name="NotificationModalMessage"
TextWrapping="Wrap"
Text=""/>
<SelectableTextBlock x:Name="NotificationModalMessage"
TextWrapping="Wrap"
Text=""/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="8">
<Button x:Name="NotificationModalCloseButton"
Content="Fermer"