Skip to content

Commit

Permalink
chore(tests): Split exhaustive tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lordrip committed Aug 20, 2024
1 parent 68a9f66 commit a348f85
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 107 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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, ICamelComponentDefinition } from '../../../models';
import { getFirstCatalogMap } from '../../../stubs/test-load-catalog';
import { SchemaService } from '../../Form';
import { CustomAutoFieldDetector } from '../../Form/CustomAutoField';

describe('Form - components', () => {
let componentCatalogMap: Record<string, ICamelComponentDefinition>;
const schemaService = new SchemaService();

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

CamelCatalogService.setCatalogKey(CatalogKind.Component, componentCatalogMap);
});

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

beforeEach(() => {
jest.spyOn(console, 'error').mockImplementation(() => {});
});

it('should render for all component without an error', async () => {
Object.entries(componentCatalogMap).forEach(([name, catalog]) => {
try {
if (name === 'default') return;

const schema = schemaService.getSchemaBridge(catalog.propertiesSchema);
render(
<AutoField.componentDetectorContext.Provider value={CustomAutoFieldDetector}>
<AutoForm schema={schema!} model={{}} onChangeModel={() => {}}>
<AutoFields omitFields={SchemaService.OMIT_FORM_FIELDS} />
</AutoForm>
</AutoField.componentDetectorContext.Provider>,
);
} catch (e) {
throw new Error(`Error rendering ${name} component: \n ${e}`);
}
});
});
});
47 changes: 47 additions & 0 deletions packages/ui/src/components/Visualization/Canvas/Form.eips.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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, ICamelProcessorDefinition } from '../../../models';
import { getFirstCatalogMap } from '../../../stubs/test-load-catalog';
import { SchemaService } from '../../Form';
import { CustomAutoFieldDetector } from '../../Form/CustomAutoField';

describe('Form - EIPs', () => {
let patternCatalogMap: Record<string, ICamelProcessorDefinition>;
const schemaService = new SchemaService();

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

CamelCatalogService.setCatalogKey(CatalogKind.Pattern, patternCatalogMap);
});

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

beforeEach(() => {
jest.spyOn(console, 'error').mockImplementation(() => {});
});

it('should render for all EIPs without an error', async () => {
Object.entries(patternCatalogMap).forEach(([name, catalog]) => {
try {
if (name === 'default') return;

const schema = schemaService.getSchemaBridge(catalog.propertiesSchema);
render(
<AutoField.componentDetectorContext.Provider value={CustomAutoFieldDetector}>
<AutoForm schema={schema!} model={{}} onChangeModel={() => {}}>
<AutoFields omitFields={SchemaService.OMIT_FORM_FIELDS} />
</AutoForm>
</AutoField.componentDetectorContext.Provider>,
);
} catch (e) {
throw new Error(`Error rendering ${name} EIP: \n ${e}`);
}
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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, IKameletDefinition } from '../../../models';
import { getFirstCatalogMap } from '../../../stubs/test-load-catalog';
import { SchemaService } from '../../Form';
import { CustomAutoFieldDetector } from '../../Form/CustomAutoField';

describe('Form - Kamelets', () => {
let kameletCatalogMap: Record<string, IKameletDefinition>;
const schemaService = new SchemaService();

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

CamelCatalogService.setCatalogKey(CatalogKind.Kamelet, kameletCatalogMap);
});

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

beforeEach(() => {
jest.spyOn(console, 'error').mockImplementation(() => {});
});

it('should render for all Kamelets without an error', async () => {
Object.entries(kameletCatalogMap).forEach(([name, catalog]) => {
try {
if (name === 'default') return;

const schema = schemaService.getSchemaBridge(catalog.propertiesSchema);
render(
<AutoField.componentDetectorContext.Provider value={CustomAutoFieldDetector}>
<AutoForm schema={schema!} model={{}} onChangeModel={() => {}}>
<AutoFields omitFields={SchemaService.OMIT_FORM_FIELDS} />
</AutoForm>
</AutoField.componentDetectorContext.Provider>,
);
} catch (e) {
throw new Error(`Error rendering ${name} Kamelet: \n ${e}`);
}
});
});
});

0 comments on commit a348f85

Please sign in to comment.