diff --git a/web-console/src/components/auto-form/auto-form.spec.tsx b/web-console/src/components/auto-form/auto-form.spec.tsx index c2beb3d498b..d0e6c410591 100644 --- a/web-console/src/components/auto-form/auto-form.spec.tsx +++ b/web-console/src/components/auto-form/auto-form.spec.tsx @@ -19,6 +19,8 @@ import { shallow } from 'enzyme'; import React from 'react'; +import { COMPACTION_CONFIG_FIELDS } from '../../druid-models'; + import { AutoForm } from './auto-form'; describe('AutoForm', () => { @@ -44,4 +46,78 @@ describe('AutoForm', () => { ); expect(autoForm).toMatchSnapshot(); }); + + describe('.issueWithModel', () => { + it('should find no issue when everything is fine', () => { + expect(AutoForm.issueWithModel({}, COMPACTION_CONFIG_FIELDS)).toBeUndefined(); + + expect( + AutoForm.issueWithModel( + { + dataSource: 'ds', + taskPriority: 25, + inputSegmentSizeBytes: 419430400, + maxRowsPerSegment: null, + skipOffsetFromLatest: 'P4D', + tuningConfig: { + maxRowsInMemory: null, + maxBytesInMemory: null, + maxTotalRows: null, + splitHintSpec: null, + partitionsSpec: { + type: 'dynamic', + maxRowsPerSegment: 5000000, + maxTotalRows: null, + }, + indexSpec: null, + indexSpecForIntermediatePersists: null, + maxPendingPersists: null, + pushTimeout: null, + segmentWriteOutMediumFactory: null, + maxNumConcurrentSubTasks: null, + maxRetry: null, + taskStatusCheckPeriodMs: null, + chatHandlerTimeout: null, + chatHandlerNumRetries: null, + maxNumSegmentsToMerge: null, + totalNumMergeTasks: null, + type: 'index_parallel', + forceGuaranteedRollup: false, + }, + taskContext: null, + }, + COMPACTION_CONFIG_FIELDS, + ), + ).toBeUndefined(); + }); + }); + + it('should find issue correctly', () => { + expect(AutoForm.issueWithModel(undefined as any, COMPACTION_CONFIG_FIELDS)).toEqual( + 'model is undefined', + ); + + expect( + AutoForm.issueWithModel( + { + dataSource: 'ds', + taskPriority: 25, + inputSegmentSizeBytes: 419430400, + skipOffsetFromLatest: 'P4D', + tuningConfig: { + partitionsSpec: { + type: 'dynamic', + maxRowsPerSegment: 5000000, + maxTotalRows: null, + }, + totalNumMergeTasks: 5, + type: 'index_parallel', + forceGuaranteedRollup: false, + }, + taskContext: null, + }, + COMPACTION_CONFIG_FIELDS, + ), + ).toEqual('field tuningConfig.totalNumMergeTasks is defined but it should not be'); + }); }); diff --git a/web-console/src/components/auto-form/auto-form.tsx b/web-console/src/components/auto-form/auto-form.tsx index edc948a07fb..32dc87407da 100644 --- a/web-console/src/components/auto-form/auto-form.tsx +++ b/web-console/src/components/auto-form/auto-form.tsx @@ -122,7 +122,7 @@ export class AutoForm> extends React.PureComponent for (const field of fields) { const fieldValue = deepGet(model, field.name); - const fieldValueDefined = typeof fieldValue !== 'undefined'; + const fieldValueDefined = fieldValue != null; const fieldThatIsDefined = definedFields[field.name]; if (fieldThatIsDefined) { if (fieldThatIsDefined === field) {