Skip to content

Commit

Permalink
Add missing pagination on concentrators #899 (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
hocinehacherouf authored Jul 25, 2022
1 parent a5641a8 commit 2d9b3ca
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class LoRaWANConcentratorsControllerTest
private Mock<IDeviceService> mockDeviceService;
private Mock<IRouterConfigManager> mockRouterConfigManager;
private Mock<IConcentratorTwinMapper> mockConcentratorTwinMapper;
private Mock<ConfigHandler> mockConfigHandler;
private Mock<IUrlHelper> mockUrlHelper;

[SetUp]
Expand All @@ -43,7 +42,6 @@ public void SetUp()
this.mockDeviceService = this.mockRepository.Create<IDeviceService>();
this.mockRouterConfigManager = this.mockRepository.Create<IRouterConfigManager>();
this.mockConcentratorTwinMapper = this.mockRepository.Create<IConcentratorTwinMapper>();
this.mockConfigHandler = this.mockRepository.Create<ConfigHandler>();
this.mockUrlHelper = this.mockRepository.Create<IUrlHelper>();
}

Expand Down Expand Up @@ -303,10 +301,6 @@ public async Task WhenDeviceAlreadyExistCreateDeviceAsyncWithValidArgumentShould
};

var routerConfig = new RouterConfig();
var mockResult = new BulkRegistryOperationResult
{
IsSuccessful = true
};

var twin = new Twin
{
Expand Down Expand Up @@ -402,8 +396,6 @@ public async Task WhenGetDeviceThrowAnErrorUpdateDeviceAsyncWithValidArgumentSho
DeviceId = concentrator.DeviceId,
};

var device = new Device(concentrator.DeviceId);

_ = this.mockDeviceService.Setup(x => x.GetDevice(It.Is<string>(c => c == concentrator.DeviceId)))
.ThrowsAsync(new InternalServerErrorException(""));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,34 @@ public void ClickToItemShouldRedirectToConcentratorDetailsPage()
// Assert
cut.WaitForAssertion(() => Services.GetService<FakeNavigationManager>()?.Uri.Should().EndWith($"/lorawan/concentrators/{deviceId}"));
}

[Test]
public void ClickOnAddNewDeviceShouldNavigateToNewDevicePage()
{
// Arrange
const string expectedUri = "api/lorawan/concentrators?pageSize=10";

_ = this.mockLoRaWanConcentratorsClientService.Setup(service =>
service.GetConcentrators(It.Is<string>(s => expectedUri.Equals(s, StringComparison.Ordinal))))
.ReturnsAsync(new PaginationResult<Concentrator>
{
Items = new List<Concentrator>
{
new(),
new(),
new()
}
});

// Act
var cut = RenderComponent<ConcentratorListPage>();
cut.WaitForAssertion(() => cut.Find("#concentrators-listing"));
cut.WaitForAssertion(() => cut.Markup.Should().NotContain("Loading..."));
cut.WaitForElement("#add-concentrator").Click();

// Assert
cut.WaitForAssertion(() => MockRepository.VerifyAll());
cut.WaitForAssertion(() => Services.GetService<FakeNavigationManager>()?.Uri.Should().EndWith("/lorawan/concentrators/new"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@attribute [Authorize]
@inject IDialogService DialogService
@inject NavigationManager navigationManager
@inject NavigationManager NavigationManager
@inject ILoRaWanConcentratorsClientService LoRaWanConcentratorsClientService

<MudGrid>
Expand All @@ -25,7 +25,7 @@
<MudIconButton Icon="@Icons.Material.Filled.Refresh" Size="Size.Medium" OnClick="Search" Class="ma-2"></MudIconButton>
</MudTooltip>
<MudTooltip Text="Add LoRaWAN concentrator">
<MudFab Color="Color.Secondary" Icon="@Icons.Material.Filled.Add" Size="Size.Medium" OnClick="AddDevice" />
<MudFab id="add-concentrator" Color="Color.Secondary" Icon="@Icons.Material.Filled.Add" Size="Size.Medium" OnClick="AddDevice" />
</MudTooltip>
</ToolBarContent>
<HeaderContent>
Expand Down Expand Up @@ -99,7 +99,7 @@

private MudTable<Concentrator> table;

private Dictionary<int, string> Pages { get; set; } = new();
private Dictionary<int, string> Pages { get; } = new();

private bool IsLoading { get; set; } = true;

Expand Down Expand Up @@ -141,7 +141,7 @@

private void AddDevice()
{
navigationManager.NavigateTo("lorawan/concentrators/new");
NavigationManager.NavigateTo("lorawan/concentrators/new");
}

private async Task DeleteDevice(Concentrator device)
Expand All @@ -168,6 +168,6 @@

private void GoToDetails(Concentrator item)
{
navigationManager.NavigateTo($"/lorawan/concentrators/{item.DeviceId}");
NavigationManager.NavigateTo($"/lorawan/concentrators/{item.DeviceId}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace AzureIoTHub.Portal.Server.Controllers.V10.LoRaWAN
using System.Linq;
using System.Threading.Tasks;
using AzureIoTHub.Portal.Models.v10.LoRaWAN;
using AzureIoTHub.Portal.Server.Filters;
using AzureIoTHub.Portal.Server.Managers;
using AzureIoTHub.Portal.Server.Mappers;
using AzureIoTHub.Portal.Server.Services;
using Filters;
using Managers;
using Mappers;
using Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -72,10 +72,16 @@ public LoRaWANConcentratorsController(
/// </summary>
[HttpGet(Name = "GET LoRaWAN Concentrator list")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult<PaginationResult<Concentrator>>> GetAllDeviceConcentrator()
public async Task<ActionResult<PaginationResult<Concentrator>>> GetAllDeviceConcentrator(
string continuationToken = null,
int pageSize = 10)
{
// Gets all the twins from this devices
var result = await this.devicesService.GetAllDevice(filterDeviceType: "LoRa Concentrator");
var result = await this.devicesService.GetAllDevice(
continuationToken: continuationToken,
filterDeviceType: "LoRa Concentrator",
pageSize: pageSize);

string nextPage = null;

if (!string.IsNullOrEmpty(result.NextPage))
Expand Down

0 comments on commit 2d9b3ca

Please sign in to comment.