Skip to content

Commit e9bf88a

Browse files
authored
feat(SocialShare): url encoding the social share icons (#91)
1 parent ffe3514 commit e9bf88a

File tree

4 files changed

+73
-6
lines changed

4 files changed

+73
-6
lines changed

package-lock.json

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"babel-plugin-quintype-assets": "^1.1.1",
5151
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
5252
"jest": "^24.8.0",
53+
"jest-dom": "^3.2.2",
5354
"onchange": "^4.1.0",
5455
"react-dom": "^16.8.6",
5556
"react-testing-library": "^7.0.0",

src/components/social-share.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ class SocialShareBase extends React.Component {
3232
const hashtags = this.props.hashtags ? this.props.hashtags : '';
3333

3434
return React.createElement(this.props.template, Object.assign({
35-
fbUrl: `https://www.facebook.com/sharer.php?u=${fullUrl}`,
36-
twitterUrl: `https://twitter.com/intent/tweet?url=${fullUrl}&text=${this.props.title}&hashtags=${hashtags}`,
37-
gplusUrl: `https://plus.google.com/share?url=${fullUrl}`,
38-
linkedinUrl: `https://www.linkedin.com/shareArticle?url=${fullUrl}&title=${this.props.title}`,
39-
whatsappUrl: `https://api.whatsapp.com/send?text=${fullUrl}`,
40-
mailtoUrl: `mailto:${''}?subject=${this.props.title}&body=${fullUrl}`,
35+
fbUrl: `https://www.facebook.com/sharer.php?u=${encodeURIComponent(fullUrl)}`,
36+
twitterUrl: `https://twitter.com/intent/tweet?url=${encodeURIComponent(fullUrl)}&text=${encodeURIComponent(this.props.title)}&hashtags=${hashtags}`,
37+
gplusUrl: `https://plus.google.com/share?url=${encodeURIComponent(fullUrl)}`,
38+
linkedinUrl: `https://www.linkedin.com/shareArticle?url=${encodeURIComponent(fullUrl)}&title=${encodeURIComponent(this.props.title)}`,
39+
whatsappUrl: `https://api.whatsapp.com/send?text=${encodeURIComponent(fullUrl)}`,
40+
mailtoUrl: `mailto:${''}?subject=${encodeURIComponent(this.props.title)}&body=${encodeURIComponent(fullUrl)}`,
4141
handleNativeShare: getNativeShareHandler(this.state.canNativeShare, this.props.title, fullUrl)
4242
}, this.props));
4343
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { SocialShare } from '..';
2+
import { Provider } from 'react-redux';
3+
import { render, cleanup } from 'react-testing-library';
4+
import 'jest-dom/extend-expect'
5+
import { createStore } from 'redux';
6+
import React from 'react';
7+
8+
afterEach(cleanup);
9+
10+
describe("SocialShare", () => {
11+
it("URL encodes the title for twitter", () => {
12+
const {container} = render(
13+
<Provider store={createStore(x => x, { qt: { config: {} } })}>
14+
<SocialShare
15+
fullUrl="https://www.google.com"
16+
title="Amazing Link"
17+
hashtags="awesome"
18+
template={({ twitterUrl }) => <span>{twitterUrl}</span>} />
19+
</Provider>
20+
)
21+
22+
expect(container.firstChild).toHaveTextContent("https://twitter.com/intent/tweet?url=https%3A%2F%2Fwww.google.com&text=Amazing%20Link&hashtags=awesome");
23+
});
24+
})

0 commit comments

Comments
 (0)