Skip to content

Commit 6ead793

Browse files
committed
test: update ObjectForm tests to use more flexible label matching for input fields
1 parent 9f0869b commit 6ead793

File tree

3 files changed

+69
-32
lines changed

3 files changed

+69
-32
lines changed

apps/console/src/__tests__/ObjectForm.test.tsx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ describe('ObjectForm with MSW Integration', () => {
6464

6565
// Wait for form to load
6666
await waitFor(() => {
67-
expect(screen.getByLabelText(/Full Name/i)).toBeInTheDocument();
67+
expect(screen.getByLabelText(/^Name/i)).toBeInTheDocument();
6868
});
6969

7070
expect(screen.getByLabelText(/Email/i)).toBeInTheDocument();
71-
expect(screen.getByLabelText(/Phone Number/i)).toBeInTheDocument();
71+
expect(screen.getByLabelText(/^Phone/i)).toBeInTheDocument();
7272
expect(screen.getByLabelText(/Company/i)).toBeInTheDocument();
7373
expect(screen.getByLabelText(/Position/i)).toBeInTheDocument();
7474
expect(screen.getByLabelText(/Priority/i)).toBeInTheDocument();
@@ -95,13 +95,13 @@ describe('ObjectForm with MSW Integration', () => {
9595

9696
// Wait for form to load
9797
await waitFor(() => {
98-
expect(screen.getByLabelText(/Full Name/i)).toBeInTheDocument();
98+
expect(screen.getByLabelText(/^Name/i)).toBeInTheDocument();
9999
});
100100

101101
// Fill in the form
102-
await user.type(screen.getByLabelText(/Full Name/i), 'Test User');
102+
await user.type(screen.getByLabelText(/^Name/i), 'Test User');
103103
await user.type(screen.getByLabelText(/Email/i), 'test@example.com');
104-
await user.type(screen.getByLabelText(/Phone Number/i), '+1234567890');
104+
await user.type(screen.getByLabelText(/^Phone/i), '+1234567890');
105105
await user.type(screen.getByLabelText(/Company/i), 'Test Company');
106106

107107
// Submit the form
@@ -138,7 +138,7 @@ describe('ObjectForm with MSW Integration', () => {
138138
);
139139

140140
await waitFor(() => {
141-
expect(screen.getByLabelText(/Full Name/i)).toBeInTheDocument();
141+
expect(screen.getByLabelText(/^Name/i)).toBeInTheDocument();
142142
});
143143

144144
// Try to submit without filling required fields
@@ -169,11 +169,11 @@ describe('ObjectForm with MSW Integration', () => {
169169
);
170170

171171
await waitFor(() => {
172-
expect(screen.getByLabelText(/Full Name/i)).toBeInTheDocument();
172+
expect(screen.getByLabelText(/^Name/i)).toBeInTheDocument();
173173
});
174174

175175
// Fill required fields only
176-
await user.type(screen.getByLabelText(/Full Name/i), 'Default Test');
176+
await user.type(screen.getByLabelText(/^Name/i), 'Default Test');
177177
await user.type(screen.getByLabelText(/Email/i), 'default@example.com');
178178

179179
// Submit
@@ -207,7 +207,7 @@ describe('ObjectForm with MSW Integration', () => {
207207

208208
// Wait for data to load
209209
await waitFor(() => {
210-
const nameInput = screen.getByLabelText(/Full Name/i) as HTMLInputElement;
210+
const nameInput = screen.getByLabelText(/^Name/i) as HTMLInputElement;
211211
expect(nameInput.value).toBe('John Doe');
212212
});
213213

@@ -238,12 +238,12 @@ describe('ObjectForm with MSW Integration', () => {
238238

239239
// Wait for data to load
240240
await waitFor(() => {
241-
const nameInput = screen.getByLabelText(/Full Name/i) as HTMLInputElement;
241+
const nameInput = screen.getByLabelText(/^Name/i) as HTMLInputElement;
242242
expect(nameInput.value).toBe('John Doe');
243243
});
244244

245245
// Update the name
246-
const nameInput = screen.getByLabelText(/Full Name/i);
246+
const nameInput = screen.getByLabelText(/^Name/i);
247247
await user.clear(nameInput);
248248
await user.type(nameInput, 'John Doe Updated');
249249

@@ -299,7 +299,7 @@ describe('ObjectForm with MSW Integration', () => {
299299
);
300300

301301
await waitFor(() => {
302-
const nameInput = screen.getByLabelText(/Full Name/i) as HTMLInputElement;
302+
const nameInput = screen.getByLabelText(/^Name/i) as HTMLInputElement;
303303
expect(nameInput.value).toBe('John Doe');
304304
expect(nameInput.disabled).toBe(true);
305305
});
@@ -324,7 +324,7 @@ describe('ObjectForm with MSW Integration', () => {
324324
);
325325

326326
await waitFor(() => {
327-
expect(screen.getByLabelText(/Full Name/i)).toBeInTheDocument();
327+
expect(screen.getByLabelText(/^Name/i)).toBeInTheDocument();
328328
});
329329

330330
const checkbox = screen.getByLabelText(/Active/i) as HTMLInputElement;
@@ -345,7 +345,7 @@ describe('ObjectForm with MSW Integration', () => {
345345
);
346346

347347
await waitFor(() => {
348-
expect(screen.getByLabelText(/Full Name/i)).toBeInTheDocument();
348+
expect(screen.getByLabelText(/^Name/i)).toBeInTheDocument();
349349
});
350350

351351
const numberInput = screen.getByLabelText(/Priority/i) as HTMLInputElement;
@@ -366,7 +366,7 @@ describe('ObjectForm with MSW Integration', () => {
366366
);
367367

368368
await waitFor(() => {
369-
expect(screen.getByLabelText(/Full Name/i)).toBeInTheDocument();
369+
expect(screen.getByLabelText(/^Name/i)).toBeInTheDocument();
370370
});
371371

372372
const textarea = screen.getByLabelText(/Notes/i) as HTMLTextAreaElement;
@@ -387,10 +387,10 @@ describe('ObjectForm with MSW Integration', () => {
387387
);
388388

389389
await waitFor(() => {
390-
expect(screen.getByLabelText(/Full Name/i)).toBeInTheDocument();
390+
expect(screen.getByLabelText(/^Name/i)).toBeInTheDocument();
391391
});
392392

393-
const phoneInput = screen.getByLabelText(/Phone Number/i) as HTMLInputElement;
393+
const phoneInput = screen.getByLabelText(/^Phone/i) as HTMLInputElement;
394394
expect(phoneInput.type).toBe('tel');
395395
});
396396
});
@@ -415,7 +415,7 @@ describe('ObjectForm with MSW Integration', () => {
415415
);
416416

417417
await waitFor(() => {
418-
expect(screen.getByLabelText(/Full Name/i)).toBeInTheDocument();
418+
expect(screen.getByLabelText(/^Name/i)).toBeInTheDocument();
419419
});
420420

421421
const cancelButton = screen.getByRole('button', { name: /cancel/i });
@@ -445,10 +445,10 @@ describe('ObjectForm with MSW Integration', () => {
445445
);
446446

447447
await waitFor(() => {
448-
expect(screen.getByLabelText(/Full Name/i)).toBeInTheDocument();
448+
expect(screen.getByLabelText(/^Name/i)).toBeInTheDocument();
449449
});
450450

451-
await user.type(screen.getByLabelText(/Full Name/i), 'Persist Test');
451+
await user.type(screen.getByLabelText(/^Name/i), 'Persist Test');
452452
await user.type(screen.getByLabelText(/Email/i), 'persist@example.com');
453453
await user.click(screen.getByRole('button', { name: /create/i }));
454454

apps/console/src/mocks/server.ts

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,55 @@ function createHandlers(baseUrl: string, kernel: ObjectKernel) {
8787
const protocol = kernel.getService('protocol') as any;
8888

8989
return [
90-
// Discovery endpoint
90+
// Discovery endpoint - Handle both with and without trailing slash
91+
http.get(`${baseUrl}`, async () => {
92+
const response = await protocol.getDiscovery();
93+
return HttpResponse.json(response, { status: 200 });
94+
}),
9195
http.get(`${baseUrl}/`, async () => {
92-
const response = await protocol.handleDiscovery();
96+
const response = await protocol.getDiscovery();
9397
return HttpResponse.json(response, { status: 200 });
9498
}),
9599

96-
// Metadata endpoints
100+
// Metadata endpoints - Support both legacy /meta and new /metadata paths
97101
http.get(`${baseUrl}/meta/objects`, async () => {
98-
const response = await protocol.handleMetadataListObjects();
102+
const response = await protocol.getMetaItems({ type: 'object' });
103+
return HttpResponse.json(response, { status: 200 });
104+
}),
105+
http.get(`${baseUrl}/metadata/objects`, async () => {
106+
const response = await protocol.getMetaItems({ type: 'object' });
99107
return HttpResponse.json(response, { status: 200 });
100108
}),
101109

102110
http.get(`${baseUrl}/meta/objects/:objectName`, async ({ params }) => {
103-
const response = await protocol.handleMetadataGetObject({ objectName: params.objectName as string });
104-
return HttpResponse.json(response, { status: 200 });
111+
console.log('MSW: getting meta item for (legacy)', params.objectName);
112+
try {
113+
const response = await protocol.getMetaItem({
114+
type: 'object',
115+
name: params.objectName as string
116+
});
117+
return HttpResponse.json(response || { error: 'Not found' }, { status: response ? 200 : 404 });
118+
} catch (e) {
119+
return HttpResponse.json({ error: String(e) }, { status: 500 });
120+
}
121+
}),
122+
123+
http.get(`${baseUrl}/metadata/object/:objectName`, async ({ params }) => {
124+
console.log('MSW: getting meta item for', params.objectName);
125+
try {
126+
const response = await protocol.getMetaItem({
127+
type: 'object',
128+
name: params.objectName as string
129+
});
130+
131+
// Unwrap item if present
132+
const payload = (response && response.item) ? response.item : response;
133+
134+
return HttpResponse.json(payload || { error: 'Not found' }, { status: payload ? 200 : 404 });
135+
} catch (e) {
136+
console.error('MSW: error getting meta item', e);
137+
return HttpResponse.json({ error: String(e) }, { status: 500 });
138+
}
105139
}),
106140

107141
// Data endpoints - Find all
@@ -118,7 +152,7 @@ function createHandlers(baseUrl: string, kernel: ObjectKernel) {
118152
}
119153
});
120154

121-
const response = await protocol.handleFind({
155+
const response = await protocol.findData({
122156
objectName: params.objectName as string,
123157
query
124158
});
@@ -127,7 +161,7 @@ function createHandlers(baseUrl: string, kernel: ObjectKernel) {
127161

128162
// Data endpoints - Find by ID
129163
http.get(`${baseUrl}/data/:objectName/:id`, async ({ params }) => {
130-
const response = await protocol.handleFindById({
164+
const response = await protocol.getData({
131165
objectName: params.objectName as string,
132166
id: params.id as string
133167
});
@@ -137,7 +171,7 @@ function createHandlers(baseUrl: string, kernel: ObjectKernel) {
137171
// Data endpoints - Create
138172
http.post(`${baseUrl}/data/:objectName`, async ({ params, request }) => {
139173
const body = await request.json();
140-
const response = await protocol.handleCreate({
174+
const response = await protocol.createData({
141175
objectName: params.objectName as string,
142176
data: body
143177
});
@@ -147,7 +181,7 @@ function createHandlers(baseUrl: string, kernel: ObjectKernel) {
147181
// Data endpoints - Update
148182
http.patch(`${baseUrl}/data/:objectName/:id`, async ({ params, request }) => {
149183
const body = await request.json();
150-
const response = await protocol.handleUpdate({
184+
const response = await protocol.updateData({
151185
objectName: params.objectName as string,
152186
id: params.id as string,
153187
data: body
@@ -157,7 +191,7 @@ function createHandlers(baseUrl: string, kernel: ObjectKernel) {
157191

158192
// Data endpoints - Delete
159193
http.delete(`${baseUrl}/data/:objectName/:id`, async ({ params }) => {
160-
const response = await protocol.handleDelete({
194+
const response = await protocol.deleteData({
161195
objectName: params.objectName as string,
162196
id: params.id as string
163197
});

examples/crm/src/objects/contact.object.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export const ContactObject = ObjectSchema.create({
99
phone: Field.text({ label: 'Phone' }),
1010
title: Field.text({ label: 'Title' }),
1111
company: Field.text({ label: 'Company' }),
12-
status: Field.select(['Active', 'Lead', 'Customer'], { label: 'Status' })
12+
status: Field.select(['Active', 'Lead', 'Customer'], { label: 'Status' }),
13+
priority: Field.number({ label: 'Priority', defaultValue: 5 }),
14+
is_active: Field.boolean({ label: 'Active', defaultValue: true }),
15+
notes: Field.textarea({ label: 'Notes' })
1316
}
1417
});

0 commit comments

Comments
 (0)