Post Files
This commit is contained in:
parent
d8c0678462
commit
41d8fad8c3
21 changed files with 659 additions and 34 deletions
|
|
@ -162,6 +162,12 @@ public class ActivitiesPageViewModelTests
|
|||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<T> CallAsync<T>(HttpMethod method, string path, Func<HttpContent> contentFactory, CancellationToken ct = default)
|
||||
=> CallAsync<T>(method, path, (object?)null, ct);
|
||||
|
||||
public Task CallAsync(HttpMethod method, string path, Func<HttpContent> contentFactory, CancellationToken ct = default)
|
||||
=> CallAsync(method, path, (object?)null, ct);
|
||||
|
||||
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -352,6 +352,12 @@ public class BillingCommandPageViewModelTests
|
|||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<T> CallAsync<T>(HttpMethod method, string path, Func<HttpContent> contentFactory, CancellationToken ct = default)
|
||||
=> CallAsync<T>(method, path, (object?)null, ct);
|
||||
|
||||
public Task CallAsync(HttpMethod method, string path, Func<HttpContent> contentFactory, CancellationToken ct = default)
|
||||
=> CallAsync(method, path, (object?)null, ct);
|
||||
|
||||
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,6 +129,12 @@ public class BillingQueriesPageViewModelTests
|
|||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<T> CallAsync<T>(HttpMethod method, string path, Func<HttpContent> contentFactory, CancellationToken ct = default)
|
||||
=> CallAsync<T>(method, path, (object?)null, ct);
|
||||
|
||||
public Task CallAsync(HttpMethod method, string path, Func<HttpContent> contentFactory, CancellationToken ct = default)
|
||||
=> CallAsync(method, path, (object?)null, ct);
|
||||
|
||||
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using Yavsc.Blogspot;
|
|||
using PostIt.Services;
|
||||
using PostIt.ViewModels;
|
||||
using PostIt.Views;
|
||||
using PostIt.Views.Blogs;
|
||||
|
||||
namespace PostIt.Tests;
|
||||
|
||||
|
|
@ -72,13 +73,13 @@ public class MainPageButtonsTests
|
|||
{ }
|
||||
}
|
||||
|
||||
private static MainViewModel MakeViewModel(BlogPostDto? selectedPost = null)
|
||||
private static BlogsViewModel MakeViewModel(BlogPostDto? selectedPost = null)
|
||||
{
|
||||
var api = new ThrowingApi();
|
||||
var blog = new BlogApiClient(api, "http://localhost/");
|
||||
var circle = new CircleApiClient(api, "http://localhost/");
|
||||
var acl = new BlogAclApiClient(api, "http://localhost/");
|
||||
// Minimal DI graph: only what MainPageViewModel resolves
|
||||
// Minimal DI graph: only what BlogsViewModel resolves
|
||||
// when the user clicks a navigation button. Today that's
|
||||
// SignaturePageViewModel / CirclesPageViewModel / ACL
|
||||
// dependencies. The graph intentionally stays local to this
|
||||
|
|
@ -93,7 +94,7 @@ public class MainPageButtonsTests
|
|||
services.AddTransient<SignaturePage>();
|
||||
services.AddTransient<CirclesPage>();
|
||||
services.AddTransient<PostAclDialog>();
|
||||
var vm = new MainViewModel(blog, services: services.BuildServiceProvider());
|
||||
var vm = new BlogsViewModel(blog, services: services.BuildServiceProvider());
|
||||
if (selectedPost is not null) vm.SelectedPost = selectedPost;
|
||||
return vm;
|
||||
}
|
||||
|
|
@ -101,7 +102,7 @@ public class MainPageButtonsTests
|
|||
/// <summary>
|
||||
/// Mount a real <see cref="MainView"/> (as
|
||||
/// <c>SessionStatusBannerTests</c> does), push a
|
||||
/// <see cref="MainPage"/> with the given VM onto
|
||||
/// <see cref="BlogsPage"/> with the given VM onto
|
||||
/// <c>NavRoot</c>. <c>PushAsync</c> is awaited (via
|
||||
/// <c>GetAwaiter().GetResult()</c>) so the page is on the
|
||||
/// nav stack before the test tries to interact with its
|
||||
|
|
@ -109,10 +110,10 @@ public class MainPageButtonsTests
|
|||
/// realised and <c>KeyPressQwerty</c> has a real
|
||||
/// <see cref="TopLevel"/> to dispatch against.
|
||||
/// </summary>
|
||||
private static (MainView window, MainPage page) MountMainPage(MainViewModel vm)
|
||||
private static (MainView window, BlogsPage page) MountMainPage(BlogsViewModel vm)
|
||||
{
|
||||
var window = new MainView();
|
||||
var page = new MainPage { DataContext = vm };
|
||||
var page = new BlogsPage { DataContext = vm };
|
||||
var app = (PostIt.App)Application.Current!;
|
||||
app.AttachMainWindow(window);
|
||||
window.NavRoot.PushAsync(page).GetAwaiter().GetResult();
|
||||
|
|
@ -203,7 +204,7 @@ public class MainPageButtonsTests
|
|||
public void Signature_dev_button_click_pushes_a_page_onto_nav_stack()
|
||||
{
|
||||
// Arrange: the "[DEV] Signature" button is bound to the
|
||||
// MainPageViewModel.OpenSignatureDevCommand [RelayCommand].
|
||||
// BlogsViewModel.OpenSignatureDevCommand [RelayCommand].
|
||||
// The click must push SignaturePage on top of NavRoot.
|
||||
// The ServiceCollection registered in MakeViewModel provides
|
||||
// SignaturePageViewModel so the command can resolve it via
|
||||
|
|
|
|||
|
|
@ -5,10 +5,11 @@ using Yavsc.Blogspot;
|
|||
using Yavsc.Api.Client;
|
||||
using PostIt.ViewModels;
|
||||
using PostIt.Views;
|
||||
using PostIt.Views.Blogs;
|
||||
namespace PostIt.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Headless UI tests for the "Save" flow in <see cref="MainPage"/>.
|
||||
/// Headless UI tests for the "Save" flow in <see cref="BlogsPage"/>.
|
||||
/// The pattern is the one <c>SessionStatusBannerTests</c>
|
||||
/// established: <c>[AvaloniaFact]</c>, a <see cref="Window"/>
|
||||
/// hosting the page (via a <see cref="Frame"/> because
|
||||
|
|
@ -40,9 +41,9 @@ public class MainPageSaveTests
|
|||
var recorder = new CallRecorder();
|
||||
var api = new RecordingYavscApiClient(recorder);
|
||||
var blog = new BlogApiClient(api, "http://localhost/");
|
||||
var viewModel = new MainViewModel(blog);
|
||||
var viewModel = new BlogsViewModel(blog);
|
||||
|
||||
var page = new MainPage { DataContext = viewModel };
|
||||
var page = new BlogsPage { DataContext = viewModel };
|
||||
// MainPage is a ContentPage (a Page, not a Control), so it
|
||||
// must be hosted in a navigation surface. The production
|
||||
// MainWindow.axaml uses NavigationPage, and the API is the
|
||||
|
|
|
|||
|
|
@ -270,6 +270,12 @@ public class PostAclDialogTests
|
|||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<T> CallAsync<T>(HttpMethod method, string path, Func<HttpContent> contentFactory, CancellationToken ct = default)
|
||||
=> CallAsync<T>(method, path, (object?)null, ct);
|
||||
|
||||
public Task CallAsync(HttpMethod method, string path, Func<HttpContent> contentFactory, CancellationToken ct = default)
|
||||
=> CallAsync(method, path, (object?)null, ct);
|
||||
|
||||
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@ public class PostItViewModelTests
|
|||
[Fact]
|
||||
public void SearchCommand_filters_posts_by_title_article_or_author()
|
||||
{
|
||||
// MainPageViewModel no longer owns a BlogApiClient instance by
|
||||
// BlogsViewModel no longer owns a BlogApiClient instance by
|
||||
// default; tests construct one with a fake YavscApiClient that
|
||||
// throws on any call (we never call the API in this test).
|
||||
var fakeApi = new ThrowingYavscApiClient();
|
||||
var blog = new BlogApiClient(fakeApi, "http://localhost/");
|
||||
var viewModel = new MainViewModel(blog);
|
||||
var viewModel = new BlogsViewModel(blog);
|
||||
|
||||
viewModel.Posts.Add(new BlogPostDto { Id = 1, Title = "First post", Article = "Hello world", AuthorId = "alice" });
|
||||
viewModel.Posts.Add(new BlogPostDto { Id = 2, Title = "Second post", Article = "Nothing here", AuthorId = "bob" });
|
||||
|
|
@ -60,7 +60,7 @@ public class PostItViewModelTests
|
|||
{
|
||||
var api = new RecordingPublishApi();
|
||||
var blog = new BlogApiClient(api, "http://localhost/");
|
||||
var viewModel = new MainViewModel(blog);
|
||||
var viewModel = new BlogsViewModel(blog);
|
||||
|
||||
viewModel.SelectedPost = new BlogPostDto { Id = 42, IsPublished = false };
|
||||
|
||||
|
|
@ -146,6 +146,12 @@ public class PostItViewModelTests
|
|||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<T> CallAsync<T>(HttpMethod method, string path, Func<HttpContent> contentFactory, CancellationToken ct = default)
|
||||
=> CallAsync<T>(method, path, (object?)null, ct);
|
||||
|
||||
public Task CallAsync(HttpMethod method, string path, Func<HttpContent> contentFactory, CancellationToken ct = default)
|
||||
=> CallAsync(method, path, (object?)null, ct);
|
||||
|
||||
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,6 +74,12 @@ public class RdvPageHeadlessTests
|
|||
public Task CallAsync(HttpMethod method, string path, object? body = null, CancellationToken ct = default)
|
||||
=> Task.CompletedTask;
|
||||
|
||||
public Task<T> CallAsync<T>(HttpMethod method, string path, Func<HttpContent> contentFactory, CancellationToken ct = default)
|
||||
=> CallAsync<T>(method, path, (object?)null, ct);
|
||||
|
||||
public Task CallAsync(HttpMethod method, string path, Func<HttpContent> contentFactory, CancellationToken ct = default)
|
||||
=> CallAsync(method, path, (object?)null, ct);
|
||||
|
||||
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue