Skip to content

Commit 9294934

Browse files
committed
Added unit tests
1 parent 4dd61a9 commit 9294934

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

test/turbocarto.spec.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('Turbocarto preprocessor', function () {
88
// CARTO might be slow sometime...
99
jest.setTimeout(40000)
1010

11-
it('must transform Trubocarto to CartoCSS', async () => {
11+
it('must transform Trubocarto with quantiles to CartoCSS', async () => {
1212
SqlApiDatasource.prototype.querySummaryStats = jest.fn().mockImplementationOnce(async () => {
1313
return [ 1, 2, 3, 4, 5 ]
1414
});
@@ -18,4 +18,37 @@ describe('Turbocarto preprocessor', function () {
1818
const cartocss = await cl.turbocarto.turbocartoToCartocss(turbocarto, sql)
1919
expect(cartocss).toBe('#layer { polygon-fill: #ffffb2; [ tabelle1_e > 1 ] { polygon-fill: #fecc5c } [ tabelle1_e > 2 ] { polygon-fill: #fd8d3c } [ tabelle1_e > 3 ] { polygon-fill: #f03b20 } [ tabelle1_e > 4 ] { polygon-fill: #bd0026 } }')
2020
});
21+
22+
it('must transform Trubocarto with equals to CartoCSS', async () => {
23+
SqlApiDatasource.prototype.querySummaryStats = jest.fn().mockImplementationOnce(async () => {
24+
return [ 1, 2, 3, 4, 5 ]
25+
});
26+
27+
const sql = 'SELECT * FROM "erde_pop_2015"'
28+
const turbocarto = '#layer { polygon-fill: ramp([tabelle1_e], (#ffffb2, #fecc5c, #fd8d3c, #f03b20, #bd0026), equals); }'
29+
const cartocss = await cl.turbocarto.turbocartoToCartocss(turbocarto, sql)
30+
expect(cartocss).toBe('#layer { polygon-fill: #ffffb2; [ tabelle1_e > 1 ] { polygon-fill: #fecc5c } [ tabelle1_e > 2 ] { polygon-fill: #fd8d3c } [ tabelle1_e > 3 ] { polygon-fill: #f03b20 } [ tabelle1_e > 4 ] { polygon-fill: #bd0026 } }')
31+
});
32+
33+
it('must transform Trubocarto with jenks to CartoCSS', async () => {
34+
SqlApiDatasource.prototype.querySummaryStats = jest.fn().mockImplementationOnce(async () => {
35+
return [ 1, 2, 3, 4, 5 ]
36+
});
37+
38+
const sql = 'SELECT * FROM "erde_pop_2015"'
39+
const turbocarto = '#layer { polygon-fill: ramp([table], (#ffffb2, #fecc5c, #fd8d3c, #f03b20, #bd0026), jenks); }'
40+
const cartocss = await cl.turbocarto.turbocartoToCartocss(turbocarto, sql)
41+
expect(cartocss).toBe('#layer { polygon-fill: #ffffb2; [ table > 1 ] { polygon-fill: #fecc5c } [ table > 2 ] { polygon-fill: #fd8d3c } [ table > 3 ] { polygon-fill: #f03b20 } [ table > 4 ] { polygon-fill: #bd0026 } }')
42+
});
43+
44+
it('must transform Trubocarto with headtails to CartoCSS', async () => {
45+
SqlApiDatasource.prototype.querySummaryStats = jest.fn().mockImplementationOnce(async () => {
46+
return [ 1, 2, 3 ]
47+
});
48+
49+
const sql = 'SELECT * FROM "erde_pop_2015"'
50+
const turbocarto = '#layer { polygon-fill: ramp([tabelle1_e], (#ffffb2, #fecc5c, #fd8d3c), headtails); }'
51+
const cartocss = await cl.turbocarto.turbocartoToCartocss(turbocarto, sql)
52+
expect(cartocss).toBe('#layer { polygon-fill: #ffffb2; [ tabelle1_e > 1 ] { polygon-fill: #fecc5c } [ tabelle1_e > 2 ] { polygon-fill: #fd8d3c } }')
53+
});
2154
});

0 commit comments

Comments
 (0)