Skip to content

Commit 983e7ae

Browse files
committed
Added Test for Sitemap
1 parent b3441c9 commit 983e7ae

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Bunit;
2+
using Bunit.TestDoubles;
3+
using LinkDotNet.Blog.Web.Pages.Admin;
4+
using LinkDotNet.Blog.Web.Shared.Services.Sitemap;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Moq;
7+
using Xunit;
8+
9+
namespace LinkDotNet.Blog.UnitTests.Web.Pages.Admin
10+
{
11+
public class SitemapTests : TestContext
12+
{
13+
[Fact]
14+
public void ShouldDisplayAndSaveSitemap()
15+
{
16+
this.AddTestAuthorization().SetAuthorized("steven");
17+
var sitemapMock = new Mock<ISitemapService>();
18+
Services.AddScoped(_ => sitemapMock.Object);
19+
var sitemap = new SitemapUrlSet();
20+
sitemapMock.Setup(s => s.CreateSitemapAsync())
21+
.ReturnsAsync(sitemap);
22+
var cut = RenderComponent<Sitemap>();
23+
24+
cut.Find("button").Click();
25+
26+
sitemapMock.Verify(s => s.SaveSitemapToFileAsync(sitemap));
27+
}
28+
}
29+
}

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@
22
@using LinkDotNet.Blog.Web.Shared.Services.Sitemap
33
@inject ISitemapService sitemapService
44
@attribute [Authorize]
5-
6-
<div class="row">
5+
<h3 xmlns="http://www.w3.org/1999/html">Sitemap</h3>
6+
<div class="row px-2">
7+
<p>A sitemap is a file which lists all important links in a webpage. It helps crawler to find all of the
8+
important pages. Especially newer sites benefit from having a sitemap.xml.
9+
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/>
10+
If you get a 404 there is currently no sitemap.xml</p>
711
<button class="btn btn-primary" @onclick="CreateSitemap">Create Sitemap</button>
812

913
@if (sitemapUrlSet != null)
1014
{
11-
<table class="table table-striped table-hover">
12-
<tbody>
15+
<table class="table table-striped table-hover h-50">
16+
<thead>
1317
<tr>
1418
<th>Url</th>
1519
<th>Last Changed</th>
1620
</tr>
21+
</thead>
22+
<tbody>
1723
@foreach (var url in sitemapUrlSet.Urls)
1824
{
1925
<tr>

0 commit comments

Comments
 (0)