Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Sep 10, 2021
1 parent 5d50916 commit 1ab424f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions LinkDotNet.Blog.UnitTests/Web/Shared/LikeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,24 @@ public void ShouldSetLocalStorageVariableOnClick()
var localStorage = new Mock<ILocalStorageService>();
Services.AddScoped(_ => localStorage.Object);
var blogPost = new BlogPostBuilder().Build();
blogPost.Id = "id";
var cut = RenderComponent<Like>(
p => p.Add(l => l.BlogPost, blogPost));

cut.Find("button").Click();

localStorage.Verify(l => l.SetItemAsync("hasLiked", true, default), Times.Once);
localStorage.Verify(l => l.SetItemAsync("hasLiked/id", true, default), Times.Once);
}

[Fact]
public void ShouldCheckLocalStorageOnInit()
{
var localStorage = new Mock<ILocalStorageService>();
localStorage.Setup(l => l.ContainKeyAsync("hasLiked", default)).ReturnsAsync(true);
localStorage.Setup(l => l.GetItemAsync<bool>("hasLiked", default)).ReturnsAsync(true);
localStorage.Setup(l => l.ContainKeyAsync("hasLiked/id", default)).ReturnsAsync(true);
localStorage.Setup(l => l.GetItemAsync<bool>("hasLiked/id", default)).ReturnsAsync(true);
Services.AddScoped(_ => localStorage.Object);
var blogPost = new BlogPostBuilder().Build();
blogPost.Id = "id";
var wasLike = true;
var cut = RenderComponent<Like>(
p => p.Add(l => l.BlogPost, blogPost)
Expand All @@ -86,12 +88,13 @@ public void ShouldCheckStorageOnClickAgainAndDoNothingOnMismatch()
var localStorage = new Mock<ILocalStorageService>();
Services.AddScoped(_ => localStorage.Object);
var blogPost = new BlogPostBuilder().Build();
blogPost.Id = "id";
var wasClicked = false;
var cut = RenderComponent<Like>(
p => p.Add(l => l.BlogPost, blogPost)
.Add(l => l.OnBlogPostLiked, _ => wasClicked = true));
localStorage.Setup(l => l.ContainKeyAsync("hasLiked", default)).ReturnsAsync(true);
localStorage.Setup(l => l.GetItemAsync<bool>("hasLiked", default)).ReturnsAsync(true);
localStorage.Setup(l => l.ContainKeyAsync("hasLiked/id", default)).ReturnsAsync(true);
localStorage.Setup(l => l.GetItemAsync<bool>("hasLiked/id", default)).ReturnsAsync(true);

cut.Find("button").Click();

Expand Down

0 comments on commit 1ab424f

Please sign in to comment.