DynamicTable: Fix rendering of boolean fields

This commit is contained in:
Gustav Hansen 2022-04-07 10:18:01 +02:00
parent 2edd2ae00c
commit 1b63360b41
2 changed files with 21 additions and 0 deletions

View File

@ -56,5 +56,9 @@ export default function hasContent(type, content, metadatas, fieldSchema) {
return isNumber(content);
}
if (type === 'boolean') {
return content !== null;
}
return !isEmpty(content);
}

View File

@ -50,6 +50,23 @@ describe('hasContent', () => {
});
});
describe('boolean', () => {
it('returns true if enabled', () => {
const normalizedContent = hasContent('boolean', true);
expect(normalizedContent).toEqual(true);
});
it('returns false if disabled', () => {
const normalizedContent = hasContent('boolean', false);
expect(normalizedContent).toEqual(true);
});
it('returns false for null', () => {
const normalizedContent = hasContent('boolean', null);
expect(normalizedContent).toEqual(false);
});
});
describe('ID', () => {
it('returns true for id main fields', () => {
const normalizedContent = hasContent('media', { id: 1 });