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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>1.4.1</Version>
<Version>1.4.2</Version>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
34 changes: 27 additions & 7 deletions src/NoteBookmark.BlazorApp.Tests/Tests/PostReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public PostReaderTests()
}

[Fact]
public void PostReader_RendersTitleAndContentAndSlider()
public void PostReader_RendersTitleAndContentAndSlidersAndBackButtonsAtTopAndBottom()
{
var cut = Render<PostReader>(ps => ps.Add(p => p.PostId, "p1"));

Expand All @@ -44,23 +44,43 @@ public void PostReader_RendersTitleAndContentAndSlider()
cut.Markup.Should().Contain("reader-content");
cut.Markup.Should().Contain("Text size:");

var slider = cut.FindComponent<FluentSlider<int>>();
slider.Instance.Min.Should().Be(8);
slider.Instance.Max.Should().Be(56);
var sliders = cut.FindComponents<FluentSlider<int>>();
sliders.Should().HaveCount(2);
sliders[0].Instance.Min.Should().Be(8);
sliders[0].Instance.Max.Should().Be(56);
sliders[1].Instance.Min.Should().Be(8);
sliders[1].Instance.Max.Should().Be(56);

var backButtons = cut.FindComponents<FluentButton>()
.Where(b => b.Instance.Title == "Back to posts")
.ToList();
backButtons.Should().HaveCount(2);
}

[Fact]
public void PostReader_SliderValueChange_UpdatesContentFontSize()
public void PostReader_TopSliderValueChange_UpdatesContentFontSize()
{
var cut = Render<PostReader>(ps => ps.Add(p => p.PostId, "p1"));

var contentDivBefore = cut.Find("div.reader-content");
contentDivBefore.GetAttribute("style").Should().Contain("font-size: 16px;");

var slider = cut.FindComponent<FluentSlider<int>>();
cut.InvokeAsync(() => slider.Instance.ValueChanged.InvokeAsync(24));
var sliders = cut.FindComponents<FluentSlider<int>>();
cut.InvokeAsync(() => sliders[0].Instance.ValueChanged.InvokeAsync(24));

var contentDivAfter = cut.Find("div.reader-content");
contentDivAfter.GetAttribute("style").Should().Contain("font-size: 24px;");
}

[Fact]
public void PostReader_BottomSliderValueChange_UpdatesContentFontSize()
{
var cut = Render<PostReader>(ps => ps.Add(p => p.PostId, "p1"));

var sliders = cut.FindComponents<FluentSlider<int>>();
cut.InvokeAsync(() => sliders[1].Instance.ValueChanged.InvokeAsync(20));

var contentDivAfter = cut.Find("div.reader-content");
contentDivAfter.GetAttribute("style").Should().Contain("font-size: 20px;");
}
}
29 changes: 29 additions & 0 deletions src/NoteBookmark.BlazorApp.Tests/Tests/PostsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,34 @@ public void Posts_ReadPostButton_IsAlwaysRendered()

cut.Markup.Should().Contain("Read post");
}

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

cut.InvokeAsync(() =>
{
_dataServiceMock.Raise(s => s.SyncProgressChanged += null, new SyncProgressEventArgs(1, 6, "Downloading 1 of 6 posts..."));
});

cut.Markup.Should().Contain("Downloading 1 of 6 posts...");
var progress = cut.FindComponent<FluentProgress>();
progress.Instance.Value.Should().Be(1);
progress.Instance.Max.Should().Be(6);
}

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

cut.InvokeAsync(() =>
{
_dataServiceMock.Raise(s => s.SyncProgressChanged += null, new SyncProgressEventArgs(0, 0, "Cleaning..."));
});

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

4 changes: 3 additions & 1 deletion src/NoteBookmark.MauiApp.Tests/SyncServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,9 @@ public async Task SyncAsync_ShouldRaiseSyncProgressChanged_WhenDownloadingPostHt
await _sut.SyncAsync();

progressEvents.Should().NotBeEmpty();
progressEvents.Should().Contain(e => e.Status.Contains("Downloading offline text"));
progressEvents.Should().Contain(e => e.Status == "Cleaning...");
progressEvents.Should().Contain(e => e.Status == "Downloading 1 of 2 posts..." && e.Current == 1 && e.Total == 2);
progressEvents.Should().Contain(e => e.Status == "Downloading 2 of 2 posts..." && e.Current == 2 && e.Total == 2);
progressEvents.Last().Status.Should().Be("Synchronization complete!");
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/NoteBookmark.MauiApp/Data/SyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ private async Task SyncHtmlAsync()
var postMap = posts.ToDictionary(p => p.Id ?? p.RowKey);
var cachedIds = localHtmlStorageService.GetCachedPostIds().ToHashSet();

