Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
test(results): bootstrap Results component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rayrutjes committed Aug 6, 2017
1 parent fe2d577 commit fff0bfe
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/components/__tests__/__snapshots__/results.js.snap
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>
`;
110 changes: 110 additions & 0 deletions src/components/__tests__/results.js
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();
});
});

0 comments on commit fff0bfe

Please sign in to comment.