Skip to content

Commit f0f4ad0

Browse files
committed
added a test for cleared event
1 parent 9271a23 commit f0f4ad0

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

elements/pfe-autocomplete/src/pfe-autocomplete.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ class PfeAutocomplete extends PFElement {
149149
this._input.setAttribute("autocapitalize", "off");
150150
this._input.setAttribute("spellcheck", "false");
151151

152-
this._input.setAttribute("style", `input[type=search]::-ms-clear { display: none; width : 0; height: 0; }input[type = search]:: -ms - reveal { display: none; width: 0; height: 0; }" nput[type="search"]::-webkit-search-decoration, input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-results-button, input[type="search"]::-webkit-search-results-decoration { display: none; }`)
152+
this._input.setAttribute(
153+
"style",
154+
`input[type=search]::-ms-clear { display: none; width : 0; height: 0; }input[type = search]:: -ms - reveal { display: none; width: 0; height: 0; }" nput[type="search"]::-webkit-search-decoration, input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-results-button, input[type="search"]::-webkit-search-results-decoration { display: none; }`
155+
);
153156
}
154157

155158
disconnectedCallback() {
@@ -273,11 +276,11 @@ class PfeAutocomplete extends PFElement {
273276
}
274277

275278
_searchCleared() {
276-
if(this._input.value == '') {
279+
if (this._input.value == "") {
277280
this.emitEvent(PfeAutocomplete.events.optionsShown, {
278281
bubbles: true,
279282
composed: true,
280-
detail: { searchValue: searchQuery }
283+
detail: { searchValue: searchQuery },
281284
});
282285
}
283286
}

elements/pfe-autocomplete/test/pfe-autocomplete_test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,24 @@ describe('<pfe-autocomplete>', () => {
177177
});
178178
});
179179

180+
it('should fire a pfe-autocomplete:option-cleared event when the input is cleared', done => {
181+
flush(() => {
182+
const items = ['option 1', 'option 2'];
183+
184+
// autocompleteElem.autocompleteRequest = function (params, callback) {
185+
// const regx = new RegExp("\^" + params.query, "i");
186+
// callback(items.filter(function (item) {
187+
// return regx.test(item);
188+
// }));
189+
// };
190+
191+
autocompleteElem.addEventListener("pfe-autocomplete:option-cleared", function (event) {
192+
assert.isTrue(true); // the event listener was called
193+
done();
194+
});
195+
});
196+
});
197+
180198
it('should set selected-value attribute after user click on an option', done => {
181199
flush(() => {
182200
droplistElem.data = ['option 1', 'option 2'];

0 commit comments

Comments
 (0)