Skip to content
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
13 changes: 8 additions & 5 deletions src/MqttProbe.UI/Components/Browser/BrowserPanel.razor
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@
protected override void OnInitialized()
{
_lastCount = MessageStoreManager.RootTopicCount;
_updateTimer = new Timer(_ =>
{
if (_disposed) return;
OnTimerTick();
}, null, 0, 1_000);
_updateTimer = CreateUpdateTimer();
}

protected virtual Timer? CreateUpdateTimer() => new Timer(_ =>
{
if (_disposed) return;
OnTimerTick();
}, null, 0, 1_000);

internal void OnTimerTick()
{
if (_disposed) return;
Expand Down Expand Up @@ -138,6 +140,7 @@
return;

await MessageStoreManager.ClearAllMessages();
_lastCount = MessageStoreManager.RootTopicCount;
Snackbar.Add("All stored messages cleared.", Severity.Success);
}

Expand Down
44 changes: 44 additions & 0 deletions tests/MqttProbe.UI.Tests/Components/Browser/BrowserPanelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,45 @@ public async Task ClearMessages_AfterClear_DisablesButtonOnNextTick()
});
}

[Test]
public async Task ClearMessages_AfterClear_WhenTrafficRestoresCount_ReenablesButtonOnNextTick()
{
var rootCount = 1;
_mockMsgStore.RootTopicCount.Returns(_ => rootCount);

_mockDialogService.ShowMessageBoxAsync(
Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(),
Arg.Any<string>(), Arg.Any<string>(), Arg.Any<DialogOptions>())
.Returns(Task.FromResult<bool?>(true));

_mockMsgStore.ClearAllMessages().Returns(Task.CompletedTask)
.AndDoes(_ => rootCount = 0);

var cut = Render<BrowserPanelWithoutUpdateTimer>();

cut.FindAll("button").First(b => b.TextContent.Contains("Clear"))
.HasAttribute("disabled").Should().BeFalse();
cut.FindAll(".mud-chip").Should().HaveCount(1);

await cut.InvokeAsync(() => cut.FindAll("button")
.First(b => b.TextContent.Contains("Clear")).Click());

cut.FindAll("button").First(b => b.TextContent.Contains("Clear"))
.HasAttribute("disabled").Should().BeTrue();
cut.FindAll(".mud-chip").Should().BeEmpty();

rootCount = 1;
cut.Instance.OnTimerTick();

cut.WaitForAssertion(() =>
{
cut.FindAll("button")
.First(b => b.TextContent.Contains("Clear"))
.HasAttribute("disabled").Should().BeFalse();
cut.FindAll(".mud-chip").Should().HaveCount(1);
});
}

[Test]
public void BrowserHint_WhenNoStoresAndNotDismissed_IsVisible()
{
Expand Down Expand Up @@ -220,4 +259,9 @@ public void MobilePicker_OpensAndCloses()

cut.Markup.Should().NotContain("topic-picker-overlay__panel");
}

private sealed class BrowserPanelWithoutUpdateTimer : BrowserPanel
{
protected override System.Threading.Timer? CreateUpdateTimer() => null;
}
}
Loading