chore: fix types
This commit is contained in:
parent
1b5878678b
commit
938bdbd2dc
6 changed files with 27 additions and 17 deletions
|
|
@ -48,7 +48,7 @@ describe('Validator', () => {
|
||||||
it('throws when executing a Validator without a name', async () => {
|
it('throws when executing a Validator without a name', async () => {
|
||||||
class MyValidator extends Validator {}
|
class MyValidator extends Validator {}
|
||||||
expect(() => {
|
expect(() => {
|
||||||
new MyValidator().execute();
|
new MyValidator().execute(undefined);
|
||||||
}).to.throw(
|
}).to.throw(
|
||||||
'A validator needs to have a name! Please set it via "static get validatorName() { return \'IsCat\'; }"',
|
'A validator needs to have a name! Please set it via "static get validatorName() { return \'IsCat\'; }"',
|
||||||
);
|
);
|
||||||
|
|
@ -61,7 +61,10 @@ describe('Validator', () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const vali = new MyValidator({}, { getMessage: 'This is the custom error message' });
|
const vali = new MyValidator(
|
||||||
|
{},
|
||||||
|
{ getMessage: async () => 'This is the custom error message' },
|
||||||
|
);
|
||||||
const { getMessage } = getProtectedMembers(vali);
|
const { getMessage } = getProtectedMembers(vali);
|
||||||
|
|
||||||
await expectThrowsAsync(
|
await expectThrowsAsync(
|
||||||
|
|
@ -76,8 +79,8 @@ describe('Validator', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('receives a config object (optionally) as a second argument on instantiation', async () => {
|
it('receives a config object (optionally) as a second argument on instantiation', async () => {
|
||||||
const vali = new Validator('myParam', { my: 'config' });
|
const vali = new Validator('myParam', { fieldName: 'X' });
|
||||||
expect(vali.config).to.eql({ my: 'config' });
|
expect(vali.config).to.eql({ fieldName: 'X' });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has access to name, type, params, config in getMessage provided by config', () => {
|
it('has access to name, type, params, config in getMessage provided by config', () => {
|
||||||
|
|
@ -87,7 +90,7 @@ describe('Validator', () => {
|
||||||
return 'MyValidator';
|
return 'MyValidator';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const vali = new MyValidator('myParam', { my: 'config', getMessage: configSpy });
|
const vali = new MyValidator('myParam', { fieldName: 'X', getMessage: configSpy });
|
||||||
const { getMessage } = getProtectedMembers(vali);
|
const { getMessage } = getProtectedMembers(vali);
|
||||||
getMessage();
|
getMessage();
|
||||||
|
|
||||||
|
|
@ -114,7 +117,7 @@ describe('Validator', () => {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const vali = new MyValidator('myParam', { my: 'config' });
|
const vali = new MyValidator('myParam', { fieldName: 'X' });
|
||||||
const { getMessage } = getProtectedMembers(vali);
|
const { getMessage } = getProtectedMembers(vali);
|
||||||
getMessage();
|
getMessage();
|
||||||
|
|
||||||
|
|
@ -137,12 +140,12 @@ describe('Validator', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fires "config-changed" event on config change', async () => {
|
it('fires "config-changed" event on config change', async () => {
|
||||||
const vali = new Validator('foo', { foo: 'bar' });
|
const vali = new Validator('foo', { fieldName: 'X' });
|
||||||
const cb = sinon.spy(() => {});
|
const cb = sinon.spy(() => {});
|
||||||
if (vali.addEventListener) {
|
if (vali.addEventListener) {
|
||||||
vali.addEventListener('config-changed', cb);
|
vali.addEventListener('config-changed', cb);
|
||||||
}
|
}
|
||||||
vali.config = { bar: 'foo' };
|
vali.config = { fieldName: 'Y' };
|
||||||
expect(cb.callCount).to.equal(1);
|
expect(cb.callCount).to.equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ describe('Form Validation Integrations', () => {
|
||||||
await fixture(html`
|
await fixture(html`
|
||||||
<${elTag}
|
<${elTag}
|
||||||
.validators=${[
|
.validators=${[
|
||||||
new Required(null, { getMessage: () => 'error' }),
|
new Required(null, { getMessage: async () => 'error' }),
|
||||||
new WarnValidator(null, { getMessage: () => 'warning' }),
|
new WarnValidator(null, { getMessage: () => 'warning' }),
|
||||||
new DefaultSuccess(),
|
new DefaultSuccess(),
|
||||||
]}
|
]}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,11 @@ import { IsNumber } from '@lion/form-core';
|
||||||
import { formatAmount, formatCurrencyLabel } from './formatters.js';
|
import { formatAmount, formatCurrencyLabel } from './formatters.js';
|
||||||
import { parseAmount } from './parsers.js';
|
import { parseAmount } from './parsers.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {import('@lion/form-core/types/FormatMixinTypes').FormatOptions} FormatOptions
|
||||||
|
* @typedef {FormatOptions & {locale?:string;currency:string|undefined}} AmountFormatOptions
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `LionInputAmount` is a class for an amount custom form element (`<lion-input-amount>`).
|
* `LionInputAmount` is a class for an amount custom form element (`<lion-input-amount>`).
|
||||||
*
|
*
|
||||||
|
|
@ -87,9 +92,10 @@ export class LionInputAmount extends LocalizeMixin(LionInput) {
|
||||||
|
|
||||||
if (changedProperties.has('locale') && this.locale !== changedProperties.get('locale')) {
|
if (changedProperties.has('locale') && this.locale !== changedProperties.get('locale')) {
|
||||||
if (this.locale) {
|
if (this.locale) {
|
||||||
this.formatOptions.locale = this.locale;
|
/** @type {AmountFormatOptions} */
|
||||||
|
(this.formatOptions).locale = this.locale;
|
||||||
} else {
|
} else {
|
||||||
delete this.formatOptions.locale;
|
delete (/** @type {AmountFormatOptions} */ (this.formatOptions).locale);
|
||||||
}
|
}
|
||||||
this.__reformat();
|
this.__reformat();
|
||||||
}
|
}
|
||||||
|
|
@ -141,7 +147,8 @@ export class LionInputAmount extends LocalizeMixin(LionInput) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.formatOptions.currency = currency || undefined;
|
/** @type {AmountFormatOptions} */
|
||||||
|
(this.formatOptions).currency = currency || undefined;
|
||||||
if (currency) {
|
if (currency) {
|
||||||
if (!this.__currencyDisplayNodeIsConnected) {
|
if (!this.__currencyDisplayNodeIsConnected) {
|
||||||
this.appendChild(this.__currencyDisplayNode);
|
this.appendChild(this.__currencyDisplayNode);
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ export class IsIBAN extends Validator {
|
||||||
* @param {string} [data.type]
|
* @param {string} [data.type]
|
||||||
* @param {Object.<string,?>} [data.config]
|
* @param {Object.<string,?>} [data.config]
|
||||||
* @param {string} [data.name]
|
* @param {string} [data.name]
|
||||||
* @returns {Promise<string|Node>}
|
* @returns {Promise<string|Element>}
|
||||||
*/
|
*/
|
||||||
static async getMessage(data) {
|
static async getMessage(data) {
|
||||||
await loadTranslations();
|
await loadTranslations();
|
||||||
|
|
@ -153,7 +153,7 @@ export class IsCountryIBAN extends IsIBAN {
|
||||||
* @param {string} [data.type]
|
* @param {string} [data.type]
|
||||||
* @param {Object.<string,?>} [data.config]
|
* @param {Object.<string,?>} [data.config]
|
||||||
* @param {string} [data.name]
|
* @param {string} [data.name]
|
||||||
* @returns {Promise<string|Node>}
|
* @returns {Promise<string|Element>}
|
||||||
*/
|
*/
|
||||||
static async getMessage(data) {
|
static async getMessage(data) {
|
||||||
await loadTranslations();
|
await loadTranslations();
|
||||||
|
|
@ -200,7 +200,7 @@ export class IsNotCountryIBAN extends IsIBAN {
|
||||||
* @param {string} [data.type]
|
* @param {string} [data.type]
|
||||||
* @param {Object.<string,?>} [data.config]
|
* @param {Object.<string,?>} [data.config]
|
||||||
* @param {string} [data.name]
|
* @param {string} [data.name]
|
||||||
* @returns {Promise<string|Node>}
|
* @returns {Promise<string|Element>}
|
||||||
*/
|
*/
|
||||||
static async getMessage(data) {
|
static async getMessage(data) {
|
||||||
await loadTranslations();
|
await loadTranslations();
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { PhoneUtilManager } from './PhoneUtilManager.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import('../types').RegionCode} RegionCode
|
* @typedef {import('../types').RegionCode} RegionCode
|
||||||
* @typedef {* & import('awesome-phonenumber').default} PhoneNumber
|
* @typedef {* & import('@lion/input-tel/lib/awesome-phonenumber-esm').default} PhoneNumber
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ export function loadDefaultFeedbackMessages() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {MessageData} data
|
* @param {MessageData} data
|
||||||
* @returns {Promise<string|Node>}
|
* @returns {Promise<string|Element>}
|
||||||
*/
|
*/
|
||||||
const getLocalizedMessage = async data => {
|
const getLocalizedMessage = async data => {
|
||||||
await forMessagesToBeReady();
|
await forMessagesToBeReady();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue