-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae8476c
commit b89703d
Showing
8 changed files
with
147 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,108 @@ | ||
import test from 'tape-catch'; | ||
import {_JSONLayer as JSONLayer} from '@deck.gl/json'; | ||
import {testLayer, testInitializeLayer} from '@deck.gl/test-utils'; | ||
|
||
const JSON_DATA = [ | ||
{ | ||
type: 'ScatterplotLayer', | ||
data: [{position: [-122.45, 37.8]}], | ||
getColor: [255, 0, 0, 255], | ||
getRadius: 1000 | ||
}, | ||
{ | ||
type: 'TextLayer', | ||
data: [{position: [-122.45, 37.8], text: 'Hello World'}] | ||
} | ||
]; | ||
import {configuration, JSON_DATA} from './json-converter.spec'; | ||
|
||
test('JSONLayer#import', t => { | ||
t.ok(JSONLayer, 'JSONLayer imported'); | ||
t.end(); | ||
}); | ||
|
||
test('JSONLayer#create', t => { | ||
const jsonLayer = new JSONLayer({data: JSON_DATA}); | ||
const jsonLayer = new JSONLayer({data: JSON_DATA.layers}); | ||
t.ok(jsonLayer, 'JSONLayer created'); | ||
t.end(); | ||
}); | ||
|
||
test('JSONLayer#lifecycle', t => { | ||
testLayer({ | ||
Layer: JSONLayer, | ||
testCases: [ | ||
{ | ||
title: 'empty', | ||
props: { | ||
data: JSON_DATA.layers | ||
} | ||
}, | ||
{ | ||
title: 'string data', | ||
updateProps: { | ||
configuration | ||
}, | ||
onAfterUpdate: ({subLayers}) => { | ||
t.is(subLayers.length, 2, 'Sublayers rendered'); | ||
t.is(typeof subLayers[0].props.getPosition, 'function', 'Accessor populated'); | ||
t.is(typeof subLayers[1].props.getPosition, 'function', 'Accessor populated'); | ||
} | ||
}, | ||
{ | ||
title: 'array data', | ||
updateProps: {data: JSON.stringify(JSON_DATA.layers)}, | ||
onAfterUpdate: ({subLayers}) => { | ||
t.is(subLayers.length, 2, 'Sublayers rendered'); | ||
} | ||
} | ||
], | ||
onError: t.notOk | ||
}); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('JSONLayer#fetch', t => { | ||
// polyfill/hijack fetch | ||
/* global global, window */ | ||
const _global = typeof global !== 'undefined' ? global : window; | ||
const fetch = _global.fetch; | ||
|
||
const data = { | ||
'data.json': JSON.stringify([{position: [-122.45, 37.8], text: 'Hello World'}]), | ||
'data.csv': `lon,lat,text | ||
-122.45,37.78,"Hello World" | ||
` | ||
}; | ||
_global.fetch = url => | ||
Promise.resolve({ | ||
text: () => data[url] | ||
}); | ||
|
||
const jsonLayer = new JSONLayer({ | ||
configuration, | ||
data: [ | ||
{ | ||
type: 'TextLayer', | ||
data: 'data.json' | ||
}, | ||
{ | ||
type: 'TextLayer', | ||
data: 'data.csv', | ||
getPosition: d => [d.lon, d.lat], | ||
getText: d => d.text | ||
} | ||
] | ||
}); | ||
|
||
testInitializeLayer({layer: jsonLayer, onError: t.notOk}); | ||
|
||
// Wait for fetch to resolve | ||
_global.setTimeout(() => { | ||
const subLayers = jsonLayer.renderLayers(); | ||
|
||
t.deepEqual( | ||
subLayers[0].props.data, | ||
[{position: [-122.45, 37.8], text: 'Hello World'}], | ||
'JSON parsed successfully' | ||
); | ||
t.deepEqual( | ||
subLayers[1].props.data, | ||
[[-122.45, 37.78, 'Hello World']], | ||
'CSV parsed successfully' | ||
); | ||
|
||
t.end(); | ||
}, 0); | ||
|
||
// restore fetcch | ||
_global.fetch = fetch; | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters