Skip to content

Commit 1938d7b

Browse files
committed
feat: tests for geomap dataprocessing functions
1 parent 1847cbf commit 1938d7b

File tree

2 files changed

+108
-5
lines changed

2 files changed

+108
-5
lines changed

vis/js/utils/data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,11 +627,11 @@ export const parseGeographicalData = (data: AquanaviPaper) => {
627627

628628
switch (formattedKey) {
629629
case "country": {
630-
result[formattedKey] = formattedValue;
630+
result[formattedKey] = formattedValue ? formattedValue : null;
631631
break;
632632
}
633633
case "continent": {
634-
result[formattedKey] = formattedValue;
634+
result[formattedKey] = formattedValue ? formattedValue : null;
635635
break;
636636
}
637637
case "east": {
Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { expect, describe, it } from 'vitest';
2-
1+
import { expect, describe, it } from "vitest";
32

43
import {
54
commentArrayValidator,
@@ -8,9 +7,11 @@ import {
87
getInternalMetric,
98
getVisibleMetric,
109
oaStateValidator,
10+
parseGeographicalData,
1111
resultTypeSanitizer,
1212
stringArrayValidator,
13-
} from "../../js/utils/data";
13+
} from "@/js/utils/data";
14+
import { AquanaviPaper } from "@/js/types";
1415

1516
describe("Data utility functions", () => {
1617
describe("date validator", () => {
@@ -221,4 +222,106 @@ describe("Data utility functions", () => {
221222
expect(result).toEqual(0);
222223
});
223224
});
225+
226+
describe("Geomap data processing functions", () => {
227+
describe("Parse geographical data correctly", () => {
228+
const createMockData = (coverageString: string): AquanaviPaper => {
229+
const MOCK_DATA = {
230+
coverage: coverageString,
231+
} as AquanaviPaper;
232+
233+
return MOCK_DATA;
234+
};
235+
236+
describe("Country name", () => {
237+
it("Return the name if it is presented in the string", () => {
238+
const COUNTRY_NAME = "France";
239+
const COVERAGE_STRING_TO_PARSE = `country=${COUNTRY_NAME}; continent=Europe; east=-0.618181; north=44.776596; start=2010-07; end=2012-06`;
240+
const MOCK_DATA = createMockData(COVERAGE_STRING_TO_PARSE);
241+
242+
const result = parseGeographicalData(MOCK_DATA);
243+
const { country } = result;
244+
245+
expect(country).toBe(COUNTRY_NAME);
246+
});
247+
248+
it("Return null instead of a name if it is not presented in the string", () => {
249+
const COVERAGE_STRING_TO_PARSE = `country=; continent=Europe; east=-0.618181; north=44.776596; start=2010-07; end=2012-06`;
250+
const MOCK_DATA = createMockData(COVERAGE_STRING_TO_PARSE);
251+
252+
const result = parseGeographicalData(MOCK_DATA);
253+
const { country } = result;
254+
255+
expect(country).toBe(null);
256+
});
257+
});
258+
259+
describe("Continent name", () => {
260+
it("Return the name if it is presented in the string", () => {
261+
const CONTINENT_NAME = "Europe";
262+
const COVERAGE_STRING_TO_PARSE = `country=France; continent=${CONTINENT_NAME}; east=-0.618181; north=44.776596; start=2010-07; end=2012-06`;
263+
const MOCK_DATA = createMockData(COVERAGE_STRING_TO_PARSE);
264+
265+
const result = parseGeographicalData(MOCK_DATA);
266+
const { continent } = result;
267+
268+
expect(continent).toBe(CONTINENT_NAME);
269+
});
270+
271+
it("Return null instead of a name if it is not presented in the string", () => {
272+
const COVERAGE_STRING_TO_PARSE = `country=France; continent=; east=-0.618181; north=44.776596; start=2010-07; end=2012-06`;
273+
const MOCK_DATA = createMockData(COVERAGE_STRING_TO_PARSE);
274+
275+
const result = parseGeographicalData(MOCK_DATA);
276+
const { continent } = result;
277+
278+
expect(continent).toBe(null);
279+
});
280+
});
281+
282+
describe("Coordinates", () => {
283+
it("Return east coordinates if they are presented in the string", () => {
284+
const COORDINATES = "-0.618181";
285+
const COVERAGE_STRING_TO_PARSE = `country=France; continent=Europe; east=${COORDINATES}; north=44.776596; start=2010-07; end=2012-06`;
286+
const MOCK_DATA = createMockData(COVERAGE_STRING_TO_PARSE);
287+
288+
const result = parseGeographicalData(MOCK_DATA);
289+
const { east } = result;
290+
291+
expect(east).toBe(Number(COORDINATES));
292+
});
293+
294+
it("Return null instead of east coordinates if they are not presented in the string", () => {
295+
const COVERAGE_STRING_TO_PARSE = `country=France; continent=Europe; east=; north=44.776596; start=2010-07; end=2012-06`;
296+
const MOCK_DATA = createMockData(COVERAGE_STRING_TO_PARSE);
297+
298+
const result = parseGeographicalData(MOCK_DATA);
299+
const { east } = result;
300+
301+
expect(east).toBe(null);
302+
});
303+
304+
it("Return north coordinates if they are presented in the string", () => {
305+
const COORDINATES = "44.776596";
306+
const COVERAGE_STRING_TO_PARSE = `country=France; continent=Europe; east=-0.618181; north=${COORDINATES}; start=2010-07; end=2012-06`;
307+
const MOCK_DATA = createMockData(COVERAGE_STRING_TO_PARSE);
308+
309+
const result = parseGeographicalData(MOCK_DATA);
310+
const { north } = result;
311+
312+
expect(north).toBe(Number(COORDINATES));
313+
});
314+
315+
it("Return null instead of north coordinates if they are not presented in the string", () => {
316+
const COVERAGE_STRING_TO_PARSE = `country=France; continent=Europe; east=-0.618181; north=; start=2010-07; end=2012-06`;
317+
const MOCK_DATA = createMockData(COVERAGE_STRING_TO_PARSE);
318+
319+
const result = parseGeographicalData(MOCK_DATA);
320+
const { north } = result;
321+
322+
expect(north).toBe(null);
323+
});
324+
});
325+
});
326+
});
224327
});

0 commit comments

Comments
 (0)