Skip to content

Commit

Permalink
Add failure message in check result detail
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonkopliku committed May 24, 2023
1 parent a6bcc87 commit 01285e7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (
<span
className={classNames({
'text-red-500': !isPassing,
})}
>
{isPassing ? 'Passing' : 'Failing'}
</span>
),
}));
const expectationsEvaluations = renderedResults.map(
({ name, passing, faliureMessage }) => ({
title: name,
content: passing,
render: (isPassing) => (
<div
className={classNames({
'text-red-500': !isPassing,
})}
>
<span>{isPassing ? 'Passing' : 'Failing'}</span>
{faliureMessage && <span className="block">{faliureMessage}</span>}
</div>
),
})
);

return (
<div className="w-full my-4 mr-4 bg-white shadow rounded-lg px-8 py-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@ import { faker } from '@faker-js/faker';

import {
executionExpectationEvaluationFactory,
failingExpectEvaluationFactory,
expectationResultFactory,
failingExpectationResultFactory,
} from '@lib/test-utils/factories';

import '@testing-library/jest-dom';
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,
}),
];

Expand All @@ -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 [
Expand All @@ -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();
Expand Down
38 changes: 34 additions & 4 deletions assets/js/lib/test-utils/factories/executions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand All @@ -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}`,
Expand Down

0 comments on commit 01285e7

Please sign in to comment.