-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUseCase23ViewTest.java
More file actions
105 lines (84 loc) · 3.66 KB
/
UseCase23ViewTest.java
File metadata and controls
105 lines (84 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package com.example.usecase23;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.test.context.support.WithMockUser;
import com.vaadin.browserless.SpringBrowserlessTest;
import com.vaadin.browserless.ViewPackages;
import com.vaadin.flow.component.board.Board;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.html.H2;
import com.vaadin.flow.component.html.Span;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@SpringBootTest
@ViewPackages(classes = UseCase23View.class)
@WithMockUser
class UseCase23ViewTest extends SpringBrowserlessTest {
@SuppressWarnings("deprecation")
@Test
void viewRendersWithBoard() {
navigate(UseCase23View.class);
assertEquals(1, $view(Board.class).all().size());
}
@Test
void highlightCardsPresent() {
navigate(UseCase23View.class);
runPendingSignalsTasks();
// 4 highlight cards with H2 titles: "Current users", "View events",
// "Conversion rate", "Custom metric"
assertTrue($view(H2.class).all().stream()
.anyMatch(h -> "Current users".equals(h.getText())));
assertTrue($view(H2.class).all().stream()
.anyMatch(h -> "View events".equals(h.getText())));
}
@Test
void serviceHealthGridRendered() {
navigate(UseCase23View.class);
runPendingSignalsTasks();
// Grid for service health should be present
assertTrue($view(Grid.class).all().size() >= 1);
}
@Test
void highlightCardUpdatesValueOnDataUpdate() {
navigate(UseCase23View.class);
runPendingSignalsTasks();
UseCase23View view = $view(UseCase23View.class).first();
// Push data update with known values
view.onDataUpdate(createTestData(42, 1500, 3.5, 99));
runPendingSignalsTasks();
// "Current users" card should show "42"
assertTrue($view(Span.class).all().stream()
.anyMatch(s -> "42".equals(s.getText())),
"Expected a Span with text '42' for current users");
}
@Test
void highlightCardShowsPercentageChangeAfterTwoUpdates() {
navigate(UseCase23View.class);
runPendingSignalsTasks();
UseCase23View view = $view(UseCase23View.class).first();
// First update: baseline
view.onDataUpdate(createTestData(100, 1000, 2.0, 50));
runPendingSignalsTasks();
// Second update: double the users (100 → 200 = +100%)
view.onDataUpdate(createTestData(200, 1000, 2.0, 50));
runPendingSignalsTasks();
runPendingSignalsTasks();
// Should show "+100.0" in the percentage badge
assertTrue($view(Span.class).all().stream().anyMatch(
s -> s.getText() != null && s.getText().contains("+100.0")),
"Expected percentage badge showing +100.0");
}
private DashboardData createTestData(int users, int views,
double conversion, double custom) {
return new DashboardData(users, views, conversion, custom,
new DashboardData.TimelineData("12:00", 10, 20, 30, 40),
List.of(new ServiceHealth(ServiceHealth.Status.OK,
"Münster", 100, 200),
new ServiceHealth(ServiceHealth.Status.EXCELLENT,
"Cluj-Napoca", 150, 250),
new ServiceHealth(ServiceHealth.Status.FAILING,
"Ciudad Victoria", 50, 75)),
List.of(10.0, 20.0, 30.0, 15.0, 25.0, 35.0));
}
}