-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [#2] Implement type definitions for password component schema
- Loading branch information
1 parent
d27ff07
commit 4ac36d7
Showing
4 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {InputComponentSchema, MultipleCapable} from '..'; | ||
|
||
type Validator = 'required'; | ||
type TranslatableKeys = 'label' | 'description' | 'tooltip'; | ||
|
||
export type PasswordInputSchema = InputComponentSchema<string, Validator, TranslatableKeys>; | ||
|
||
/** | ||
* @group Form.io components | ||
* @category Base types | ||
* | ||
* @deprecated | ||
* | ||
* The password component should not be used anymore - it's intended usage has never | ||
* been clear. | ||
*/ | ||
export interface BasePasswordComponentSchema | ||
extends Omit<PasswordInputSchema, 'hideLabel' | 'disabled' | 'placeholder'> { | ||
type: 'password'; | ||
autocomplete?: string; | ||
} | ||
|
||
/** | ||
* @group Form.io components | ||
* @category Concrete types | ||
* | ||
* @deprecated | ||
* | ||
* The password component should not be used anymore - it's intended usage has never | ||
* been clear. | ||
*/ | ||
export type PasswordComponentSchema = MultipleCapable<BasePasswordComponentSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import {expectAssignable, expectNotAssignable} from 'tsd'; | ||
|
||
import {PasswordComponentSchema} from '../../../lib'; | ||
|
||
// minimal password component schema | ||
expectAssignable<PasswordComponentSchema>({ | ||
id: 'yejak', | ||
type: 'password', | ||
key: 'somePassword', | ||
label: 'Some password', | ||
}); | ||
|
||
// with additional, password-component specific properties | ||
expectAssignable<PasswordComponentSchema>({ | ||
id: 'yejak', | ||
type: 'password', | ||
key: 'somePassword', | ||
label: 'Some password', | ||
autocomplete: 'password', | ||
}); | ||
|
||
// multiple false and appropriate default value type | ||
expectAssignable<PasswordComponentSchema>({ | ||
id: 'yejak', | ||
type: 'password', | ||
key: 'somePassword', | ||
label: 'Some password', | ||
multiple: false, | ||
defaultValue: '', | ||
}); | ||
|
||
// multiple true and appropriate default value type | ||
expectAssignable<PasswordComponentSchema>({ | ||
id: 'yejak', | ||
type: 'password', | ||
key: 'somePassword', | ||
label: 'Some password', | ||
multiple: true, | ||
defaultValue: [''], | ||
}); | ||
|
||
// full, correct schema | ||
expectAssignable<PasswordComponentSchema>({ | ||
id: 'yejak', | ||
type: 'password', | ||
defaultValue: '', | ||
// basic tab | ||
label: 'Some password', | ||
key: 'somePassword', | ||
description: '', | ||
tooltip: 'A tooltip', | ||
showInSummary: true, | ||
showInEmail: false, | ||
showInPDF: true, | ||
multiple: false, | ||
hidden: false, | ||
clearOnHide: true, | ||
isSensitiveData: true, | ||
autocomplete: 'password', | ||
// Advanced tab | ||
conditional: { | ||
show: undefined, | ||
when: '', | ||
eq: '', | ||
}, | ||
// Validation tab | ||
validate: { | ||
required: false, | ||
plugins: [], | ||
}, | ||
translatedErrors: {nl: {required: 'Geef wachtwoord.'}}, | ||
errors: {required: 'Geef wachtwoord.'}, | ||
// registration tab | ||
registration: { | ||
attribute: '', | ||
}, | ||
// translations tab in builder form | ||
openForms: { | ||
translations: { | ||
nl: {label: 'foo', description: 'bar', tooltip: 'baz'}, | ||
}, | ||
}, | ||
}); | ||
|
||
// invalid, multiple true and non-array default value | ||
expectNotAssignable<PasswordComponentSchema>({ | ||
id: 'yejak', | ||
type: 'password' as const, | ||
key: 'somePassword', | ||
label: 'Some password', | ||
multiple: true, | ||
defaultValue: '', | ||
}); | ||
|
||
// invalid, multiple false and array default value | ||
expectNotAssignable<PasswordComponentSchema>({ | ||
id: 'yejak', | ||
type: 'password' as const, | ||
key: 'somePassword', | ||
label: 'Some password', | ||
multiple: false, | ||
defaultValue: [''], | ||
}); | ||
|
||
// invalid, multiple true and wrong default value in array element | ||
expectNotAssignable<PasswordComponentSchema>({ | ||
id: 'yejak', | ||
type: 'password' as const, | ||
key: 'somePassword', | ||
label: 'Some password', | ||
multiple: true, | ||
defaultValue: [0], | ||
}); |