-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathget_component_api.test.ts
More file actions
84 lines (72 loc) · 3.61 KB
/
Copy pathget_component_api.test.ts
File metadata and controls
84 lines (72 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import test, { type ExecutionContext } from 'ava';
import { z } from 'zod';
import { getComponentApiTool } from './get_component_api.js';
const handler = getComponentApiTool.handler;
const outputSchema = z.object(getComponentApiTool.outputSchema);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function getStructured(response: ReturnType<typeof handler>): any {
if (!('structuredContent' in response)) {
throw new Error('Expected structuredContent in response');
}
return response.structuredContent;
}
function assertMatchesOutputSchema(t: ExecutionContext, data: unknown) {
const result = outputSchema.safeParse(data);
if (!result.success) {
t.fail(
`Output schema validation failed:\n${result.error.issues.map((i) => ` ${i.path.join('.')}: ${i.message}`).join('\n')}`,
);
}
}
test('handler: finds component case-insensitively from generated component-apis.json', (t) => {
// component-apis.json is gitignored (generated by extract:descriptions)
// Also verifies findComponent() toLowerCase logic
const result = getStructured(handler({ componentName: 'button' }));
t.truthy(result.props);
t.falsy(result.error);
});
test('handler: AnalyticalTable is from @ui5/webcomponents-react', (t) => {
// Verifies the "components" category (separate from webComponents tested above)
const result = getStructured(handler({ componentName: 'AnalyticalTable' }));
t.is(result.package, '@ui5/webcomponents-react');
});
test('handler: not-found returns error with available components list', (t) => {
// Input is z.string() (not z.enum), so this path is reachable
const result = getStructured(handler({ componentName: 'FakeWidget' }));
t.is(result.errorType, 'not_found');
t.true(result.availableComponents.length > 0);
});
test('handler: AnalyticalTable response passes outputSchema validation', (t) => {
const result = getStructured(handler({ componentName: 'AnalyticalTable' }));
assertMatchesOutputSchema(t, result);
t.pass();
});
test('handler: not-found response passes outputSchema validation', (t) => {
const result = getStructured(handler({ componentName: 'FakeWidget' }));
assertMatchesOutputSchema(t, result);
t.pass();
});
test('handler: web components with DomRef methods include them in output', (t) => {
const result = getStructured(handler({ componentName: 'Carousel' }));
t.truthy(result.methods, 'Carousel should have methods array');
t.true(result.methods.length > 0, 'Carousel should have at least one method');
const navigateTo = result.methods.find((m: { name: string }) => m.name === 'navigateTo');
t.truthy(navigateTo, 'Carousel should have navigateTo method');
t.true(navigateTo.params.length > 0, 'navigateTo should have parameters');
});
test('handler: Dialog has applyFocus method extracted from DomRef', (t) => {
const result = getStructured(handler({ componentName: 'Dialog' }));
t.truthy(result.methods);
const applyFocus = result.methods.find((m: { name: string }) => m.name === 'applyFocus');
t.truthy(applyFocus, 'Dialog should have applyFocus method');
});
test('handler: abstract component is flagged with isAbstract', (t) => {
// Tab is marked @abstract (_ui5abstract in the CEM) -> isAbstract set in enrichWithCem
const result = getStructured(handler({ componentName: 'Tab' }));
t.true(result.isAbstract, 'Tab should be flagged isAbstract: true');
});
test('handler: non-abstract component does not set isAbstract', (t) => {
// Button is a regular self-rendering component -> flag should be absent/falsy
const result = getStructured(handler({ componentName: 'Button' }));
t.falsy(result.isAbstract, 'Button should not be flagged as abstract');
});