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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #252 from algolia/feat/results-tag-name
test(results): bootstrap Results component tests
- Loading branch information
Showing
2 changed files
with
166 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`can stack results 1`] = ` | ||
<div class="ais-results"> | ||
Result 'objectID': 1Result 'objectID': 2 | ||
</div> | ||
`; | ||
|
||
exports[`can stack results 2`] = ` | ||
<div class="ais-results"> | ||
Result 'objectID': 1Result 'objectID': 2Result 'objectID': 3Result 'objectID': 4 | ||
</div> | ||
`; | ||
|
||
exports[`renders proper HTML 1`] = ` | ||
<div class="ais-results"> | ||
Result 'objectID': 1Result 'objectID': 2Result 'objectID': 3Result 'objectID': 4 | ||
</div> | ||
`; | ||
|
||
exports[`should allow to override result rendering 1`] = ` | ||
<div class="ais-results"> | ||
<h2> | ||
1 | ||
</h2> | ||
<h2> | ||
2 | ||
</h2> | ||
</div> | ||
`; | ||
|
||
exports[`should be hidden if not results are yielded 1`] = `undefined`; | ||
|
||
exports[`should not stack results by default 1`] = ` | ||
<div class="ais-results"> | ||
Result 'objectID': 1Result 'objectID': 2 | ||
</div> | ||
`; | ||
|
||
exports[`should not stack results by default 2`] = ` | ||
<div class="ais-results"> | ||
Result 'objectID': 3Result 'objectID': 4 | ||
</div> | ||
`; |
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,110 @@ | ||
import Vue from 'vue'; | ||
import { Results } from 'vue-instantsearch'; | ||
|
||
test('renders proper HTML', () => { | ||
const searchStore = { | ||
results: [ | ||
{ objectID: 1 }, | ||
{ objectID: 2 }, | ||
{ objectID: 3 }, | ||
{ objectID: 4 }, | ||
], | ||
}; | ||
const Component = Vue.extend(Results); | ||
const vm = new Component({ | ||
propsData: { | ||
searchStore, | ||
}, | ||
}); | ||
vm.$mount(); | ||
|
||
expect(vm.$el.outerHTML).toMatchSnapshot(); | ||
}); | ||
|
||
test('should be hidden if not results are yielded', () => { | ||
const searchStore = { | ||
results: [], | ||
}; | ||
const Component = Vue.extend(Results); | ||
const vm = new Component({ | ||
propsData: { | ||
searchStore, | ||
}, | ||
}); | ||
vm.$mount(); | ||
|
||
expect(vm.$el.outerHTML).toMatchSnapshot(); | ||
}); | ||
|
||
test('should allow to override result rendering', () => { | ||
const searchStore = { | ||
results: [{ objectID: 1 }, { objectID: 2 }], | ||
}; | ||
|
||
const Component = Vue.extend({ | ||
render(h) { | ||
return h('ais-results', { | ||
props: { searchStore }, | ||
scopedSlots: { | ||
default: ({ result }) => h('h2', result.objectID), | ||
}, | ||
}); | ||
}, | ||
components: { | ||
'ais-results': Results, | ||
}, | ||
}); | ||
|
||
const vm = new Component(); | ||
|
||
vm.$mount(); | ||
|
||
expect(vm.$el.outerHTML).toMatchSnapshot(); | ||
}); | ||
|
||
test('can stack results', () => { | ||
const searchStore = { | ||
page: 1, | ||
results: [{ objectID: 1 }, { objectID: 2 }], | ||
}; | ||
const Component = Vue.extend(Results); | ||
const vm = new Component({ | ||
propsData: { | ||
searchStore, | ||
stack: true, | ||
}, | ||
}); | ||
vm.$mount(); | ||
|
||
expect(vm.$el.outerHTML).toMatchSnapshot(); | ||
|
||
vm.searchStore.page = 2; | ||
vm.searchStore.results = [{ objectID: 3 }, { objectID: 4 }]; | ||
|
||
vm.$nextTick(() => { | ||
expect(vm.$el.outerHTML).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
test('should not stack results by default', () => { | ||
const searchStore = { | ||
page: 1, | ||
results: [{ objectID: 1 }, { objectID: 2 }], | ||
}; | ||
const Component = Vue.extend(Results); | ||
const vm = new Component({ | ||
propsData: { | ||
searchStore, | ||
}, | ||
}); | ||
vm.$mount(); | ||
|
||
expect(vm.$el.outerHTML).toMatchSnapshot(); | ||
|
||
vm.searchStore.page = 2; | ||
vm.searchStore.results = [{ objectID: 3 }, { objectID: 4 }]; | ||
|
||
vm.$nextTick(() => { | ||
expect(vm.$el.outerHTML).toMatchSnapshot(); | ||
}); | ||
}); |