Skip to content

Commit 604145a

Browse files
Copilothotlong
andcommitted
Fix BrowserSimulation test timeout issues
- Add findOne method to MockDataSource - Increase timeout for form field loading to 15 seconds - Wrap each field label check in waitFor to handle async rendering - Fixes "expected 0 to be greater than 0" assertion error for Date field Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 896720e commit 604145a

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ const mocks = vi.hoisted(() => {
3030
}
3131
return { data: [] };
3232
}
33+
async findOne(objectName: string, id: string) {
34+
if (objectName === 'kitchen_sink') {
35+
return { id, name: 'Test Sink', amount: 100 };
36+
}
37+
return null;
38+
}
3339
async getObjectSchema(name: string) {
3440
if (name === 'kitchen_sink') {
3541
return {
@@ -164,10 +170,11 @@ describe('Console Application Simulation', () => {
164170
});
165171

166172
// 4. Verify Field Inputs
167-
// Wait for at least one field to appear to ensure form is loaded
173+
// Wait for form to finish loading and fields to appear
174+
// Note: Increased timeout to account for async schema fetching and form generation
168175
await waitFor(() => {
169176
expect(screen.getByText(/Text \(Name\)/i)).toBeInTheDocument();
170-
}, { timeout: 5000 });
177+
}, { timeout: 15000 });
171178

172179
const fieldLabels = [
173180
'Text (Name)',
@@ -178,16 +185,14 @@ describe('Console Application Simulation', () => {
178185
'Boolean (Switch)',
179186
];
180187

181-
// Check each label exists
188+
// Check each label exists - use waitFor for each to handle async rendering
182189
for (const label of fieldLabels) {
183-
const escaped = label.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
184-
const regex = new RegExp(escaped, 'i');
185-
const elements = screen.queryAllByText(regex);
186-
if (elements.length === 0) {
187-
console.log(`Failed to find label: ${label}`);
188-
// console.log(document.body.innerHTML); // Too large, but useful if localized
189-
}
190-
expect(elements.length).toBeGreaterThan(0);
190+
await waitFor(() => {
191+
const escaped = label.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
192+
const regex = new RegExp(escaped, 'i');
193+
const elements = screen.queryAllByText(regex);
194+
expect(elements.length).toBeGreaterThan(0);
195+
}, { timeout: 5000 });
191196
}
192197

193198
// 5. Test specific interaction (e.g. typing in name)

0 commit comments

Comments
 (0)