-
- {/* Icon */}
- {!isMultiple && (
-
this._optionId)(this);
+
+ return html`
+
+
+
+ ${!isMultiple
+ ? html`
- {this.iconName && }
-
- )}
-
- {/* Checkbox */}
- {isMultiple && (
-
- )}
-
- {/* Label */}
-
- this._setupHighlightHandler(event)} />
-
- {/* Search highlight */}
- {this._isAutocomplete &&
- this._label &&
- !this._disableLabelHighlight &&
- this._getHighlightedLabel()}
-
- {this._inertAriaGroups && this._groupLabel && (
- ({this._groupLabel})
- )}
-
-
- {/* Selected tick */}
- {this._isSelect && !isMultiple && this.selected && }
-
+
+ ${this.iconName ? html`` : nothing}
+
+ `
+ : nothing}
+
+
+ ${isMultiple
+ ? html`
`
+ : nothing}
+
+
+
+
+
+
+ ${this._isAutocomplete && this._label && !this._disableLabelHighlight
+ ? this._getHighlightedLabel()
+ : nothing}
+ ${this._inertAriaGroups && this._groupLabel
+ ? html`
+ (${this._groupLabel})`
+ : nothing}
+
+
+
+ ${this._isSelect && !isMultiple && this.selected
+ ? html`
`
+ : nothing}
-
- );
+
+ `;
+ }
+}
+
+declare global {
+ interface HTMLElementTagNameMap {
+ // eslint-disable-next-line @typescript-eslint/naming-convention
+ 'sbb-option': SbbOption;
}
}
diff --git a/src/components/sbb-select/index.ts b/src/components/sbb-select/index.ts
new file mode 100644
index 0000000000..618f8ad275
--- /dev/null
+++ b/src/components/sbb-select/index.ts
@@ -0,0 +1 @@
+export * from './sbb-select';
diff --git a/src/components/sbb-select/sbb-select.custom.d.ts b/src/components/sbb-select/sbb-select.custom.d.ts
deleted file mode 100644
index af67fe4e6b..0000000000
--- a/src/components/sbb-select/sbb-select.custom.d.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-export interface SelectChange {
- type: 'value';
- value: string | string[];
-}
diff --git a/src/components/sbb-select/sbb-select.e2e.ts b/src/components/sbb-select/sbb-select.e2e.ts
index 2c78e22fb1..86cbd85902 100644
--- a/src/components/sbb-select/sbb-select.e2e.ts
+++ b/src/components/sbb-select/sbb-select.e2e.ts
@@ -1,23 +1,24 @@
-import { E2EElement, E2EPage, newE2EPage } from '@stencil/core/testing';
-import events from './sbb-select.events';
-import optionEvents from '../sbb-option/sbb-option.events';
-import { waitForCondition } from '../../global/testing';
+import { SbbOption, events as optionEvents } from '../sbb-option';
+import { waitForCondition, waitForLitRender } from '../../global/testing';
+import { aTimeout, assert, expect, fixture } from '@open-wc/testing';
+import { html } from 'lit/static-html.js';
+import { sendKeys } from '@web/test-runner-commands';
+import { EventSpy } from '../../global/testing/event-spy';
+import { events, SbbSelect } from './sbb-select';
describe('sbb-select', () => {
- let element: E2EElement,
- focusableElement: E2EElement,
- firstOption: E2EElement,
- secondOption: E2EElement,
- thirdOption: E2EElement,
- displayValue: E2EElement,
- comboBoxElement: E2EElement,
- page: E2EPage;
+ let element: SbbSelect,
+ focusableElement: HTMLElement,
+ firstOption: SbbOption,
+ secondOption: SbbOption,
+ thirdOption: SbbOption,
+ displayValue: HTMLElement,
+ comboBoxElement: HTMLElement;
beforeEach(async () => {
- page = await newE2EPage();
- await page.setContent(`
+ await fixture(html`
-
+
First
Second
Third
@@ -25,125 +26,118 @@ describe('sbb-select', () => {
`);
- element = await page.find('sbb-select');
- comboBoxElement = await page.find('[role="combobox"]');
+ element = document.querySelector('sbb-select');
+ comboBoxElement = document.querySelector('[role="combobox"]');
focusableElement = comboBoxElement;
- firstOption = await page.find('sbb-select > sbb-option#option-1');
- secondOption = await page.find('sbb-select > sbb-option#option-2');
- thirdOption = await page.find('sbb-select > sbb-option#option-3');
- displayValue = await page.find('sbb-select >>> .sbb-select__trigger');
- await page.waitForChanges();
+ firstOption = element.querySelector('#option-1');
+ secondOption = element.querySelector('#option-2');
+ thirdOption = element.querySelector('#option-3');
+ displayValue = element.shadowRoot.querySelector('.sbb-select__trigger');
});
it('renders', async () => {
- expect(element).toHaveClass('hydrated');
+ assert.instanceOf(element, SbbSelect);
+ assert.instanceOf(firstOption, SbbOption);
});
it('opens and closes the dialog', async () => {
- const willOpen = await page.spyOnEvent(events.willOpen);
- const didOpen = await page.spyOnEvent(events.didOpen);
- const willClose = await page.spyOnEvent(events.willClose);
- const didClose = await page.spyOnEvent(events.didClose);
- await element.triggerEvent('click');
- await page.waitForChanges();
+ const willOpen = new EventSpy(events.willOpen);
+ const didOpen = new EventSpy(events.didOpen);
+ const willClose = new EventSpy(events.willClose);
+ const didClose = new EventSpy(events.didClose);
+ element.dispatchEvent(new CustomEvent('click'));
+ await waitForLitRender(element);
await waitForCondition(() => willOpen.events.length === 1);
-
- expect(willOpen).toHaveReceivedEventTimes(1);
- await page.waitForChanges();
+ expect(willOpen.count).to.be.equal(1);
await waitForCondition(() => didOpen.events.length === 1);
- expect(didOpen).toHaveReceivedEventTimes(1);
- await page.waitForChanges();
+ expect(didOpen.count).to.be.equal(1);
+ await waitForLitRender(element);
- expect(comboBoxElement).toEqualAttribute('aria-expanded', 'true');
+ expect(comboBoxElement).to.have.attribute('aria-expanded', 'true');
- await element.triggerEvent('click');
- await page.waitForChanges();
+ element.dispatchEvent(new CustomEvent('click'));
+ await waitForLitRender(element);
await waitForCondition(() => willClose.events.length === 1);
-
- expect(willClose).toHaveReceivedEventTimes(1);
- await page.waitForChanges();
+ expect(willClose.count).to.be.equal(1);
await waitForCondition(() => didClose.events.length === 1);
- expect(didClose).toHaveReceivedEventTimes(1);
- await page.waitForChanges();
+ expect(didClose.count).to.be.equal(1);
+ await waitForLitRender(element);
- expect(comboBoxElement).toEqualAttribute('aria-expanded', 'false');
+ expect(comboBoxElement).to.have.attribute('aria-expanded', 'false');
});
it('displays placeholder if no value is set and there is no selected element', async () => {
- expect(await element.getProperty('value')).toBeUndefined();
- const placeholder = await page.find('sbb-select >>> .sbb-select__trigger--placeholder');
- expect(placeholder).not.toBeNull();
- expect(placeholder.textContent).toEqualText('Placeholder');
+ expect(element.value).to.be.undefined;
+ const placeholder = element.shadowRoot.querySelector('.sbb-select__trigger--placeholder');
+ expect(placeholder).not.to.be.null;
+ expect(placeholder).to.have.trimmed.text('Placeholder');
});
it("displays value if it's set, or placeholder if value doesn't match available options", async () => {
- expect(displayValue.textContent).toEqualText('Placeholder');
-
- element.setProperty('value', '1');
- await page.waitForChanges();
- expect(displayValue).toEqualText('First');
- expect(firstOption).toHaveAttribute('selected');
- expect(secondOption).not.toHaveAttribute('selected');
- expect(thirdOption).not.toHaveAttribute('selected');
-
- element.setProperty('value', '000000000');
- await page.waitForChanges();
- expect(displayValue).toEqualText('Placeholder');
- expect(firstOption).not.toHaveAttribute('selected');
- expect(secondOption).not.toHaveAttribute('selected');
- expect(thirdOption).not.toHaveAttribute('selected');
+ expect(displayValue).to.have.trimmed.text('Placeholder');
+
+ element.value = '1';
+ await waitForLitRender(element);
+ expect(displayValue).to.have.trimmed.text('First');
+ expect(firstOption).to.have.attribute('selected');
+ expect(secondOption).not.to.have.attribute('selected');
+ expect(thirdOption).not.to.have.attribute('selected');
+
+ element.value = '000000000';
+ await waitForLitRender(element);
+ expect(displayValue).to.have.trimmed.text('Placeholder');
+ expect(firstOption).not.to.have.attribute('selected');
+ expect(secondOption).not.to.have.attribute('selected');
+ expect(thirdOption).not.to.have.attribute('selected');
});
it("displays joined string if both multiple and value props are set, or placeholder if value doesn't match available options", async () => {
- expect(displayValue.textContent).toEqualText('Placeholder');
- element.setAttribute('multiple', true);
-
- element.setProperty('value', ['1', '3']);
- await page.waitForChanges();
- expect(displayValue).toEqualText('First, Third');
- expect(firstOption).toHaveAttribute('selected');
- expect(secondOption).not.toHaveAttribute('selected');
- expect(thirdOption).toHaveAttribute('selected');
-
- element.setProperty('value', '000000000');
- await page.waitForChanges();
- expect(displayValue).toEqualText('Placeholder');
- expect(firstOption).not.toHaveAttribute('selected');
- expect(secondOption).not.toHaveAttribute('selected');
- expect(thirdOption).not.toHaveAttribute('selected');
+ expect(displayValue).to.have.trimmed.text('Placeholder');
+ element.setAttribute('multiple', '');
+
+ element.value = ['1', '3'];
+ await waitForLitRender(element);
+ expect(displayValue).to.have.trimmed.text('First, Third');
+ expect(firstOption).to.have.attribute('selected');
+ expect(secondOption).not.to.have.attribute('selected');
+ expect(thirdOption).to.have.attribute('selected');
+
+ element.value = '000000000';
+ await waitForLitRender(element);
+ expect(displayValue).to.have.trimmed.text('Placeholder');
+ expect(firstOption).not.to.have.attribute('selected');
+ expect(secondOption).not.to.have.attribute('selected');
+ expect(thirdOption).not.to.have.attribute('selected');
});
it("displays value if it's set with 'wrong' selected attributes on sbb-options", async () => {
- page = await newE2EPage();
- await page.setContent(`
+ const root = await fixture(html`
-
+
First
Second
Third
`);
- element = await page.find('sbb-select');
- await page.waitForChanges();
-
- const displayValue = await page.find('sbb-select >>> .sbb-select__trigger');
- const firstOption = await page.find('sbb-select > sbb-option#option-1');
- const secondOption = await page.find('sbb-select > sbb-option#option-2');
- const thirdOption = await page.find('sbb-select > sbb-option#option-3');
-
- expect(await element.getProperty('value')).toEqual('2');
- expect(displayValue).toEqualText('Second');
- expect(firstOption).not.toHaveAttribute('selected');
- expect(secondOption).toHaveAttribute('selected');
- expect(thirdOption).not.toHaveAttribute('selected');
+ element = root.querySelector('sbb-select');
+
+ const displayValue = element.shadowRoot.querySelector('.sbb-select__trigger');
+ const firstOption = element.querySelector('#option-1');
+ const secondOption = element.querySelector('#option-2');
+ const thirdOption = element.querySelector('#option-3');
+
+ expect(element.value).to.be.equal('2');
+ expect(displayValue).to.have.trimmed.text('Second');
+ expect(firstOption).not.to.have.attribute('selected');
+ expect(secondOption).to.have.attribute('selected');
+ expect(thirdOption).not.to.have.attribute('selected');
});
it('display selected sbb-option if no value is set, then handles selection', async () => {
- page = await newE2EPage();
- await page.setContent(`
+ const root = await fixture(html`
First
@@ -152,202 +146,211 @@ describe('sbb-select', () => {
`);
- element = await page.find('sbb-select');
- comboBoxElement = await page.find('[role="combobox"]');
+ element = root.querySelector('sbb-select');
+ comboBoxElement = root.querySelector('[role="combobox"]');
focusableElement = comboBoxElement;
- await page.waitForChanges();
+ await waitForLitRender(element);
+
+ const displayValue = element.shadowRoot.querySelector('.sbb-select__trigger');
+ expect(displayValue).to.have.trimmed.text('First');
+ expect(element.value).to.be.equal('1');
- const displayValue = await page.find('sbb-select >>> .sbb-select__trigger');
- expect(displayValue).toEqualText('First');
- expect(await element.getProperty('value')).toEqual('1');
+ const willOpen = new EventSpy(events.willOpen);
+ const didOpen = new EventSpy(events.didOpen);
+ element.click();
- const willOpen = await page.spyOnEvent(events.willOpen);
- const didOpen = await page.spyOnEvent(events.didOpen);
- await element.triggerEvent('click');
- await page.waitForChanges();
await waitForCondition(() => willOpen.events.length === 1);
- expect(willOpen).toHaveReceivedEventTimes(1);
- await page.waitForChanges();
+ expect(willOpen.count).to.be.equal(1);
await waitForCondition(() => didOpen.events.length === 1);
- expect(didOpen).toHaveReceivedEventTimes(1);
- const firstOption = await page.find('sbb-select > sbb-option#option-1');
- expect(firstOption).not.toHaveAttribute('active');
- expect(firstOption).toHaveAttribute('selected');
- const secondOption = await page.find('sbb-select > sbb-option#option-2');
- expect(secondOption).not.toHaveAttribute('active');
- expect(secondOption).not.toHaveAttribute('selected');
-
- const selectionChange = await page.spyOnEvent(optionEvents.selectionChange);
- const optionSelected = await page.spyOnEvent(optionEvents.optionSelected);
- const willClose = await page.spyOnEvent(events.willClose);
- const didClose = await page.spyOnEvent(events.didClose);
- await secondOption.triggerEvent('click');
- await page.waitForChanges();
+ expect(didOpen.count).to.be.equal(1);
+ await waitForLitRender(element);
+
+ firstOption = element.querySelector('#option-1');
+ expect(firstOption).not.to.have.attribute('active');
+ expect(firstOption).to.have.attribute('selected');
+ secondOption = element.querySelector('#option-2');
+ expect(secondOption).not.to.have.attribute('active');
+ expect(secondOption).not.to.have.attribute('selected');
+
+ const selectionChange = new EventSpy(optionEvents.selectionChange);
+ const optionSelected = new EventSpy(optionEvents.optionSelected);
+ const willClose = new EventSpy(events.willClose);
+ const didClose = new EventSpy(events.didClose);
+
+ secondOption.click();
+ await waitForLitRender(element);
// Event received, panel is closed
- expect(selectionChange).toHaveReceivedEventTimes(1);
- expect(optionSelected).toHaveReceivedEventTimes(1);
+ expect(selectionChange.count).to.be.equal(1);
+ expect(optionSelected.count).to.be.equal(1);
- await page.waitForChanges();
await waitForCondition(() => willClose.events.length === 1);
- expect(willClose).toHaveReceivedEventTimes(1);
- await page.waitForChanges();
+ expect(willClose.count).to.be.equal(1);
await waitForCondition(() => didClose.events.length === 1);
- expect(didClose).toHaveReceivedEventTimes(1);
- expect(await element.getProperty('value')).toEqual('2');
- expect(comboBoxElement).toEqualAttribute('aria-expanded', 'false');
+ expect(didClose.count).to.be.equal(1);
+ await waitForLitRender(element);
+
+ expect(element.value).to.be.equal('2');
+ expect(comboBoxElement).to.have.attribute('aria-expanded', 'false');
});
it('handles selection in multiple', async () => {
- element.setAttribute('multiple', 'true');
- await page.waitForChanges();
+ element.setAttribute('multiple', '');
+ await waitForLitRender(element);
+
+ const willOpen = new EventSpy(events.willOpen);
+ const didOpen = new EventSpy(events.didOpen);
+ element.dispatchEvent(new CustomEvent('click'));
- const willOpen = await page.spyOnEvent(events.willOpen);
- const didOpen = await page.spyOnEvent(events.didOpen);
- await element.triggerEvent('click');
- await page.waitForChanges();
await waitForCondition(() => willOpen.events.length === 1);
- expect(willOpen).toHaveReceivedEventTimes(1);
- await page.waitForChanges();
+ expect(willOpen.count).to.be.equal(1);
await waitForCondition(() => didOpen.events.length === 1);
- expect(didOpen).toHaveReceivedEventTimes(1);
-
- const firstOption = await page.find('sbb-select > sbb-option#option-1');
- expect(firstOption).not.toHaveAttribute('active');
- expect(firstOption).not.toHaveAttribute('selected');
- const secondOption = await page.find('sbb-select > sbb-option#option-2');
- expect(secondOption).not.toHaveAttribute('active');
- expect(secondOption).not.toHaveAttribute('selected');
-
- const selectionChange = await page.spyOnEvent(optionEvents.selectionChange);
- await firstOption.triggerEvent('click');
- await page.waitForChanges();
- expect(selectionChange).toHaveReceivedEventTimes(1);
- expect(await element.getProperty('value')).toEqual(['1']);
- expect(displayValue).toEqualText('First');
-
- await secondOption.triggerEvent('click');
- await page.waitForChanges();
- expect(selectionChange).toHaveReceivedEventTimes(2);
- expect(await element.getProperty('value')).toEqual(['1', '2']);
- expect(displayValue).toEqualText('First, Second');
-
- await firstOption.triggerEvent('click');
- await page.waitForChanges();
- expect(await element.getProperty('value')).toEqual(['2']);
- await secondOption.triggerEvent('click');
- await page.waitForChanges();
- expect(await element.getProperty('value')).toEqual([]);
- expect(displayValue).toEqualText('Placeholder');
+ expect(didOpen.count).to.be.equal(1);
+ await waitForLitRender(element);
+ expect(firstOption).not.to.have.attribute('active');
+ expect(firstOption).not.to.have.attribute('selected');
+ expect(secondOption).not.to.have.attribute('active');
+ expect(secondOption).not.to.have.attribute('selected');
+
+ const selectionChange = new EventSpy(optionEvents.selectionChange);
+ firstOption.dispatchEvent(new CustomEvent('click'));
+ await waitForLitRender(element);
+ expect(selectionChange.count).to.be.equal(1);
+ expect(element.value).to.be.eql(['1']);
+ expect(displayValue).to.have.trimmed.text('First');
+
+ secondOption.dispatchEvent(new CustomEvent('click'));
+ await waitForLitRender(element);
+ expect(selectionChange.count).to.be.equal(2);
+ expect(element.value).to.be.eql(['1', '2']);
+ expect(displayValue).to.have.trimmed.text('First, Second');
+
+ firstOption.dispatchEvent(new CustomEvent('click'));
+ await waitForLitRender(element);
+ expect(element.value).to.be.eql(['2']);
+ secondOption.dispatchEvent(new CustomEvent('click'));
+ await waitForLitRender(element);
+ expect(element.value).to.be.eql([]);
+ expect(displayValue).to.have.trimmed.text('Placeholder');
// Panel is still open
- expect(comboBoxElement).toEqualAttribute('aria-expanded', 'true');
+ expect(comboBoxElement).to.have.attribute('aria-expanded', 'true');
});
it('handles keypress on host', async () => {
- const didOpen = await page.spyOnEvent(events.didOpen);
- const didClose = await page.spyOnEvent(events.didClose);
+ const didOpen = new EventSpy(events.didOpen);
+ const didClose = new EventSpy(events.didClose);
- await focusableElement.press('Enter');
- await page.waitForChanges();
+ focusableElement.focus();
+ await sendKeys({ press: 'Enter' });
+ await waitForLitRender(element);
await waitForCondition(() => didOpen.events.length === 1);
- expect(didOpen).toHaveReceivedEventTimes(1);
+ expect(didOpen.count).to.be.equal(1);
- await focusableElement.press('Escape');
- await page.waitForChanges();
+ focusableElement.focus();
+ await sendKeys({ press: 'Escape' });
+ await waitForLitRender(element);
await waitForCondition(() => didClose.events.length === 1);
- expect(didClose).toHaveReceivedEventTimes(1);
+ expect(didClose.count).to.be.equal(1);
- await focusableElement.press('ArrowDown');
- await page.waitForChanges();
+ focusableElement.focus();
+ await sendKeys({ press: 'ArrowDown' });
await waitForCondition(() => didOpen.events.length === 2);
- expect(didOpen).toHaveReceivedEventTimes(2);
+ expect(didOpen.count).to.be.equal(2);
- await focusableElement.press('Tab');
- await page.waitForChanges();
+ focusableElement.focus();
+ await sendKeys({ press: 'Tab' });
await waitForCondition(() => didClose.events.length === 2);
- expect(didClose).toHaveReceivedEventTimes(2);
-
- await focusableElement.press('F', { delay: 2000 });
- await page.waitForChanges();
- expect(didOpen).toHaveReceivedEventTimes(2);
- expect(didClose).toHaveReceivedEventTimes(2);
- expect(await page.find('sbb-select >>> .sbb-select__trigger')).toEqualText('First');
-
- await focusableElement.press('S', { delay: 2000 });
- await page.waitForChanges();
- expect(didOpen).toHaveReceivedEventTimes(2);
- expect(didClose).toHaveReceivedEventTimes(2);
- expect(await page.find('sbb-select >>> .sbb-select__trigger')).toEqualText('Second');
+ expect(didClose.count).to.be.equal(2);
+
+ focusableElement.focus();
+ await sendKeys({ press: 'F' });
+ await waitForLitRender(element);
+ expect(didOpen.count).to.be.equal(2);
+ expect(didClose.count).to.be.equal(2);
+ expect(displayValue).to.have.trimmed.text('First');
+
+ await aTimeout(1100); // wait for the reset of _searchString timeout
+
+ focusableElement.focus();
+ await sendKeys({ press: 'S' });
+ await waitForLitRender(element);
+ expect(didOpen.count).to.be.equal(2);
+ expect(didClose.count).to.be.equal(2);
+ expect(displayValue).to.have.trimmed.text('Second');
});
it('handles keyboard selection', async () => {
- const didOpen = await page.spyOnEvent(events.didOpen);
- await focusableElement.press(' ');
- await page.waitForChanges();
+ const didOpen = new EventSpy(events.didOpen);
+ focusableElement.focus();
+ await sendKeys({ press: ' ' });
await waitForCondition(() => didOpen.events.length === 1);
- expect(didOpen).toHaveReceivedEventTimes(1);
-
- const firstOption = await page.find('sbb-select > sbb-option#option-1');
- expect(firstOption).not.toHaveAttribute('active');
- expect(firstOption).not.toHaveAttribute('selected');
- await focusableElement.press('ArrowDown');
- expect(firstOption).toHaveAttribute('active');
- expect(firstOption).toHaveAttribute('selected');
- expect(await element.getProperty('value')).toEqual('1');
- expect(displayValue).toEqualText('First');
- expect(comboBoxElement).toEqualAttribute('aria-expanded', 'true');
-
- const thirdOption = await page.find('sbb-select > sbb-option#option-3');
- await focusableElement.press('T', { delay: 2000 });
- await page.waitForChanges();
- expect(didOpen).toHaveReceivedEventTimes(1);
- expect(displayValue).toEqualText('Third');
- expect(thirdOption).toHaveAttribute('active');
- expect(thirdOption).toHaveAttribute('selected');
- expect(await element.getProperty('value')).toEqual('3');
-
- const secondOption = await page.find('sbb-select > sbb-option#option-2');
- await focusableElement.press('S', { delay: 2000 });
- await page.waitForChanges();
- expect(didOpen).toHaveReceivedEventTimes(1);
- expect(displayValue).toEqualText('Second');
- expect(secondOption).toHaveAttribute('active');
- expect(secondOption).toHaveAttribute('selected');
- expect(await element.getProperty('value')).toEqual('2');
+ expect(didOpen.count).to.be.equal(1);
+ expect(firstOption).not.to.have.attribute('active');
+ expect(firstOption).not.to.have.attribute('selected');
+
+ focusableElement.focus();
+ await sendKeys({ press: 'ArrowDown' });
+ expect(firstOption).to.have.attribute('active');
+ expect(firstOption).to.have.attribute('selected');
+ expect(element.value).to.be.equal('1');
+ expect(displayValue).to.have.trimmed.text('First');
+ expect(comboBoxElement).to.have.attribute('aria-expanded', 'true');
+
+ focusableElement.focus();
+ await sendKeys({ press: 'T' });
+ await waitForLitRender(element);
+ expect(didOpen.count).to.be.equal(1);
+ expect(displayValue).to.have.trimmed.text('Third');
+ expect(thirdOption).to.have.attribute('active');
+ expect(thirdOption).to.have.attribute('selected');
+ expect(element.value).to.be.equal('3');
+
+ await aTimeout(1100); // wait for the reset of _searchString timeout
+
+ focusableElement.focus();
+ await sendKeys({ press: 'S' });
+ await waitForLitRender(element);
+ expect(didOpen.count).to.be.equal(1);
+ expect(displayValue).to.have.trimmed.text('Second');
+ expect(secondOption).to.have.attribute('active');
+ expect(secondOption).to.have.attribute('selected');
+ expect(element.value).to.be.equal('2');
});
it('handles keyboard selection in multiple', async () => {
- element.setAttribute('multiple', 'true');
- await page.waitForChanges();
+ element.setAttribute('multiple', '');
+ await waitForLitRender(element);
- const didOpen = await page.spyOnEvent(events.didOpen);
- const didClose = await page.spyOnEvent(events.didClose);
- await focusableElement.press('ArrowUp');
- await page.waitForChanges();
+ const didOpen = new EventSpy(events.didOpen);
+ const didClose = new EventSpy(events.didClose);
+ focusableElement.focus();
+ await sendKeys({ press: 'ArrowUp' });
await waitForCondition(() => didOpen.events.length === 1);
- expect(didOpen).toHaveReceivedEventTimes(1);
-
- const secondOption = await page.find('sbb-select > sbb-option#option-2');
- expect(secondOption).not.toHaveAttribute('active');
- expect(secondOption).not.toHaveAttribute('selected');
- await focusableElement.press('ArrowDown');
- await focusableElement.press('ArrowDown');
- await focusableElement.press('Enter');
- expect(secondOption).toHaveAttribute('active');
- expect(secondOption).toHaveAttribute('selected');
- expect(await element.getProperty('value')).toEqual(['2']);
- expect(displayValue).toEqualText('Second');
- await focusableElement.press('Escape');
- await page.waitForChanges();
+ expect(didOpen.count).to.be.equal(1);
+
+ expect(secondOption).not.to.have.attribute('active');
+ expect(secondOption).not.to.have.attribute('selected');
+ focusableElement.focus();
+ await sendKeys({ press: 'ArrowDown' });
+ await sendKeys({ press: 'ArrowDown' });
+ await sendKeys({ press: 'Enter' });
+ expect(secondOption).to.have.attribute('active');
+ expect(secondOption).to.have.attribute('selected');
+ expect(element.value).to.be.eql(['2']);
+ expect(displayValue).to.have.trimmed.text('Second');
+
+ await sendKeys({ press: 'Escape' });
await waitForCondition(() => didClose.events.length === 1);
- expect(didClose).toHaveReceivedEventTimes(1);
-
- await element.press('ArrowDown');
- await page.waitForChanges();
- expect(didOpen).toHaveReceivedEventTimes(2);
- expect(secondOption).not.toHaveAttribute('active');
- expect(secondOption).toHaveAttribute('selected');
- expect(comboBoxElement).toEqualAttribute('aria-expanded', 'true');
+ expect(didClose.count).to.be.equal(1);
+
+ element.focus();
+ await sendKeys({ press: 'ArrowDown' });
+ await waitForLitRender(element);
+ await waitForCondition(() => didOpen.events.length === 2);
+ expect(didOpen.count).to.be.equal(2);
+ expect(secondOption).not.to.have.attribute('active');
+ expect(secondOption).to.have.attribute('selected');
+ expect(comboBoxElement).to.have.attribute('aria-expanded', 'true');
});
});
diff --git a/src/components/sbb-select/sbb-select.events.ts b/src/components/sbb-select/sbb-select.events.ts
deleted file mode 100644
index 656a569dda..0000000000
--- a/src/components/sbb-select/sbb-select.events.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-/**
- * This file is autogenerated by the event-sync plugin.
- * See stencil.config.ts in the root directory.
- */
-export default {
- change: 'change',
- didChange: 'didChange',
- didClose: 'did-close',
- didOpen: 'did-open',
- input: 'input',
- stateChange: 'state-change',
- willClose: 'will-close',
- willOpen: 'will-open',
-};
diff --git a/src/components/sbb-select/sbb-select.spec.ts b/src/components/sbb-select/sbb-select.spec.ts
index 83cdc38ab3..0f728296e8 100644
--- a/src/components/sbb-select/sbb-select.spec.ts
+++ b/src/components/sbb-select/sbb-select.spec.ts
@@ -1,24 +1,23 @@
-import { SbbSelect } from './sbb-select';
-import { newSpecPage } from '@stencil/core/testing';
-import { SbbOption } from '../sbb-option/sbb-option';
+import { expect, fixture } from '@open-wc/testing';
+import { html } from 'lit/static-html.js';
+import '../sbb-option';
+import './sbb-select';
+import { isSafari } from '../../global/dom';
-// NOTE: it needs to load also the SbbOption component, otherwise the value is not correctly read as a component's attribute.
describe('sbb-select', () => {
it('renders', async () => {
- const { root } = await newSpecPage({
- components: [SbbSelect, SbbOption],
- html: `
-
- Option 1
- Option 2
- Option 3
-
- `,
- });
+ const root = await fixture(html`
+
+ Option 1
+ Option 2
+ Option 3
+
+ `);
+ const listboxAttr = 'id="sbb-select-1" role="listbox"';
- expect(root.shadowRoot.host).toEqualAttribute('dir', 'ltr');
- expect(root.shadowRoot.host).toEqualAttribute('data-state', 'closed');
- expect(root.shadowRoot).toEqualHtml(`
+ expect(root.shadowRoot.host).to.have.attribute('dir', 'ltr');
+ expect(root.shadowRoot.host).to.have.attribute('data-state', 'closed');
+ expect(root).shadowDom.to.be.equal(`
@@ -34,7 +33,7 @@ describe('sbb-select', () => {