-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5dbd986
commit 1f98e22
Showing
8 changed files
with
115 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const WINDOW_ROUTE_POINTS_KEY = '__MapCountdownRoutePoints' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const ROUTE_OPTIONS_MISSING = `MapCountdown: route points are missing. | ||
Did you include routePoints.js in head section? | ||
Check for more information: https://github.com/dawidjaniga/map-countdown#add-mapcountdown` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`MapCountdown should construct MapCountdown in provided container 1`] = ` | ||
<body> | ||
<div | ||
class="map-countdown" | ||
id="countdown" | ||
/> | ||
</body> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* global document, jest, describe, it, expect, beforeEach, afterAll */ | ||
import cloneDeep from 'lodash/cloneDeep' | ||
import MapCountdown from '../src/map-countdown' | ||
import routePoints from '../test/__fixtures__/routePoints' | ||
import { WINDOW_ROUTE_POINTS_KEY } from '../src/constants' | ||
import { ROUTE_OPTIONS_MISSING_ERROR } from '../src/texts' | ||
jest.mock('../src/map/map') | ||
jest.mock('../src/countdown') | ||
const originalDocument = cloneDeep(document) | ||
|
||
/* eslint-disable no-global-assign */ | ||
describe('MapCountdown', () => { | ||
const spiedConsole = jest.spyOn(console, 'error').mockImplementation() | ||
const key = 'google-generated-api-key' | ||
const options = { | ||
selector: '#countdown', | ||
key: key, | ||
meta: '2019-07-13 11:00:00' | ||
} | ||
|
||
beforeEach(() => { | ||
document = cloneDeep(originalDocument) | ||
window[WINDOW_ROUTE_POINTS_KEY] = routePoints | ||
}) | ||
|
||
afterAll(() => { | ||
document = cloneDeep(originalDocument) | ||
spiedConsole.mockRestore() | ||
delete window[WINDOW_ROUTE_POINTS_KEY] | ||
}) | ||
|
||
it('should construct MapCountdown in provided container', () => { | ||
document.body.innerHTML = `<div id="countdown"></div>` | ||
new MapCountdown(options) // eslint-disable-line no-new | ||
|
||
expect(document.body).toMatchSnapshot() | ||
}) | ||
|
||
it('should delete routePoints from window', () => { | ||
document.body.innerHTML = `<div id="countdown"></div>` | ||
new MapCountdown(options) // eslint-disable-line no-new | ||
expect(window[WINDOW_ROUTE_POINTS_KEY]).not.toBeDefined() | ||
}) | ||
|
||
it('updateMap() should run updatePolygons on Map', () => { | ||
document.body.innerHTML = `<div id="countdown"></div>` | ||
const mapCountdown = new MapCountdown(options) | ||
const args = { | ||
days: 1, | ||
hours: 2 | ||
} | ||
mapCountdown.updateMap(args) | ||
expect(mapCountdown.map.updatePolygons).toBeCalledWith( | ||
...Object.values(args) | ||
) | ||
}) | ||
|
||
it('should print error in console when routePoints is missing', () => { | ||
delete window[WINDOW_ROUTE_POINTS_KEY] | ||
document.body.innerHTML = `<div id="countdown"></div>` | ||
new MapCountdown(options) // eslint-disable-line no-new | ||
|
||
expect(spiedConsole).toBeCalledWith(ROUTE_OPTIONS_MISSING_ERROR) | ||
}) | ||
}) | ||
|
||
/* eslint-enable no-global-assign */ |