Skip to content

Commit

Permalink
Merge branch 'master' into update-hu-capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
VIKTORVAV99 authored Aug 27, 2024
2 parents d3468cc + 826009e commit 7b8454f
Show file tree
Hide file tree
Showing 50 changed files with 1,221 additions and 212 deletions.
108 changes: 108 additions & 0 deletions web/geo/__snapshots__/utilities.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`handleMultiPolygon > should correctly handle a valid MultiPolygon feature 1`] = `
[
{
"geometry": {
"coordinates": [
[
[
0,
0,
],
[
0,
1,
],
[
1,
1,
],
[
1,
0,
],
[
0,
0,
],
],
],
"type": "Polygon",
},
"properties": {
"name": "Test MultiPolygon",
},
"type": "Feature",
},
{
"geometry": {
"coordinates": [
[
[
2,
2,
],
[
2,
3,
],
[
3,
3,
],
[
3,
2,
],
[
2,
2,
],
],
],
"type": "Polygon",
},
"properties": {
"name": "Test MultiPolygon",
},
"type": "Feature",
},
]
`;

exports[`handlePolygon > should correctly handle a valid polygon feature 1`] = `
{
"geometry": {
"coordinates": [
[
[
0,
0,
],
[
0,
1,
],
[
1,
1,
],
[
1,
0,
],
[
0,
0,
],
],
],
"type": "Polygon",
},
"properties": {
"name": "Test Polygon",
},
"type": "Feature",
}
`;
86 changes: 86 additions & 0 deletions web/geo/utilities.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Properties } from '@turf/turf';
import { Feature, MultiPolygon, Polygon } from 'geojson';
import { describe, expect, it, vi } from 'vitest';

import { handleMultiPolygon, handlePolygon, log } from './utilities';

describe('log', () => {
it('should log the correct error message with formatting', () => {
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});

const message = 'Test error message';
log(message);

expect(consoleErrorSpy).toHaveBeenCalledWith(
'\u001B[31m%s\u001B[0m',
`ERROR: ${message}`
);

consoleErrorSpy.mockRestore();
});
});

describe('handlePolygon', () => {
it('should correctly handle a valid polygon feature', () => {
const feature: Feature<Polygon, Properties> = {
type: 'Feature',
geometry: {
type: 'Polygon',
coordinates: [
[
[0, 0],
[0, 1],
[1, 1],
[1, 0],
[0, 0],
],
],
},
properties: {
name: 'Test Polygon',
},
};

const actual = handlePolygon(feature);

expect(actual).toMatchSnapshot();
});
});

describe('handleMultiPolygon', () => {
it('should correctly handle a valid MultiPolygon feature', () => {
const feature: Feature<MultiPolygon, Properties> = {
type: 'Feature',
geometry: {
type: 'MultiPolygon',
coordinates: [
[
[
[0, 0],
[0, 1],
[1, 1],
[1, 0],
[0, 0],
],
],
[
[
[2, 2],
[2, 3],
[3, 3],
[3, 2],
[2, 2],
],
],
],
},
properties: {
name: 'Test MultiPolygon',
},
};

const actual = handleMultiPolygon(feature);

expect(actual).toMatchSnapshot();
});
});
13 changes: 12 additions & 1 deletion web/geo/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,15 @@ function log(message: string) {
const round = (number: number, decimals = 2): number =>
Math.round((number + Number.EPSILON) * 10 ** decimals) / 10 ** decimals;

export { fileExists, getHoles, getJSON, getPolygons, isSliver, log, round, writeJSON };
export {
fileExists,
getHoles,
getJSON,
getPolygons,
handleMultiPolygon,
handlePolygon,
isSliver,
log,
round,
writeJSON,
};
4 changes: 2 additions & 2 deletions web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electricitymaps-web",
"version": "1.158.0",
"version": "1.160.0",
"description": "A real-time visualisation of the CO2 emissions of electricity consumption",
"repository": {
"type": "git",
Expand Down Expand Up @@ -87,7 +87,7 @@
"i18next-resources-to-backend": "^1.2.1",
"jotai": "^2.9.1",
"js-yaml": "^4.1.0",
"lucide-react": "^0.419.0",
"lucide-react": "^0.435.0",
"maplibre-gl": "^3.6.2",
"react": "18.3.1",
"react-dom": "18.3.1",
Expand Down
18 changes: 9 additions & 9 deletions web/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions web/public/images/aggregated_dark.svg

This file was deleted.

3 changes: 0 additions & 3 deletions web/public/images/aggregated_light.svg

This file was deleted.

3 changes: 0 additions & 3 deletions web/public/images/estimated_dark.svg

This file was deleted.

3 changes: 0 additions & 3 deletions web/public/images/estimated_light.svg

This file was deleted.

3 changes: 0 additions & 3 deletions web/public/images/preliminary_dark.svg

This file was deleted.

3 changes: 0 additions & 3 deletions web/public/images/preliminary_light.svg

This file was deleted.

3 changes: 0 additions & 3 deletions web/public/images/warning_dark.svg

This file was deleted.

3 changes: 0 additions & 3 deletions web/public/images/warning_light.svg

This file was deleted.

33 changes: 33 additions & 0 deletions web/src/api/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, expect, it } from 'vitest';

import { cacheBuster } from './helpers';

describe('cacheBuster', () => {
it('should return a valid ISO string', () => {
const result = cacheBuster();
expect(new Date(result).toISOString()).toBe(result);
});

it('should round down the minutes to the nearest multiple of 5', () => {
const mockDate = new Date('2023-01-01T12:07:45.000Z');
vi.setSystemTime(mockDate);

const result = cacheBuster();
const resultDate = new Date(result);

expect(resultDate.getMinutes()).toBe(5);
expect(resultDate.getSeconds()).toBe(0);
expect(resultDate.getMilliseconds()).toBe(0);
});

it('should set seconds and milliseconds to 0', () => {
const mockDate = new Date('2023-01-01T12:07:45.678Z');
vi.setSystemTime(mockDate);

const result = cacheBuster();
const resultDate = new Date(result);

expect(resultDate.getSeconds()).toBe(0);
expect(resultDate.getMilliseconds()).toBe(0);
});
});
Loading

0 comments on commit 7b8454f

Please sign in to comment.