From 3285edb2296a753488e28b6b5ad06d9d0a374c34 Mon Sep 17 00:00:00 2001 From: chentsulin Date: Tue, 15 May 2018 00:09:28 +0800 Subject: [PATCH] support cta_text --- README.md | 25 ++++++++++++ src/MessengerSendToMessenger.js | 39 ++++++++++++++++++- .../MessengerSendToMessenger.spec.js | 16 ++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2935f33..2577068 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,30 @@ static propTypes = { color: PropTypes.string, size: PropTypes.string, enforceLogin: PropTypes.bool, + ctaText: PropTypes.oneOf([ + 'GET_THIS_IN_MESSENGER', + 'RECEIVE_THIS_IN_MESSENGER', + 'SEND_THIS_TO_ME', + 'GET_CUSTOMER_ASSISTANCE', + 'GET_CUSTOMER_SERVICE', + 'GET_SUPPORT', + 'LET_US_CHAT', + 'SEND_ME_MESSAGES', + 'ALERT_ME_IN_MESSENGER', + 'SEND_ME_UPDATES', + 'MESSAGE_ME', + 'LET_ME_KNOW', + 'KEEP_ME_UPDATED', + 'TELL_ME_MORE', + 'SUBSCRIBE_IN_MESSENGER', + 'SUBSCRIBE_TO_UPDATES', + 'GET_MESSAGES', + 'SUBSCRIBE', + 'GET_STARTED_IN_MESSENGER', + 'LEARN_MORE_IN_MESSENGER', + 'GET_STARTED', + 'SEND_TO_MESSENGER', + ]), autoLogAppEvents: PropTypes.bool, xfbml: PropTypes.bool, version: PropTypes.string, @@ -64,6 +88,7 @@ static defaultProps = { color: 'blue', size: 'large', enforceLogin: false, + ctaText: undefined, autoLogAppEvents: true, xfbml: true, version: '2.11', diff --git a/src/MessengerSendToMessenger.js b/src/MessengerSendToMessenger.js index d41e1e4..60dfec3 100644 --- a/src/MessengerSendToMessenger.js +++ b/src/MessengerSendToMessenger.js @@ -10,6 +10,30 @@ export default class MessengerSendToMessenger extends Component { color: PropTypes.string, size: PropTypes.string, enforceLogin: PropTypes.bool, + ctaText: PropTypes.oneOf([ + 'GET_THIS_IN_MESSENGER', + 'RECEIVE_THIS_IN_MESSENGER', + 'SEND_THIS_TO_ME', + 'GET_CUSTOMER_ASSISTANCE', + 'GET_CUSTOMER_SERVICE', + 'GET_SUPPORT', + 'LET_US_CHAT', + 'SEND_ME_MESSAGES', + 'ALERT_ME_IN_MESSENGER', + 'SEND_ME_UPDATES', + 'MESSAGE_ME', + 'LET_ME_KNOW', + 'KEEP_ME_UPDATED', + 'TELL_ME_MORE', + 'SUBSCRIBE_IN_MESSENGER', + 'SUBSCRIBE_TO_UPDATES', + 'GET_MESSAGES', + 'SUBSCRIBE', + 'GET_STARTED_IN_MESSENGER', + 'LEARN_MORE_IN_MESSENGER', + 'GET_STARTED', + 'SEND_TO_MESSENGER', + ]), autoLogAppEvents: PropTypes.bool, xfbml: PropTypes.bool, version: PropTypes.string, @@ -22,6 +46,7 @@ export default class MessengerSendToMessenger extends Component { color: 'blue', size: 'large', enforceLogin: false, + ctaText: undefined, autoLogAppEvents: true, xfbml: true, version: '2.11', @@ -69,11 +94,22 @@ export default class MessengerSendToMessenger extends Component { } createMarkup() { - const { pageId, appId, dataRef, color, size, enforceLogin } = this.props; + const { + pageId, + appId, + dataRef, + color, + size, + enforceLogin, + ctaText, + } = this.props; const dataRefAttribute = dataRef !== undefined ? `data-ref="${dataRef}"` : ''; + const ctaTextAttribute = + ctaText !== undefined ? `cta_text="${ctaText}"` : ''; + return { __html: `
`, }; } diff --git a/src/__tests__/MessengerSendToMessenger.spec.js b/src/__tests__/MessengerSendToMessenger.spec.js index 5878b98..1c92fe6 100644 --- a/src/__tests__/MessengerSendToMessenger.spec.js +++ b/src/__tests__/MessengerSendToMessenger.spec.js @@ -87,6 +87,22 @@ describe('', () => { ).toBe('true'); }); + it('render cta_text to DOM element', () => { + const wrapper = mount( + + ); + expect( + wrapper + .render() + .find('.fb-send-to-messenger') + .prop('cta_text') + ).toBe('GET_THIS_IN_MESSENGER'); + }); + it('define fbAsyncInit and call loadSdkAsynchronously when facebook-jssdk does not exist', () => { mount();