-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(Tests): Split form-related tests
Currently, we have 3 that take a long time due to their nature. Each of these tests takes one catalog category and renders the configuration form for each of them. While this works, the penalty is that we block jest worker nodes (threads) so the tests are pinned to a single worker without any chance of splitting the work, making the test slow. This commit splits them into smaller sections, so the tests are better distributed among all available worker nodes (threads). Comparison: * No split ``` Time: 109.227 s Time: 143.646 s ``` * Split ``` Time: 23.485 s Time: 24.143 s ```
- Loading branch information
Showing
18 changed files
with
176 additions
and
141 deletions.
There are no files selected for viewing
47 changes: 0 additions & 47 deletions
47
packages/ui/src/components/Visualization/Canvas/Form/Form.components.test.tsx
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
packages/ui/src/components/Visualization/Canvas/Form/Form.eips.test.tsx
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
packages/ui/src/components/Visualization/Canvas/Form/Form.kamelets.test.tsx
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
packages/ui/src/components/Visualization/Canvas/Form/Tests/Form.components.000-050.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/ui/src/components/Visualization/Canvas/Form/Tests/Form.components.050-100.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/ui/src/components/Visualization/Canvas/Form/Tests/Form.components.100-150.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/ui/src/components/Visualization/Canvas/Form/Tests/Form.components.150-200.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/ui/src/components/Visualization/Canvas/Form/Tests/Form.components.200-250.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/ui/src/components/Visualization/Canvas/Form/Tests/Form.components.250-300.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/ui/src/components/Visualization/Canvas/Form/Tests/Form.components.300-end.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/ui/src/components/Visualization/Canvas/Form/Tests/Form.eips.000-end.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/ui/src/components/Visualization/Canvas/Form/Tests/Form.kamelets.000-050.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/ui/src/components/Visualization/Canvas/Form/Tests/Form.kamelets.050-100.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/ui/src/components/Visualization/Canvas/Form/Tests/Form.kamelets.100-150.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/ui/src/components/Visualization/Canvas/Form/Tests/Form.kamelets.150-200.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/ui/src/components/Visualization/Canvas/Form/Tests/Form.kamelets.200-end.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
51 changes: 51 additions & 0 deletions
51
packages/ui/src/components/Visualization/Canvas/Form/Tests/FormTest.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
}); | ||
}); | ||
}; |
21 changes: 21 additions & 0 deletions
21
packages/ui/src/components/Visualization/Canvas/Form/Tests/get-schemas-slices.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
}; |