From bff494ec37d264965dcdba1ab32e971ddcf702d1 Mon Sep 17 00:00:00 2001 From: "Paul.Li" Date: Mon, 3 Feb 2025 17:18:31 -0700 Subject: [PATCH] feat: update the jsonforms unit test --- .../FormStepper/FormStepperControl.spec.tsx | 56 ++++++++++++++++++- .../FormStepper/FormStepperTester.tsx | 2 +- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/libs/jsonforms-components/src/lib/Controls/FormStepper/FormStepperControl.spec.tsx b/libs/jsonforms-components/src/lib/Controls/FormStepper/FormStepperControl.spec.tsx index 31009bf3a7..c07c595454 100644 --- a/libs/jsonforms-components/src/lib/Controls/FormStepper/FormStepperControl.spec.tsx +++ b/libs/jsonforms-components/src/lib/Controls/FormStepper/FormStepperControl.spec.tsx @@ -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(); @@ -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( + + + + ); + 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 = { @@ -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); + }); }); diff --git a/libs/jsonforms-components/src/lib/Controls/FormStepper/FormStepperTester.tsx b/libs/jsonforms-components/src/lib/Controls/FormStepper/FormStepperTester.tsx index 5ff49b8e4d..a73da87ddd 100644 --- a/libs/jsonforms-components/src/lib/Controls/FormStepper/FormStepperTester.tsx +++ b/libs/jsonforms-components/src/lib/Controls/FormStepper/FormStepperTester.tsx @@ -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) => {