Skip to content

Commit 0004cc7

Browse files
committed
Loading bar when creating sitemap
1 parent d1a8b65 commit 0004cc7

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

LinkDotNet.Blog.UnitTests/Web/Pages/Admin/SitemapTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System.Collections.Generic;
22
using System.Linq;
3+
using System.Threading.Tasks;
34
using Bunit;
45
using Bunit.TestDoubles;
56
using FluentAssertions;
67
using LinkDotNet.Blog.Web.Pages.Admin;
8+
using LinkDotNet.Blog.Web.Shared;
79
using LinkDotNet.Blog.Web.Shared.Services.Sitemap;
810
using Microsoft.Extensions.DependencyInjection;
911
using Moq;
@@ -53,4 +55,32 @@ public void ShouldDisplaySitemap()
5355
row.Children.First().InnerHtml.Should().Be("loc");
5456
row.Children.Last().InnerHtml.Should().Be("Now");
5557
}
58+
59+
[Fact]
60+
public void ShouldShowLoadingWhenGenerating()
61+
{
62+
this.AddTestAuthorization().SetAuthorized("steven");
63+
var sitemapMock = new Mock<ISitemapService>();
64+
Services.AddScoped(_ => sitemapMock.Object);
65+
var sitemap = new SitemapUrlSet
66+
{
67+
Urls = new List<SitemapUrl>
68+
{
69+
new() { Location = "loc", LastModified = "Now" },
70+
},
71+
};
72+
sitemapMock.Setup(s => s.CreateSitemapAsync())
73+
.Returns(async () =>
74+
{
75+
await Task.Delay(1000);
76+
return sitemap;
77+
});
78+
var cut = RenderComponent<Sitemap>();
79+
80+
cut.Find("button").Click();
81+
82+
cut.FindComponents<Loading>().Count.Should().Be(1);
83+
var btn = cut.Find("button");
84+
btn.Attributes.Any(a => a.Name == "disabled").Should().BeTrue();
85+
}
5686
}

LinkDotNet.Blog.Web/Pages/Admin/Sitemap.razor

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
important pages. Especially newer sites benefit from having a sitemap.xml.
99
The file will be created at the root of the site. To see the sitemap.xml go here: <a href="/sitemap.xml">sitemap.xml</a>.<br/>
1010
If you get a 404 there is currently no sitemap.xml</p>
11-
<button class="btn btn-primary" @onclick="CreateSitemap">Create Sitemap</button>
11+
<button class="btn btn-primary" @onclick="CreateSitemap" disabled="@isGenerating">Create Sitemap</button>
1212

13+
@if (isGenerating)
14+
{
15+
<Loading></Loading>
16+
}
1317
@if (sitemapUrlSet != null)
1418
{
1519
<table class="table table-striped table-hover h-50">
@@ -34,10 +38,13 @@
3438

3539
@code {
3640
private SitemapUrlSet sitemapUrlSet;
41+
private bool isGenerating;
3742

3843
private async Task CreateSitemap()
3944
{
45+
isGenerating = true;
4046
sitemapUrlSet = await sitemapService.CreateSitemapAsync();
47+
isGenerating = false;
4148
await sitemapService.SaveSitemapToFileAsync(sitemapUrlSet);
4249
}
4350
}

0 commit comments

Comments
 (0)