Skip to content

Commit ba8eedf

Browse files
committed
feat(webUI): using tests header and new style for failures report
Refs: #58
1 parent 047c2d8 commit ba8eedf

File tree

6 files changed

+29
-20
lines changed

6 files changed

+29
-20
lines changed

pom.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
<dependency>
114114
<groupId>io.github.nergal-perm</groupId>
115115
<artifactId>java-decita</artifactId>
116-
<version>0.8.0-SNAPSHOT</version>
116+
<version>0.8.0</version>
117117
</dependency>
118118
<dependency>
119119
<groupId>com.renomad</groupId>
@@ -125,11 +125,6 @@
125125
<artifactId>jcabi-matchers</artifactId>
126126
<scope>test</scope>
127127
</dependency>
128-
<dependency>
129-
<groupId>org.assertj</groupId>
130-
<artifactId>assertj-core</artifactId>
131-
<version>3.24.2</version>
132-
</dependency>
133128
<dependency>
134129
<groupId>org.hamcrest</groupId>
135130
<artifactId>hamcrest</artifactId>

src/main/java/ru/ewc/checklogic/ServerInstance.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import java.net.URI;
2828
import java.nio.file.Paths;
29-
import java.util.HashMap;
3029
import java.util.List;
3130
import java.util.Map;
3231
import ru.ewc.decisions.api.ComputationContext;
@@ -107,14 +106,6 @@ public void perform(final String command, final Map<String, String> args) {
107106
}
108107
}
109108

110-
public Map<String, String> stateFor(final String table, final Map<String, String> entities) {
111-
final Map<String, String> actual = HashMap.newHashMap(entities.size());
112-
for (final String fragment : entities.keySet()) {
113-
actual.put(fragment, this.context.valueFor(table, fragment));
114-
}
115-
return actual;
116-
}
117-
118109
public Map<String, Map<String, Object>> storedState() {
119110
return this.context.storedState();
120111
}

src/main/java/ru/ewc/checklogic/TestResult.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
*/
2424
package ru.ewc.checklogic;
2525

26-
public record TestResult(String file, boolean successful, String error) {
26+
public record TestResult(
27+
String file,
28+
boolean successful,
29+
String error
30+
) implements Comparable<TestResult> {
2731

2832
public String result() {
2933
final String result;
@@ -64,4 +68,14 @@ private String classBasedOnSuccess() {
6468
}
6569
return result;
6670
}
71+
72+
@Override
73+
public int compareTo(TestResult o) {
74+
final int success = Boolean.compare(this.successful, o.successful);
75+
if (success == 0) {
76+
return this.file.compareTo(o.file);
77+
} else {
78+
return success;
79+
}
80+
}
6781
}

src/main/java/ru/ewc/checklogic/server/WebPages.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import ru.ewc.checklogic.ServerContextFactory;
3333
import ru.ewc.checklogic.ServerInstance;
3434
import ru.ewc.checklogic.TestResult;
35+
import ru.ewc.decisions.api.CheckFailure;
3536
import ru.ewc.decisions.api.CheckSuite;
3637
import ru.ewc.decisions.api.ComputationContext;
3738
import ru.ewc.decisions.api.OutputTracker;
@@ -96,7 +97,7 @@ public Response testPage() {
9697
)
9798
).toList();
9899
final String rows = results.stream()
99-
.sorted(Comparator.comparing(TestResult::result))
100+
.sorted(Comparator.naturalOrder())
100101
.map(TestResult::asHtmlTableRow)
101102
.collect(Collectors.joining());
102103
final double elapsed = (System.currentTimeMillis() - start) / 1000.0;
@@ -135,7 +136,13 @@ private String renderInLayout(final String template, final Map<String, String> v
135136
return this.processors.renderInLayout(template, values);
136137
}
137138

138-
private static String resultAsUnorderedList(final Map.Entry<String, List<String>> entry) {
139-
return "<ul><li>%s</li></ul>".formatted(String.join("</li></li>", entry.getValue()));
139+
private static String resultAsUnorderedList(final Map.Entry<String, List<CheckFailure>> entry) {
140+
return "<ul>%s</ul>".formatted(String.join("", checkFailureAsHtml(entry.getValue())));
141+
}
142+
143+
private static String checkFailureAsHtml(final List<CheckFailure> failure) {
144+
return failure.stream()
145+
.map(f -> "<li>Expected: <kbd>%s</kbd>, but got: <kbd>%s</kbd></li>".formatted(f.expectation(), f.actual()))
146+
.collect(Collectors.joining());
140147
}
141148
}

src/test/resources/tic-tac-toe/tests/00-initialize.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
OUT;execute;initialize
22
CND;table::currentPlayer;X
3-
CND;cells::A1;X
3+
CND;table::nextPlayer;O
4+
CND;cells::A1;empty
45
CND;cells::A2;empty
56
CND;cells::A3;empty
67
CND;cells::B1;empty

src/test/resources/tic-tac-toe/tests/01-first-move.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
HDR;first move;non current player;current player;
12
ASG;request::player;O;X
23
ASG;request::move;A1;A1
34
ASG;table::currentPlayer;X;X

0 commit comments

Comments
 (0)