@internetarchive/bookreader 5.0.0-44-a7 → 5.0.0-44
Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
@@ -128,5 +128,40 @@ describe('Search Provider', () => {
|
|
128
128
|
expect(urlPluginMock.pullFromAddressBar.callCount).toEqual(2);
|
129
129
|
expect(urlPluginMock.removeUrlParam.callCount).toEqual(2);
|
130
130
|
});
|
131
|
+
it('updateSearchInUrl', async () => {
|
132
|
+
let fieldToSet;
|
133
|
+
let valueOfFieldToSet;
|
134
|
+
let setUrlParamCalled = false;
|
135
|
+
const urlPluginMock = {
|
136
|
+
pullFromAddressBar: sinon.fake(),
|
137
|
+
removeUrlParam: sinon.fake(),
|
138
|
+
setUrlParam: (field, val) => {
|
139
|
+
fieldToSet = field;
|
140
|
+
valueOfFieldToSet = val;
|
141
|
+
setUrlParamCalled = true;
|
142
|
+
}
|
143
|
+
};
|
144
|
+
const provider = new searchProvider({
|
145
|
+
onProviderChange: sinon.fake(),
|
146
|
+
bookreader: {
|
147
|
+
leafNumToIndex: sinon.fake(),
|
148
|
+
_searchPluginGoToResult: sinon.fake(),
|
149
|
+
urlPlugin: urlPluginMock,
|
150
|
+
search: sinon.fake()
|
151
|
+
}
|
152
|
+
});
|
153
|
+
|
154
|
+
const searchInitiatedEvent = new CustomEvent('bookSearchInitiated', { detail: { query: 'foobar' } });
|
155
|
+
// set initial seachState with a query
|
156
|
+
provider.onBookSearchInitiated(searchInitiatedEvent);
|
157
|
+
await provider.updateComplete;
|
158
|
+
// checking this fn:
|
159
|
+
provider.updateSearchInUrl();
|
160
|
+
await provider.updateComplete;
|
161
|
+
|
162
|
+
expect(fieldToSet).toEqual('q');
|
163
|
+
expect(valueOfFieldToSet).toEqual('foobar');
|
164
|
+
expect(setUrlParamCalled).toBe(true);
|
165
|
+
});
|
131
166
|
});
|
132
167
|
});
|
@@ -236,4 +236,17 @@ describe('<ia-book-search-results>', () => {
|
|
236
236
|
|
237
237
|
expect(response).toBeDefined();
|
238
238
|
});
|
239
|
+
it('cancels search when input is cleared', async () => {
|
240
|
+
const el = await fixture(container(results));
|
241
|
+
|
242
|
+
el.cancelSearch = sinon.fake();
|
243
|
+
await el.updateComplete;
|
244
|
+
|
245
|
+
const searchInput = el.shadowRoot.querySelector('[name="query"]');
|
246
|
+
|
247
|
+
searchInput.value = '';
|
248
|
+
searchInput.dispatchEvent(new Event('search'));
|
249
|
+
|
250
|
+
expect(el.cancelSearch.callCount).toEqual(1);
|
251
|
+
});
|
239
252
|
});
|