Skip to content

Commit

Permalink
Add href prop
Browse files Browse the repository at this point in the history
  • Loading branch information
Coston Perkins committed Apr 11, 2019
1 parent ce61180 commit 0e0d5d3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
7 changes: 5 additions & 2 deletions dist/obfuscate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ const headerCode = `
<br />
➡️ Facetime:
<Obfuscate facetime="202.224.5744" />
<br />
➡️ href:
<Obfuscate href="https://wa.me/15551234567">Chat On WhatsApp</Obfuscate>
<br/>
➡️ href:
<Obfuscate href="skype:exampleusername">Skype Me</Obfuscate>
<div>
➡️ Child Elements:
<Obfuscate email="[email protected]">
Expand Down
5 changes: 4 additions & 1 deletion src/obfuscate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -81,14 +83,15 @@ export default class Obfuscate extends Component {
sms,
facetime,
email,
href,
headers,
obfuscate,
linkText,
style,
...others
} = this.props

const propsList = children || tel || sms || facetime || email
const propsList = children || tel || sms || facetime || email || href

const obsStyle = {
...(style || {}),
Expand Down
30 changes: 20 additions & 10 deletions test/obfuscate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ describe('obfuscate', () => {
}
})

test('renders an ofuscated href', () => {
test('renders an obfuscated href', () => {
const wrapper = shallow(
<Obfuscate tel={testTel} />
)

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(
<Obfuscate email={testEmail} />
)
Expand All @@ -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: '[email protected]',
bcc: '[email protected]',
Expand All @@ -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(
<Obfuscate tel={testTel} />
)
Expand All @@ -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(
<Obfuscate href={testTel} />
)

wrapper.simulate('click', { preventDefault: () => {} })
expect(global.window.location.href).toEqual(testTel)
})


test('properly sets location.href when obfuscated sms is clicked', () => {
const wrapper = shallow(
<Obfuscate sms={testTel} />
)
Expand All @@ -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(
<Obfuscate facetime={testTel} />
)
Expand All @@ -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(
<Obfuscate>test</Obfuscate>
)
Expand All @@ -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(
<Obfuscate obfuscate={false} sms={testTel} />
)
Expand All @@ -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(
<Obfuscate obfuscate={false} facetime={testTel} />
)
Expand All @@ -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(
<Obfuscate obfuscate={true} tel={testTel} />
)
Expand Down

0 comments on commit 0e0d5d3

Please sign in to comment.