From 1501568f789ec1fb506ccb94126293b16872f474 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Fri, 1 Jul 2022 00:15:02 +0400 Subject: Display Test Names For Unittest Failures Signed-off-by: Hassan Abouelela --- src/components/Question.tsx | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/components/Question.tsx b/src/components/Question.tsx index 61e66e0..2ce84b2 100644 --- a/src/components/Question.tsx +++ b/src/components/Question.tsx @@ -239,6 +239,29 @@ class RenderedQuestion extends React.Component { } } + generateUnitTestErrorMessage(valid: boolean): JSX.Element { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + const failures: string = this.props.public_state.get("error"); + let inner; + + if (this.props.public_state.get("testFailure")) { + inner =
+ {"Unittest Failure:\n"} +
    + {failures.split(";").map(testName => +
  • {testName}
  • + )} +
+
; + } else { + inner = `Unittest Failure:\n\n${failures}`; + } + + const element =
{inner}
; + return ; + } + render(): JSX.Element { const question = this.props.question; @@ -299,10 +322,15 @@ class RenderedQuestion extends React.Component { if (!this.props.public_state.get("valid")) { valid = false; } - const rawError = this.props.public_state.get("error"); - let error = ""; - if (typeof rawError === "string") { - error = rawError; + + let error; + if (this.props.question.type === QuestionType.Code && this.props.public_state.get("unittestsFailed")) { + error = this.generateUnitTestErrorMessage(valid); + } else { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + const message: string = this.props.public_state.get("error"); + error = ; } return
@@ -310,7 +338,7 @@ class RenderedQuestion extends React.Component { {name}* { create_input(this.props, this.handler, this.blurHandler, this.props.focus_ref) } - + {error}
; } -- cgit v1.2.3