From 493e245f9a612c4478bca024cb6e5fc9d6a78d59 Mon Sep 17 00:00:00 2001 From: Ben Verbeken Date: Thu, 24 Jan 2019 09:10:55 +0100 Subject: [PATCH 1/2] don't pass chartJsUrl to the designer/renderer/EM config --- src/main/Embeddable.js | 6 +++--- src/test/SeatsioDesigner.test.js | 20 +++++++++++++++++++- src/test/SeatsioEventManager.test.js | 19 ++++++++++++++++++- src/test/SeatsioSeatingChart.test.js | 22 +++++++++++++++++++--- 4 files changed, 59 insertions(+), 8 deletions(-) diff --git a/src/main/Embeddable.js b/src/main/Embeddable.js index c09b5e3..6d8b427 100644 --- a/src/main/Embeddable.js +++ b/src/main/Embeddable.js @@ -6,9 +6,9 @@ export default class Embeddable extends React.Component { async componentDidMount() { let seatsio = await this.getSeatsio(); - let {id, className, onRenderStarted, ...config} = this.props; + let {id, className, onRenderStarted, chartJsUrl, ...config} = this.props; config.divId = this.props.id; - config.chartJsUrl = this.props.chartJsUrl; + this.chartJsUrl = chartJsUrl; let chart = this.createChart(seatsio, config).render(); this.chart = chart; if (this.props.onRenderStarted) this.props.onRenderStarted(chart); @@ -32,7 +32,7 @@ export default class Embeddable extends React.Component { let script = document.createElement('script'); script.onload = () => resolve(seatsio); script.onerror = () => reject(`Could not load ${script.src}`); - script.src = this.props.chartJsUrl; + script.src = this.chartJsUrl; document.head.appendChild(script); }); } diff --git a/src/test/SeatsioDesigner.test.js b/src/test/SeatsioDesigner.test.js index 2c85bb7..2f619b4 100644 --- a/src/test/SeatsioDesigner.test.js +++ b/src/test/SeatsioDesigner.test.js @@ -35,6 +35,25 @@ describe("SeatsioDesigner", () => { }); it('passes parameters onto the designer', () => { + return new Promise(resolve => { + mount( + { + expect(chart.props).toEqual({ + divId: 'someID', + designerKey: 'aDesignerKey', + }); + resolve(); + }}/> + ); + }); + }); + + + it('does not pass chartJsUrl onto the designer', () => { return new Promise(resolve => { mount( { expect(chart.props).toEqual({ divId: 'someID', designerKey: 'aDesignerKey', - chartJsUrl: 'https://www.google.com' }); resolve(); }}/> diff --git a/src/test/SeatsioEventManager.test.js b/src/test/SeatsioEventManager.test.js index f4e6372..fed6595 100644 --- a/src/test/SeatsioEventManager.test.js +++ b/src/test/SeatsioEventManager.test.js @@ -35,6 +35,24 @@ describe("SeatsioEventManager", () => { }); it('passes parameters onto the event manager', () => { + return new Promise(resolve => { + mount(( + { + expect(chart.props).toEqual({ + divId: 'someID', + publicKey: 'aPublicKey', + }); + resolve(); + }}/> + )); + }); + }); + + it('does not pass chartJsUrl onto the event manager', () => { return new Promise(resolve => { mount(( { expect(chart.props).toEqual({ divId: 'someID', publicKey: 'aPublicKey', - chartJsUrl:"https://www.google.com" }); resolve(); }}/> diff --git a/src/test/SeatsioSeatingChart.test.js b/src/test/SeatsioSeatingChart.test.js index bc245b8..cf956eb 100644 --- a/src/test/SeatsioSeatingChart.test.js +++ b/src/test/SeatsioSeatingChart.test.js @@ -40,8 +40,7 @@ describe("SeatsioSeatingChart", () => { { expect(chart.props).toEqual({ - divId: "chart", - chartJsUrl:"https://cdn.seatsio.net/chart.js" + divId: "chart" }); resolve(); }}/> @@ -66,6 +65,24 @@ describe("SeatsioSeatingChart", () => { }); it('passes parameters onto the chart', () => { + return new Promise(resolve => { + mount(( + { + expect(chart.props).toEqual({ + divId: 'someID', + publicKey: 'aPublicKey', + }); + resolve(); + }}/> + )); + }); + }); + + it('does not pass chartJsUrl onto the chart', () => { return new Promise(resolve => { mount(( { expect(chart.props).toEqual({ divId: 'someID', publicKey: 'aPublicKey', - chartJsUrl:"https://www.google.com" }); resolve(); }}/> From 98cdc624d4125b8fbfb0004794c93852b56ec81f Mon Sep 17 00:00:00 2001 From: Ben Verbeken Date: Thu, 24 Jan 2019 09:26:42 +0100 Subject: [PATCH 2/2] code cleanup --- src/main/Embeddable.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/Embeddable.js b/src/main/Embeddable.js index 6d8b427..9c96ecd 100644 --- a/src/main/Embeddable.js +++ b/src/main/Embeddable.js @@ -5,13 +5,20 @@ import React from 'react'; export default class Embeddable extends React.Component { async componentDidMount() { - let seatsio = await this.getSeatsio(); - let {id, className, onRenderStarted, chartJsUrl, ...config} = this.props; + const seatsio = await this.getSeatsio(); + const config = this.extractConfigFromProps(); config.divId = this.props.id; - this.chartJsUrl = chartJsUrl; - let chart = this.createChart(seatsio, config).render(); + const chart = this.createChart(seatsio, config).render(); this.chart = chart; - if (this.props.onRenderStarted) this.props.onRenderStarted(chart); + if (this.props.onRenderStarted) { + this.props.onRenderStarted(chart); + } + } + + extractConfigFromProps() { + // noinspection JSUnusedLocalSymbols + let {id, className, onRenderStarted, chartJsUrl, ...config} = this.props; + return config; } componentWillUnmount() { @@ -32,7 +39,7 @@ export default class Embeddable extends React.Component { let script = document.createElement('script'); script.onload = () => resolve(seatsio); script.onerror = () => reject(`Could not load ${script.src}`); - script.src = this.chartJsUrl; + script.src = this.props.chartJsUrl; document.head.appendChild(script); }); }