-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
widget-tooltip.spec.ts
179 lines (170 loc) · 5.1 KB
/
widget-tooltip.spec.ts
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// eslint-disable-next-line
/* global document */
import test from 'tape-promise/tape';
import makeTooltip, {
getTooltipDefault,
substituteIn,
toText
} from '@deck.gl/jupyter-widget/playground/widget-tooltip';
const pickedInfo = {object: {elevationValue: 10, position: [0, 0]}, x: 0, y: 0, picked: true};
// eslint-disable-next-line
const TOOLTIP_HTML = {
html:
'<div style="display: flex; flex-direction: row; justify-content: space-between; align-items: stretch;">' +
'<div class="header" style="font-weight: 700; margin-right: 10px; flex: 1 1 0%;">elevationValue</div>' +
'<div class="value" style="flex: 0 0 auto; max-width: 250px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">10' +
'</div>' +
'</div>',
style: {
fontFamily: '"Helvetica Neue", Helvetica, Arial, sans-serif',
display: 'flex',
flex: 'wrap',
maxWidth: '500px',
flexDirection: 'column',
zIndex: 2
}
};
test('jupyter-widget: tooltip', t0 => {
t0.test('getTooltipDefault', t => {
Object.assign(pickedInfo, {picked: false});
t.equal(getTooltipDefault(pickedInfo), null, 'should return null if nothing picked');
Object.assign(pickedInfo, {picked: true});
const tooltip = getTooltipDefault(pickedInfo);
t.deepEquals(tooltip, TOOLTIP_HTML, 'tooltip is expected result');
const tooltipCached = getTooltipDefault(pickedInfo);
t.deepEquals(tooltipCached, TOOLTIP_HTML, 'tooltip called twice hits its cached value');
t.end();
});
t0.test('toText', t => {
const TESTING_TABLE = [
{
input: ['arma', 'virumque', 'cano', 'Troiae'],
expected: '["arma","virumque","cano","Troiae"]',
message: 'should convert arrays to strings'
},
{
input: ['arma', 'virumque', 'cano', 'Troiae', 'ab', 'oris'],
expected: 'Array<6>',
message: 'should convert arrays to shorthand if excessively long'
},
{
input: 4.51,
expected: '4.51',
message: 'should convert numbers to strings'
},
{
input: {id: 1},
expected: '{"id":1}',
message: 'should convert JSON to strings'
},
{
// eslint-disable-next-line
input: {id: BigInt(2)},
expected: '<Non-Serializable Object>',
message: 'should convert unserializable objects to a message'
},
{
// eslint-disable-next-line
input: 'input'.repeat(10) + '1',
expected: 'input'.repeat(10),
message: 'should cap length'
}
];
for (const kv of TESTING_TABLE) {
t.equal(toText(kv.input), kv.expected, kv.message);
}
t.end();
});
t0.test('substituteIn', t => {
const TESTING_TABLE = [
{
template: '"{quote}" - {origin}',
json: {
quote: "Be an optimist. There's not much use being anything else.",
origin: 'Winston Churchill'
},
expected: '"Be an optimist. There\'s not much use being anything else." - Winston Churchill'
},
{
template: 'Total population ({city}): {pop}',
json: {
properties: {
pop: 3305408,
city: 'Madrid'
}
},
expected: 'Total population (Madrid): 3305408'
},
{
template: 'Total population ({properties.city}): {properties.pop}',
json: {
properties: {
pop: 3305408,
city: 'Madrid'
}
},
expected: 'Total population (Madrid): 3305408'
},
{
template: '{true} {false} {null} {undefined}',
json: {
true: true,
false: false,
null: null
},
expected: 'true false null undefined'
},
{
template:
'The Answer to the Ultimate Question of Life, The Universe, and Everything: {a.b.c}',
json: {
a: {
b: {
c: 42
}
}
},
expected: 'The Answer to the Ultimate Question of Life, The Universe, and Everything: 42'
},
{
template:
'The Answer to the Ultimate Question of Life, The Universe, and Everything: {a.b.c}',
json: {
a: {}
},
expected:
'The Answer to the Ultimate Question of Life, The Universe, and Everything: undefined'
}
];
for (const kv of TESTING_TABLE) {
t.equal(substituteIn(kv.template, kv.json), kv.expected);
}
t.end();
});
t0.test('makeTooltip', t => {
t.equal(makeTooltip(null), null, 'If no tooltip JSON passed, return null');
const htmlTooltip = {
html: '<b>Elevation Value:</b> {elevationValue}',
style: {
backgroundColor: 'lemonchiffon'
}
};
const tooltip = makeTooltip(htmlTooltip)(pickedInfo);
t.deepEquals(tooltip, {
style: {backgroundColor: 'lemonchiffon'},
html: '<b>Elevation Value:</b> 10'
});
const textTooltip = {
text: 'testing',
style: {
backgroundColor: 'lemonchiffon'
}
};
t.deepEquals(textTooltip, {
style: {backgroundColor: 'lemonchiffon'},
text: 'testing'
});
t.end();
});
t0.end();
});