File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
LinkDotNet.Blog.UnitTests/Web/Pages/Admin
LinkDotNet.Blog.Web/Pages/Admin Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 11using System . Collections . Generic ;
22using System . Linq ;
3+ using System . Threading . Tasks ;
34using Bunit ;
45using Bunit . TestDoubles ;
56using FluentAssertions ;
67using LinkDotNet . Blog . Web . Pages . Admin ;
8+ using LinkDotNet . Blog . Web . Shared ;
79using LinkDotNet . Blog . Web . Shared . Services . Sitemap ;
810using Microsoft . Extensions . DependencyInjection ;
911using 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}
Original file line number Diff line number Diff line change 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" >
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}
You can’t perform that action at this time.
0 commit comments