This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 157
feat(search-client): Add support for Custom Search Clients #432
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a6ab032
feat: Add `search-client` support
francoischalifour f5651ce
feat: Call `addAlgoliaAgent` only if exists
francoischalifour 39179bf
test: Add tests for `search-client`
francoischalifour ebe4647
docs: Add `search-client` prop to Index documentation
francoischalifour 7d807e5
refactor: Remove `Object.create()` to create client
francoischalifour 346019a
refactor: Use `else if` for ESLint
francoischalifour 03fa0d2
docs: Add section on store with custom search client
francoischalifour File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Search Client API collision and apiKey 1`] = `"vue-instantsearch: \`apiKey\` cannot be used with \`searchClient\`"`; | ||
|
||
exports[`Search Client API collision and appId 1`] = `"vue-instantsearch: \`appId\` cannot be used with \`searchClient\`"`; | ||
|
||
exports[`Search Client API collision and searchStore 1`] = `"\`searchStore\` cannot be used with \`searchClient\`"`; | ||
|
||
exports[`Search Client API collision without indexName 1`] = `"vue-instantsearch: \`indexName\` is required with \`searchClient\`"`; | ||
|
||
exports[`Search Client Properties throws if no \`search()\` method 1`] = `"vue-instantsearch: \`searchClient\` must implement a method \`search(requests)\`"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import Vue from 'vue'; | ||
import Index from '../Index.vue'; | ||
|
||
describe('Search Client', () => { | ||
describe('Properties', () => { | ||
it('throws if no `search()` method', () => { | ||
expect(() => { | ||
const Component = Vue.extend(Index); | ||
|
||
const vm = new Component({ | ||
propsData: { | ||
indexName: 'indexName', | ||
searchClient: {}, | ||
}, | ||
}); | ||
|
||
vm.$mount(); | ||
}).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('API collision', () => { | ||
test('and indexName', () => { | ||
expect(() => { | ||
const Component = Vue.extend(Index); | ||
|
||
const vm = new Component({ | ||
propsData: { | ||
indexName: 'indexName', | ||
searchClient: { | ||
search() { | ||
return Promise.resolve({ results: [{ hits: [] }] }); | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
vm.$mount(); | ||
}).not.toThrow(); | ||
}); | ||
|
||
test('without indexName', () => { | ||
expect(() => { | ||
const Component = Vue.extend(Index); | ||
|
||
const vm = new Component({ | ||
propsData: { | ||
searchClient: { | ||
search() { | ||
return Promise.resolve({ results: [{ hits: [] }] }); | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
vm.$mount(); | ||
}).toThrowErrorMatchingSnapshot(); | ||
}); | ||
|
||
test('and appId', () => { | ||
expect(() => { | ||
const Component = Vue.extend(Index); | ||
|
||
const vm = new Component({ | ||
propsData: { | ||
indexName: 'indexName', | ||
appId: 'appId', | ||
searchClient: { | ||
search() { | ||
return Promise.resolve({ results: [{ hits: [] }] }); | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
vm.$mount(); | ||
}).toThrowErrorMatchingSnapshot(); | ||
}); | ||
|
||
test('and apiKey', () => { | ||
expect(() => { | ||
const Component = Vue.extend(Index); | ||
|
||
const vm = new Component({ | ||
propsData: { | ||
indexName: 'indexName', | ||
apiKey: 'apiKey', | ||
searchClient: { | ||
search() { | ||
return Promise.resolve({ results: [{ hits: [] }] }); | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
vm.$mount(); | ||
}).toThrowErrorMatchingSnapshot(); | ||
}); | ||
|
||
test('and searchStore', () => { | ||
expect(() => { | ||
const Component = Vue.extend(Index); | ||
|
||
const vm = new Component({ | ||
propsData: { | ||
indexName: 'indexName', | ||
searchStore: {}, | ||
searchClient: { | ||
search() { | ||
return Promise.resolve({ results: [{ hits: [] }] }); | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
vm.$mount(); | ||
}).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could add this conditionally in the helper so we can call it without checking here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK with this change. It's yet another helper upgrade though haha. WDYT @bobylito?