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
33 changes: 33 additions & 0 deletions src/NoteBookmark.BlazorApp.Tests/Tests/PostsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,36 @@ public void Posts_RendersEmptyState_WhenNoPostsReturned()
cut.Markup.Should().Contain("Nothing to see here");
}
}

public sealed class PostsHtmlCacheTests : BunitContext
{
[Fact]
public void Posts_ChecksHtmlCacheWithPostId_WhenIdIsPresent()
{
this.AddFluentUI();
this.AddAuthorization().SetAuthorized("testuser");

var dataServiceMock = new Mock<IDataService>();
dataServiceMock.Setup(s => s.GetUnreadPosts()).ReturnsAsync([
new PostL { PartitionKey = "p", RowKey = "row-key-456", Id = "custom-id-123", Title = "Post With Id", Url = "https://example.com/id", Date_published = "2025-01-15T00:00:00", is_read = false }
]);
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);

var htmlCacheMock = new Mock<ILocalHtmlCache>();
htmlCacheMock.Setup(c => c.IsHtmlCached("custom-id-123")).Returns(true);

Services.AddSingleton(dataServiceMock.Object);
Services.AddSingleton(new Mock<IToastService>().Object);
Services.AddSingleton(new Mock<IDialogService>().Object);
Services.AddSingleton(htmlCacheMock.Object);

var cut = Render<Posts>();

htmlCacheMock.Verify(c => c.IsHtmlCached("custom-id-123"), Times.Once);
cut.Markup.Should().Contain("Read post");
}
}

4 changes: 2 additions & 2 deletions src/NoteBookmark.SharedUI/Components/Pages/Posts.razor
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
{
<FluentButton OnClick="@(() => EditNoteForPost(context!.NoteId))" IconEnd="@(new Icons.Filled.Size20.NoteEdit())" />
}
@if (localHtmlCache.IsHtmlCached(context!.RowKey))
@if (localHtmlCache.IsHtmlCached(context!.Id ?? context!.RowKey))
{
<FluentButton OnClick="@(() => ReadPost(context!.RowKey))" IconEnd="@(new Icons.Regular.Size20.Book())" Title="Read post" />
<FluentButton OnClick="@(() => ReadPost(context!.Id ?? context!.RowKey))" IconEnd="@(new Icons.Regular.Size20.Book())" Title="Read post" />
}
</TemplateColumn>
<PropertyColumn Title="Title" Property="@(c => c!.Title)" Sortable="true" Filtered="!string.IsNullOrWhiteSpace(titleFilter)" >
Expand Down
Loading