Skip to content

Commit 27e042a

Browse files
committed
Minor test refactoring
1 parent 315f889 commit 27e042a

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ refreshing the page will be sufficient.
1818
2. Bundle plugin in dev mode: `npx yarn dev`
1919
3. Bundle plugin in dev mode and start a watcher: `npx yarn watch`
2020
4. Run the tests before submitting a PR: `npx yarn test`
21-
21+
5. Run specific tests: `npx yarn test --testNamePattern "when some fields"`
2222

2323
# Building the Grafana Map Panel
2424
1. Install packages: `npx yarn install`

src/worldmap.test.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,26 @@ describe('WorldmapFoundation', () => {
460460
});
461461
});
462462

463+
function setupInteractionMocks() {
464+
465+
// Setup interaction mock for "window.location.assign".
466+
// https://remarkablemark.org/blog/2018/11/17/mock-window-location/
467+
Object.defineProperty(window.location, 'assign', {
468+
configurable: true,
469+
});
470+
window.location.assign = jest.fn();
471+
472+
// Setup interaction mock for "window.open".
473+
Object.defineProperty(window, 'open',{
474+
configurable: true,
475+
});
476+
window.open = jest.fn();
477+
478+
}
479+
463480
describe('ClickthroughLinks', () => {
464481
/*
465-
* These tests proof the clickthrough link works.
482+
* These tests proof that "clickthrough links" work.
466483
*
467484
* See also https://community.hiveeyes.org/t/developing-grafana-worldmap-ng/1824/13
468485
*/
@@ -505,17 +522,15 @@ describe('ClickthroughLinks', () => {
505522
});
506523

507524
it('should do its job when actually clicked', () => {
508-
// Setup interaction mock for "window.location.assign".
509-
// https://remarkablemark.org/blog/2018/11/17/mock-window-location/
510-
Object.defineProperty(window.location, 'assign', {
511-
configurable: true,
512-
});
513-
window.location.assign = jest.fn();
525+
526+
// Prepare interaction with window object.
527+
setupInteractionMocks();
514528

515529
// Capture interaction.
516530
worldMap.circles[0].fire('click');
517531
expect(window.location.assign).toHaveBeenCalledWith('http://foo.bar');
518532
});
533+
519534
});
520535

521536
describe('when a Worldmap is created with clickthrough-links enabled to another window', () => {
@@ -537,16 +552,14 @@ describe('ClickthroughLinks', () => {
537552
});
538553

539554
it('should do its job when actually clicked', () => {
540-
// Setup interaction mock for "window.open".
541-
// https://remarkablemark.org/blog/2018/11/17/mock-window-location/
542-
Object.defineProperty(window, 'open', {
543-
configurable: true,
544-
});
545-
window.open = jest.fn();
555+
556+
// Prepare interaction with window object.
557+
setupInteractionMocks();
546558

547559
// Capture interaction.
548560
worldMap.circles[0].fire('click');
549561
expect(window.open).toHaveBeenCalledWith('http://foo.bar', 'test');
550562
});
563+
551564
});
552565
});

0 commit comments

Comments
 (0)