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

chore(Tests): Split form-related tests #1474

Merged
merged 1 commit into from
Sep 25, 2024
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

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Component, range: { start: 0, end: 50 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Component, range: { start: 50, end: 100 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Component, range: { start: 100, end: 150 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Component, range: { start: 150, end: 200 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Component, range: { start: 200, end: 250 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Component, range: { start: 250, end: 300 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Component, range: { start: 300, end: undefined } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Pattern, range: { start: 0, end: undefined } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Kamelet, range: { start: 0, end: 50 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Kamelet, range: { start: 50, end: 100 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Kamelet, range: { start: 100, end: 150 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Kamelet, range: { start: 150, end: 200 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Kamelet, range: { start: 200, end: undefined } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { AutoField, AutoFields, AutoForm } from '@kaoto-next/uniforms-patternfly';
import catalogLibrary from '@kaoto/camel-catalog/index.json';
import { CatalogLibrary } from '@kaoto/camel-catalog/types';
import { render } from '@testing-library/react';
import { CamelCatalogService, CatalogKind, KaotoSchemaDefinition } from '../../../../../models';
import { getFirstCatalogMap } from '../../../../../stubs/test-load-catalog';
import { SchemaService } from '../../../../Form';
import { CustomAutoFieldDetector } from '../../../../Form/CustomAutoField';
import { getSchemasSlice } from './get-schemas-slices';

export const FormTest = (target: { kind: CatalogKind; range: { start: number; end: number | undefined } }) => {
let schemas: [string, KaotoSchemaDefinition['schema']][] = [];

beforeAll(async () => {
const catalogsMap = await getFirstCatalogMap(catalogLibrary as CatalogLibrary);

CamelCatalogService.setCatalogKey(CatalogKind.Component, catalogsMap.componentCatalogMap);
CamelCatalogService.setCatalogKey(CatalogKind.Pattern, catalogsMap.patternCatalogMap);
CamelCatalogService.setCatalogKey(CatalogKind.Kamelet, catalogsMap.kameletsCatalogMap);

schemas = getSchemasSlice(CamelCatalogService.getCatalogByKey(target.kind), target.range);
jest.spyOn(console, 'error').mockImplementation(() => {});
});

afterAll(() => {
jest.clearAllMocks();
});

it('should have schemas', () => {
expect(schemas).not.toHaveLength(0);
});

it('should render the form without an error', () => {
schemas.forEach(([name, schema]) => {
try {
const schemaService = new SchemaService();
const schemaBridge = schemaService.getSchemaBridge(schema);
render(
<AutoField.componentDetectorContext.Provider value={CustomAutoFieldDetector}>
<AutoForm schema={schemaBridge!} model={{}} onChangeModel={() => {}}>
<AutoFields omitFields={SchemaService.OMIT_FORM_FIELDS} />
</AutoForm>
</AutoField.componentDetectorContext.Provider>,
);
} catch (e) {
console.error(e);
throw new Error(`Error rendering ${name} ${target.kind}`);

Check warning on line 47 in packages/ui/src/components/Visualization/Canvas/Form/Tests/FormTest.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/Canvas/Form/Tests/FormTest.tsx#L46-L47

Added lines #L46 - L47 were not covered by tests
}
});
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
ICamelComponentDefinition,
ICamelProcessorDefinition,
IKameletDefinition,
KaotoSchemaDefinition,
} from '../../../../../models';

export const getSchemasSlice = (
catalogMap:
| Record<string, ICamelComponentDefinition>
| Record<string, ICamelProcessorDefinition>
| Record<string, IKameletDefinition>
| undefined,
range: { start: number; end: number | undefined },
): [string, KaotoSchemaDefinition['schema']][] => {
if (!catalogMap) return [];

return Object.entries(catalogMap)
.slice(range.start, range.end)
.map(([name, { propertiesSchema }]) => [name, propertiesSchema]);
};