From 01285e70e67f3c06c585a9761873863f975930ac Mon Sep 17 00:00:00 2001 From: Nelson Kopliku Date: Wed, 24 May 2023 14:42:03 +0200 Subject: [PATCH] Add failure message in check result detail --- .../CheckResultDetail/ExpectationsResults.jsx | 35 +++++++++-------- .../ExpectationsResults.test.jsx | 22 ++++++----- .../js/lib/test-utils/factories/executions.js | 38 +++++++++++++++++-- 3 files changed, 67 insertions(+), 28 deletions(-) diff --git a/assets/js/components/ExecutionResults/CheckResultDetail/ExpectationsResults.jsx b/assets/js/components/ExecutionResults/CheckResultDetail/ExpectationsResults.jsx index 931de4cd53..0bda8c5b6a 100644 --- a/assets/js/components/ExecutionResults/CheckResultDetail/ExpectationsResults.jsx +++ b/assets/js/components/ExecutionResults/CheckResultDetail/ExpectationsResults.jsx @@ -10,28 +10,33 @@ function ExpectationsResults({ errorMessage = 'An error occurred', }) { const renderedResults = isTargetHost - ? results.map(({ name, return_value }) => ({ + ? results.map(({ name, return_value, failure_message }) => ({ name, passing: !!return_value, + faliureMessage: failure_message, })) - : results.map(({ name, result }) => ({ + : results.map(({ name, result, failure_message }) => ({ name, passing: !!result, + faliureMessage: failure_message, })); - const expectationsEvaluations = renderedResults.map(({ name, passing }) => ({ - title: name, - content: passing, - render: (isPassing) => ( - - {isPassing ? 'Passing' : 'Failing'} - - ), - })); + const expectationsEvaluations = renderedResults.map( + ({ name, passing, faliureMessage }) => ({ + title: name, + content: passing, + render: (isPassing) => ( +
+ {isPassing ? 'Passing' : 'Failing'} + {faliureMessage && {faliureMessage}} +
+ ), + }) + ); return (
diff --git a/assets/js/components/ExecutionResults/CheckResultDetail/ExpectationsResults.test.jsx b/assets/js/components/ExecutionResults/CheckResultDetail/ExpectationsResults.test.jsx index d98adff883..f0bce40ebf 100644 --- a/assets/js/components/ExecutionResults/CheckResultDetail/ExpectationsResults.test.jsx +++ b/assets/js/components/ExecutionResults/CheckResultDetail/ExpectationsResults.test.jsx @@ -5,7 +5,9 @@ import { faker } from '@faker-js/faker'; import { executionExpectationEvaluationFactory, + failingExpectEvaluationFactory, expectationResultFactory, + failingExpectationResultFactory, } from '@lib/test-utils/factories'; import '@testing-library/jest-dom'; @@ -13,12 +15,13 @@ import ExpectationsResults from './ExpectationsResults'; describe('ExpectationsResults Component', () => { it('should render expect statements results', () => { + const failureMessage = faker.lorem.sentence(); const results = [ ...executionExpectationEvaluationFactory.buildList(3, { return_value: true, }), - ...executionExpectationEvaluationFactory.buildList(2, { - return_value: false, + ...failingExpectEvaluationFactory.buildList(2, { + failure_message: failureMessage, }), ]; @@ -28,22 +31,22 @@ describe('ExpectationsResults Component', () => { expect(screen.getAllByText('Passing')).toHaveLength(3); expect(screen.getAllByText('Failing')).toHaveLength(2); + expect(screen.getAllByText(failureMessage)).toHaveLength(2); expect(screen.getByText(expectationName1)).toBeVisible(); expect(screen.getByText(expectationName3)).toBeVisible(); }); it('should render expect_same statements results', () => { + const failureMessage = faker.lorem.sentence(); const results = [ - ...expectationResultFactory.buildList(3, { - result: null, + ...failingExpectationResultFactory.buildList(7, { + type: 'expect_same', + failure_message: failureMessage, }), ...expectationResultFactory.buildList(2, { - result: undefined, + result: true, + type: 'expect_same', }), - ...expectationResultFactory.buildList(2, { - result: false, - }), - ...expectationResultFactory.buildList(2, { result: true }), ]; const [ @@ -56,6 +59,7 @@ describe('ExpectationsResults Component', () => { expect(screen.getAllByText('Passing')).toHaveLength(2); expect(screen.getAllByText('Failing')).toHaveLength(7); + expect(screen.getAllByText(failureMessage)).toHaveLength(7); expect(screen.getByText(expectationName1)).toBeVisible(); expect(screen.getByText(expectationName2)).toBeVisible(); expect(screen.getByText(expectationName3)).toBeVisible(); diff --git a/assets/js/lib/test-utils/factories/executions.js b/assets/js/lib/test-utils/factories/executions.js index daf502be0a..5a5c6cb181 100644 --- a/assets/js/lib/test-utils/factories/executions.js +++ b/assets/js/lib/test-utils/factories/executions.js @@ -17,15 +17,30 @@ export const executionValueFactory = Factory.define(({ sequence }) => ({ export const executionExpectationEvaluationFactory = Factory.define( ({ sequence, params }) => { const name = params.name || `expectation_${sequence}`; + const type = params.type || expectationReturnTypeEnum(); + const return_value = params.return_value || faker.datatype.number(); + const failure_message = params.failure_message + ? { failure_message: params.failure_message } + : {}; return { name, - return_value: faker.datatype.number(), - type: expectationReturnTypeEnum(), + return_value, + type, + ...failure_message, }; } ); +export const failingExpectEvaluationFactory = Factory.define(({ params }) => + executionExpectationEvaluationFactory.build({ + ...params, + return_value: false, + type: 'expect', + failure_message: params.failure_message || faker.lorem.sentence(), + }) +); + export const executionExpectationEvaluationErrorFactory = Factory.define( ({ sequence, params }) => { const name = params.name || `expectation_${sequence}`; @@ -41,15 +56,30 @@ export const executionExpectationEvaluationErrorFactory = Factory.define( export const expectationResultFactory = Factory.define( ({ sequence, params }) => { const name = params.name || `expectation_${sequence}`; + const type = params.type || expectationReturnTypeEnum(); + const result = params.result || faker.datatype.boolean(); + const failure_message = params.failure_message + ? { failure_message: params.failure_message } + : {}; return { name, - result: faker.datatype.boolean(), - type: expectationReturnTypeEnum(), + result, + type, + ...failure_message, }; } ); +export const failingExpectationResultFactory = Factory.define(({ params }) => + expectationResultFactory.build({ + ...params, + result: false, + type: params.type || expectationReturnTypeEnum(), + failure_message: params.failure_message || faker.lorem.sentence(), + }) +); + export const executionFactFactory = Factory.define(({ sequence }) => ({ check_id: faker.datatype.uuid(), name: `${faker.lorem.word()}_${sequence}`,