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

feat: update the jsonforms unit test #4060

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -9,6 +9,7 @@ import { FormStepperOptionProps } from './FormStepperControl';
import { getProperty } from './util/helpers';
import { CategorizationStepperLayoutRendererProps } from './types';
import { JsonFormsStepperContextProvider } from './context';
import { categoriesAreValid } from './FormStepperTester';

export const ContextProvider = ContextProviderFactory();

Expand Down Expand Up @@ -384,6 +385,34 @@ describe('Form Stepper Control', () => {
});
});

it('will render a "view" anchor using key', () => {
const newStepperProps = {
...stepperBaseProps,
data: { ...formData, name: { firstName: 'Bob', lastName: 'Bing' } },
};
const onSubmit = jest.fn();
// eslint-disable-next-line
newStepperProps.activeId = 2;
const { getByTestId } = render(
<ContextProvider submit={{ submitForm: onSubmit }}>
<JsonFormsStepperContextProvider
StepperProps={newStepperProps}
children={getForm(
{
name: { firstName: 'Bob', lastName: 'Bing' },
address: { street: 'Sesame', city: 'Seattle' },
},
categorization,
{ readOnly: false }
)}
/>
</ContextProvider>
);
const nameAnchor = getByTestId('Name-review-link');
fireEvent.keyDown(nameAnchor, { key: 'Enter', code: 13, charCode: 13 });
expect(mockDispatch.mock.calls[2][0].type === 'page/to/index');
});

describe('submit tests', () => {
it('will open a modal if no submit function is present', () => {
const newStepperProps = {
Expand Down Expand Up @@ -448,10 +477,35 @@ describe('Form Stepper Control', () => {

describe('test stepper helper', () => {
const obj = { prop: 'test' };

const result = getProperty(obj, 'props');
const result2 = getProperty(obj, 'prop');
expect(result).toBe(undefined);
expect(result2).toBe('test');
});

describe('test the jsonforms stepper layout tester', () => {
// eslint-disable-next-line
const isCategoryLayout = categoriesAreValid({
type: 'Categorization',
// eslint-disable-next-line
elements: [
{
type: 'Category',
elements: [
{
type: 'Control',
},
],
},
],
} as UISchemaElement);

const isNotCategoryLayout = categoriesAreValid({
type: 'Categorization',
elements: [{ type: 'Control' }],
// eslint-disable-next-line
} as UISchemaElement);
expect(isCategoryLayout).toBe(true);
expect(isNotCategoryLayout).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { rankWith, RankedTester, uiTypeIs, and, optionIs, UISchemaElement, isCat

// Ensure that all children (Category) have valid elements or things tend
// to blow up. If not, the the error control will report the problem.
const categoriesAreValid = (uischema: UISchemaElement): boolean => {
export const categoriesAreValid = (uischema: UISchemaElement): boolean => {
let isValid = true;
if ('type' in uischema && uischema.type === 'Categorization' && 'elements' in uischema) {
(uischema.elements as UISchemaElement[]).forEach((e) => {
Expand Down