End-to-end tests against the pasture; profiles, follows, search, votes, reactions
tests/e2e (Playwright for .NET 1.61.0 on xunit v3, the Chromium 1228 already cached, never downloaded, never in CI) runs the published app against SocialPub's pasture and its town: run.sh publishes it with the Pasture environment (wwwroot/appsettings.Pasture.json, published only then; the deploy fails if it ever ships) and serves it as https://decepub.test. The tests sign in through the real login page and persona chooser, check that every request goes only to decepub.test and privapub.test with the right credential on the right API, render one post of each kind from each platform as its author wrote it, and check every action on the other side of the wire (town.sh stored): favourites, boosts and replies with their undoing, follows from a profile, votes, reactions. Each test is also a cell of the town's report (out/client.jsonl). They found two PrivaPub bugs fixed there (a blocked author's status answered null; sensitive remote media invented a content warning) and a reply addressed to nobody. New in the app, all checked by those tests: - profiles at /account/{id}: header, bio, fields, counts, the account's posts as posts, posts and replies, or media, and follow, unfollow, cancel a request, mute and block (AccountService); post authors and notifications open them in the app; - search at /search: accounts, posts and hashtags, a handle or an address resolved by PrivaPub; - poll voting on the card, and emoji reactions shown and given with one tap; before a persona's first reaction or vote it is told once that both are public (PublicNoticeService, the owner's decision); - follow requests answered from their notification. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
This commit is contained in:
1 parent
0f68e74e38
commit
011bafb6af
39 files changed
+2074
-17
No files matched your search
@@ -0,0 +1,84 @@
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
using decePubClient.E2E.Support;
|
||||
|
||||
using Microsoft.Playwright;
|
||||
|
||||
namespace decePubClient.E2E.Render
|
||||
{
|
||||
// One object of each kind from each platform, opened in decePub (/expand/{id}) by a persona it was for, and checked
|
||||
// against what its author put in it: the text, the content warning, every picture's alt text and its proxied source,
|
||||
// the poll's options, the quoted post. town.sh expect says what each object holds and who may read it.
|
||||
public sealed class RenderMatrixTests(Browser browser)
|
||||
{
|
||||
static readonly Lazy<JsonArray> Expected = new(() => Pasture.Town("expect").GetAwaiter().GetResult().AsArray());
|
||||
|
||||
public static TheoryData<string, string, string> Samples()
|
||||
{
|
||||
var data = new TheoryData<string, string, string>();
|
||||
var seen = new HashSet<string>();
|
||||
var personas = Pasture.Personas().Select(p => p.UserName).ToHashSet();
|
||||
foreach (var item in Expected.Value)
|
||||
{
|
||||
var key = $"{item!["origin"]}|{item["kind"]}|{item["visibility"]}";
|
||||
if (!item["readers"]!.AsArray().Any(r => personas.Contains(r!.GetValue<string>())) || !seen.Add(key))
|
||||
continue;
|
||||
data.Add(item["origin"]!.GetValue<string>(), $"{item["kind"]}.{item["visibility"]}", item["ref"]!.GetValue<string>());
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Samples))]
|
||||
public async Task Renders_as_written(string origin, string kind, string reference)
|
||||
{
|
||||
var item = Expected.Value.First(i => i!["ref"]!.GetValue<string>() == reference)!;
|
||||
var personas = Pasture.Personas();
|
||||
var reader = item["readers"]!.AsArray().Select(r => r!.GetValue<string>())
|
||||
.Select(name => personas.FirstOrDefault(p => p.UserName == name)).First(p => p is not null);
|
||||
|
||||
await Results.Cell($"client.render.{kind}", origin, reference, async () =>
|
||||
{
|
||||
await using var session = await SignIn.As(browser, reader);
|
||||
await session.Page.GotoAsync($"{Pasture.Site}/expand/{item["id"]!.GetValue<string>()}");
|
||||
var card = session.Page.Locator($"article[data-uri='{item["uri"]!.GetValue<string>()}']").First;
|
||||
await card.WaitForAsync(new() { Timeout = 30000 });
|
||||
|
||||
var marker = item["marker"]!.GetValue<string>();
|
||||
if (item["cw"]?.GetValue<string>() is { } cw)
|
||||
{
|
||||
await Assertions.Expect(card).ToContainTextAsync(cw);
|
||||
Assert.False(await card.GetByText(marker).IsVisibleAsync(), "the text shows before its content warning is opened");
|
||||
await card.GetByText(cw).First.ClickAsync();
|
||||
}
|
||||
await Assertions.Expect(card.Locator(".post-content").First).ToContainTextAsync(marker);
|
||||
|
||||
// each reveal re-renders the media, so reveal the first hidden one until none is left
|
||||
var hidden = card.GetByRole(AriaRole.Button).Filter(new() { HasText = "Sensitive media" });
|
||||
for (var i = 0; i < 8 && await hidden.CountAsync() > 0; i++)
|
||||
await hidden.First.ClickAsync();
|
||||
foreach (var alt in item["alts"]!.AsArray().Select(a => a!.GetValue<string>()))
|
||||
{
|
||||
var picture = card.Locator($"img[alt='{alt}']").First;
|
||||
await Assertions.Expect(picture).ToBeVisibleAsync();
|
||||
var src = new Uri(await picture.GetAttributeAsync("src") ?? "");
|
||||
Assert.Equal("privapub.test", src.Host);
|
||||
Assert.True(await picture.EvaluateAsync<bool>("img => img.complete && img.naturalWidth > 0"), $"picture '{alt}' did not load");
|
||||
}
|
||||
if (item["poll"] is JsonArray options)
|
||||
foreach (var option in options)
|
||||
await Assertions.Expect(card).ToContainTextAsync(option!.GetValue<string>());
|
||||
if (item["quote"]?.GetValue<string>() is { } quoted)
|
||||
{
|
||||
var quotedRef = Expected.Value.FirstOrDefault(i => i!["uri"]!.GetValue<string>() == quoted)?["marker"]?.GetValue<string>();
|
||||
Assert.True(await card.Locator("article").CountAsync() > 0, "the quoted post is not shown");
|
||||
if (quotedRef is not null)
|
||||
await Assertions.Expect(card.Locator("article").First).ToContainTextAsync(quotedRef);
|
||||
}
|
||||
if (item["title"]?.GetValue<string>() is { } title)
|
||||
await Assertions.Expect(card).ToContainTextAsync(title);
|
||||
await session.AssertGuards();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user