diff --git a/dist/obfuscate.js b/dist/obfuscate.js index a3bd7b6e..8328ea74 100644 --- a/dist/obfuscate.js +++ b/dist/obfuscate.js @@ -76,6 +76,8 @@ function (_Component) { link = "sms:".concat(props.sms); } else if (props.facetime) { link = "facetime:".concat(props.facetime); + } else if (props.href) { + link = props.href; } else if (_typeof(props.children) !== 'object') { link = props.children; } else { @@ -124,13 +126,14 @@ function (_Component) { sms = _this$props.sms, facetime = _this$props.facetime, email = _this$props.email, + href = _this$props.href, headers = _this$props.headers, obfuscate = _this$props.obfuscate, linkText = _this$props.linkText, style = _this$props.style, - others = _objectWithoutProperties(_this$props, ["element", "children", "tel", "sms", "facetime", "email", "headers", "obfuscate", "linkText", "style"]); + others = _objectWithoutProperties(_this$props, ["element", "children", "tel", "sms", "facetime", "email", "href", "headers", "obfuscate", "linkText", "style"]); - var propsList = children || tel || sms || facetime || email; + var propsList = children || tel || sms || facetime || email || href; var obsStyle = _objectSpread({}, style || {}, { unicodeBidi: 'bidi-override', diff --git a/pages/index.js b/pages/index.js index 68087a1a..9b53a8fb 100644 --- a/pages/index.js +++ b/pages/index.js @@ -157,6 +157,12 @@ const headerCode = `
➡️ Facetime: +
+ ➡️ href: + Chat On WhatsApp +
+ ➡️ href: + Skype Me
➡️ Child Elements: diff --git a/src/obfuscate.js b/src/obfuscate.js index 3f04728e..2fb87c8f 100644 --- a/src/obfuscate.js +++ b/src/obfuscate.js @@ -32,6 +32,8 @@ export default class Obfuscate extends Component { link = `sms:${props.sms}` } else if (props.facetime) { link = `facetime:${props.facetime}` + } else if (props.href) { + link = props.href } else if (typeof props.children !== 'object') { link = props.children } else { @@ -81,6 +83,7 @@ export default class Obfuscate extends Component { sms, facetime, email, + href, headers, obfuscate, linkText, @@ -88,7 +91,7 @@ export default class Obfuscate extends Component { ...others } = this.props - const propsList = children || tel || sms || facetime || email + const propsList = children || tel || sms || facetime || email || href const obsStyle = { ...(style || {}), diff --git a/test/obfuscate.test.js b/test/obfuscate.test.js index b406fb13..9f3eb279 100755 --- a/test/obfuscate.test.js +++ b/test/obfuscate.test.js @@ -15,7 +15,7 @@ describe('obfuscate', () => { } }) - test('renders an ofuscated href', () => { + test('renders an obfuscated href', () => { const wrapper = shallow( ) @@ -23,7 +23,7 @@ describe('obfuscate', () => { expect(wrapper.prop('href')).toEqual('obfuscated') }) - test('properly sets location.href when ofuscated email is clicked', () => { + test('properly sets location.href when obfuscated email is clicked', () => { const wrapper = shallow( ) @@ -32,7 +32,7 @@ describe('obfuscate', () => { expect(global.window.location.href).toEqual(`mailto:${testEmail}`) }) - test('properly sets location.href when ofuscated email with headers is clicked', () => { + test('properly sets location.href when obfuscated email with headers is clicked', () => { const headers = { cc: 'dade@zero-cool.af', bcc: 'smith@machina.net', @@ -49,7 +49,7 @@ describe('obfuscate', () => { .join('&')}`) }) - test('properly sets location.href when ofuscated tel is clicked', () => { + test('properly sets location.href when obfuscated tel is clicked', () => { const wrapper = shallow( ) @@ -58,7 +58,17 @@ describe('obfuscate', () => { expect(global.window.location.href).toEqual(`tel:${testTel}`) }) - test('properly sets location.href when ofuscated sms is clicked', () => { + test('properly sets location.href when obfuscated href is clicked', () => { + const wrapper = shallow( + + ) + + wrapper.simulate('click', { preventDefault: () => {} }) + expect(global.window.location.href).toEqual(testTel) + }) + + + test('properly sets location.href when obfuscated sms is clicked', () => { const wrapper = shallow( ) @@ -67,7 +77,7 @@ describe('obfuscate', () => { expect(global.window.location.href).toEqual(`sms:${testTel}`) }) - test('properly sets location.href when ofuscated facetime is clicked', () => { + test('properly sets location.href when obfuscated facetime is clicked', () => { const wrapper = shallow( ) @@ -76,7 +86,7 @@ describe('obfuscate', () => { expect(global.window.location.href).toEqual(`facetime:${testTel}`) }) - test('properly sets location.href when ofuscated without type is clicked', () => { + test('properly sets location.href when obfuscated without type is clicked', () => { const wrapper = shallow( test ) @@ -85,7 +95,7 @@ describe('obfuscate', () => { expect(global.window.location.href).toEqual('test') }) - test('renders an unofuscated href when obfuscate prop equals false', () => { + test('renders an unobfuscated href when obfuscate prop equals false', () => { const wrapper = shallow( ) @@ -94,7 +104,7 @@ describe('obfuscate', () => { expect(wrapper.prop('href')).toEqual(`sms:${testTel}`) }) - test('renders an unofuscated child element left to right when obfuscate prop equals false', () => { + test('renders an unobfuscated child element left to right when obfuscate prop equals false', () => { const wrapper = shallow( ) @@ -103,7 +113,7 @@ describe('obfuscate', () => { expect(wrapper.prop('href')).toEqual(`facetime:${testTel}`) }) - test('renders an unofuscated child element right to left when obfuscated', () => { + test('renders an unobfuscated child element right to left when obfuscated', () => { const wrapper = shallow( )