Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Squad: union merge for append-only team state files
.ai-team/decisions.md merge=union
.ai-team/agents/*/history.md merge=union
.ai-team/log/** merge=union
.ai-team/orchestration-log/** merge=union
# Squad: union merge for append-only team state files
.squad/decisions.md merge=union
.squad/agents/*/history.md merge=union
.squad/log/** merge=union
.squad/orchestration-log/** merge=union
# Squad: union merge for append-only team state files
.ai-team/decisions.md merge=union
.ai-team/agents/*/history.md merge=union
.ai-team/log/** merge=union
.ai-team/orchestration-log/** merge=union
# Squad: union merge for append-only team state files
.squad/decisions.md merge=union
.squad/agents/*/history.md merge=union
.squad/log/** merge=union
.squad/orchestration-log/** merge=union
# Squad: union merge for append-only team state files
.squad/rai/audit-trail.md merge=union
.squad/fact-checker/audit-trail.md merge=union
18 changes: 9 additions & 9 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project>
<PropertyGroup>
<Version>1.2.2</Version>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
</Project>
<Project>
<PropertyGroup>
<Version>1.3.0</Version>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
</Project>
22 changes: 11 additions & 11 deletions skills-lock.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"version": 1,
"skills": {
"grill-with-docs": {
"source": "mattpocock/skills",
"sourceType": "github",
"skillPath": "skills/engineering/grill-with-docs/SKILL.md",
"computedHash": "1adf321072f53cce3dcaf5357d91b8230d4aa647bb8a51756745337a6ee567b8"
}
}
}
{
"version": 1,
"skills": {
"grill-with-docs": {
"source": "mattpocock/skills",
"sourceType": "github",
"skillPath": "skills/engineering/grill-with-docs/SKILL.md",
"computedHash": "9c460cbd94fd3c63cdef967dbdb6e66ca687103cdc380cd37834e4d10b738f78"
}
}
}
15 changes: 15 additions & 0 deletions src/NoteBookmark.Api/PostEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public static void MapPostEndpoints(this IEndpointRouteBuilder app)
.WithDescription("Get all read posts");
endpoints.MapGet("/{id}", Get)
.WithDescription("Get a post by id");
endpoints.MapGet("/{postId}/html", GetPostHtml)
.WithDescription("Get cleaned HTML for a post");
endpoints.MapPost("/", SavePost)
.WithDescription("Save or Create a post");
endpoints.MapPost("/extractPostDetails", ExtractPostDetails)
Expand Down Expand Up @@ -55,6 +57,18 @@ static List<PostL> GetReadPosts(TableServiceClient tblClient, BlobServiceClient
return posts;
}

static async Task<Results<ContentHttpResult, NotFound<ErrorMessage>>> GetPostHtml(
string postId, BlobServiceClient blobClient)
{
var containerClient = blobClient.GetBlobContainerClient("cleanedposts");
var blob = containerClient.GetBlobClient($"{postId}.html");
if (!await blob.ExistsAsync())
return TypedResults.NotFound(new ErrorMessage("Post HTML not found"));
var download = await blob.DownloadContentAsync();
var html = download.Value.Content.ToString();
return TypedResults.Content(html, "text/html");
}

static Results<Ok<Post>, NotFound> Get(string id, TableServiceClient tblClient, BlobServiceClient blobClient)
{
var dataStorageService = new DataStorageService(tblClient, blobClient);
Expand Down Expand Up @@ -186,3 +200,4 @@ static Results<Ok<Post>, NotFound, BadRequest> PatchPost(string id, Post post, T
}

public record ExtractPostRequest(string url, string? tags = null, string? category = null);
public record ErrorMessage(string error);
129 changes: 129 additions & 0 deletions src/NoteBookmark.BlazorApp.Tests/Tests/PostsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using Bunit;
using Bunit.TestDoubles;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.FluentUI.AspNetCore.Components;
using Moq;
using NoteBookmark.BlazorApp.Tests.Helpers;
using NoteBookmark.Domain;
using NoteBookmark.SharedUI;
using NoteBookmark.SharedUI.Components.Pages;

namespace NoteBookmark.BlazorApp.Tests.Tests;

/// <summary>
/// Tests for the Posts page in NoteBookmark.SharedUI.
/// Covers the show/hide published date toggle, title filter, and read/unread switching.
/// </summary>
public sealed class PostsTests : BunitContext
{
private readonly Mock<IDataService> _dataServiceMock;

private static List<PostL> SamplePosts() =>
[
new PostL { PartitionKey = "p", RowKey = "1", Title = "First Post", Url = "https://example.com/1", Date_published = "2025-01-15T00:00:00", is_read = false },
new PostL { PartitionKey = "p", RowKey = "2", Title = "Second Post", Url = "https://example.com/2", Date_published = "2025-06-20T00:00:00", is_read = false },
];

public PostsTests()
{
this.AddFluentUI();
this.AddAuthorization().SetAuthorized("testuser");

_dataServiceMock = new Mock<IDataService>();
_dataServiceMock.Setup(s => s.GetUnreadPosts()).ReturnsAsync(SamplePosts());
_dataServiceMock.Setup(s => s.GetReadPosts()).ReturnsAsync([]);
_dataServiceMock.Setup(s => s.SyncAsync()).Returns(Task.CompletedTask);
_dataServiceMock.SetupGet(s => s.IsOffline).Returns(false);
_dataServiceMock.SetupGet(s => s.CanSync).Returns(false);

Services.AddSingleton(_dataServiceMock.Object);
Services.AddSingleton(new Mock<IToastService>().Object);
Services.AddSingleton(new Mock<IDialogService>().Object);
Services.AddSingleton<ILocalHtmlCache>(new NoteBookmark.BlazorApp.AlwaysAvailableHtmlCache());
}

[Fact]
public void Posts_RendersWithoutThrowing()
{
var cut = Render<Posts>();

cut.Markup.Should().NotBeNullOrEmpty();
}

[Fact]
public void Posts_RendersPostTitles()
{
var cut = Render<Posts>();

cut.Markup.Should().Contain("First Post");
cut.Markup.Should().Contain("Second Post");
}

[Fact]
public void Posts_PublishedDateColumn_HiddenByDefault()
{
var cut = Render<Posts>();

// The Published column header text should not appear as a grid header;
// "Show Published Date" (the checkbox label) still contains "Published" as a substring,
// so we look for the exact header cell pattern instead.
cut.Markup.Should().NotMatchRegex(@"col-title-text[^>]*>Published<");
}

[Fact]
public void Posts_PublishedDateColumn_VisibleAfterToggle()
{
var cut = Render<Posts>();

// Find and click the "Show Published Date" checkbox
var checkbox = cut.Find("fluent-checkbox");
checkbox.Click();

cut.Markup.Should().Contain("Published");
}

[Fact]
public void Posts_ShowPublishedDateCheckbox_IsRendered()
{
var cut = Render<Posts>();

cut.Markup.Should().Contain("Show Published Date");
}

[Fact]
public void Posts_TitleFilter_RendersFilterButton()
{
var cut = Render<Posts>();

// The Title column renders a filter button; the options panel (with the search input)
// only opens after the button is clicked, so we verify the button is present.
cut.Markup.Should().Contain("Filter this column");
}

[Fact]
public void Posts_LoadsUnreadPostsByDefault()
{
Render<Posts>();

_dataServiceMock.Verify(s => s.GetUnreadPosts(), Times.AtLeastOnce);
}

[Fact]
public void Posts_RendersAddButton()
{
var cut = Render<Posts>();

// The URL input and add button are present
cut.Markup.Should().Contain("Enter URL");
}

[Fact]
public void Posts_RendersEmptyState_WhenNoPostsReturned()
{
_dataServiceMock.Setup(s => s.GetUnreadPosts()).ReturnsAsync([]);

var cut = Render<Posts>();

cut.Markup.Should().Contain("Nothing to see here");
}
}
8 changes: 8 additions & 0 deletions src/NoteBookmark.BlazorApp/AlwaysAvailableHtmlCache.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using NoteBookmark.SharedUI;

namespace NoteBookmark.BlazorApp;

public class AlwaysAvailableHtmlCache : ILocalHtmlCache
{
public bool IsHtmlCached(string postId) => true;
}
1 change: 1 addition & 0 deletions src/NoteBookmark.BlazorApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();
builder.AddAzureTableClient("nb-tables");

Check warning on line 13 in src/NoteBookmark.BlazorApp/Program.cs

View workflow job for this annotation

GitHub Actions / Run Unit Tests

'AspireTablesExtensions.AddAzureTableClient(IHostApplicationBuilder, string, Action<AzureDataTablesSettings>?, Action<IAzureClientBuilder<TableServiceClient, TableClientOptions>>?)' is obsolete: 'Use AddAzureTableServiceClient instead. This method will be removed in a future version.'

// Add HTTP client for API calls
builder.Services.AddHttpClient<PostNoteClient>(client =>
Expand All @@ -18,6 +18,7 @@
client.BaseAddress = new Uri("https+http://api");
});
builder.Services.AddTransient<IDataService>(sp => sp.GetRequiredService<PostNoteClient>());
builder.Services.AddSingleton<ILocalHtmlCache, NoteBookmark.BlazorApp.AlwaysAvailableHtmlCache>();

// Register server-side AI settings provider (direct database access, unmasked)
builder.Services.AddScoped<AISettingsProvider>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<Compile Include="..\NoteBookmark.MauiApp\Data\ILocalDataService.cs" Link="Data\ILocalDataService.cs" />
<Compile Include="..\NoteBookmark.MauiApp\Data\LocalDataService.cs" Link="Data\LocalDataService.cs" />
<Compile Include="..\NoteBookmark.MauiApp\Data\ISyncApiClient.cs" Link="Data\ISyncApiClient.cs" />
<Compile Include="..\NoteBookmark.MauiApp\Data\ILocalHtmlStorageService.cs" Link="Data\ILocalHtmlStorageService.cs" />
<Compile Include="..\NoteBookmark.MauiApp\Data\SyncService.cs" Link="Data\SyncService.cs" />
<Compile Include="..\NoteBookmark.MauiApp\Data\SyncApiClient.cs" Link="Data\SyncApiClient.cs" />
</ItemGroup>
Expand Down
6 changes: 5 additions & 1 deletion src/NoteBookmark.MauiApp.Tests/SyncServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ public class SyncServiceTests
private readonly Mock<ISyncApiClient> _apiClientMock;
private readonly Mock<ILocalDataService> _localDataServiceMock;
private readonly Mock<ILogger<SyncService>> _loggerMock;
private readonly Mock<ILocalHtmlStorageService> _localHtmlStorageServiceMock;
private readonly SyncService _sut;

public SyncServiceTests()
{
_apiClientMock = new Mock<ISyncApiClient>();
_localDataServiceMock = new Mock<ILocalDataService>();
_loggerMock = new Mock<ILogger<SyncService>>();
_localHtmlStorageServiceMock = new Mock<ILocalHtmlStorageService>();

_apiClientMock.Setup(c => c.GetNote(It.IsAny<string>())).ReturnsAsync((Note?)null);
_apiClientMock.Setup(c => c.GetPostHtmlAsync(It.IsAny<string>())).ReturnsAsync((string?)null);
_localDataServiceMock.Setup(c => c.GetPostsAsync()).ReturnsAsync(new List<Post>());
_localHtmlStorageServiceMock.Setup(s => s.GetCachedPostIds()).Returns(new List<string>());

_sut = new SyncService(_apiClientMock.Object, _localDataServiceMock.Object, _loggerMock.Object);
_sut = new SyncService(_apiClientMock.Object, _localDataServiceMock.Object, _loggerMock.Object, _localHtmlStorageServiceMock.Object);

SyncService.ClearInMemoryPreferences();
}
Expand Down
13 changes: 13 additions & 0 deletions src/NoteBookmark.MauiApp/Data/ILocalHtmlStorageService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace NoteBookmark.MauiApp.Data;

public interface ILocalHtmlStorageService
{
Task SavePostHtmlAsync(string postId, string html);
Task<string?> GetPostHtmlAsync(string postId);
bool IsPostHtmlCached(string postId);
void RemovePostHtml(string postId);
IEnumerable<string> GetCachedPostIds();
}
1 change: 1 addition & 0 deletions src/NoteBookmark.MauiApp/Data/ISyncApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public interface ISyncApiClient
Task<bool> UpdateNote(Note note);
Task<bool> CreateNote(Note note);
Task<bool> DeleteNote(string rowKey);
Task<string?> GetPostHtmlAsync(string postId);
}
41 changes: 41 additions & 0 deletions src/NoteBookmark.MauiApp/Data/LocalHtmlStorageService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using NoteBookmark.SharedUI;

namespace NoteBookmark.MauiApp.Data;

public class LocalHtmlStorageService(string baseDirectory) : ILocalHtmlStorageService, ILocalHtmlCache
{
private string FilePath(string postId) => Path.Combine(baseDirectory, $"{postId}.html");

public async Task SavePostHtmlAsync(string postId, string html)
=> await File.WriteAllTextAsync(FilePath(postId), html);

public async Task<string?> GetPostHtmlAsync(string postId)
{
var path = FilePath(postId);
if (!File.Exists(path)) return null;
return await File.ReadAllTextAsync(path);
}

public bool IsPostHtmlCached(string postId) => File.Exists(FilePath(postId));

public bool IsHtmlCached(string postId) => IsPostHtmlCached(postId);

public void RemovePostHtml(string postId)
{
var path = FilePath(postId);
if (File.Exists(path)) File.Delete(path);
}

public IEnumerable<string> GetCachedPostIds()
{
if (!Directory.Exists(baseDirectory)) return Enumerable.Empty<string>();
return Directory.GetFiles(baseDirectory, "*.html")
.Select(Path.GetFileNameWithoutExtension)
.Where(id => id != null)
.Cast<string>();
}
}
5 changes: 4 additions & 1 deletion src/NoteBookmark.MauiApp/Data/OfflineDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace NoteBookmark.MauiApp.Data;

public class OfflineDataService(PostNoteClient apiClient, ILocalDataService localDataService, IConnectivity connectivity, ISyncService syncService) : IDataService
public class OfflineDataService(PostNoteClient apiClient, ILocalDataService localDataService, IConnectivity connectivity, ISyncService syncService, ILocalHtmlStorageService localHtmlStorageService) : IDataService
{
private bool IsOnline => connectivity.NetworkAccess == NetworkAccess.Internet;

Expand Down Expand Up @@ -275,6 +275,9 @@ public async Task<bool> DeletePost(string id)

public Task<bool> SaveReadingNotesMarkdown(string markdown, string number) => apiClient.SaveReadingNotesMarkdown(markdown, number);

public Task<string?> GetPostHtmlAsync(string postId)
=> localHtmlStorageService.GetPostHtmlAsync(postId);

public Task SyncAsync() => syncService.SyncAsync();
public bool IsOffline => connectivity.NetworkAccess != NetworkAccess.Internet;
public bool CanSync => true;
Expand Down
1 change: 1 addition & 0 deletions src/NoteBookmark.MauiApp/Data/SyncApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ public async Task<bool> CreateNote(Note note)
return true;
}
public Task<bool> DeleteNote(string rowKey) => client.DeleteNote(rowKey);
public Task<string?> GetPostHtmlAsync(string postId) => client.GetPostHtmlAsync(postId);
}
Loading
Loading