-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResultsPane.test.js
76 lines (62 loc) · 1.88 KB
/
ResultsPane.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import ResultsPane from '@/components/ResultsPane';
import merge from 'lodash.merge';
import { shallowMount } from '@vue/test-utils';
function createWrapper( overrides ) {
const defaultMountingOptions = {
propsData : {
display : false,
error : false,
highlights : {},
numBooks : 0,
results : [],
},
};
return shallowMount( ResultsPane, merge( defaultMountingOptions, overrides ) );
}
describe( 'ResultsPane', () => {
const RESULTS =
require( '../fixtures/solr-responses/solr-search.json' );
let wrapper;
async function simulateError() {
wrapper.setProps(
{
display : true,
error : true,
}
);
await wrapper.vm.$nextTick();
}
async function simulateSearch() {
wrapper.setProps(
{
display : true,
highlights : RESULTS.highlighting,
numBooks : RESULTS.length,
results : RESULTS.response.docs,
}
);
await wrapper.vm.$nextTick();
}
beforeEach( () => {
wrapper = createWrapper();
} );
test( 'renders no results found correctly', async () => {
wrapper.setProps(
{
display : true,
numBooks : 0,
results : [],
}
);
await wrapper.vm.$nextTick();
expect( wrapper.element ).toMatchSnapshot();
} );
test( 'renders results correctly', async () => {
await simulateSearch();
expect( wrapper.element ).toMatchSnapshot();
} );
test( 'renders error condition correctly', async () => {
await simulateError();
expect( wrapper.element ).toMatchSnapshot();
} );
} );