Skip to content

Commit b43bfb8

Browse files
committed
refactor: update ObjectForm and ObjectGrid tests to use ContactObject schema and adjust field labels
1 parent fd7fa48 commit b43bfb8

File tree

2 files changed

+16
-38
lines changed

2 files changed

+16
-38
lines changed

packages/plugin-form/src/ObjectForm.msw.test.tsx

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { setupServer } from 'msw/node';
66
import { http, HttpResponse } from 'msw';
77
import { registerAllFields } from '@object-ui/fields';
88
import React from 'react';
9+
// @ts-ignore - Import from examples
10+
import { ContactObject } from '../../../examples/crm/src/objects/contact.object';
911

1012
// Register widget renderers
1113
registerAllFields();
@@ -14,35 +16,13 @@ const BASE_URL = 'http://test-api.com';
1416

1517
// --- Mock Data ---
1618

17-
const mockSchema = {
18-
name: 'contact',
19-
label: 'Contact',
20-
fields: {
21-
name: {
22-
type: 'text',
23-
label: 'Full Name',
24-
required: true
25-
},
26-
email: {
27-
type: 'email',
28-
label: 'Email Address'
29-
},
30-
status: {
31-
type: 'select',
32-
label: 'Status',
33-
options: [
34-
{ label: 'Active', value: 'active' },
35-
{ label: 'Inactive', value: 'inactive' }
36-
]
37-
}
38-
}
39-
};
19+
const mockSchema = ContactObject;
4020

4121
const mockRecord = {
4222
_id: 'rec_123',
4323
name: 'Alice Smith',
4424
email: 'alice@example.com',
45-
status: 'active'
25+
status: 'Customer'
4626
};
4727

4828
// --- MSW Setup ---
@@ -114,9 +94,10 @@ describe('ObjectForm with ObjectStack/MSW', () => {
11494

11595
// Verify fields appear (async as schema loads via HTTP)
11696
await waitFor(() => {
117-
expect(screen.getByText('Full Name')).toBeInTheDocument();
97+
// Changed from 'Full Name' to 'Name' based on CRM example schema
98+
expect(screen.getByText('Name')).toBeInTheDocument();
11899
});
119-
expect(screen.getByText('Email Address')).toBeInTheDocument();
100+
expect(screen.getByText('Email')).toBeInTheDocument();
120101
expect(screen.getByText('Status')).toBeInTheDocument();
121102
});
122103

@@ -135,9 +116,11 @@ describe('ObjectForm with ObjectStack/MSW', () => {
135116

136117
// Initial load of schema logic + data fetch
137118
await waitFor(() => {
138-
expect(screen.getByRole('textbox', { name: /Full Name/i })).toHaveValue('Alice Smith');
119+
// Changed from 'Full Name' to 'Name'
120+
expect(screen.getByRole('textbox', { name: /Name/i })).toHaveValue('Alice Smith');
139121
}, { timeout: 2000 }); // Give slight buffer for network mock
140122

141-
expect(screen.getByRole('textbox', { name: /Email Address/i })).toHaveValue('alice@example.com');
123+
// Changed from 'Email Address' to 'Email'
124+
expect(screen.getByRole('textbox', { name: /Email/i })).toHaveValue('alice@example.com');
142125
});
143126
});

packages/plugin-grid/src/ObjectGrid.msw.test.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,16 @@ import { setupServer } from 'msw/node';
66
import { http, HttpResponse } from 'msw';
77
import { registerAllFields } from '@object-ui/fields';
88
import React from 'react';
9+
// @ts-ignore - Import from examples
10+
import { ContactObject } from '../../../examples/crm/src/objects/contact.object';
911

1012
registerAllFields();
1113

1214
const BASE_URL = 'http://test-api.com';
1315

1416
// --- Mock Data ---
1517

16-
const mockSchema = {
17-
name: 'contact',
18-
label: 'Contact',
19-
fields: {
20-
name: { type: 'text', label: 'Full Name' },
21-
email: { type: 'email', label: 'Email' },
22-
company: { type: 'text', label: 'Company' }
23-
}
24-
};
18+
const mockSchema = ContactObject;
2519

2620
const mockData = {
2721
value: [
@@ -91,7 +85,8 @@ describe('ObjectGrid with ObjectStack/MSW', () => {
9185

9286
// Verify Column Headers (from schema or props)
9387
await waitFor(() => {
94-
expect(screen.getByText('Full Name')).toBeInTheDocument();
88+
// Changed from 'Full Name' to 'Name' to match CRM example schema
89+
expect(screen.getByText('Name')).toBeInTheDocument();
9590
});
9691
expect(screen.getByText('Email')).toBeInTheDocument();
9792
expect(screen.getByText('Company')).toBeInTheDocument();

0 commit comments

Comments
 (0)