mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-21 02:17:20 +02:00
feat: added login/out buttons to nav menu and index page
This commit is contained in:
1 parent
6cbb809f44
commit
6390c454d0
8 files changed
+190
-6
No files matched your search
@@ -1,22 +1,28 @@
|
||||
using System.Threading;
|
||||
using Bunit;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Radzen;
|
||||
using WotBlitzStatisticsPro.Blazor.Messages;
|
||||
using WotBlitzStatisticsPro.Blazor.Model;
|
||||
using WotBlitzStatisticsPro.Blazor.Services;
|
||||
using WotBlitzStatisticsPro.Blazor.Shared;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Blazor.Tests.Pages
|
||||
{
|
||||
public class MainLayoutTest : TestContextBase
|
||||
{
|
||||
private Mock<ILocalStorageService> _localStorageServiceMock;
|
||||
private IRenderedComponent<MainLayout> _component;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_localStorageServiceMock = new();
|
||||
TestContext?.Services.AddSingleton(_localStorageServiceMock.Object);
|
||||
|
||||
_component = TestContext?.RenderComponent<MainLayout>();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,12 @@ using System.Threading;
|
||||
using AngleSharp.Dom;
|
||||
using Bunit;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using WotBlitzStatisticsPro.Blazor.Messages;
|
||||
using WotBlitzStatisticsPro.Blazor.Model;
|
||||
using WotBlitzStatisticsPro.Blazor.Services;
|
||||
using WotBlitzStatisticsPro.Blazor.Shared;
|
||||
using Index = WotBlitzStatisticsPro.Blazor.Pages.Index;
|
||||
|
||||
@@ -25,10 +27,17 @@ namespace WotBlitzStatisticsPro.Blazor.Tests.Pages
|
||||
private IRenderedComponent<Index> _indexComponent;
|
||||
private IRefreshableElementCollection<IElement> _indexButtons;
|
||||
|
||||
private LoginInfo _loginInfo;
|
||||
private Mock<ILocalStorageService> _localStorageServiceMock;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_loginInfo = new LoginInfo { NickName = "Fake_Nick", AccountId = 123456789 };
|
||||
_localStorageServiceMock = new();
|
||||
|
||||
TestContext?.Services.AddSingleton(_localStorageServiceMock.Object);
|
||||
|
||||
_navMenuComponent = TestContext?.RenderComponent<NavMenu>();
|
||||
_indexComponent = TestContext?.RenderComponent<Index>();
|
||||
|
||||
@@ -104,5 +113,112 @@ namespace WotBlitzStatisticsPro.Blazor.Tests.Pages
|
||||
|
||||
}
|
||||
|
||||
[TestCase(ComponentType.NavMenu)]
|
||||
[TestCase(ComponentType.Index)]
|
||||
public void ShouldShowLoginItemAndHideNickIfLoginInfoIsMissing(ComponentType componentType)
|
||||
{
|
||||
switch (componentType)
|
||||
{
|
||||
case ComponentType.NavMenu:
|
||||
_navMenuElements.Should().Contain(e => e.InnerHtml.Contains("Login with WG.net ID"));
|
||||
_navMenuElements.Should().NotContain(e => e.InnerHtml.Contains(_loginInfo.NickName));
|
||||
_navMenuElements.Should().NotContain(e => e.InnerHtml.Contains("Log out"));
|
||||
break;
|
||||
case ComponentType.Index:
|
||||
_indexButtons.Should().Contain(e => e.InnerHtml.Contains("Login with WG.net ID"));
|
||||
_indexButtons.Should().NotContain(e => e.InnerHtml.Contains(_loginInfo.NickName));
|
||||
_indexButtons.Should().NotContain(e => e.InnerHtml.Contains("Log out"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase(ComponentType.NavMenu)]
|
||||
[TestCase(ComponentType.Index)]
|
||||
public void ShouldShowNickItemAndHideLoginIfLoginInfoIsPresent(ComponentType componentType)
|
||||
{
|
||||
_localStorageServiceMock.Setup(s => s.GetItemAsync<LoginInfo>(It.IsAny<string>())).ReturnsAsync(_loginInfo);
|
||||
|
||||
switch (componentType)
|
||||
{
|
||||
case ComponentType.NavMenu:
|
||||
var navMenuComponent = TestContext?.RenderComponent<NavMenu>();
|
||||
var navMenuElements = navMenuComponent?.FindAll(".rz-navigation-item");
|
||||
navMenuElements.Should().NotBeNull();
|
||||
navMenuElements.Count.Should().Be(5);
|
||||
navMenuElements.Should().NotContain(e => e.InnerHtml.Contains("Login with WG.net ID"));
|
||||
navMenuElements.Should().Contain(e => e.InnerHtml.Contains(_loginInfo.NickName));
|
||||
navMenuElements.Should().Contain(e => e.InnerHtml.Contains("Log out"));
|
||||
break;
|
||||
case ComponentType.Index:
|
||||
var indexComponent = TestContext?.RenderComponent<Index>();
|
||||
var indexButtons = indexComponent?.FindAll(".rz-button");
|
||||
indexButtons.Should().NotBeNull();
|
||||
indexButtons.Count.Should().Be(4);
|
||||
indexButtons.Should().NotContain(e => e.InnerHtml.Contains("Login with WG.net ID"));
|
||||
indexButtons.Should().Contain(e => e.InnerHtml.Contains(_loginInfo.NickName));
|
||||
indexButtons.Should().Contain(e => e.InnerHtml.Contains("Log out"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase(ComponentType.NavMenu)]
|
||||
[TestCase(ComponentType.Index)]
|
||||
public void ShouldFireOpenPlayerMessageWhenNickItemClicked(ComponentType componentType)
|
||||
{
|
||||
_localStorageServiceMock.Setup(s => s.GetItemAsync<LoginInfo>(It.IsAny<string>())).ReturnsAsync(_loginInfo);
|
||||
|
||||
IElement targetElement = null;
|
||||
|
||||
switch (componentType)
|
||||
{
|
||||
case ComponentType.NavMenu:
|
||||
var navMenuComponent = TestContext?.RenderComponent<NavMenu>();
|
||||
var navMenuElements = navMenuComponent?.FindAll(".rz-navigation-item");
|
||||
targetElement = navMenuElements[1];
|
||||
break;
|
||||
case ComponentType.Index:
|
||||
var indexComponent = TestContext?.RenderComponent<Index>();
|
||||
var indexButtons = indexComponent?.FindAll(".rz-button");
|
||||
targetElement = indexButtons[0];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
targetElement?.Click();
|
||||
|
||||
MediatorMock.Verify(m => m.Publish(
|
||||
It.Is<OpenPlayerInfoMessage>(m => m.AccountId == _loginInfo.AccountId && m.IsLoggedIn),
|
||||
It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
|
||||
[TestCase(ComponentType.NavMenu)]
|
||||
[TestCase(ComponentType.Index)]
|
||||
public void ShouldFireLoGoutMessageIfLogOutItemClicked(ComponentType componentType)
|
||||
{
|
||||
_localStorageServiceMock.Setup(s => s.GetItemAsync<LoginInfo>(It.IsAny<string>())).ReturnsAsync(_loginInfo);
|
||||
|
||||
IElement targetElement = null;
|
||||
|
||||
switch (componentType)
|
||||
{
|
||||
case ComponentType.NavMenu:
|
||||
var navMenuComponent = TestContext?.RenderComponent<NavMenu>();
|
||||
var navMenuElements = navMenuComponent?.FindAll(".rz-navigation-item");
|
||||
targetElement = navMenuElements[2];
|
||||
break;
|
||||
case ComponentType.Index:
|
||||
var indexComponent = TestContext?.RenderComponent<Index>();
|
||||
var indexButtons = indexComponent?.FindAll(".rz-button");
|
||||
targetElement = indexButtons[1];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
targetElement?.Click();
|
||||
|
||||
MediatorMock.Verify(m => m.Publish(
|
||||
It.IsAny<LogOutFromWgMessage>(),
|
||||
It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user