Skip to content

Commit

Permalink
feat(countdown): Pass configuration object to Countdown
Browse files Browse the repository at this point in the history
  • Loading branch information
janigowski committed Jun 21, 2019
1 parent e60b8e0 commit 0053112
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
8 changes: 6 additions & 2 deletions examples/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
window.addEventListener('DOMContentLoaded', function () {
var countdown = new MapCountdown({
selector: '#countdown',
key: 'google_api_key',
key: 'AIzaSyDcmgIuq0hlMuvj0kGQqpZcDVFvR5Vft8Y',
routePoints: routePoints
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/countdown.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
2 changes: 1 addition & 1 deletion src/map-countdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions test/countdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0053112

Please sign in to comment.