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

Fix Device Model list page loading since portal settings changes #452

Merged
merged 1 commit into from
Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -7,6 +7,7 @@ namespace AzureIoTHub.Portal.Server.Tests.Unit.Pages
using System.Net.Http;
using AzureIoTHub.Portal.Client.Pages.DeviceModels;
using AzureIoTHub.Portal.Server.Tests.Unit.Helpers;
using AzureIoTHub.Portal.Shared.Models.V10;
using AzureIoTHub.Portal.Shared.Models.V10.DeviceModel;
using Bunit;
using Bunit.TestDoubles;
Expand All @@ -26,11 +27,9 @@ public class DeviceModelListPageTests : IDisposable

private MockRepository mockRepository;
private Mock<IDialogService> mockDialogService;
private FakeNavigationManager mockNavigationManager;
private MockHttpMessageHandler mockHttpClient;

private readonly string apiBaseUrl = "/api/models";
private readonly string apiSettingsBaseUrl = "/api/settings/lora";

[SetUp]
public void SetUp()
Expand All @@ -49,8 +48,6 @@ public void SetUp()
_ = testContext.JSInterop.SetupVoid("mudKeyInterceptor.connect", _ => true);
_ = testContext.JSInterop.SetupVoid("mudPopover.connect", _ => true);
_ = testContext.JSInterop.Setup<BoundingClientRect>("mudElementRef.getBoundingClientRect", _ => true);

mockNavigationManager = testContext.Services.GetRequiredService<FakeNavigationManager>();
}

private IRenderedComponent<TComponent> RenderComponent<TComponent>(params ComponentParameter[] parameters)
Expand All @@ -69,9 +66,7 @@ public void WhenLoraFeatureEnableDeviceDetailLinkShouldContainLora()
.When(HttpMethod.Get, apiBaseUrl)
.RespondJson(new DeviceModel[] { new DeviceModel { ModelId = deviceId, SupportLoRaFeatures = true } });

_ = this.mockHttpClient
.When(HttpMethod.Get, apiSettingsBaseUrl)
.RespondJson(true);
_ = testContext.Services.AddSingleton(new PortalSettings { IsLoRaSupported = true });

var cut = RenderComponent<DeviceModelListPage>();
_ = cut.WaitForElements(".detail-link");
Expand All @@ -97,9 +92,7 @@ public void WhenLoraFeatureDisableDeviceDetailLinkShouldNotContainLora()
.When(HttpMethod.Get, apiBaseUrl)
.RespondJson(new DeviceModel[] { new DeviceModel { ModelId = deviceId, SupportLoRaFeatures = true } });

_ = this.mockHttpClient
.When(HttpMethod.Get, apiSettingsBaseUrl)
.RespondJson(false);
_ = testContext.Services.AddSingleton(new PortalSettings { IsLoRaSupported = false });

var cut = RenderComponent<DeviceModelListPage>();
_ = cut.WaitForElements(".detail-link");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@page "/device-models"
@using AzureIoTHub.Portal.Shared.Models.V10
@using AzureIoTHub.Portal.Shared.Models.V10.DeviceModel
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
Expand All @@ -10,6 +11,7 @@
@attribute [Authorize]
@inject HttpClient httpClient
@inject NavigationManager navigationManager
@inject PortalSettings Portal
@inject ISnackbar snackBar
@inject IDialogService dialogService

Expand Down Expand Up @@ -51,13 +53,13 @@
<img height="25" src="@context.ImageUrl" />
</MudTd>
<MudTd DataLabel="Name" Style="word-break: break-all;">
<a class="detail-link" href=@($"device-models/{@context.ModelId}{((@context.SupportLoRaFeatures && isLoraEnable) ? "?isLora=true": "")}")>@context.Name</a>
<a class="detail-link" href=@($"device-models/{@context.ModelId}{((@context.SupportLoRaFeatures && Portal.IsLoRaSupported) ? "?isLora=true": "")}")>@context.Name</a>
</MudTd>
<MudTd DataLabel="Description" Style="word-break: break-all; ">
@context.Description
</MudTd>
<MudTd DataLabel="Details" Style="text-align: center">
<a class="detail-link" href="@($"device-models/{@context.ModelId}{((@context.SupportLoRaFeatures && isLoraEnable) ? "?isLora=true": "")}")"><MudIconButton Icon="@Icons.Filled.Visibility" Color="Color.Default" /></a>
<a class="detail-link" href="@($"device-models/{@context.ModelId}{((@context.SupportLoRaFeatures && Portal.IsLoRaSupported) ? "?isLora=true": "")}")"><MudIconButton Icon="@Icons.Filled.Visibility" Color="Color.Default" /></a>
</MudTd>
<MudTd DataLabel="Delete" Style="text-align: center">
<MudIconButton Color="Color.Default" Disabled="context.IsBuiltin" Icon="@Icons.Material.Filled.Delete" Size="Size.Medium" OnClick="@(e => DeleteDeviceModel(context))"></MudIconButton>
Expand All @@ -78,11 +80,9 @@
@code {
private DeviceModel[] result;
private int[] pageSizeOptions = new int[] { 2, 5, 10 };
private bool isLoraEnable;

protected override async Task OnInitializedAsync()
{
isLoraEnable = await this.httpClient.GetFromJsonAsync<bool>("api/settings/lora");
await LoadDeviceModels();
}

Expand Down Expand Up @@ -122,4 +122,4 @@
// Update the list of devices after the deletion
await LoadDeviceModels();
}
}
}