From ceedb212128f56c11b3cce71ff8be9483699514c Mon Sep 17 00:00:00 2001 From: Steve Mckellar Date: Tue, 20 Aug 2019 11:17:28 +0100 Subject: [PATCH 1/2] decodeURIComponent for url imported protocols --- src/ducks/modules/__tests__/importProtocol.test.js | 11 +++++++++-- src/ducks/modules/importProtocol.js | 7 ++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/ducks/modules/__tests__/importProtocol.test.js b/src/ducks/modules/__tests__/importProtocol.test.js index bc79f60ecc..370a12b55b 100644 --- a/src/ducks/modules/__tests__/importProtocol.test.js +++ b/src/ducks/modules/__tests__/importProtocol.test.js @@ -1,7 +1,14 @@ /* eslint-env jest */ -import reducer, { initialState } from '../importProtocol'; +import reducer, { initialState, helpers } from '../importProtocol'; + +describe('importProtocol', () => { + describe('helpers', () => { + it('filenameFromURI should correctly extract protocol name', () => { + const exampleUrl = 'https://documentation.networkcanvas.com/protocols/Public%20Health%20Protocol.netcanvas?foo=bar#bazz'; + expect(helpers.filenameFromURI(exampleUrl)).toEqual('Public Health Protocol.netcanvas'); + }); + }); -describe('protocol module', () => { describe('reducer', () => { it('should return the initial state', () => { expect( diff --git a/src/ducks/modules/importProtocol.js b/src/ducks/modules/importProtocol.js index 66409ce520..00dad83d84 100644 --- a/src/ducks/modules/importProtocol.js +++ b/src/ducks/modules/importProtocol.js @@ -121,7 +121,8 @@ const cleanUpProtocol = (uid) => { const cancelledImport = () => Promise.reject(new CancellationError('Import cancelled.')); -const filenameFromURI = uri => uri.split('/').pop().split('#')[0].split('?')[0]; +const filenameFromURI = uri => + decodeURIComponent(uri.split('/').pop().split('#')[0].split('?')[0]); const filenameFromPath = path => path.split(/.*[/|\\]/)[1]; @@ -228,6 +229,9 @@ const importProtocolFromFile = filePath => (dispatch, getState) => { ); }; +const helpers = { + filenameFromURI, +}; const actionCreators = { importProtocolFromURI, @@ -256,4 +260,5 @@ const actionTypes = { export { actionCreators, actionTypes, + helpers, }; From 99f0ce9d19c6fcefd4e089eca730f57967130cbb Mon Sep 17 00:00:00 2001 From: Steve Mckellar Date: Tue, 20 Aug 2019 11:18:42 +0100 Subject: [PATCH 2/2] Delete commented out importProtocol tests --- .../modules/__tests__/importProtocol.test.js | 153 ------------------ 1 file changed, 153 deletions(-) diff --git a/src/ducks/modules/__tests__/importProtocol.test.js b/src/ducks/modules/__tests__/importProtocol.test.js index 370a12b55b..a5a346b224 100644 --- a/src/ducks/modules/__tests__/importProtocol.test.js +++ b/src/ducks/modules/__tests__/importProtocol.test.js @@ -15,158 +15,5 @@ describe('importProtocol', () => { reducer(undefined, {}), ).toEqual(initialState); }); - - // TODO: rewrite these to account for the new import thunk flow. - // it('setProtocol() sets protocol on state and changes the loaded state', () => { - // expect( - // reducer( - // initialState, - // actionCreators.setProtocol( - // '/tmp/foo/mockPath.protocol', - // { stages: [{ foo: 'bar' }] }, - // ), - // ), - // ).toEqual({ - // ...initialState, - // path: '/tmp/foo/mockPath.protocol', - // stages: [{ foo: 'bar' }], - // isLoaded: true, - // isLoading: false, - // }); - // }); - - // it('downloadProtocol()', () => { - // expect( - // reducer( - // initialState, - // actionCreators.downloadProtocol( - // 'https://tmp/foo/mockPath.protocol', - // ), - // ), - // ).toEqual({ - // ...initialState, - // isLoaded: false, - // isLoading: true, - // }); - // }); - - // it('importProtocol()', () => { - // expect( - // reducer( - // initialState, - // actionCreators.importProtocol( - // '/tmp/foo/mockPath.protocol', - // ), - // ), - // ).toEqual({ - // ...initialState, - // isLoaded: false, - // isLoading: true, - // }); - // }); - - // it('loadProtocol()', () => { - // expect( - // reducer( - // initialState, - // actionCreators.loadProtocol( - // '/tmp/foo/mockPath.protocol', - // ), - // ), - // ).toEqual({ - // ...initialState, - // isLoaded: false, - // isLoading: true, - // type: 'download', - // }); - // }); - - // it('loadFactoryProtocol()', () => { - // expect( - // reducer( - // initialState, - // actionCreators.loadFactoryProtocol( - // '/tmp/foo/mockPath.protocol', - // ), - // ), - // ).toEqual({ - // ...initialState, - // isLoaded: false, - // isLoading: true, - // }); - // }); - - // it('should clear protocol state when session ends', () => { - // const newState = reducer( - // initialState, - // actionCreators.setProtocol( - // '/tmp/foo/mockPath.protocol', - // { stages: [{ foo: 'bar' }] }, - // ), - // ); - // expect( - // reducer(newState, { type: SessionActionTypes.END_SESSION }), - // ).toEqual(initialState); - // }); }); - - // describe('epics', () => { - // beforeAll(() => { - // getEnvironment.mockReturnValue(environments.ELECTRON); - // }); - - // it('downloadProtocolEpic', () => { - // const action$ = ActionsObservable.of( - // actionCreators.downloadProtocol('https://tmp/foo/mockPath.protocol'), - // ); - - // const expectedActions = - // [actionCreators.importProtocol('/downloaded/protocol/to/temp/path')]; - // return epics(action$).toArray().toPromise().then((result) => { - // expect(result).toEqual(expectedActions); - // }); - // }); - - // it('importProtocolEpic', () => { - // const action$ = ActionsObservable.of( - // actionCreators.importProtocol('/downloaded/protocol/to/temp/path'), - // ); - - // const expectedActions = [actionCreators.loadProtocol('/app/data/protocol/path')]; - // return epics(action$).toArray().toPromise().then((result) => { - // expect(result.map(element => omit(element, 'sessionId'))).toEqual( - // expectedActions.map(action => omit(action, 'sessionId'))); - // }); - // }); - - // it('loadProtocolEpic', () => { - // const action$ = ActionsObservable.of( - // actionCreators.loadProtocol('/app/data/protocol/path'), - // ); - - // const expectedAction = actionCreators.setProtocol( - // '/app/data/protocol/path', - // { fake: { installedProtocols: { json: true } } }, - // false, - // ); - // return epics(action$).toArray().toPromise().then((result) => { - // expect(result).toContainEqual(expectedAction); - // }); - // }); - - // it('loadFactoryProtocolEpic', () => { - // const action$ = ActionsObservable.of( - // actionCreators.loadFactoryProtocol('factory_protocol_name'), - // ); - - // const expectedAction = actionCreators.setProtocol( - // 'factory_protocol_name', - // { fake: { factory: { installedProtocols: { json: true } } } }, - // true, - // ); - // return epics(action$).toArray().toPromise().then((result) => { - // expect(result).toContainEqual(expectedAction); - // }); - // }); - // }); });