import { aTimeout, expect, waitUntil } from '@open-wc/testing'; import { html } from 'lit'; import sinon from 'sinon'; import { fixtures } from '../../internal/test/fixture.js'; import { runFormControlBaseTests } from '../../internal/test/form-control-base-tests.js'; import type WaButton from './button.js'; const variants = ['brand', 'success', 'neutral', 'warning', 'danger']; describe('', () => { runFormControlBaseTests({ tagName: 'wa-button', variantName: 'type="button"', init: (control: WaButton) => { control.type = 'button'; }, }); runFormControlBaseTests({ tagName: 'wa-button', variantName: 'type="submit"', init: (control: WaButton) => { control.type = 'submit'; }, }); runFormControlBaseTests({ tagName: 'wa-button', variantName: 'href="xyz"', init: (control: WaButton) => { control.href = 'some-url'; }, }); for (const fixture of fixtures) { describe(`with "${fixture.type}" rendering`, () => { describe('accessibility tests', () => { variants.forEach(variant => { it(`should be accessible when variant is "${variant}"`, async () => { const el = await fixture(html` Button Label `); await expect(el).to.be.accessible(); }); }); }); describe('when an attribute is removed', () => { it("should return to 'neutral' when attribute removed with no initial attribute", async () => { const el = await fixture(html`Button label`); expect(el.variant).to.equal('neutral'); expect(el.getAttribute('variant')).to.equal('neutral'); el.removeAttribute('variant'); await el.updateComplete; expect(el.variant).to.equal('neutral'); expect(el.getAttribute('variant')).to.equal('neutral'); }); it("should return to 'neutral' when attribute removed with an initial attribute", async () => { const el = await fixture(html`Button label`); expect(el.variant).to.equal('primary'); expect(el.getAttribute('variant')).to.equal('primary'); el.removeAttribute('variant'); await el.updateComplete; expect(el.variant).to.equal('neutral'); expect(el.getAttribute('variant')).to.equal('neutral'); }); }); describe('when a property is set to null', () => { it("should return to 'default' when property set to null with no initial attribute", async () => { const el = await fixture(html`Button label`); expect(el.variant).to.equal('neutral'); expect(el.getAttribute('variant')).to.equal('neutral'); // @ts-expect-error Its a test. Stop. el.variant = null; await el.updateComplete; expect(el.variant).to.equal('neutral'); expect(el.getAttribute('variant')).to.equal('neutral'); }); it("should return to 'default' when property set to null with an initial attribute", async () => { const el = await fixture(html`Button label`); expect(el.variant).to.equal('primary'); expect(el.getAttribute('variant')).to.equal('primary'); // @ts-expect-error Its a test. Stop. el.variant = null; await el.updateComplete; expect(el.variant).to.equal('neutral'); expect(el.getAttribute('variant')).to.equal('neutral'); }); }); describe('when provided no parameters', () => { it('passes accessibility test', async () => { const el = await fixture(html` Button Label `); await expect(el).to.be.accessible(); }); it('default values are set correctly', async () => { const el = await fixture(html` Button Label `); expect(el.title).to.equal(''); expect(el.variant).to.equal('neutral'); expect(el.appearance).to.equal('accent'); expect(el.size).to.equal('medium'); expect(el.disabled).to.equal(false); expect(el.caret).to.equal(false); expect(el.loading).to.equal(false); expect(el.pill).to.equal(false); }); it('should render as a