Skip to content

Commit 2264644

Browse files
authored
feat: Display passing test cases for valid schemas (#179)
Updates the output view to show passing test cases. Also applies automated formatting and lint fixes to the entire codebase.
1 parent 56509c4 commit 2264644

File tree

5 files changed

+38
-17
lines changed

5 files changed

+38
-17
lines changed

app/components/NavBarMenus/NavBarMenus.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export default function NavBarMenu() {
3838
className={navBarStyles.menuButton}
3939
onBlur={() => setIsOpen(false)}
4040
onClick={() => {
41-
4241
sendGAEvent("event", "buttonClicked", {
4342
value: "Settings",
4443
});

app/components/Output/Output.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useState } from "react";
22
import styles from "./Output.module.css";
33
import classnames from "classnames";
44
import { OutputResult } from "@/lib/types";
5-
import FailedTestCasesWindow from "../TestCaseWindow/TestCaseWindow";
5+
import TestCasesWindow from "../TestCaseWindow/TestCaseWindow";
66
import MyBtn from "../MyBtn";
77
import { InvalidSchemaError } from "@hyperjump/json-schema/draft-2020-12";
88
import { schemaUrl } from "@/lib/validators";
@@ -101,12 +101,18 @@ function Output({
101101
);
102102
} else if (outputResult.validityStatus == "valid") {
103103
outputBodyContent = (
104-
<div className={styles.valid}>
105-
<b className={styles.validMessage}>Valid Schema!</b>
106-
<span className={styles.validSmallMessage}>
107-
Let&apos;s move on to the next step
108-
</span>
109-
</div>
104+
<>
105+
<div className={styles.valid}>
106+
<b className={styles.validMessage}>Valid Schema!</b>
107+
<span className={styles.validSmallMessage}>
108+
Let&apos;s move on to the next step
109+
</span>
110+
</div>
111+
<TestCasesWindow
112+
testCaseResult={outputResult.testCaseResults!}
113+
totalTestCases={outputResult.totalTestCases!}
114+
/>
115+
</>
110116
);
111117
} else if (outputResult.validityStatus == "syntaxError") {
112118
outputBodyContent = (
@@ -128,7 +134,7 @@ function Output({
128134
);
129135
} else {
130136
outputBodyContent = (
131-
<FailedTestCasesWindow
137+
<TestCasesWindow
132138
testCaseResult={outputResult.testCaseResults!}
133139
totalTestCases={outputResult.totalTestCases!}
134140
/>

app/components/TestCaseWindow/TestCaseWindow.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,14 @@ export default function TestCasesWindow({
110110

111111
return (
112112
<div className={styles.TestCasesWindow}>
113-
<div className={styles.TestCasesHeaderWrapper}>
114-
<span className={styles.TestCasesHeader}>Invalid Schema!</span>
115-
<span className={styles.TestCasesSubtitle}>
116-
{numberOfFailedTestCases} out of {totalTestCases} test cases failed
117-
</span>
118-
</div>
113+
{numberOfFailedTestCases > 0 && (
114+
<div className={styles.TestCasesHeaderWrapper}>
115+
<span className={styles.TestCasesHeader}>Invalid Schema!</span>
116+
<span className={styles.TestCasesSubtitle}>
117+
{numberOfFailedTestCases} out of {totalTestCases} test cases failed
118+
</span>
119+
</div>
120+
)}
119121
<Flex dir="row" gap={2}>
120122
{!areBothDisabled && (
121123
<button

lib/client-functions.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,16 @@ export async function validateCode(
5858
}
5959

6060
if (validationStatus === "valid") {
61-
dispatchOutput({ type: "valid", payload: {} });
61+
const sortedResults = testCaseResults.sort((a, b) => {
62+
if (a.passed === b.passed) {
63+
return 0; // If both are the same, their order doesn't change
64+
}
65+
return a.passed ? 1 : -1; // If a.passed is true, put a after b; if false, put a before b
66+
});
67+
dispatchOutput({
68+
type: "valid",
69+
payload: { testCaseResults: sortedResults, totalTestCases },
70+
});
6271
completeStep(chapterIndex, stepIndex);
6372
sendGAEvent("event", "validation", {
6473
validation_result: "passed",

lib/reducers.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ export function outputReducer(
1616
): OutputResult {
1717
switch (action.type) {
1818
case "valid":
19-
return { ...state, validityStatus: "valid" };
19+
return {
20+
...state,
21+
validityStatus: "valid",
22+
testCaseResults: action.payload.testCaseResults,
23+
totalTestCases: action.payload.totalTestCases,
24+
};
2025
case "syntaxError":
2126
return {
2227
...state,

0 commit comments

Comments
 (0)