From 7f42a114980f9c0f38786fbc30ee8131e6bb4814 Mon Sep 17 00:00:00 2001 From: Randy Schott <1815175+schottra@users.noreply.github.com> Date: Mon, 16 Nov 2020 12:33:07 -0800 Subject: [PATCH] fix: convert empty array literals to empty collection literals (#121) --- .../LaunchForm/inputHelpers/collection.ts | 3 -- .../inputHelpers/test/inputHelpers.test.ts | 30 ++++++++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/components/Launch/LaunchForm/inputHelpers/collection.ts b/src/components/Launch/LaunchForm/inputHelpers/collection.ts index 5bc1d7db8..d5a5b737e 100644 --- a/src/components/Launch/LaunchForm/inputHelpers/collection.ts +++ b/src/components/Launch/LaunchForm/inputHelpers/collection.ts @@ -64,9 +64,6 @@ function toLiteral({ return literalNone(); } parsed = parseCollection(stringValue); - if (!parsed.length) { - return literalNone(); - } } const helper = getHelperForInput(subtype.type); diff --git a/src/components/Launch/LaunchForm/inputHelpers/test/inputHelpers.test.ts b/src/components/Launch/LaunchForm/inputHelpers/test/inputHelpers.test.ts index 4bed1617e..964eb4b10 100644 --- a/src/components/Launch/LaunchForm/inputHelpers/test/inputHelpers.test.ts +++ b/src/components/Launch/LaunchForm/inputHelpers/test/inputHelpers.test.ts @@ -1,7 +1,7 @@ import { stringifyValue } from 'common/utils'; import { Core } from 'flyteidl'; import * as Long from 'long'; -import { BlobDimensionality } from 'models'; +import { BlobDimensionality, SimpleType } from 'models'; import { collectionInputTypeDefinition, nestedCollectionInputTypeDefinition, @@ -207,6 +207,34 @@ describe('inputToLiteral', () => { ).toEqual(output); }); }); + + it('should convert empty array string literal to empty collection', () => { + const input = makeCollectionInput( + { + type: InputType.String, + literalType: { simple: SimpleType.STRING } + }, + '[]' + ); + const expected: Core.ILiteral = { + collection: { literals: [] } + }; + expect(inputToLiteral(input)).toEqual(expected); + }); + + it('should convert nested empty array string literal to nested empty collection', () => { + const input = makeNestedCollectionInput( + { + type: InputType.String, + literalType: { simple: SimpleType.STRING } + }, + '[[]]' + ); + const expected: Core.ILiteral = { + collection: { literals: [{ collection: { literals: [] } }] } + }; + expect(inputToLiteral(input)).toEqual(expected); + }); }); describe('Unsupported Types', () => {