fix(#691): bind invalid values as empty strings#700
fix(#691): bind invalid values as empty strings#700garethbowen wants to merge 4 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: c65f3e2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| type SetIntInputValueCase = { | ||
| [T in SetIntInputValueType]: BaseSetIntInputValueCase<T>; | ||
| }[SetIntInputValueType]; | ||
|
|
||
| it.each<SetIntInputValueCase>([ | ||
| { inputType: 'bigint', inputValue: 89n, expectedValue: 89n }, | ||
| { inputType: 'number', inputValue: 10, expectedValue: 10n }, | ||
| { inputType: 'string', inputValue: '23', expectedValue: 23n }, | ||
| { inputType: 'null', inputValue: null, expectedValue: null }, | ||
| { inputType: 'string', inputValue: '10.1', expectedValue: 10n }, | ||
| { inputType: 'number', inputValue: 10.1, expectedValue: 10n }, | ||
| ])( | ||
| '$inputValue ($inputType), resulting in value $expectedValue', | ||
| ({ inputValue, expectedValue }) => { | ||
| scenario.answer('/root/int-value', inputValue); | ||
| answer = getTypedInputNodeAnswer('/root/int-value', 'int'); | ||
|
|
||
| expectTypeOf(answer.value).toEqualTypeOf<bigint | null>(); | ||
| expectTypeOf(answer.value).toEqualTypeOf<bigint | null>(); | ||
|
|
||
| if (expectedValue == null) { | ||
| expect(answer.value).toBeNull(); | ||
| expect(answer.stringValue).toBe(''); | ||
| } else { | ||
| expect(answer.value).toBeTypeOf('bigint'); | ||
| expect(answer.value).toBe(expectedValue); | ||
| expect(answer.stringValue).toBe(`${expectedValue}`); | ||
| if (expectedValue == null) { | ||
| expect(answer.value).toBeNull(); | ||
| expect(answer.stringValue).toBe(''); | ||
| } else { | ||
| expect(answer.value).toBeTypeOf('bigint'); | ||
| expect(answer.value).toBe(expectedValue); | ||
| expect(answer.stringValue).toBe(`${expectedValue}`); | ||
| } | ||
| } | ||
| }); | ||
| ); | ||
| }); |
There was a problem hiding this comment.
I just reformatted this so because it was silly to have a describe per test.
| scenario.answer('/stats/balance', '-5'); | ||
| expect(scenario.answerOf('/stats/balance').getValue()).toBe(''); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
I couldn't find any existing tests for range which was weird, so wrote this very basic one. It didn't fit in bind-types because range is a style not a type.
latin-panda
left a comment
There was a problem hiding this comment.
Thank you! It’s great to have the codecs consistent now :)
I’ve been thinking about the UI/UX for invalid data entry and feel we still need Aly’s perspective. What do you think about opening a follow-up ticket so we can dive deeper into that later?
Closes #691
I have verified this PR works in these browsers (latest versions):
What else has been done to verify that this works as intended?
Why is this the best possible solution? Were any other approaches considered?
How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
Do we need any specific form for testing your changes? If so, please attach one.
What's changed