console.log('onEdit'),
onDelete: () => console.log('onDelete'),
}
+
+export const withoutHttps = Template.bind({})
+withoutHttps.args = {
+ id: 'abcd',
+ text: 'Google Googledy',
+ url: 'www.google.com',
+ onEdit: () => console.log('onEdit'),
+ onDelete: () => console.log('onDelete'),
+}
diff --git a/src/components/__tests__/ShortcutIcon.test.js b/src/components/__tests__/ShortcutIcon.test.js
index c294fba1..ab30da63 100644
--- a/src/components/__tests__/ShortcutIcon.test.js
+++ b/src/components/__tests__/ShortcutIcon.test.js
@@ -29,6 +29,16 @@ describe('ShortcutIcon component', () => {
expect(wrapper.find(Link).prop('to')).toEqual(mockProps.url)
})
+ it('has an https link with url property', () => {
+ const ShortcutIcon = require('src/components/ShortcutIcon').default
+ const mockProps = {
+ ...getMockProps(),
+ url: 'www.google.com',
+ }
+ const wrapper = mount()
+ expect(wrapper.find(Link).prop('to')).toEqual('http://www.google.com')
+ })
+
it('displays abbreviated version of link name along with full title', () => {
const ShortcutIcon = require('src/components/ShortcutIcon').default
const mockProps = getMockProps()
diff --git a/src/utils/__tests__/urls.test.js b/src/utils/__tests__/urls.test.js
index 6c74b3d5..78555854 100644
--- a/src/utils/__tests__/urls.test.js
+++ b/src/utils/__tests__/urls.test.js
@@ -35,3 +35,10 @@ describe('Urls: getSquadsLink', () => {
)
})
})
+
+describe('addProtocolToURLIfNeeded', () => {
+ it('appends https if applicable', () => {
+ const { addProtocolToURLIfNeeded } = require('src/utils/urls')
+ expect(addProtocolToURLIfNeeded('test-user')).toBe('http://test-user')
+ })
+})
diff --git a/src/utils/urls.js b/src/utils/urls.js
index 03063d44..38320da6 100644
--- a/src/utils/urls.js
+++ b/src/utils/urls.js
@@ -1,3 +1,5 @@
+/* eslint no-useless-escape: 0 */
+
import ensureValuesAreDefined from 'src/utils/ensureValuesAreDefined'
import { withBasePath } from 'src/utils/navigationUtils'
import { MEDIA_ENDPOINT } from 'src/utils/constants'
@@ -108,3 +110,16 @@ export const shopLandingURL = 'https://shop.gladly.io/'
export const groupImpactLeaderboardFAQ =
'https://gladly.zendesk.com/hc/en-us/articles/17622871939725-Leaderboards'
+
+export const addProtocolToURLIfNeeded = (url) => {
+ const hasProtocol = (s) => {
+ const regexp =
+ /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
+ return regexp.test(s)
+ }
+
+ if (!hasProtocol(url)) {
+ return `http://${url}`
+ }
+ return url
+}