Skip to content

Commit

Permalink
✨ [#2] PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Oct 27, 2023
1 parent 0a1c0e0 commit 6d6d1db
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
13 changes: 4 additions & 9 deletions src/formio/components/currency.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
import {InputComponentSchema, MultipleCapable, PrefillConfig} from '..';
import {InputComponentSchema, MultipleCapable} from '..';

type Validator = 'required' | 'min' | 'max';
type TranslatableKeys = 'label' | 'description' | 'tooltip' | 'suffix';
type TranslatableKeys = 'label' | 'description' | 'tooltip';

export type CurrencyInputSchema = InputComponentSchema<number, Validator, TranslatableKeys>;

/**
* @group Form.io components
* @category Base types
*/
export interface BaseCurrencyComponentSchema
extends Omit<CurrencyInputSchema, 'hideLabel'>,
PrefillConfig {
export interface BaseCurrencyComponentSchema extends Omit<CurrencyInputSchema, 'hideLabel'> {
type: 'currency';
// additional properties
currency?: 'EUR';
currency: 'EUR';
decimalLimit?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
allowNegative?: boolean;
// re-add
prefix?: string;
suffix?: string;
}

/**
Expand Down
47 changes: 35 additions & 12 deletions test-d/formio/components/currency.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@ expectNotAssignable<CurrencyComponentSchema>({
hideLabel: true,
} as const);

// no multiple support -> no array defaultValue
expectNotAssignable<CurrencyComponentSchema>({
id: '123',
type: 'currency',
key: 'aCurrency',
label: 'A currency',
currency: 'EUR',
defaultValue: [],
} as const);

expectNotAssignable<CurrencyComponentSchema>({
id: '123',
type: 'currency',
Expand Down Expand Up @@ -139,7 +129,40 @@ expectAssignable<CurrencyComponentSchema>({
// translations tab in builder form
openForms: {
translations: {
nl: {suffix: 'foo', tooltip: 'bar'},
nl: {tooltip: 'bar'},
},
},
});
});

// invalid, multiple true and non-array default value
expectNotAssignable<CurrencyComponentSchema>({
id: '123',
type: 'currency',
key: 'aCurrency',
label: 'A currency',
currency: 'EUR',
multiple: true,
defaultValue: 2,
});

// invalid, multiple false and array default value
expectNotAssignable<CurrencyComponentSchema>({
id: '123',
type: 'currency',
key: 'aCurrency',
label: 'A currency',
currency: 'EUR',
multiple: false,
defaultValue: [1],
});

// invalid, multiple true and wrong default value in array element
expectNotAssignable<CurrencyComponentSchema>({
id: '123',
type: 'currency',
key: 'aCurrency',
label: 'A currency',
currency: 'EUR',
multiple: true,
defaultValue: ['a string and not a number'],
});

0 comments on commit 6d6d1db

Please sign in to comment.