Skip to content

Commit

Permalink
Add refresh button on device tags #794 (#887)
Browse files Browse the repository at this point in the history
Add refresh button on device tags #794
  • Loading branch information
hocinehacherouf authored Jun 29, 2022
1 parent cf9fb68 commit 0a4e046
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,40 @@ public void DeviceListPageRendersCorrectly()
cut.WaitForAssertion(() => MockRepository.VerifyAll());
}

[Test]
public void OnclickOnReloadShouldReloadTags()
{
// Arrange
_ = MockHttpClient.When(HttpMethod.Get, $"{ApiBaseUrl}")
.Throw(new ProblemDetailsException(new ProblemDetailsWithExceptionDetails()));

var cut = RenderComponent<DeviceTagsPage>();

cut.WaitForAssertion(() => cut.Markup.Should().NotContain("Loading..."));
cut.WaitForAssertion(() => cut.Markup.Should().Contain("No matching records found"));

MockHttpClient.Clear();

_ = MockHttpClient.When(HttpMethod.Get, $"{ApiBaseUrl}")
.RespondJson(new List<DeviceTag>{
new(),
new(),
new()
});

// Act
cut.WaitForElement("#reload-tags").Click();

// Assert
cut.WaitForAssertion(() => cut.Markup.Should().NotContain("Loading..."));
cut.WaitForAssertion(() => cut.Markup.Should().NotContain("No matching records found"));
cut.WaitForAssertion(() => cut.FindAll("table tbody tr").Count.Should().Be(3));

cut.WaitForAssertion(() => MockHttpClient.VerifyNoOutstandingRequest());
cut.WaitForAssertion(() => MockHttpClient.VerifyNoOutstandingExpectation());
cut.WaitForAssertion(() => MockRepository.VerifyAll());
}

[Test]
public void OnInitializedAsyncShouldProcessProblemDetailsExceptionWhenIssueOccursOnGettingDeviceTags()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
@page "/settings/device-tag"
@using AzureIoTHub.Portal.Models.v10
@using System.ComponentModel.DataAnnotations
@using System.IO
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using AzureIoTHub.Portal.Client.Validators

@attribute [Authorize]
@inject HttpClient HttpClient
Expand All @@ -18,6 +13,9 @@
<ToolBarContent>
<MudText Typo="Typo.h6">Tags</MudText>
<MudSpacer />
<MudTooltip Text="Refresh list">
<MudIconButton id="reload-tags" Icon="@Icons.Material.Filled.Refresh" Size="Size.Medium" OnClick="LoadTags" Class="ma-2"></MudIconButton>
</MudTooltip>
</ToolBarContent>

<ColGroup>
Expand Down Expand Up @@ -88,11 +86,16 @@
private bool IsLoading { get; set; }

protected override async Task OnInitializedAsync()
{
await LoadTags();
}

private async Task LoadTags()
{
try
{
IsLoading = true;
Tags.AddRange(await HttpClient.GetFromJsonAsync<List<DeviceTag>>($"/api/settings/device-tags"));
Tags = await HttpClient.GetFromJsonAsync<List<DeviceTag>>("/api/settings/device-tags");
}
catch (ProblemDetailsException exception)
{
Expand All @@ -102,7 +105,6 @@
{
IsLoading = false;
}

}

private void AddTag()
Expand Down

0 comments on commit 0a4e046

Please sign in to comment.