forked from algolia/vue-instantsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(search-client): Add support for Custom Search Clients (algolia#432)
* feat: Add `search-client` support * feat: Call `addAlgoliaAgent` only if exists * test: Add tests for `search-client` * docs: Add `search-client` prop to Index documentation * refactor: Remove `Object.create()` to create client * refactor: Use `else if` for ESLint * docs: Add section on store with custom search client
- Loading branch information
1 parent
dc8de87
commit c3d35bc
Showing
6 changed files
with
211 additions
and
3 deletions.
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