Skip to content

Commit f24b93e

Browse files
committed
Add tests for "two data points on the same spot"
1 parent 921f39b commit f24b93e

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/worldmap.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,49 @@ describe('Worldmap', () => {
345345
});
346346
});
347347

348+
describe('when the data has two points at the same spot', () => {
349+
beforeEach(() => {
350+
ctrl.data = new DataBuilder()
351+
.withCountryAndValue('SE', 1)
352+
.withCountryAndValue('SE', 2)
353+
.build();
354+
worldMap.drawCircles();
355+
});
356+
357+
it('should draw just one circle on the map', () => {
358+
expect(worldMap.circles.length).toBe(1);
359+
});
360+
361+
it('should create a single circle popup with both data point values', () => {
362+
expect(worldMap.circles[0]._popup._content).toBe('Sweden: 1\nSweden: 2');
363+
});
364+
});
365+
366+
describe('when the data is updated with two points at the same spot', () => {
367+
beforeEach(() => {
368+
ctrl.data = new DataBuilder()
369+
.withCountryAndValue('SE', 1)
370+
.withCountryAndValue('IE', 1)
371+
.build();
372+
worldMap.drawCircles();
373+
374+
ctrl.data = new DataBuilder()
375+
.withCountryAndValue('SE', 1)
376+
.withCountryAndValue('IE', 1)
377+
.withCountryAndValue('SE', 2)
378+
.build();
379+
worldMap.drawCircles();
380+
});
381+
382+
it('should draw just one circle on the map', () => {
383+
expect(worldMap.circles.length).toBe(2);
384+
});
385+
386+
it('should create a single circle popup with both data point values', () => {
387+
expect(worldMap.circles[0]._popup._content).toBe('Sweden: 1\nSweden: 2');
388+
});
389+
});
390+
348391
afterEach(() => {
349392
const fixture: HTMLElement = document.getElementById('fixture')!;
350393
document.body.removeChild(fixture);

src/worldmap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,14 @@ export default class WorldMap {
193193
// Create circle.
194194
if (circles_by_key[dataPoint.key] == undefined) {
195195
circle = this.createCircle(dataPoint);
196+
circles.push(circle);
196197
circles_by_key[dataPoint.key] = circle;
197198

198199
// Amend popup content if circle has been created already.
199200
} else {
200201
circle = circles_by_key[dataPoint.key];
201202
this.extendPopupContent(circle, dataPoint);
202203
}
203-
circles.push(circle);
204204
});
205205
this.circlesLayer = this.addCircles(circles);
206206
this.circles = circles;

test/data_builder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export default class DataBuilder {
3535
value: value,
3636
valueRounded: value,
3737
};
38+
} else {
39+
throw new Error(`Unable to create fixture for country code ${countryCode}`);
3840
}
3941
this.data.push(dataPoint);
4042

0 commit comments

Comments
 (0)