chore: some tests

This commit is contained in:
Mikhail Shabanov committed 2021-05-19 16:32:11 +02:00
1 parent a7f9ce19ac
commit 85ed224769
3 files changed
+57 -3

No files matched your search

@@ -3,12 +3,14 @@ using Bunit;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using Radzen;
using WotBlitzStatisticsPro.Blazor.Messages;
using WotBlitzStatisticsPro.Blazor.Model;
using WotBlitzStatisticsPro.Blazor.Shared;
namespace WotBlitzStatisticsPro.Blazor.Tests.Pages
{
public class MainLayoutTest: TestContextBase
public class MainLayoutTest : TestContextBase
{
private IRenderedComponent<MainLayout> _component;
@@ -45,9 +47,34 @@ By.css('.parent .child') // get child who has a parent
{
elements[i].Click();
MediatorMock.Verify(m => m.Publish(
It.Is<ChangeCurrentCultureMessage>(m => m.CultureName == expectedLanguages[0]),
It.Is<ChangeCurrentCultureMessage>(m => m.CultureName == expectedLanguages[0]),
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);
}
[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]
public void TearDown() => _testContext?.Dispose();
@@ -1,11 +1,17 @@
using System;
using Microsoft.JSInterop;
using WotBlitzStatisticsPro.Blazor.Model;
namespace WotBlitzStatisticsPro.Blazor.Services
{
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;
@@ -21,6 +27,7 @@ namespace WotBlitzStatisticsPro.Blazor.Services
Message = message;
Summary = summary;
MessageArrived?.Invoke();
_jsRuntime.InvokeVoidAsync("console.log", summary, message);
}
public void ReportWarning(string summary, string message)
@@ -29,6 +36,7 @@ namespace WotBlitzStatisticsPro.Blazor.Services
Message = message;
Summary = summary;
MessageArrived?.Invoke();
_jsRuntime.InvokeVoidAsync("console.warn", summary, message);
}
public void ReportError(string summary, string message)
@@ -37,6 +45,7 @@ namespace WotBlitzStatisticsPro.Blazor.Services
Message = message;
Summary = summary;
MessageArrived?.Invoke();
_jsRuntime.InvokeVoidAsync("console.error", summary, message);
}
}
}