Skip to content

Commit 27c9694

Browse files
committed
test(search-input): correct test cases
1 parent 5bc1ecd commit 27c9694

File tree

1 file changed

+8
-31
lines changed

1 file changed

+8
-31
lines changed

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

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,13 @@ import { PfSearchInput } from '../pf-search-input.js';
44
import { a11ySnapshot } from '@patternfly/pfe-tools/test/a11y-snapshot.js';
55
import { sendKeys } from '@web/test-runner-commands';
66
import { clickElementAtCenter, clickElementAtOffset } from '@patternfly/pfe-tools/test/utils.js';
7-
import type { PfOption } from '../../pf-select/pf-option.js';
87

98
function press(key: string) {
109
return async function() {
1110
await sendKeys({ press: key });
1211
};
1312
}
1413

15-
/**
16-
* Get the value of the first selected option
17-
* @param element pf-select
18-
* @returns the value of the selected option, or undefined if none selected
19-
*/
20-
function getSelectedOptionValue(element: PfSearchInput): string[] {
21-
return Array.from(element.querySelectorAll<PfOption>('[selected]'), x => x.value);
22-
}
23-
24-
2514
// a11yShapshot does not surface the options
2615
function getVisibleOptionValues(element: PfSearchInput): string[] {
2716
return element.options.filter(x => !x.hidden).map(x => x.value);
@@ -385,9 +374,7 @@ describe('<pf-search-input>', function() {
385374
beforeEach(updateComplete);
386375

387376
it('selects option 3', function() {
388-
expect(getSelectedOptionValue(element)).to.deep.equal([
389-
'3',
390-
]);
377+
expect(element.value).to.equal('3');
391378
});
392379

393380
it('exposes selection to assistive technology', async function() {
@@ -425,7 +412,7 @@ describe('<pf-search-input>', function() {
425412
});
426413
});
427414

428-
describe('text input interaction', function() {
415+
describe('with alphabetically sorted items', function() {
429416
let element: PfSearchInput;
430417
const label = 'label';
431418
const updateComplete = () => element.updateComplete;
@@ -508,9 +495,7 @@ describe('<pf-search-input>', function() {
508495
});
509496

510497
it('selects option 1', function() {
511-
expect(getSelectedOptionValue(element)).to.deep.equal([
512-
'Blue',
513-
]);
498+
expect(element.value).to.equal('Blue');
514499
});
515500

516501
it('closes the listbox', async function() {
@@ -524,9 +509,7 @@ describe('<pf-search-input>', function() {
524509
});
525510

526511
it('selects option 1', function() {
527-
expect(getSelectedOptionValue(element)).to.deep.equal([
528-
'Green',
529-
]);
512+
expect(element.value).to.equal('Green');
530513
});
531514

532515
it('closes the listbox', async function() {
@@ -612,9 +595,7 @@ describe('<pf-search-input>', function() {
612595
beforeEach(updateComplete);
613596

614597
it('selects option 2', function() {
615-
expect(getSelectedOptionValue(element)).to.deep.equal([
616-
'Green',
617-
]);
598+
expect(element.value).to.equal('Green');
618599
});
619600

620601
it('sets typeahead input to second option value', async function() {
@@ -730,9 +711,7 @@ describe('<pf-search-input>', function() {
730711
beforeEach(updateComplete);
731712

732713
it('selects the option "Purple"', function() {
733-
expect(getSelectedOptionValue(element)).to.deep.equal([
734-
'Purple',
735-
]);
714+
expect(element.value).to.equal('Purple');
736715
});
737716

738717
describe('Backspace (x5)', function() {
@@ -942,7 +921,7 @@ describe('<pf-search-input>', function() {
942921
});
943922

944923
it('removes the selected option value', async function() {
945-
expect(getSelectedOptionValue(element)).to.deep.equal([]);
924+
expect(element.value).to.be.undefined;
946925
});
947926

948927
it('clears the input value', async function() {
@@ -1169,9 +1148,7 @@ describe('<pf-search-input>', function() {
11691148
beforeEach(updateComplete);
11701149

11711150
it('should select the option', function() {
1172-
expect(getSelectedOptionValue(searchInput)).to.deep.equal([
1173-
'New York',
1174-
]);
1151+
expect(searchInput.value).to.equal('New York');
11751152
});
11761153

11771154
it('should close the dropdown after selection', function() {

0 commit comments

Comments
 (0)