SyncProgressChanged?.Invoke(this, new SyncProgressEventArgs(0, 0, "Cleaning..."));

// Prune cached HTML for posts that are read or no longer exist
foreach (var cachedId in cachedIds)
{
Expand All @@ -258,7 +260,7 @@ private async Task SyncHtmlAsync()

if (total > 0)
{
SyncProgressChanged?.Invoke(this, new SyncProgressEventArgs(0, total, $"Downloading offline text (0/{total})..."));
SyncProgressChanged?.Invoke(this, new SyncProgressEventArgs(0, total, $"Downloading 0 of {total} posts..."));

for (int i = 0; i < unreadToDownload.Count; i++)
{
Expand All @@ -279,7 +281,7 @@ private async Task SyncHtmlAsync()
}

int current = i + 1;
SyncProgressChanged?.Invoke(this, new SyncProgressEventArgs(current, total, $"Downloading offline text ({current}/{total})..."));
SyncProgressChanged?.Invoke(this, new SyncProgressEventArgs(current, total, $"Downloading {current} of {total} posts..."));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/NoteBookmark.MauiApp/NoteBookmark.MauiApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
<ApplicationId>c5m.notebookmark.mauiapp</ApplicationId>

<!-- Versions -->
<ApplicationDisplayVersion>1.3.3</ApplicationDisplayVersion>
<ApplicationVersion>6</ApplicationVersion>
<Version>1.3.3</Version>
<ApplicationDisplayVersion>1.4.2</ApplicationDisplayVersion>
<ApplicationVersion>7</ApplicationVersion>
<Version>1.4.2</Version>

<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
<WindowsPackageType>None</WindowsPackageType>
Expand Down
18 changes: 14 additions & 4 deletions src/NoteBookmark.SharedUI/Components/Pages/PostReader.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
<PageTitle>@(post?.Title ?? "Reading...")</PageTitle>

<FluentStack Orientation="Orientation.Vertical" Style="width: 100%; max-width: 800px; margin: 0 auto; padding: 1rem; box-sizing: border-box;">
<FluentStack Orientation="Orientation.Horizontal">
<FluentButton OnClick="@(() => Navigation.NavigateTo("/posts"))"
IconStart="@(new Icons.Regular.Size20.ArrowLeft())"
Title="Back to posts">Back</FluentButton>
<FluentStack Orientation="Orientation.Vertical" Style="width: 100%; gap: 0.5rem; margin-bottom: 1rem;">
<FluentStack Orientation="Orientation.Horizontal" VerticalAlignment="VerticalAlignment.Center">
<FluentButton OnClick="@(() => Navigation.NavigateTo("/posts"))"
IconStart="@(new Icons.Regular.Size20.ArrowLeft())"
Title="Back to posts">Back</FluentButton>
<FluentSpacer />
<span style="font-weight: 600;">Text size:</span>
<span>@(textSize)px</span>
</FluentStack>
<FluentSlider Min="8" Max="56" Step="1" @bind-Value="textSize" Style="width: 100%;" aria-label="Text size slider" />
</FluentStack>

@if (isLoading)
Expand Down Expand Up @@ -51,6 +57,10 @@

<FluentStack Orientation="Orientation.Vertical" Style="width: 100%; gap: 0.5rem; margin-top: 1rem;">
<FluentStack Orientation="Orientation.Horizontal" VerticalAlignment="VerticalAlignment.Center">
<FluentButton OnClick="@(() => Navigation.NavigateTo("/posts"))"
IconStart="@(new Icons.Regular.Size20.ArrowLeft())"
Title="Back to posts">Back</FluentButton>
<FluentSpacer />
<span style="font-weight: 600;">Text size:</span>
<span>@(textSize)px</span>
</FluentStack>
Expand Down
14 changes: 13 additions & 1 deletion src/NoteBookmark.SharedUI/Components/Pages/Posts.razor
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,22 @@

try
{
isSyncing = true;
await client.SyncAsync();
await LoadPosts();
StateHasChanged();
}
catch (Exception)
{
// Ignore background sync errors
}
finally
{
isSyncing = false;
syncProgressStatus = string.Empty;
syncProgressCurrent = 0;
syncProgressTotal = 0;
StateHasChanged();
}
}

private async Task OpenUrlInNewWindow(string? url)
Expand Down Expand Up @@ -287,6 +295,10 @@
finally
{
isSyncing = false;
syncProgressStatus = string.Empty;
syncProgressCurrent = 0;
syncProgressTotal = 0;
StateHasChanged();
}
}

Expand Down
Loading