Skip to content

Commit 9b62b5b

Browse files
committed
chore: test cases added for close button functionality
1 parent 4ab93a5 commit 9b62b5b

File tree

2 files changed

+107
-24
lines changed

2 files changed

+107
-24
lines changed

elements/pf-search-input/pf-search-input.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ export class PfSearchInput extends LitElement {
244244
}
245245
}
246246

247-
async #onClickCloseButton() {
247+
#onClickCloseButton() {
248248
this._toggleInput!.value = '';
249249
this.#updateValue(this._toggleInput?.value ?? '');
250250
this.#combobox.selected = [];
@@ -322,7 +322,10 @@ export class PfSearchInput extends LitElement {
322322
#setIsExpanded() {
323323
if (this.#clickedCloseButton) {
324324
this.#clickedCloseButton = false;
325-
// prevent the listbox from showing when we only intend to clear the input
325+
setTimeout(() =>{
326+
this.hide();
327+
// prevent the listbox from showing when we only intend to clear the input
328+
}, 10);
326329
return true;
327330
}
328331
return this.expanded;

elements/pf-search-input/test/pf-search-input.spec.ts

Lines changed: 102 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -657,28 +657,6 @@ describe('<pf-search-input>', function() {
657657
});
658658
});
659659

660-
describe('clicking the close button', function() {
661-
beforeEach(async function() {
662-
await clickElementAtOffset(element, [-10, 10]);
663-
});
664-
665-
it('hides the listbox', async function() {
666-
expect(element.expanded).not.to.be.true;
667-
expect(await a11ySnapshot()).to.not.axContainRole('listbox');
668-
});
669-
670-
it('hides the close button', async function() {
671-
expect(await a11ySnapshot()).not.to.axContainQuery({
672-
name: 'close',
673-
role: 'button',
674-
});
675-
});
676-
677-
it('removes the selected option value', async function() {
678-
expect(getSelectedOptionValue(element)).to.deep.equal([]);
679-
});
680-
});
681-
682660
describe('"p"', function() {
683661
beforeEach(press('p'));
684662
beforeEach(() => aTimeout(300));
@@ -896,6 +874,22 @@ describe('<pf-search-input>', function() {
896874
expect(await a11ySnapshot()).to.not.axContainRole('listbox');
897875
});
898876
});
877+
878+
describe('"1" when input is disabled', function() {
879+
beforeEach(press('1'));
880+
beforeEach(() => aTimeout(300));
881+
beforeEach(updateComplete);
882+
883+
it('does not show any options', async function() {
884+
expect(element.expanded).to.be.false;
885+
expect(await a11ySnapshot()).to.not.axContainRole('listbox');
886+
});
887+
888+
it('does not add any value to the input', async function() {
889+
const input = element.shadowRoot?.querySelector('input');
890+
expect(input?.value).to.equal('');
891+
});
892+
});
899893
});
900894

901895
describe('clicking the element', function() {
@@ -908,5 +902,91 @@ describe('<pf-search-input>', function() {
908902
});
909903
});
910904
});
905+
906+
describe('clicking the close button', function() {
907+
let element: PfSearchInput;
908+
const updateComplete = () => element.updateComplete;
909+
const focus = () => element.focus();
910+
911+
beforeEach(async function() {
912+
element = await createFixture<PfSearchInput>(html`
913+
<pf-search-input id="disabled-search" disabled>
914+
<pf-option value="1">1</pf-option>
915+
<pf-option value="2">2</pf-option>
916+
<pf-option value="3">3</pf-option>
917+
</pf-search-input>
918+
<label for="disabled-search">Disabled</label>`);
919+
await updateComplete();
920+
});
921+
922+
it('passes aXe audit', async function() {
923+
await expect(element).to.be.accessible();
924+
});
925+
926+
describe('clicking the close button when list box is open', function() {
927+
beforeEach(async function() {
928+
await clickElementAtOffset(element, [-10, 10]);
929+
});
930+
931+
it('hides the listbox', async function() {
932+
expect(element.expanded).not.to.be.true;
933+
expect(await a11ySnapshot()).to.not.axContainRole('listbox');
934+
});
935+
936+
it('hides the close button', async function() {
937+
expect(await a11ySnapshot()).not.to.axContainQuery({
938+
name: 'close',
939+
role: 'button',
940+
});
941+
});
942+
943+
it('removes the selected option value', async function() {
944+
expect(getSelectedOptionValue(element)).to.deep.equal([]);
945+
});
946+
947+
it('clears the input value', async function() {
948+
const input = element.shadowRoot?.querySelector('input');
949+
expect(input?.value).to.equal('');
950+
});
951+
});
952+
953+
describe('clicking the close button when list box is closed and input has value', function() {
954+
describe('focus()', function() {
955+
beforeEach(focus);
956+
beforeEach(updateComplete);
957+
describe(' press "z"', function() {
958+
beforeEach(press('z'));
959+
beforeEach(() => aTimeout(300));
960+
beforeEach(updateComplete);
961+
962+
it('does not show any options', async function() {
963+
expect(element.expanded).to.be.false;
964+
expect(await a11ySnapshot()).to.not.axContainRole('listbox');
965+
});
966+
});
967+
968+
beforeEach(async function() {
969+
await clickElementAtOffset(element, [-10, 10]);
970+
});
971+
972+
it('hides the listbox', async function() {
973+
expect(element.expanded).not.to.be.true;
974+
expect(await a11ySnapshot()).to.not.axContainRole('listbox');
975+
});
976+
977+
it('hides the close button', async function() {
978+
expect(await a11ySnapshot()).not.to.axContainQuery({
979+
name: 'close',
980+
role: 'button',
981+
});
982+
});
983+
984+
it('clears the input value', async function() {
985+
const input = element.shadowRoot?.querySelector('input');
986+
expect(input?.value).to.equal('');
987+
});
988+
});
989+
});
990+
});
911991
});
912992
});

0 commit comments

Comments
 (0)