mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-24 11:50:05 +02:00
chore: some tests
This commit is contained in:
1 parent
a7f9ce19ac
commit
85ed224769
3 files changed
+56
-2
No files matched your search
@@ -3,12 +3,14 @@ using Bunit;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using Radzen;
|
||||||
using WotBlitzStatisticsPro.Blazor.Messages;
|
using WotBlitzStatisticsPro.Blazor.Messages;
|
||||||
|
using WotBlitzStatisticsPro.Blazor.Model;
|
||||||
using WotBlitzStatisticsPro.Blazor.Shared;
|
using WotBlitzStatisticsPro.Blazor.Shared;
|
||||||
|
|
||||||
namespace WotBlitzStatisticsPro.Blazor.Tests.Pages
|
namespace WotBlitzStatisticsPro.Blazor.Tests.Pages
|
||||||
{
|
{
|
||||||
public class MainLayoutTest: TestContextBase
|
public class MainLayoutTest : TestContextBase
|
||||||
{
|
{
|
||||||
private IRenderedComponent<MainLayout> _component;
|
private IRenderedComponent<MainLayout> _component;
|
||||||
|
|
||||||
@@ -49,5 +51,30 @@ By.css('.parent .child') // get child who has a parent
|
|||||||
It.IsAny<CancellationToken>()), Times.Once);
|
It.IsAny<CancellationToken>()), Times.Once);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestCase(NotificationType.Info, NotificationSeverity.Info)]
|
||||||
|
[TestCase(NotificationType.Warning, NotificationSeverity.Warning)]
|
||||||
|
[TestCase(NotificationType.Error, NotificationSeverity.Error)]
|
||||||
|
public void ShouldEmitRadzenMessageWhenNotificationsServiceHasMessage(NotificationType notificationType, NotificationSeverity expectedSeverity)
|
||||||
|
{
|
||||||
|
string expectedSummary = "Foo";
|
||||||
|
string expectedMessage = "Bar";
|
||||||
|
|
||||||
|
NotificationsServiceMock.SetupGet(n => n.Type).Returns(notificationType);
|
||||||
|
NotificationsServiceMock.SetupGet(n => n.Summary).Returns(expectedSummary);
|
||||||
|
NotificationsServiceMock.SetupGet(n => n.Message).Returns(expectedMessage);
|
||||||
|
|
||||||
|
// Action
|
||||||
|
NotificationsServiceMock.Raise(n => n.MessageArrived += null);
|
||||||
|
|
||||||
|
var radzenNotification = TestContext?.Services.GetService<NotificationService>();
|
||||||
|
var msg = radzenNotification?.Messages;
|
||||||
|
msg.Should().NotBeNull();
|
||||||
|
msg?.Count.Should().Be(1);
|
||||||
|
|
||||||
|
msg?[0].Summary.Should().Be(expectedSummary);
|
||||||
|
msg?[0].Detail.Should().Be(expectedMessage);
|
||||||
|
msg?[0].Severity.Should().Be(expectedSeverity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,6 +58,24 @@ namespace WotBlitzStatisticsPro.Blazor.Tests.Services
|
|||||||
_navigationManagerMock.NavigationCount.Should().Be(1);
|
_navigationManagerMock.NavigationCount.Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ShouldInvokeJsLocalStorageSetWithAppropriateDataOnChangeCurrentRealm()
|
||||||
|
{
|
||||||
|
var expectedRealm = RealmType.Asia;
|
||||||
|
await _localStorageService.Handle(new ChangeCurrentRealmTypeMessage(expectedRealm), CancellationToken.None);
|
||||||
|
|
||||||
|
_jsRuntimeMock.Invocations.Count.Should().Be(2);
|
||||||
|
var jsInvocations = _jsRuntimeMock.Invocations.ToArray();
|
||||||
|
jsInvocations[0].Identifier.Should().Be("localStorage.getItem");
|
||||||
|
jsInvocations[1].Identifier.Should().Be("localStorage.setItem");
|
||||||
|
|
||||||
|
var args = jsInvocations[1].Arguments;
|
||||||
|
args.Should().NotBeNull();
|
||||||
|
args.Count.Should().Be(2);
|
||||||
|
args[0].Should().Be("user-settings");
|
||||||
|
args[1].Should().Be($"{{\"Culture\":\"en-US\",\"RealmType\":{(int)expectedRealm}}}");
|
||||||
|
}
|
||||||
|
|
||||||
[TearDown]
|
[TearDown]
|
||||||
public void TearDown() => _testContext?.Dispose();
|
public void TearDown() => _testContext?.Dispose();
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Microsoft.JSInterop;
|
||||||
using WotBlitzStatisticsPro.Blazor.Model;
|
using WotBlitzStatisticsPro.Blazor.Model;
|
||||||
|
|
||||||
namespace WotBlitzStatisticsPro.Blazor.Services
|
namespace WotBlitzStatisticsPro.Blazor.Services
|
||||||
{
|
{
|
||||||
public class NotificationsService: INotificationsService
|
public class NotificationsService: INotificationsService
|
||||||
{
|
{
|
||||||
// ToDo: Add JSInterop console.log
|
private readonly IJSRuntime _jsRuntime;
|
||||||
|
|
||||||
|
public NotificationsService(IJSRuntime jsRuntime)
|
||||||
|
{
|
||||||
|
_jsRuntime = jsRuntime;
|
||||||
|
}
|
||||||
|
|
||||||
public NotificationType Type { get; private set; } = NotificationType.Info;
|
public NotificationType Type { get; private set; } = NotificationType.Info;
|
||||||
|
|
||||||
@@ -21,6 +27,7 @@ namespace WotBlitzStatisticsPro.Blazor.Services
|
|||||||
Message = message;
|
Message = message;
|
||||||
Summary = summary;
|
Summary = summary;
|
||||||
MessageArrived?.Invoke();
|
MessageArrived?.Invoke();
|
||||||
|
_jsRuntime.InvokeVoidAsync("console.log", summary, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReportWarning(string summary, string message)
|
public void ReportWarning(string summary, string message)
|
||||||
@@ -29,6 +36,7 @@ namespace WotBlitzStatisticsPro.Blazor.Services
|
|||||||
Message = message;
|
Message = message;
|
||||||
Summary = summary;
|
Summary = summary;
|
||||||
MessageArrived?.Invoke();
|
MessageArrived?.Invoke();
|
||||||
|
_jsRuntime.InvokeVoidAsync("console.warn", summary, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReportError(string summary, string message)
|
public void ReportError(string summary, string message)
|
||||||
@@ -37,6 +45,7 @@ namespace WotBlitzStatisticsPro.Blazor.Services
|
|||||||
Message = message;
|
Message = message;
|
||||||
Summary = summary;
|
Summary = summary;
|
||||||
MessageArrived?.Invoke();
|
MessageArrived?.Invoke();
|
||||||
|
_jsRuntime.InvokeVoidAsync("console.error", summary, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user