feat: add site header (#2)
* tests: setup initial infra for end to end tests * tests: rework end to end host * tests: remove need for bang operator * tests: correct header component tests * docs: add README.md to blog directory with instructions on setting up local dev environment with and without docker * docs: update non-developer run command * feat: finish layout of header * feat: add favicon * tests: setup test coverage * chore: update workflow with missing playwright step * chore: add install command
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using Microsoft.AspNetCore.Hosting.Server.Features;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Blog.Tests.EndToEnd;
|
||||
|
||||
public class BlogHostFactory<TProgram> : WebApplicationFactory<TProgram> where TProgram : class
|
||||
{
|
||||
private IHost? _host;
|
||||
|
||||
private void EnsureServer()
|
||||
{
|
||||
if (_host is null)
|
||||
{
|
||||
using var _ = CreateDefaultClient();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
_host?.Dispose();
|
||||
}
|
||||
|
||||
public string ServerAddress
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureServer();
|
||||
return ClientOptions.BaseAddress.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
protected override IHost CreateHost(IHostBuilder builder)
|
||||
{
|
||||
var testHost = builder
|
||||
.ConfigureWebHost(
|
||||
webHostBuilder => webHostBuilder.ConfigureLogging(
|
||||
config => config.ClearProviders()
|
||||
)
|
||||
)
|
||||
.Build();
|
||||
|
||||
builder.ConfigureWebHost(
|
||||
webHostBuilder => webHostBuilder.UseKestrel(
|
||||
o => o.Listen(IPAddress.Loopback, 0)
|
||||
)
|
||||
);
|
||||
|
||||
_host = builder.Build();
|
||||
_host.Start();
|
||||
|
||||
var server = _host.Services.GetRequiredService<IServer>();
|
||||
var addresses = server.Features.GetRequiredFeature<IServerAddressesFeature>();
|
||||
|
||||
ClientOptions.BaseAddress = addresses.Addresses
|
||||
.Select(x => new Uri(x))
|
||||
.Last();
|
||||
|
||||
testHost.Start();
|
||||
return testHost;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Microsoft.AspNetCore.Hosting.Server.Features;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
|
||||
namespace Blog.Tests.EndToEnd;
|
||||
|
||||
[TestFixture]
|
||||
public class BlogTest : PageTest
|
||||
{
|
||||
private readonly BlogHostFactory<Program> _factory = new();
|
||||
|
||||
public override BrowserNewContextOptions ContextOptions()
|
||||
{
|
||||
var options = base.ContextOptions();
|
||||
options.BaseURL = _factory.ServerAddress;
|
||||
return options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace Blog.Tests.EndToEnd;
|
||||
|
||||
[TestFixture]
|
||||
public class HomeTests : BlogTest
|
||||
{
|
||||
[Test]
|
||||
public async Task Home_WhenNavigatedTo_ItShouldDisplayCorrectPageTitle()
|
||||
{
|
||||
await Page.GotoAsync("/");
|
||||
var title = await Page.TitleAsync();
|
||||
title.Should().Be("journal - A blog by Stevan Freeborn");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Home_WhenNavigatedTo_ItShouldCorrectSiteTitle()
|
||||
{
|
||||
await Page.GotoAsync("/");
|
||||
var message = Page.GetByRole(AriaRole.Heading, new () { Name = "journal" });
|
||||
await Expect(message).ToBeVisibleAsync();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Home_WhenNavigatedTo_ItShouldDisplayWrittenByAttribution()
|
||||
{
|
||||
await Page.GotoAsync("/");
|
||||
var message = Page.GetByText("by");
|
||||
var image = Page.GetByAltText("Stevan Freeborn");
|
||||
|
||||
await Expect(message).ToBeVisibleAsync();
|
||||
await Expect(image).ToBeVisibleAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user