-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
binary-transport.spec.js
83 lines (74 loc) · 2 KB
/
binary-transport.spec.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
import test from 'tape-promise/tape';
import {deserializeMatrix} from '@deck.gl/jupyter-widget/lib/utils/deserialize-matrix';
import {jsonConverter} from '@deck.gl/jupyter-widget/playground/create-deck';
import {processDataBuffer} from '@deck.gl/jupyter-widget/playground/playground';
const DEMO_ARRAY = new Uint32Array([0, 10, 2, 20]);
const DEMO_VALUE = new DataView(DEMO_ARRAY.buffer, DEMO_ARRAY.byteOffset, DEMO_ARRAY.byteLength);
const EXAMPLE_TRANSFER = {
'layer-id': {
length: 2,
attributes: {
getPosition: {
value: DEMO_VALUE,
size: 2,
dtype: 'uint32'
}
}
}
};
const EXPECTED_CONVERSION = {
'layer-id': {
length: 2,
attributes: {
getPosition: {
value: DEMO_ARRAY,
size: 2,
dtype: 'uint32'
}
}
}
};
test('jupyter-widget: binary-transport', t0 => {
t0.test('deserializeMatrix', t => {
const TEST_TABLE = [
{input: null, expected: null, msg: 'Null arr should produce null output'},
{
input: EXAMPLE_TRANSFER,
expected: EXPECTED_CONVERSION,
msg: 'Should convert DataView and dtype to TypedArray'
}
];
for (const testCase of TEST_TABLE) {
t.deepEquals(
deserializeMatrix(testCase.input),
testCase.expected,
`deserializeMatrix: ${testCase.msg}`
);
}
t.end();
});
// Test deck.gl JSON configuration
const DEMO_JSON_PROPS = {
viewport: null,
description: 'Test JSON config, converted into a deck.gl Layer before testing',
layers: [
{
radius: 100,
id: 'layer-id',
'@@type': 'ScatterplotLayer'
}
]
};
t0.test('processDataBuffer', t => {
const newDeckProps = processDataBuffer({
binary: EXPECTED_CONVERSION,
convertedJson: jsonConverter.convert(DEMO_JSON_PROPS)
});
t.deepEquals(
newDeckProps.layers[0].props.data,
EXPECTED_CONVERSION['layer-id'],
'should convert buffer input and props to new layers'
);
t.end();
});
});