Skip to content

Commit d56593c

Browse files
authored
add tests (#18)
* add tests * add travis.yml Signed-off-by: Shan He <[email protected]>
1 parent c178539 commit d56593c

File tree

4 files changed

+189
-1
lines changed

4 files changed

+189
-1
lines changed

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: node_js
2+
os: linux
3+
env:
4+
- CXX=g++-6
5+
install:
6+
- yarn --ignore-engines
7+
node_js:
8+
- 8
9+
- 10
10+
script:
11+
- npm run test
12+
cache: yarn

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ open tableau workbook (get it from public folder of this repo)
6464
- NOTE: if you want to enable remote debugging, use this command in terminal to open tableau
6565

6666
```sh
67-
open /Applications/Tableau\ Desktop\ 2019\.1.app --args --remote-debugging-port=8696
67+
open /Applications/Tableau\ Desktop\ 2020\.1.app --args --remote-debugging-port=8696
6868
```
6969

7070
A debug session will be available in browser http://localhost:8696

src/__test__/fixture.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) 2019 Chris DeMartini
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
import {processCsvData} from 'kepler.gl/processors';
22+
import {DATA_ID} from '../constants';
23+
24+
const rawCsv = `gps_data.utc_timestamp,gps_data.lat,gps_data.lng,gps_data.types,epoch,has_result,id,time,begintrip_ts_utc,begintrip_ts_local,date
25+
2016-09-17 00:09:55,29.9900937,31.2590542,driver_analytics_0,1472688000000,False,1,2016-09-23T00:00:00.000Z,2016-10-01 09:41:39+00:00,2016-10-01 09:41:39+00:00,2016-09-23
26+
2016-09-17 00:10:56,29.9927699,31.2461142,driver_analytics,1472688000000,False,2,2016-09-23T00:00:00.000Z,2016-10-01 09:46:37+00:00,2016-10-01 16:46:37+00:00,2016-09-23
27+
2016-09-17 00:11:56,29.9907261,31.2312742,driver_analytics,1472688000000,False,3,2016-09-23T00:00:00.000Z,,,2016-09-23
28+
2016-09-17 00:12:58,29.9870074,31.2175827,driver_analytics,1472688000000,False,4,2016-09-23T00:00:00.000Z,,,2016-09-23
29+
2016-09-17 00:14:00,29.9923041,31.2154899,driver_analytics,1472688000000,False,5,2016-09-23T00:00:00.000Z,2016-10-01 09:47:37+00:00,2016-10-01 16:47:37+00:00,
30+
2016-09-17 00:15:01,29.9968249,31.2149361,driver_analytics,1472688000000,False,12124,2016-09-23T05:00:00.000Z,,,
31+
2016-09-17 00:16:03,30.0037217,31.2164035,driver_analytics,1472688000000,False,222,2016-09-23T05:00:00.000Z,,,
32+
2016-09-17 00:17:05,30.0116207,31.2179346,driver_analytics,1472688000000,False,345,2016-09-23T00:00:00.000Z,,,2016-09-24
33+
2016-09-17 00:18:09,30.0208925,31.2179556,driver_analytics,1472708000000,False,,2016-09-23T00:00:00.000Z,,,2016-09-24
34+
2016-09-17 00:19:12,30.0218999,31.2178842,driver_analytics,1472708000000,False,,2016-09-23T06:00:00.000Z,,,2016-09-24
35+
2016-09-17 00:19:27,30.0229344,31.2179138,driver_analytics,1472708000000,False,,2016-09-23T05:00:00.000Z,,,2016-09-24
36+
2016-09-17 00:20:14,30.0264237,31.2179415,driver_analytics,1472708000000,False,,,,,2016-09-24
37+
2016-09-17 00:21:17,30.0292134,31.2181809,driver_analytics,1472754400000,False,,,,,2016-09-24
38+
2016-09-17 00:22:20,30.034391,31.2193991,driver_analytics,1472754400000,,,2016-09-23T06:00:00.000Z,,,
39+
2016-09-17 00:23:22,30.0352752,31.2181803,driver_analytics,1472754400000,,,2016-09-23T06:00:00.000Z,2016-10-01 10:01:54+00:00,2016-10-01 17:01:54+00:00,
40+
2016-09-17 00:24:24,30.0395918,31.2195902,driver_analytics,1472754400000,,1,2016-09-23T00:00:00.000Z,2016-10-01 09:53:04+00:00,2016-10-01 16:53:04+00:00,
41+
2016-09-17 00:25:28,30.0497387,31.2174421,driver_analytics,1472774400000,,,2016-09-23T07:00:00.000Z,2016-10-01 09:55:23+00:00,2016-10-01 16:55:23+00:00,
42+
2016-09-17 00:26:29,30.0538936,31.2165983,driver_analytics,1472774400000,,43,2016-09-23T07:00:00.000Z,2016-10-01 09:59:53+00:00,2016-10-01 16:59:53+00:00,2016-10-10
43+
2016-09-17 00:27:31,30.060911,31.2148748,driver_analytics,1472774400000,,4,2016-09-23T07:00:00.000Z,2016-10-01 09:57:11+00:00,2016-10-01 16:57:11+00:00,2016-10-10
44+
2016-09-17 00:28:35,30.060334,31.2212278,driver_analytics,1472774400000,,5,2016-09-23T07:00:00.000Z,2016-10-01 09:59:27+00:00,2016-10-01 16:59:27+00:00,2016-10-10
45+
2016-09-17 00:29:40,30.0554663,31.2288985,driver_analytics,1472774400000,True,,2016-09-23T07:00:00.000Z,2016-10-01 09:46:36+00:00,2016-10-01 16:46:36+00:00,2016-10-10
46+
2016-09-17 00:30:03,30.0614122,31.2187021,driver_gps,1472774400000,True,6,2016-09-23T08:00:00.000Z,2016-10-01 09:54:31+00:00,2016-10-01 16:54:31+00:00,2016-10-10
47+
2016-09-17 00:30:03,30.0612697,31.2191059,driver_gps,1472774400000,True,7,2016-09-23T08:00:00.000Z,2016-10-01 09:53:35+00:00,2016-10-01 16:53:35+00:00,2016-10-10
48+
2016-09-17 00:30:08,30.0610977,31.2194728,driver_gps,1472774400000,True,,2016-09-23T08:00:00.000Z,,,`;
49+
50+
const data = processCsvData(rawCsv);
51+
const dataset = {
52+
data,
53+
info: {
54+
id: DATA_ID
55+
}
56+
}
57+
58+
export default dataset;

