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

Add refresh button on device tags #794 #887

Merged
merged 2 commits into from
Jun 29, 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 @@ -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