treat null as not defined (#10751)

This commit is contained in:
Vadim Ogievetsky 2021-01-14 18:22:59 -08:00 committed by GitHub
parent 4437c6af60
commit e52db19823
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 77 additions and 1 deletions

View File

@ -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');
});
});

View File

@ -122,7 +122,7 @@ export class AutoForm<T extends Record<string, any>> 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) {