Skip to content

Commit

Permalink
test: add input and change event tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeripeierSBB committed Nov 26, 2024
1 parent 8f9a448 commit 6935428
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/elements/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ describe(`sbb-autocomplete`, () => {
it('select by mouse', async () => {
const didOpenEventSpy = new EventSpy(SbbAutocompleteElement.events.didOpen);
const optionSelectedEventSpy = new EventSpy(SbbOptionElement.events.optionSelected);
const inputEventSpy = new EventSpy('input', input);
const changeEventSpy = new EventSpy('change', input);
const optTwo = element.querySelector<SbbOptionElement>('#option-2')!;

input.focus();
Expand All @@ -134,6 +136,8 @@ describe(`sbb-autocomplete`, () => {
});
await waitForLitRender(element);

expect(inputEventSpy.count).to.be.equal(1);
expect(changeEventSpy.count).to.be.equal(1);
expect(optionSelectedEventSpy.count).to.be.equal(1);
expect(optionSelectedEventSpy.firstEvent!.target).to.have.property('id', 'option-2');
});
Expand All @@ -142,6 +146,8 @@ describe(`sbb-autocomplete`, () => {
const didOpenEventSpy = new EventSpy(SbbAutocompleteElement.events.didOpen);
const didCloseEventSpy = new EventSpy(SbbAutocompleteElement.events.didClose);
const optionSelectedEventSpy = new EventSpy(SbbOptionElement.events.optionSelected);
const inputEventSpy = new EventSpy('input', input);
const changeEventSpy = new EventSpy('change', input);
const optOne = element.querySelector('#option-1');
const optTwo = element.querySelector('#option-2');
const keydownSpy = new EventSpy('keydown', input);
Expand All @@ -167,6 +173,8 @@ describe(`sbb-autocomplete`, () => {

expect(optTwo).not.to.have.attribute('data-active');
expect(optTwo).to.have.attribute('selected');
expect(inputEventSpy.count).to.be.equal(1);
expect(changeEventSpy.count).to.be.equal(1);
expect(optionSelectedEventSpy.count).to.be.equal(1);
expect(input).to.have.attribute('aria-expanded', 'false');
expect(input).not.to.have.attribute('aria-activedescendant');
Expand Down

0 comments on commit 6935428

Please sign in to comment.