Skip to content

Commit d774271

Browse files
Copilothotlong
andcommitted
Refactor: Extract helper function for label validation
- Add expectLabelToExist helper function to reduce code duplication - Improves readability and maintainability - All tests still passing Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent eb764d6 commit d774271

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ describe('Console Application Simulation', () => {
153153
});
154154

155155
it('Scenario 4: Object Create Form (All Field Types)', async () => {
156+
// Helper function to check if a label exists in the form
157+
const expectLabelToExist = (label: string) => {
158+
const escaped = label.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
159+
const regex = new RegExp(escaped, 'i');
160+
const elements = screen.queryAllByText(regex);
161+
expect(elements.length).toBeGreaterThan(0);
162+
};
163+
156164
renderApp('/kitchen_sink');
157165

158166
// 1. Wait for Object View
@@ -187,12 +195,7 @@ describe('Console Application Simulation', () => {
187195
// Check all labels exist concurrently using Promise.all for faster execution
188196
await Promise.all(
189197
fieldLabels.map(label =>
190-
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 })
198+
waitFor(() => expectLabelToExist(label), { timeout: 5000 })
196199
)
197200
);
198201

0 commit comments

Comments
 (0)