import { expect, fixture, aTimeout } from '@open-wc/testing'; import { html } from '@lion/core'; import { localize } from '@lion/localize'; import { localizeTearDown } from '@lion/localize/test-helpers.js'; import { formatAmount } from '../src/formatters.js'; import { parseAmount } from '../src/parsers.js'; import '../lion-input-amount.js'; describe('', () => { beforeEach(() => { localizeTearDown(); }); it('uses formatAmount for formatting', async () => { const el = await fixture(``); expect(el.formatter).to.equal(formatAmount); }); it('formatAmount uses currency provided on webcomponent', async () => { // JOD displays 3 fraction digits by default localize.locale = 'fr-FR'; const el = await fixture( html` `, ); expect(el.formattedValue).to.equal('123,000'); }); it('formatAmount uses locale provided in formatOptions', async () => { let el = await fixture( html` `, ); expect(el.formattedValue).to.equal('123.00'); el = await fixture( html` `, ); expect(el.formattedValue).to.equal('123,00'); }); it('ignores global locale change if property is provided', async () => { const el = await fixture(html` `); expect(el.formattedValue).to.equal('123,456.78'); // British localize.locale = 'nl-NL'; await aTimeout(); expect(el.formattedValue).to.equal('123,456.78'); // should stay British }); it('uses parseAmount for parsing', async () => { const el = await fixture(``); expect(el.parser).to.equal(parseAmount); }); it('has type="text" to activate default keyboard on mobile with all necessary symbols', async () => { const el = await fixture(``); expect(el.inputElement.type).to.equal('text'); }); it('shows no currency', async () => { const el = await fixture(``); expect(el.$$slot('suffix')).to.be.undefined; }); it('displays currency if provided', async () => { const el = await fixture(``); expect(el.$$slot('after').innerText).to.equal('EUR'); }); it('can update currency', async () => { const el = await fixture(``); el.currency = 'USD'; await el.updateComplete; expect(el.$$slot('after').innerText).to.equal('USD'); }); it('ignores currency if a suffix is already present', async () => { const el = await fixture( `my-currency`, ); expect(el.$$slot('suffix').innerText).to.equal('my-currency'); el.currency = 'EUR'; await el.updateComplete; expect(el.$$slot('suffix').innerText).to.equal('my-currency'); }); });