Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework problem details exceptions on edge devices views #809

Merged
merged 19 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
10f792b
Remove unused code on EdgeDeviceClientService.GetEdgeDeviceLogs
hocinehacherouf Jun 15, 2022
9ba0ee3
Rework pb details exceptions on Edge delete confirmation #790
hocinehacherouf Jun 15, 2022
e6eaadd
Rework pb details exceptions on Edge details #790
hocinehacherouf Jun 15, 2022
6225cc8
Rework pb details exceptions on Edge module logs #790
hocinehacherouf Jun 15, 2022
5aeecc4
Rework pb details exceptions on Edge listing #790
hocinehacherouf Jun 15, 2022
10107cc
Rework pb details exceptions on Edge create #790
hocinehacherouf Jun 15, 2022
71b38ad
Rework pb details exceptions on Edge connection string #790
hocinehacherouf Jun 15, 2022
fb61167
Fix ut GetEdgeDeviceLogsMustThrowProblemDetailsExceptionWhenErrorOccurs
hocinehacherouf Jun 15, 2022
4402c8a
Fix ut ClickOnSaveShouldDisplaySnackbarIfUnexpectedError
hocinehacherouf Jun 15, 2022
f1a7fcd
Fix ut ClickOnSaveShouldDisplaySnackbarIfValidationError
hocinehacherouf Jun 15, 2022
87fb739
Update unit test on ModuleLogsDialog
hocinehacherouf Jun 15, 2022
3253eb0
Add unit tests on EdgeDeviceDeleteConfirmationDialog
hocinehacherouf Jun 15, 2022
a3dbd19
Fix http mockups
hocinehacherouf Jun 16, 2022
af5c86f
Add unit tests on ConnectionStringDialog for edge
hocinehacherouf Jun 16, 2022
6ad0e5f
Add unit tests on EdgeDeviceListPage
hocinehacherouf Jun 16, 2022
d97b516
Add unit tests on CreateEdgeDeviceDialog
hocinehacherouf Jun 16, 2022
903cb3f
Add unit tests on EdgeDeviceDetailPage
hocinehacherouf Jun 16, 2022
f2d4f4f
Merge branch 'main' into feature/790_rework_pb_details_on_edge_device…
hocinehacherouf Jun 16, 2022
1c74799
Merge branch 'main' into feature/790_rework_pb_details_on_edge_device…
hocinehacherouf Jun 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// Copyright (c) CGI France. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace AzureIoTHub.Portal.Server.Tests.Unit.Pages.Edge_Devices
{
using System;
using System.Net.Http;
using System.Threading.Tasks;
using AzureIoTHub.Portal.Client.Pages.Edge_Devices;
using Models.v10;
using Bunit;
using Client.Exceptions;
using Client.Models;
using Client.Services;
using FluentAssertions;
using Helpers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.JSInterop;
using Moq;
using MudBlazor;
using MudBlazor.Interop;
using MudBlazor.Services;
using NUnit.Framework;
using RichardSzalay.MockHttp;

[TestFixture]
public class ConnectionStringDialogTests : TestContextWrapper, IDisposable
{
private MockHttpMessageHandler mockHttpClient;
private DialogService dialogService;
private MockRepository mockRepository;
private Mock<IJSRuntime> mockJSRuntime;

[SetUp]
public void Setup()
{
TestContext = new Bunit.TestContext();
_ = TestContext.Services.AddMudServices();
this.mockHttpClient = TestContext.Services.AddMockHttpClient();
_ = TestContext.Services.AddSingleton(new PortalSettings { IsLoRaSupported = false });

this.mockRepository = new MockRepository(MockBehavior.Strict);
this.mockJSRuntime = this.mockRepository.Create<IJSRuntime>();
_ = TestContext.Services.AddSingleton(new ClipboardService(this.mockJSRuntime.Object));

this.mockHttpClient.AutoFlush = true;

_ = TestContext.JSInterop.Setup<BoundingClientRect>("mudElementRef.getBoundingClientRect", _ => true);
_ = TestContext.JSInterop.SetupVoid("mudPopover.connect", _ => true);
_ = TestContext.JSInterop.SetupVoid("mudElementRef.saveFocus", _ => true);

this.dialogService = TestContext.Services.GetService<IDialogService>() as DialogService;
}

[TearDown]
public void TearDown() => TestContext?.Dispose();

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
}

[Test]
public async Task ConnectionStringDialogMustShowEnrollmentCredentials()
{
// Arrange
var deviceId = Guid.NewGuid().ToString();

_ = this.mockHttpClient
.When(HttpMethod.Get, $"/api/edge/devices/{deviceId}/credentials")
.RespondJson(new EnrollmentCredentials());

var cut = RenderComponent<MudDialogProvider>();

var parameters = new DialogParameters
{
{
"deviceId", deviceId
}
};

// Act
await cut.InvokeAsync(() => this.dialogService?.Show<ConnectionStringDialog>(string.Empty, parameters));
_ = cut.WaitForElement("div.mud-paper");

// Assert
_ = cut.FindAll("div.mud-grid-item").Count.Should().Be(4);
this.mockHttpClient.VerifyNoOutstandingRequest();
this.mockHttpClient.VerifyNoOutstandingExpectation();
}

[Test]
public async Task ConnectionStringDialogMustBeCancelledWhenProblemDetailsOccurs()
{
// Arrange
var deviceId = Guid.NewGuid().ToString();

_ = this.mockHttpClient
.When(HttpMethod.Get, $"/api/edge/devices/{deviceId}/credentials")
.Throw(new ProblemDetailsException(new ProblemDetailsWithExceptionDetails()));

var cut = RenderComponent<MudDialogProvider>();

var parameters = new DialogParameters
{
{
"deviceId", deviceId
}
};

IDialogReference dialogReference = null;

// Act
await cut.InvokeAsync(() => dialogReference = this.dialogService?.Show<ConnectionStringDialog>(string.Empty, parameters));
var result = await dialogReference.Result;

// Assert
_ = result.Cancelled.Should().BeTrue();
this.mockHttpClient.VerifyNoOutstandingRequest();
this.mockHttpClient.VerifyNoOutstandingExpectation();
}

[Test]
public async Task ConnectionStringDialogMustBeCancelledOnClickOnCancel()
{
// Arrange
var deviceId = Guid.NewGuid().ToString();

_ = this.mockHttpClient
.When(HttpMethod.Get, $"api/devices/{deviceId}/credentials")
.RespondJson(new EnrollmentCredentials());

var cut = RenderComponent<MudDialogProvider>();

var parameters = new DialogParameters
{
{
"deviceId", deviceId
}
};

IDialogReference dialogReference = null;

// Act
await cut.InvokeAsync(() => dialogReference = this.dialogService?.Show<ConnectionStringDialog>(string.Empty, parameters));
cut.Find("#cancel").Click();
var result = await dialogReference.Result;

// Assert
_ = result.Cancelled.Should().BeTrue();
this.mockHttpClient.VerifyNoOutstandingRequest();
this.mockHttpClient.VerifyNoOutstandingExpectation();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright (c) CGI France. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace AzureIoTHub.Portal.Server.Tests.Unit.Pages.Edge_Devices
{
using System;
using System.Threading.Tasks;
using AzureIoTHub.Portal.Client.Pages.Edge_Devices;
using Models.v10;
using Bunit;
using Client.Services;
using FluentAssertions;
using Helpers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.JSInterop;
using Moq;
using MudBlazor;
using MudBlazor.Interop;
using MudBlazor.Services;
using NUnit.Framework;
using RichardSzalay.MockHttp;

[TestFixture]
public class CreateEdgeDeviceDialogTests : TestContextWrapper, IDisposable
{
private MockHttpMessageHandler mockHttpClient;
private MockRepository mockRepository;
private Mock<IJSRuntime> mockJsRuntime;
private DialogService dialogService;

[SetUp]
public void Setup()
{
TestContext = new Bunit.TestContext();
_ = TestContext.Services.AddMudServices();
this.mockHttpClient = TestContext.Services.AddMockHttpClient();
_ = TestContext.Services.AddSingleton(new PortalSettings { IsLoRaSupported = false });

this.mockRepository = new MockRepository(MockBehavior.Strict);
this.mockJsRuntime = this.mockRepository.Create<IJSRuntime>();
_ = TestContext.Services.AddSingleton(new ClipboardService(this.mockJsRuntime.Object));

this.mockHttpClient.AutoFlush = true;

_ = TestContext.JSInterop.Setup<BoundingClientRect>("mudElementRef.getBoundingClientRect", _ => true);
_ = TestContext.JSInterop.SetupVoid("mudKeyInterceptor.connect", _ => true);
_ = TestContext.JSInterop.SetupVoid("mudPopover.connect", _ => true);
_ = TestContext.JSInterop.SetupVoid("mudElementRef.saveFocus", _ => true);

this.dialogService = TestContext.Services.GetService<IDialogService>() as DialogService;
}

[TearDown]
public void TearDown() => TestContext?.Dispose();

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
}

[Test]
public async Task CreateEdgeDeviceDialogMustRenderCorrectly()
{
// Arrange
var cut = RenderComponent<MudDialogProvider>();

var parameters = new DialogParameters();

// Act
await cut.InvokeAsync(() => this.dialogService?.Show<CreateEdgeDeviceDialog>(string.Empty, parameters));
_ = cut.WaitForElement("div.mud-paper");

// Assert
_ = cut.FindAll("#name").Count.Should().Be(1);
_ = cut.FindAll("#type").Count.Should().Be(1);
_ = cut.FindAll("#environment").Count.Should().Be(1);
_ = cut.FindAll("#cancel").Count.Should().Be(1);
_ = cut.FindAll("#create").Count.Should().Be(1);
}

[Test]
public async Task CreateEdgeDeviceDialogMustBeCancelledOnClickOnCancel()
{
// Arrange
var cut = RenderComponent<MudDialogProvider>();

var parameters = new DialogParameters();

IDialogReference dialogReference = null;

// Act
await cut.InvokeAsync(() => dialogReference = this.dialogService?.Show<CreateEdgeDeviceDialog>(string.Empty, parameters));
_ = cut.WaitForElement("div.mud-paper");
cut.Find("#cancel").Click();
var result = await dialogReference.Result;

// Assert
_ = result.Cancelled.Should().BeTrue();
}
}
}
Loading