From 0053112be38d54b8826c9748cd97a9f2db9dc561 Mon Sep 17 00:00:00 2001 From: Dawid Janiga Date: Sat, 22 Jun 2019 00:52:19 +0200 Subject: [PATCH] feat(countdown): Pass configuration object to Countdown --- examples/bundle.js | 8 ++++++-- examples/index.html | 2 +- src/countdown.js | 2 +- src/map-countdown.js | 2 +- test/countdown.spec.js | 10 +++++----- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/examples/bundle.js b/examples/bundle.js index 7cec510..c9b7650 100644 --- a/examples/bundle.js +++ b/examples/bundle.js @@ -82,9 +82,11 @@ var MapCountdown = (function () { var Countdown = /*#__PURE__*/ function () { - function Countdown(containerElement) { + function Countdown(_ref) { var _this = this; + var containerElement = _ref.containerElement; + _classCallCheck(this, Countdown); this.containerElement = containerElement; @@ -527,7 +529,9 @@ var MapCountdown = (function () { this.containerElement = document.querySelector(selector); this.containerElement.classList.add('map-countdown'); - this.countdown = new Countdown(this.containerElement); + this.countdown = new Countdown({ + containerElement: this.containerElement + }); this.map = new Map({ key: key, containerElement: this.containerElement diff --git a/examples/index.html b/examples/index.html index 42150df..0d4c717 100644 --- a/examples/index.html +++ b/examples/index.html @@ -11,7 +11,7 @@ window.addEventListener('DOMContentLoaded', function () { var countdown = new MapCountdown({ selector: '#countdown', - key: 'google_api_key', + key: 'AIzaSyDcmgIuq0hlMuvj0kGQqpZcDVFvR5Vft8Y', routePoints: routePoints }) }) diff --git a/src/countdown.js b/src/countdown.js index 0983abf..e57d2fd 100644 --- a/src/countdown.js +++ b/src/countdown.js @@ -1,5 +1,5 @@ export default class Countdown { - constructor (containerElement) { + constructor ({ containerElement }) { this.containerElement = containerElement this.countdownContainer = document.createElement('div') this.countdownContainer.classList.add('map-countdown__countdown') diff --git a/src/map-countdown.js b/src/map-countdown.js index 1565cba..62242d3 100644 --- a/src/map-countdown.js +++ b/src/map-countdown.js @@ -6,7 +6,7 @@ export default class MapCountdown { constructor ({ selector, routePoints, key }) { this.containerElement = document.querySelector(selector) this.containerElement.classList.add('map-countdown') - this.countdown = new Countdown(this.containerElement) + this.countdown = new Countdown({ containerElement: this.containerElement }) this.map = new Map({ key, containerElement: this.containerElement diff --git a/test/countdown.spec.js b/test/countdown.spec.js index 49cb0d8..8791410 100644 --- a/test/countdown.spec.js +++ b/test/countdown.spec.js @@ -14,15 +14,15 @@ describe('Countdown', () => { }) it('should construct MapCountdown in provided container', () => { - const container = document.createElement('div') - const countdown = new Countdown(container) + const containerElement = document.createElement('div') + const countdown = new Countdown({ containerElement }) expect(countdown).toBeDefined() - expect(container).toMatchSnapshot() + expect(containerElement).toMatchSnapshot() }) it('should start timer', () => { const containerElement = document.createElement('div') - const countdown = new Countdown(containerElement) + const countdown = new Countdown({ containerElement }) const elementName = 'hours' const value = 10 countdown.setElementValue(elementName, value) @@ -50,7 +50,7 @@ describe('Countdown', () => { it('should start setInterval', () => { jest.useFakeTimers() const containerElement = document.createElement('div') - new Countdown(containerElement) // eslint-disable-line no-new + new Countdown({ containerElement }) // eslint-disable-line no-new expect(setInterval).toHaveBeenCalledTimes(1) expect(setInterval).toHaveBeenLastCalledWith(expect.any(Function), 1000)