Skip to content

Commit adbd8a6

Browse files
authored
Patch % sort options (#156)
1 parent a4d2683 commit adbd8a6

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

src/components/conformance/ResultsDisplay/nav.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ type SortProps = {
132132
};
133133

134134
function SortingDropdown(props: SortProps): JSX.Element {
135-
const [sortValue, setSortValue] = React.useState<string>(props.sortValue ? props.sortValue : "alpha");
135+
const [sortValue, setSortValue] = React.useState<string>(
136+
props.sortValue ? props.sortValue : "alpha",
137+
);
136138

137139
React.useEffect(() => {
138140
setSortValue(props.sortValue);

src/components/conformance/utils.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,20 @@ export const availableSortingOptions: SortOption[] = [
5454
{
5555
id: "most-pass-percentage",
5656
name: "Most Passed (%)",
57-
callback: (a, b) =>
58-
b.stats.total -
59-
a.stats.total +
60-
b.stats.passed / b.stats.total -
61-
a.stats.passed / a.stats.total,
57+
callback: (a, b) => {
58+
const p1 = a.stats.passed / a.stats.total;
59+
const p2 = b.stats.passed / b.stats.total;
60+
return p1 === p2 ? b.stats.total - a.stats.total : p2 - p1;
61+
},
6262
},
6363
{
6464
id: "least-pass-percentage",
6565
name: "Least Passed (%)",
66-
callback: (a, b) =>
67-
b.stats.total -
68-
a.stats.total +
69-
a.stats.passed / a.stats.total -
70-
b.stats.passed / b.stats.total,
66+
callback: (a, b) => {
67+
const p1 = a.stats.passed / a.stats.total;
68+
const p2 = b.stats.passed / b.stats.total;
69+
return p1 === p2 ? b.stats.total - a.stats.total : p1 - p2;
70+
},
7171
},
7272
{
7373
id: "most-ignored",
@@ -98,21 +98,20 @@ export const availableSortingOptions: SortOption[] = [
9898
{
9999
id: "most-fail-percentage",
100100
name: "Most Failed (%)",
101-
callback: (a, b) =>
102-
b.stats.total -
103-
a.stats.total +
104-
(b.stats.total - (b.stats.passed + b.stats.ignored)) -
105-
(a.stats.total - (a.stats.passed + a.stats.ignored)),
101+
callback: (a, b) => {
102+
const p1 = (b.stats.passed + b.stats.ignored) / b.stats.total;
103+
const p2 = (a.stats.passed + a.stats.ignored) / a.stats.total;
104+
return p2 === p1 ? b.stats.total - a.stats.total : p2 - p1;
105+
},
106106
},
107107
{
108108
id: "least-fail-percentage",
109109
name: "Least Failed (%)",
110-
callback: (a, b) =>
111-
b.stats.total -
112-
a.stats.total +
113-
(a.stats.total - b.stats.total) +
114-
a.stats.passed / a.stats.total -
115-
b.stats.passed / b.stats.total,
110+
callback: (a, b) => {
111+
const p1 = (b.stats.passed + b.stats.ignored) / b.stats.total;
112+
const p2 = (a.stats.passed + a.stats.ignored) / a.stats.total;
113+
return p2 === p1 ? b.stats.total - a.stats.total : p1 - p2;
114+
},
116115
},
117116
];
118117

0 commit comments

Comments
 (0)