Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display check failure message #1451

Merged
merged 2 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
failureMessage: failure_message,
}))
: results.map(({ name, result }) => ({
: results.map(({ name, result, failure_message }) => ({
name,
passing: !!result,
failureMessage: 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, failureMessage }) => ({
title: name,
content: passing,
render: (isPassing) => (
<div
className={classNames({
'text-red-500': !isPassing,
})}
>
<span>{isPassing ? 'Passing' : 'Failing'}</span>
{failureMessage && <span className="block">{failureMessage}</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
54 changes: 39 additions & 15 deletions assets/js/lib/test-utils/factories/executions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,31 @@ export const executionValueFactory = Factory.define(({ sequence }) => ({

export const executionExpectationEvaluationFactory = Factory.define(
({ sequence, params }) => {
const name = params.name || `expectation_${sequence}`;
const {
name = `expectation_${sequence}`,
failure_message = params.failure_message
? { failure_message: params.failure_message }
: {},
} = params;

return {
name,
return_value: faker.datatype.number(),
type: expectationReturnTypeEnum(),
...failure_message,
};
}
);

export const failingExpectEvaluationFactory = Factory.define(({ params }) =>
executionExpectationEvaluationFactory.build({
...params,
return_value: false,
type: 'expect',
failure_message: faker.lorem.sentence(),
})
);

export const executionExpectationEvaluationErrorFactory = Factory.define(
({ sequence, params }) => {
const name = params.name || `expectation_${sequence}`;
Expand All @@ -40,16 +55,31 @@ export const executionExpectationEvaluationErrorFactory = Factory.define(

export const expectationResultFactory = Factory.define(
({ sequence, params }) => {
const name = params.name || `expectation_${sequence}`;
const {
name = `expectation_${sequence}`,
failure_message = params.failure_message
? { failure_message: params.failure_message }
: {},
} = params;

return {
name,
result: faker.datatype.boolean(),
type: expectationReturnTypeEnum(),
...failure_message,
};
}
);

export const failingExpectationResultFactory = Factory.define(({ params }) =>
expectationResultFactory.build({
...params,
result: false,
type: expectationReturnTypeEnum(),
failure_message: faker.lorem.sentence(),
})
);

export const executionFactFactory = Factory.define(({ sequence }) => ({
check_id: faker.datatype.uuid(),
name: `${faker.lorem.word()}_${sequence}`,
Expand Down Expand Up @@ -196,17 +226,6 @@ export const addPassingExpectation = (checkResult, type, expectationName) => {
return addExpectation(checkResult, name, expectation, true);
};

export const addCriticalExpectation = (checkResult, type, expectationName) => {
const name = expectationName || faker.company.name();
const expectation = executionExpectationEvaluationFactory.build({
name,
type,
return_value: false,
});

return addExpectation(checkResult, name, expectation, false);
};

export const addExpectationWithError = (checkResult, expectationName) => {
const name = expectationName || faker.company.name();
const expectation = executionExpectationEvaluationErrorFactory.build({
Expand All @@ -219,9 +238,14 @@ export const addExpectationWithError = (checkResult, expectationName) => {
export const addPassingExpectExpectation = (checkResult, expectationName) =>
addPassingExpectation(checkResult, 'expect', expectationName);

export const addCriticalExpectExpectation = (checkResult, expectationName) =>
addCriticalExpectation(checkResult, 'expect', expectationName);
export const addCriticalExpectExpectation = (checkResult, expectationName) => {
const name = expectationName || faker.company.name();
const expectation = failingExpectEvaluationFactory.build({
name,
});

return addExpectation(checkResult, name, expectation, false);
};
export const addPassingExpectSameExpectation = (checkResult, expectationName) =>
addPassingExpectation(checkResult, 'expect_same', expectationName);

Expand Down