Skip to content

Commit 1bd584c

Browse files
committed
Improve tests
1 parent 0e19f0d commit 1bd584c

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/lib/DocsSearchBar.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class DocsSearchBar {
180180
* @returns {void}
181181
*/
182182
static checkArguments(args) {
183-
if (!args.indexUid || !args.hostUrl) {
183+
if (!args.inputSelector || !args.indexUid || !args.hostUrl) {
184184
throw new Error(usage)
185185
}
186186

@@ -277,6 +277,7 @@ class DocsSearchBar {
277277
// Given a list of hits returned by the API, will reformat them to be used in
278278
// a Hogan template
279279
static formatHits(receivedHits) {
280+
console.log("WESH")
280281
const clonedHits = utils.deepClone(receivedHits)
281282
const hits = clonedHits.map((hit) => {
282283
if (hit._formatted) {
@@ -302,7 +303,7 @@ class DocsSearchBar {
302303
groupedHits[level] = flattenedHits
303304
})
304305
groupedHits = utils.flattenAndFlagFirst(groupedHits, 'isCategoryHeader')
305-
306+
console.log({ groupedHits });
306307
// Translate hits into smaller objects to be send to the template
307308
return groupedHits.map((hit) => {
308309
const url = DocsSearchBar.formatURL(hit)
@@ -331,6 +332,20 @@ class DocsSearchBar {
331332
!isLvl2 && subcategory && subcategory !== '' && subcategory !== category
332333
const isLvl0 = !isLvl1 && !isLvl2
333334

335+
console.log({
336+
isLvl0,
337+
isLvl1,
338+
isLvl2,
339+
isLvl1EmptyOrDuplicate,
340+
isCategoryHeader: hit.isCategoryHeader,
341+
isSubCategoryHeader: hit.isSubCategoryHeader,
342+
isTextOrSubcategoryNonEmpty,
343+
category,
344+
subcategory,
345+
title: displayTitle,
346+
text,
347+
url,
348+
})
334349
return {
335350
isLvl0,
336351
isLvl1,

src/lib/__tests__/DocsSearchBar-test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,15 @@ describe('DocsSearchBar', () => {
245245
const options = {
246246
apiKey: 'apiKey',
247247
indexUid: 'indexUID',
248+
inputSelector: '#',
248249
}
249250

250251
// When
251252
expect(() => {
252253
checkArguments(options)
253254
}).toThrow(/^Usage:/)
254255
})
255-
it('should throw an error if no apiKey defined', () => {
256+
it('should throw an error if no inputSelector defined', () => {
256257
// Given
257258
const options = {
258259
hostUrl: 'test.com',
@@ -268,7 +269,7 @@ describe('DocsSearchBar', () => {
268269
// Given
269270
const options = {
270271
hostUrl: 'test.com',
271-
apiKey: 'apiKey',
272+
inputSelector: '#',
272273
}
273274

274275
// When

0 commit comments

Comments
 (0)