src/__test__/reducer.spec.js

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*global it, expect*/
2+
3+
// Copyright (c) 2019 Chris DeMartini
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
22+
import reducer from '../reducers';
23+
import dataset from './fixture';
24+
import {MAP_ID, DATA_ID} from '../constants';
25+
26+
import {registerEntry, addDataToMap} from 'kepler.gl/actions';
27+
import {markerSelect} from '../actions';
28+
29+
it('initial reducer', () => {
30+
const initialState = reducer(undefined, {});
31+
expect(initialState.keplerGl).toEqual({});
32+
});
33+
34+
it('initial reducer with kepler', () => {
35+
const stateWKepler = reducer(undefined, registerEntry({id: MAP_ID}));
36+
expect(stateWKepler.keplerGl[MAP_ID]).toBeDefined();
37+
expect(stateWKepler.keplerGl[MAP_ID]).toEqual(
38+
expect.objectContaining({
39+
visState: expect.any(Object),
40+
uiState: expect.any(Object),
41+
mapState: expect.any(Object),
42+
mapStyle: expect.any(Object),
43+
providerState: expect.any(Object)
44+
})
45+
);
46+
});
47+
48+
it('reducer addDataToMap', () => {
49+
const stateWKepler = reducer(undefined, registerEntry({id: MAP_ID}));
50+
51+
const stateWData = reducer(
52+
stateWKepler,
53+
addDataToMap({
54+
datasets: [dataset]
55+
})
56+
);
57+
expect(stateWData.keplerGl.map.visState.datasets).toBeDefined();
58+
expect(stateWData.keplerGl.map.visState.datasets).toEqual(
59+
expect.objectContaining({
60+
[DATA_ID]: expect.any(Object)
61+
})
62+
);
63+
});
64+
65+
it('reducer marketSelect', () => {
66+
const stateWKepler = reducer(undefined, registerEntry({id: MAP_ID}));
67+
const stateWData = reducer(
68+
stateWKepler,
69+
addDataToMap({
70+
datasets: [dataset]
71+
})
72+
);
73+
74+
const payload = {
75+
field: 'date',
76+
values: ['2016-09-23']
77+
};
78+
79+
const stateFiltered = reducer(stateWData, markerSelect(payload));
80+
81+
// should add filter
82+
expect(stateFiltered.keplerGl.map.visState.filters.length).toBe(1);
83+
84+
expect(stateFiltered.keplerGl.map.visState.filters[0].dataId).toEqual([
85+
DATA_ID
86+
]);
87+
expect(stateFiltered.keplerGl.map.visState.filters[0].name).toEqual(['date']);
88+
expect(stateFiltered.keplerGl.map.visState.filters[0].value).toEqual([
89+
'2016-09-23'
90+
]);
91+
expect(stateFiltered.keplerGl.map.visState.filters[0].domain).toEqual([
92+
'2016-09-23',
93+
'2016-09-24',
94+
'2016-10-10'
95+
]);
96+
97+
expect(
98+
stateFiltered.keplerGl.map.visState.datasets[DATA_ID].filteredIndex
99+
).toEqual([0, 1, 2, 3]);
100+
101+
// set filter again
102+
const payload2 = {
103+
field: 'date',
104+
values: ['2016-09-23', '2016-09-24']
105+
};
106+
const stateFiltered2 = reducer(stateFiltered, markerSelect(payload2));
107+
expect(
108+
stateFiltered2.keplerGl.map.visState.datasets[DATA_ID].filteredIndex
109+
).toEqual([0, 1, 2, 3, 7, 8, 9, 10, 11, 12]);
110+
111+
// set it to empty should remove filter
112+
const payload3 = {
113+
field: 'date',
114+
values: []
115+
};
116+
const stateFiltered3 = reducer(stateFiltered2, markerSelect(payload3));
117+
expect(stateFiltered3.keplerGl.map.visState.filters.length).toBe(0);
118+
});

0 commit comments

Comments
 (0)