import { expect, fixture as _fixture } from '@open-wc/testing'; import { html } from '@lion/core'; import { getInputMembers } from '@lion/input/test-helpers'; import { IsCountryIBAN } from '../src/validators.js'; import { formatIBAN } from '../src/formatters.js'; import { parseIBAN } from '../src/parsers.js'; import '@lion/input-iban/define'; /** * @typedef {import('../src/LionInputIban').LionInputIban} LionInputIban * @typedef {import('@lion/core').TemplateResult} TemplateResult */ const fixture = /** @type {(arg: TemplateResult|string) => Promise} */ (_fixture); describe('', () => { it('uses formatIBAN for formatting', async () => { const el = await fixture(``); expect(el.formatter).to.equal(formatIBAN); }); it('uses parseIBAN for parsing', async () => { const el = await fixture(``); expect(el.parser).to.equal(parseIBAN); }); it('has a type = text', async () => { const el = await fixture(``); const { _inputNode } = getInputMembers(el); expect(_inputNode.type).to.equal('text'); }); it('has validator "IsIBAN" applied by default', async () => { const el = await fixture(``); el.modelValue = 'FOO'; expect(el.hasFeedbackFor).to.include('error'); expect(el.validationStates).to.have.property('error'); expect(el.validationStates.error).to.have.property('IsIBAN'); el.modelValue = 'DE89370400440532013000'; expect(el.hasFeedbackFor).not.to.include('error'); expect(el.validationStates).to.have.property('error'); expect(el.validationStates.error).not.to.have.property('IsIBAN'); }); it('can apply validator "IsCountryIBAN" to restrict countries', async () => { const el = await fixture(html` `); el.modelValue = 'DE89370400440532013000'; expect(el.hasFeedbackFor).to.include('error'); expect(el.validationStates).to.have.property('error'); expect(el.validationStates.error).to.have.property('IsCountryIBAN'); el.modelValue = 'NL17INGB0002822608'; expect(el.hasFeedbackFor).not.to.include('error'); expect(el.validationStates).to.have.property('error'); expect(el.validationStates.error).not.to.have.property('IsCountryIBAN'); el.modelValue = 'FOO'; expect(el.hasFeedbackFor).to.include('error'); expect(el.validationStates).to.have.property('error'); expect(el.validationStates.error).to.have.property('IsIBAN'); expect(el.validationStates.error).to.have.property('IsCountryIBAN'); }); it('is accessible', async () => { const el = await fixture( ``, ); await expect(el).to.be.accessible(); }); it('is accessible when readonly', async () => { const el = await fixture( ``, ); await expect(el).to.be.accessible(); }); it('is accessible when disabled', async () => { const el = await fixture( ``, ); await expect(el).to.be.accessible(); }); });