Co-authored-by: Alex Ghiu <alex.ghiu@ing.com> Co-authored-by: Gerjan van Geest <Gerjan.van.Geest@ing.com> Co-authored-by: Thijs Louisse <Thijs.Louisse@ing.com> Co-authored-by: Joren Broekema <joren.broekema@ing.com> Co-authored-by: Erik Kroes <erik.kroes@ing.com>
56 lines
2.3 KiB
JavaScript
56 lines
2.3 KiB
JavaScript
import { expect, fixture } from '@open-wc/testing';
|
|
import { html } from '@lion/core';
|
|
|
|
import { IsCountryIBAN } from '../src/validators.js';
|
|
import { formatIBAN } from '../src/formatters.js';
|
|
import { parseIBAN } from '../src/parsers.js';
|
|
|
|
import '../lion-input-iban.js';
|
|
|
|
describe('<lion-input-iban>', () => {
|
|
it('uses formatIBAN for formatting', async () => {
|
|
const el = await fixture(`<lion-input-iban></lion-input-iban>`);
|
|
expect(el.formatter).to.equal(formatIBAN);
|
|
});
|
|
|
|
it('uses parseIBAN for parsing', async () => {
|
|
const el = await fixture(`<lion-input-iban></lion-input-iban>`);
|
|
expect(el.parser).to.equal(parseIBAN);
|
|
});
|
|
|
|
it('has a type = text', async () => {
|
|
const el = await fixture(`<lion-input-iban></lion-input-iban>`);
|
|
expect(el._inputNode.type).to.equal('text');
|
|
});
|
|
|
|
it('has validator "IsIBAN" applied by default', async () => {
|
|
const el = await fixture(`<lion-input-iban></lion-input-iban>`);
|
|
el.modelValue = 'FOO';
|
|
expect(el.hasFeedbackFor).to.include('error');
|
|
expect(el.validationStates).to.have.a.property('error');
|
|
expect(el.validationStates.error).to.have.a.property('IsIBAN');
|
|
el.modelValue = 'DE89370400440532013000';
|
|
expect(el.hasFeedbackFor).not.to.include('error');
|
|
expect(el.validationStates).to.have.a.property('error');
|
|
expect(el.validationStates.error).not.to.have.a.property('IsIBAN');
|
|
});
|
|
|
|
it('can apply validator "IsCountryIBAN" to restrict countries', async () => {
|
|
const el = await fixture(html`
|
|
<lion-input-iban .validators=${[new IsCountryIBAN('NL')]}> </lion-input-iban>
|
|
`);
|
|
el.modelValue = 'DE89370400440532013000';
|
|
expect(el.hasFeedbackFor).to.include('error');
|
|
expect(el.validationStates).to.have.a.property('error');
|
|
expect(el.validationStates.error).to.have.a.property('IsCountryIBAN');
|
|
el.modelValue = 'NL17INGB0002822608';
|
|
expect(el.hasFeedbackFor).not.to.include('error');
|
|
expect(el.validationStates).to.have.a.property('error');
|
|
expect(el.validationStates.error).not.to.have.a.property('IsCountryIBAN');
|
|
el.modelValue = 'FOO';
|
|
expect(el.hasFeedbackFor).to.include('error');
|
|
expect(el.validationStates).to.have.a.property('error');
|
|
expect(el.validationStates.error).to.have.a.property('IsIBAN');
|
|
expect(el.validationStates.error).to.have.a.property('IsCountryIBAN');
|
|
});
|
|
});
|