Sort dashboard warnings by number of warning items (the largest warning tile first)

This commit is contained in:
danielbroll
2022-08-11 18:42:57 +02:00
committed by Carsten Otto
parent 12360b5641
commit a984cc7242
6 changed files with 65 additions and 13 deletions

View File

@@ -31,17 +31,15 @@ public class DemoWarningService extends WarningService {
public static final DashboardWarningDto POCKET_WARNING = new DashboardWarningDto(
POCKET.remoteAlias(),
POCKET.remotePubkey(),
List.of("No flow in the past 35 days.", "Rating of 182 is below threshold of 1,000"),
List.of()
List.of("Rating of 182 is below threshold of 1,000"),
List.of(new ChannelWarningDto(POCKET.channelId(), "Channel has accumulated 500,000 updates."))
);
public static final DashboardWarningDto BCASH_WARNING = new DashboardWarningDto(
B_CASH_IS_TRASH.remoteAlias(),
B_CASH_IS_TRASH.remotePubkey(),
List.of("Node has been online 66% in the past 14 days."),
List.of(new ChannelWarningDto(
B_CASH_IS_TRASH.channelId(), "Channel has accumulated 500,000 updates.")
)
List.of("Node has been online 66% in the past 14 days.", "No flow in the past 35 days."),
List.of()
);
public static final DashboardWarningDto TRY_BTC_WARNING = new DashboardWarningDto(

View File

@@ -11,4 +11,7 @@ public record DashboardWarningDto(
List<ChannelWarningDto> channelWarnings
) {
public int numberOfWarningItems() {
return nodeWarnings.size() + channelWarnings.size();
}
}

View File

@@ -8,6 +8,7 @@ import de.cotto.lndmanagej.ui.WarningService;
import de.cotto.lndmanagej.ui.controller.param.SortBy;
import de.cotto.lndmanagej.ui.dto.NodeDto;
import de.cotto.lndmanagej.ui.dto.OpenChannelDto;
import de.cotto.lndmanagej.ui.dto.warning.DashboardWarningDto;
import de.cotto.lndmanagej.ui.page.channel.ChannelDetailsPage;
import de.cotto.lndmanagej.ui.page.channel.ChannelsPage;
import de.cotto.lndmanagej.ui.page.general.DashboardPage;
@@ -39,10 +40,17 @@ public class PageService {
return new DashboardPage(
sortChannels(dataService.getOpenChannels(), sortBy),
sortNodes(dataService.createNodeList(), sortBy),
warningService.getWarnings()
sortWarnings(warningService.getWarnings())
);
}
private List<DashboardWarningDto> sortWarnings(List<DashboardWarningDto> warnings) {
return warnings.stream()
.sorted(Comparator.comparing(DashboardWarningDto::numberOfWarningItems)
.reversed().thenComparing(DashboardWarningDto::pubkey))
.toList();
}
public ChannelsPage channels(SortBy sortBy) {
return new ChannelsPage(sortChannels(dataService.getOpenChannels(), sortBy));
}

View File

@@ -30,4 +30,9 @@ class DashboardWarningDtoTest {
void channelWarnings() {
assertThat(DASHBOARD_WARNING.channelWarnings()).isEqualTo(List.of(CHANNEL_WARNING_DTO));
}
@Test
void getNumberOfWarnings() {
assertThat(DASHBOARD_WARNING.numberOfWarningItems()).isEqualTo(2);
}
}

View File

@@ -14,6 +14,7 @@ import de.cotto.lndmanagej.ui.dto.BalanceInformationModel;
import de.cotto.lndmanagej.ui.dto.ChannelDetailsDto;
import de.cotto.lndmanagej.ui.dto.NodeDto;
import de.cotto.lndmanagej.ui.dto.OpenChannelDto;
import de.cotto.lndmanagej.ui.dto.warning.DashboardWarningDto;
import de.cotto.lndmanagej.ui.page.channel.ChannelDetailsPage;
import de.cotto.lndmanagej.ui.page.channel.ChannelsPage;
import de.cotto.lndmanagej.ui.page.general.DashboardPage;
@@ -49,6 +50,9 @@ import static de.cotto.lndmanagej.ui.dto.OpenChannelDtoFixture.CAPACITY_SAT;
import static de.cotto.lndmanagej.ui.dto.OpenChannelDtoFixture.OPEN_CHANNEL_DTO;
import static de.cotto.lndmanagej.ui.dto.OpenChannelDtoFixture.OPEN_CHANNEL_DTO2;
import static de.cotto.lndmanagej.ui.dto.OpenChannelDtoFixture.UNANNOUNCED_CHANNEL;
import static de.cotto.lndmanagej.ui.dto.warning.DashboardWarningsFixture.DASHBOARD_WARNING;
import static de.cotto.lndmanagej.ui.dto.warning.DashboardWarningsFixture.DASHBOARD_WARNING_2;
import static de.cotto.lndmanagej.ui.dto.warning.DashboardWarningsFixture.DASHBOARD_WARNING_3;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
@@ -64,23 +68,36 @@ class PageServiceTest {
private WarningService warningService;
@Test
void dashboard() {
void dashboard_noWarnings() {
List<OpenChannelDto> channels = List.of(OPEN_CHANNEL_DTO);
List<NodeDto> nodes = List.of(NODE_DTO);
mockChannelsAndNodesWithoutWarning(channels, nodes);
mockChannelsAndNodesAndWarnings(channels, nodes, List.of());
assertThat(pageService.dashboard(SortBy.DEFAULT_SORT)).usingRecursiveComparison().isEqualTo(
new DashboardPage(channels, nodes, List.of())
);
}
@Test
void dashboard_withWarnings_sorted() {
List<OpenChannelDto> channels = List.of(OPEN_CHANNEL_DTO);
List<NodeDto> nodes = List.of(NODE_DTO);
List<DashboardWarningDto> warnings = List.of(DASHBOARD_WARNING, DASHBOARD_WARNING_2, DASHBOARD_WARNING_3);
mockChannelsAndNodesAndWarnings(channels, nodes, warnings);
List<DashboardWarningDto> sortedWarnings = List.of(DASHBOARD_WARNING_2, DASHBOARD_WARNING, DASHBOARD_WARNING_3);
assertThat(pageService.dashboard(SortBy.DEFAULT_SORT)).usingRecursiveComparison().isEqualTo(
new DashboardPage(channels, nodes, sortedWarnings)
);
}
@Test
void dashboard_nodes_alphabeticalOrder() {
NodeDto bob = new NodeDto(PUBKEY.toString(), "Bob", true, RATING.getRating());
NodeDto alice = new NodeDto(PUBKEY_3.toString(), "Alice", true, RATING.getRating());
NodeDto charlie = new NodeDto(PUBKEY_2.toString(), "Charlie", true, RATING.getRating());
List<NodeDto> nodesUnsorted = List.of(bob, charlie, alice);
mockChannelsAndNodesWithoutWarning(List.of(), nodesUnsorted);
mockChannelsAndNodesAndWarnings(List.of(), nodesUnsorted, List.of());
List<NodeDto> nodesSorted = List.of(alice, bob, charlie);
assertThat(pageService.dashboard(SortBy.DEFAULT_SORT).getNodes()).isEqualTo(nodesSorted);
@@ -92,16 +109,20 @@ class PageServiceTest {
NodeDto onlineNode = new NodeDto(PUBKEY.toString(), "Online-Node", true, RATING.getRating());
NodeDto offlineNode2 = new NodeDto(PUBKEY_2.toString(), "Offline-Node2", false, RATING.getRating());
List<NodeDto> nodesUnsorted = List.of(onlineNode, offlineNode2, offlineNode1);
mockChannelsAndNodesWithoutWarning(List.of(), nodesUnsorted);
mockChannelsAndNodesAndWarnings(List.of(), nodesUnsorted, List.of());
List<NodeDto> nodesSorted = List.of(offlineNode1, offlineNode2, onlineNode);
assertThat(pageService.dashboard(SortBy.DEFAULT_SORT).getNodes()).isEqualTo(nodesSorted);
}
private void mockChannelsAndNodesWithoutWarning(List<OpenChannelDto> channels, List<NodeDto> nodes) {
private void mockChannelsAndNodesAndWarnings(
List<OpenChannelDto> channels,
List<NodeDto> nodes,
List<DashboardWarningDto> warnings
) {
when(dataService.getOpenChannels()).thenReturn(channels);
when(dataService.createNodeList()).thenReturn(nodes);
when(warningService.getWarnings()).thenReturn(List.of());
when(warningService.getWarnings()).thenReturn(warnings);
}
@Test

View File

@@ -3,7 +3,10 @@ package de.cotto.lndmanagej.ui.dto.warning;
import java.util.List;
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_3;
import static de.cotto.lndmanagej.ui.dto.warning.ChannelWarningDtoFixture.CHANNEL_WARNING_DTO;
import static de.cotto.lndmanagej.ui.dto.warning.ChannelWarningDtoFixture.CHANNEL_WARNING_DTO_2;
public class DashboardWarningsFixture {
public static final DashboardWarningDto DASHBOARD_WARNING = new DashboardWarningDto(
@@ -13,4 +16,18 @@ public class DashboardWarningsFixture {
List.of(CHANNEL_WARNING_DTO)
);
public static final DashboardWarningDto DASHBOARD_WARNING_2 = new DashboardWarningDto(
"Node 2",
PUBKEY_2,
List.of("This is another node warning."),
List.of(CHANNEL_WARNING_DTO, CHANNEL_WARNING_DTO_2)
);
public static final DashboardWarningDto DASHBOARD_WARNING_3 = new DashboardWarningDto(
"Node 3",
PUBKEY_3,
List.of("This is only a node warning."),
List.of()
);
}