-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfilter-links.test.js
147 lines (135 loc) · 3.23 KB
/
filter-links.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
const test = require('tape');
const JSONToHTML = require('../lib/transforms/json-to-html-data');
test('Normal date and place test', (t) => {
t.plan(7);
const resource = {
data: {
type: 'objects',
attributes: {
creation: {
date: [{ value: '1912' }]
}
},
links: { root: 'http://localhost:8000' },
record: {
groupingType: 'SPH'
}
},
included: [
{
type: 'place',
attributes: {
role: {
value: 'made'
},
summary: {
title: 'London'
}
}
}
]
};
const JSONData = JSONToHTML(resource);
const made = JSONData.fact.find(el => el.key === 'Made');
t.ok(made, 'Data has facts');
t.ok(made.place, 'Data has a place');
t.ok(made.date, 'Data has a date');
t.ok(made.place.find(e => e.value === 'London'), 'Made location is correct');
t.equal(made.date.value, '1912', 'Made date is correct');
t.ok(made.place.find(e => e.link === 'http://localhost:8000/search/places/london'), 'Place Link is correct');
t.equal(made.date.link, 'http://localhost:8000/search/date[from]/1912/date[to]/1912', 'Date link is correct');
t.end();
});
test('date range test', (t) => {
t.plan(1);
const resource = {
data: {
type: 'objects',
attributes: {
creation: {
date: [{ value: '1912-1917' }]
}
},
links: { root: 'http://localhost:8000' }
},
included: [
{
type: 'place',
attributes: {
role: {
value: 'made'
},
summary: {
title: 'London'
}
}
}
]
};
const JSONData = JSONToHTML(resource);
const made = JSONData.fact.find(el => el.key === 'Made');
t.equal(made.date.link, 'http://localhost:8000/search/date[from]/1912/date[to]/1917', 'Handles date ranges correctly');
t.end();
});
test('bad date test', (t) => {
t.plan(1);
const resource = {
data: {
type: 'objects',
attributes: {
creation: {
date: [{ value: '1-91-2/1917' }]
}
},
links: { root: 'http://localhost:8000' }
},
included: [
{
type: 'place',
attributes: {
role: {
value: 'made'
},
summary: {
title: 'London'
}
}
}
]
};
const JSONData = JSONToHTML(resource);
const made = JSONData.fact.find(el => el.key === 'Made');
t.notOk(made.date.link, 'Ignores malformed dates');
t.end();
});
test('bad date range test', (t) => {
t.plan(1);
const resource = {
data: {
type: 'objects',
attributes: {
creation: {
date: [{ value: '1912-19FG=17' }]
}
},
links: { root: 'http://localhost:8000' }
},
included: [
{
type: 'place',
attributes: {
role: {
value: 'made'
},
summary: {
title: 'London'
}
}
}
]
};
const JSONData = JSONToHTML(resource);
const made = JSONData.fact.find(el => el.key === 'Made');
t.equal(made.date.link, 'http://localhost:8000/search/date[from]/1912/date[to]/1912', 'uses one date if only one is good');
t.end();
});