Skip to content

Commit ccf6bbb

Browse files
authored
Fix TestDefinitionForm validation test expectations (#27781)
* test(ui): fix TestDefinitionForm required-field validation assertions Update TestDefinitionForm tests to account for current required fields and make validation assertions resilient to multiple matching error messages. Made-with: Cursor * checkstyle fix
1 parent 7140502 commit ccf6bbb

1 file changed

Lines changed: 26 additions & 18 deletions

File tree

openmetadata-ui/src/main/resources/ui/src/components/TestLibrary/TestDefinitionForm/TestDefinitionForm.test.tsx

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,9 @@ describe('TestDefinitionForm Component', () => {
351351
});
352352
};
353353

354-
// testPlatforms defaults to [OpenMetadata] so it never fires an error on empty submit.
355-
// name + entityType are the two required fields without defaults.
356-
it('should show exactly 2 validation errors when create form is submitted empty', async () => {
354+
// name, entityType, and supportedDataTypes are required on empty submit.
355+
// supportedDataTypes is required because testPlatforms defaults to [OpenMetadata].
356+
it('should show exactly 3 validation errors when create form is submitted empty', async () => {
357357
render(
358358
<TestDefinitionForm onCancel={mockOnCancel} onSuccess={mockOnSuccess} />
359359
);
@@ -363,7 +363,7 @@ describe('TestDefinitionForm Component', () => {
363363
await waitFor(() => {
364364
const errors = screen.getAllByText('message.field-text-is-required');
365365

366-
expect(errors).toHaveLength(2);
366+
expect(errors).toHaveLength(3);
367367
});
368368
});
369369

@@ -379,14 +379,18 @@ describe('TestDefinitionForm Component', () => {
379379
await submitEmptyForm();
380380

381381
await waitFor(() => {
382-
const nameFormItem = screen
383-
.getByLabelText('label.name')
384-
.closest('.ant-form-item');
385-
386-
expect(nameFormItem).toHaveTextContent(
387-
'message.field-text-is-required'
388-
);
382+
expect(
383+
screen.getAllByText('message.field-text-is-required').length
384+
).toBeGreaterThan(0);
389385
});
386+
387+
const nameFormItem = screen
388+
.getByLabelText('label.name')
389+
.closest('.ant-form-item');
390+
391+
expect(nameFormItem).toHaveTextContent(
392+
'message.field-text-is-required'
393+
);
390394
});
391395

392396
it('entityType field is required', async () => {
@@ -400,14 +404,18 @@ describe('TestDefinitionForm Component', () => {
400404
await submitEmptyForm();
401405

402406
await waitFor(() => {
403-
const entityTypeFormItem = screen
404-
.getByLabelText('label.entity-type')
405-
.closest('.ant-form-item');
406-
407-
expect(entityTypeFormItem).toHaveTextContent(
408-
'message.field-text-is-required'
409-
);
407+
expect(
408+
screen.getAllByText('message.field-text-is-required').length
409+
).toBeGreaterThan(0);
410410
});
411+
412+
const entityTypeFormItem = screen
413+
.getByLabelText('label.entity-type')
414+
.closest('.ant-form-item');
415+
416+
expect(entityTypeFormItem).toHaveTextContent(
417+
'message.field-text-is-required'
418+
);
411419
});
412420

413421
it('testPlatforms field is required', () => {

0 commit comments

Comments
 (0)