Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Open external URLs on openUrl event - Closes #787 #788

Merged
merged 6 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import App from './components/app';
import store from './store';
import i18n from './i18n'; // initialized i18next instance
import proxyLogin from './utils/proxyLogin';
import externalLinks from './utils/externalLinks';
import env from './constants/env';

if (env.production) {
proxyLogin.init();
externalLinks.init();
}

const rootElement = document.getElementById('app');
Expand Down
15 changes: 15 additions & 0 deletions src/utils/externalLinks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import history from '../history';

export default {
init: () => {
const { ipc } = window;
const protocolReg = /[lL][iI][sS][kK]:\/\//;

if (ipc) {
ipc.on('openUrl', (action, url) => {
history.push(url.replace(protocolReg, '/'));
});
}
},
};

26 changes: 26 additions & 0 deletions src/utils/externalLinks.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { expect } from 'chai';
import { spy } from 'sinon';
import externalLinks from './externalLinks';

describe('externalLinks', () => {
const ipc = {
on: spy(),
};

describe('init', () => {
it('should be a function', () => {
expect(typeof externalLinks.init).to.be.equal('function');
});

it('calling init when ipc is not on window should do nothing', () => {
externalLinks.init();
expect(ipc.on).to.not.have.been.calledWith();
});

it('calling init when ipc is available on window should bind listeners', () => {
window.ipc = ipc;
externalLinks.init();
expect(ipc.on).to.have.been.calledWith();
});
});
});