@integry/sdk 4.6.8 → 4.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD_PARTY_LICENSES +0 -37
- package/dist/esm/index.csm.js +7310 -1
- package/dist/umd/index.umd.js +7310 -1
- package/generateTests.js +51 -0
- package/package.json +2 -1
- package/src/components/form/ObjectField/index.ts +16 -1
- package/src/components/form/ObjectField/index.ts.test.tsx +108 -0
- package/src/features/common/ActionForm/index.ts +3 -1
package/generateTests.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import dotenv from 'dotenv';
|
|
5
|
+
|
|
6
|
+
dotenv.config();
|
|
7
|
+
|
|
8
|
+
const openai = new OpenAI({
|
|
9
|
+
apiKey: "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",
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
async function generateTest(filePath) {
|
|
13
|
+
const code = fs.readFileSync(filePath, 'utf-8');
|
|
14
|
+
|
|
15
|
+
const prompt = `Write Vitest unit tests for the following Preact component:
|
|
16
|
+
${code}
|
|
17
|
+
|
|
18
|
+
Make sure to cover:
|
|
19
|
+
- Props validation
|
|
20
|
+
- Event handlers
|
|
21
|
+
- Conditional rendering
|
|
22
|
+
- User interactions
|
|
23
|
+
- Edge cases
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
const completion = await openai.chat.completions.create({
|
|
27
|
+
model: 'gpt-4-turbo',
|
|
28
|
+
messages: [
|
|
29
|
+
{ role: 'system', content: 'You are a senior frontend developer with expertise in testing.' },
|
|
30
|
+
{ role: 'user', content: prompt },
|
|
31
|
+
],
|
|
32
|
+
temperature: 0.2,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const generatedTests = completion.choices[0]?.message?.content || '';
|
|
36
|
+
|
|
37
|
+
const testFilePath = path.join(path.dirname(filePath), `${path.basename(filePath, '.tsx')}.test.tsx`);
|
|
38
|
+
fs.writeFileSync(testFilePath, generatedTests);
|
|
39
|
+
console.log(`Test file generated: ${testFilePath}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function main() {
|
|
43
|
+
const componentsFolder = './src/components/form/ObjectField/'; // Update with your components folder
|
|
44
|
+
const files = fs.readdirSync(componentsFolder).filter((file) => file.endsWith('.ts'));
|
|
45
|
+
console.log(files);
|
|
46
|
+
for (const file of files) {
|
|
47
|
+
await generateTest(path.join(componentsFolder, file));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
main().catch(console.error);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@integry/sdk",
|
|
3
|
-
"version": "4.6.
|
|
3
|
+
"version": "4.6.10",
|
|
4
4
|
"description": "Integry SDK",
|
|
5
5
|
"main": "dist/umd/index.umd.js",
|
|
6
6
|
"module": "dist/esm/index.csm.js",
|
|
@@ -102,6 +102,7 @@
|
|
|
102
102
|
"fuzzysort": "^1.1.4",
|
|
103
103
|
"htm": "3.1.0",
|
|
104
104
|
"lit": "^3.2.1",
|
|
105
|
+
"openai": "^4.86.1",
|
|
105
106
|
"preact": "^10.2.0",
|
|
106
107
|
"superstruct": "^0.15.2",
|
|
107
108
|
"unfetch": "^4.2.0",
|
|
@@ -287,7 +287,22 @@ const ObjectField = (props: ObjectFieldProps) => {
|
|
|
287
287
|
: `Enter value here...`);
|
|
288
288
|
|
|
289
289
|
const fieldElement = html`
|
|
290
|
-
<div
|
|
290
|
+
<div
|
|
291
|
+
id=${[
|
|
292
|
+
'integry-action-field-wrap',
|
|
293
|
+
field?.activity_field?.machine_name !==
|
|
294
|
+
fieldDetails?.meta?.machine_name
|
|
295
|
+
? field?.activity_field?.machine_name
|
|
296
|
+
: null,
|
|
297
|
+
fieldDetails?.meta?.machine_name,
|
|
298
|
+
isArray ? objectIndex : null,
|
|
299
|
+
]
|
|
300
|
+
.filter(Boolean)
|
|
301
|
+
.join('-')}
|
|
302
|
+
class="${styles.functionFieldWrap
|
|
303
|
+
? styles.functionFieldWrap
|
|
304
|
+
: ''} integry-action-field-wrap"
|
|
305
|
+
>
|
|
291
306
|
<${ConfigureFieldWrapper} field=${fieldDetails}>
|
|
292
307
|
${fieldType === 'TEXTFIELD' &&
|
|
293
308
|
html`
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
To write Vitest unit tests for the `ObjectField` Preact component, we need to cover various aspects such as props validation, event handlers, conditional rendering, user interactions, and edge cases. Below are examples of how these tests can be structured using Vitest along with the Testing Library for Preact.
|
|
2
|
+
|
|
3
|
+
### Setup
|
|
4
|
+
|
|
5
|
+
First, ensure you have the necessary dependencies:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install vitest @testing-library/preact @testing-library/user-event --save-dev
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Test File: `ObjectField.test.tsx`
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
15
|
+
import { render, fireEvent, screen } from '@testing-library/preact';
|
|
16
|
+
import userEvent from '@testing-library/user-event';
|
|
17
|
+
import { ObjectField } from './ObjectField';
|
|
18
|
+
|
|
19
|
+
describe('ObjectField Component', () => {
|
|
20
|
+
const mockOnChange = vi.fn();
|
|
21
|
+
const mockOnChangeInFlow = vi.fn();
|
|
22
|
+
const mockApiHandler = vi.fn();
|
|
23
|
+
|
|
24
|
+
const baseProps = {
|
|
25
|
+
field: {
|
|
26
|
+
title: 'Test Field',
|
|
27
|
+
description: 'Test Description',
|
|
28
|
+
template_fields: [],
|
|
29
|
+
type: 'TEXTFIELD',
|
|
30
|
+
properties: {},
|
|
31
|
+
},
|
|
32
|
+
functionArguments: {},
|
|
33
|
+
connectedAccount: 'test-account',
|
|
34
|
+
appName: 'Test App',
|
|
35
|
+
onChange: mockOnChange,
|
|
36
|
+
onChangeInFlow: mockOnChangeInFlow,
|
|
37
|
+
apiHandler: mockApiHandler,
|
|
38
|
+
activityOutputData: {},
|
|
39
|
+
activityOutputDataRaw: {},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
it('renders without crashing', () => {
|
|
43
|
+
const { container } = render(<ObjectField {...baseProps} />);
|
|
44
|
+
expect(container).toBeInTheDocument();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('calls onChange when input changes', async () => {
|
|
48
|
+
const user = userEvent.setup();
|
|
49
|
+
render(<ObjectField {...baseProps} />);
|
|
50
|
+
const input = screen.getByRole('textbox');
|
|
51
|
+
await user.type(input, 'New Value');
|
|
52
|
+
expect(mockOnChange).toHaveBeenCalled();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('conditionally renders add more button based on isArray prop', () => {
|
|
56
|
+
const { rerender } = render(<ObjectField {...baseProps} isArray={true} />);
|
|
57
|
+
expect(screen.queryByText('+ Add another Test Field')).toBeInTheDocument();
|
|
58
|
+
|
|
59
|
+
rerender(<ObjectField {...baseProps} isArray={false} />);
|
|
60
|
+
expect(screen.queryByText('+ Add another Test Field')).not.toBeInTheDocument();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('handles array of objects and adds more on button click', async () => {
|
|
64
|
+
const user = userEvent.setup();
|
|
65
|
+
render(<ObjectField {...baseProps} isArray={true} />);
|
|
66
|
+
await user.click(screen.getByText('+ Add another Test Field'));
|
|
67
|
+
expect(screen.getAllByText('Test Field').length).toBe(2);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('removes an item from the list when delete is clicked', async () => {
|
|
71
|
+
const user = userEvent.setup();
|
|
72
|
+
render(<ObjectField {...baseProps} isArray={true} objectValue={[{}, {}]} />);
|
|
73
|
+
expect(screen.getAllByText('Test Field').length).toBe(2);
|
|
74
|
+
await user.click(screen.getAllByRole('button')[0]); // Assuming the delete button is the first button
|
|
75
|
+
expect(screen.getAllByText('Test Field').length).toBe(1);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('validates props and throws if required props are missing', () => {
|
|
79
|
+
const consoleError = vi.spyOn(console, 'error');
|
|
80
|
+
consoleError.mockImplementation(() => {});
|
|
81
|
+
|
|
82
|
+
expect(() => render(<ObjectField />)).toThrow();
|
|
83
|
+
expect(consoleError).toHaveBeenCalled();
|
|
84
|
+
|
|
85
|
+
consoleError.mockRestore();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Additional tests can be added here to cover more complex interactions and edge cases
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Explanation
|
|
93
|
+
|
|
94
|
+
1. **Setup and Imports**: We import necessary functions from Vitest and Testing Library. We also mock functions that will be used as props.
|
|
95
|
+
|
|
96
|
+
2. **Base Props**: A base props object is defined to reuse in multiple tests, ensuring consistency and reducing redundancy.
|
|
97
|
+
|
|
98
|
+
3. **Simple Render Test**: Checks if the component renders without throwing.
|
|
99
|
+
|
|
100
|
+
4. **Event Handler Test**: Simulates user input and checks if the appropriate handler (`onChange`) is called.
|
|
101
|
+
|
|
102
|
+
5. **Conditional Rendering**: Tests the conditional rendering of the "Add another" button based on the `isArray` prop.
|
|
103
|
+
|
|
104
|
+
6. **Dynamic List Manipulation**: Tests adding and removing items from a list, which is crucial for components managing arrays of data.
|
|
105
|
+
|
|
106
|
+
7. **Props Validation**: Optionally, you can test for required props and ensure the component throws or logs errors when props are missing or invalid.
|
|
107
|
+
|
|
108
|
+
This setup provides a robust starting point for testing the `ObjectField` component comprehensively, ensuring it behaves correctly under various conditions and interactions.
|
|
@@ -1490,7 +1490,9 @@ class ActionForm extends Component<ActionFormPropsType, ActionFormStateType> {
|
|
|
1490
1490
|
html`
|
|
1491
1491
|
<div id=${`integry-action-field-wrap-${
|
|
1492
1492
|
el?.activity_field?.machine_name || ''
|
|
1493
|
-
}`} class=${`integry-action-field-wrap
|
|
1493
|
+
}`} class=${`integry-action-field-wrap ${
|
|
1494
|
+
el.is_visible ? '' : styles.fNotVisible
|
|
1495
|
+
}`}>
|
|
1494
1496
|
<${ConfigureFieldWrapper}
|
|
1495
1497
|
field=${el}
|
|
1496
1498
|
stepId=${step.id}
|