From 05b00c7342f1aece8ab4c3d9e271159847161b63 Mon Sep 17 00:00:00 2001 From: Jaden Diefenbaugh <jaden.diefenbaugh@idiap.ch> Date: Thu, 9 Aug 2018 11:55:34 -0700 Subject: [PATCH] [js] fixed toolchain issue with multiprocessing code! closes #39 --- .../toolchain/ToolchainEditor.spec.jsx | 51 ++++++++++++++----- conda/js/src/store/index.js | 17 +------ conda/js/src/store/store.js | 32 ++++++++++++ 3 files changed, 73 insertions(+), 27 deletions(-) create mode 100644 conda/js/src/store/store.js diff --git a/conda/js/src/components/toolchain/ToolchainEditor.spec.jsx b/conda/js/src/components/toolchain/ToolchainEditor.spec.jsx index 601ee040..cb73d692 100644 --- a/conda/js/src/components/toolchain/ToolchainEditor.spec.jsx +++ b/conda/js/src/components/toolchain/ToolchainEditor.spec.jsx @@ -3,14 +3,20 @@ import React from 'react'; import { expect } from 'chai'; import { mount } from 'enzyme'; import sinon from 'sinon'; +import { Provider } from 'react-redux'; import { spies } from '@test'; +import { getValidToolchainObj as getValidObj, getValidDatabaseObj, getValidAlgorithmObj } from '@helpers/beat'; import { ToolchainEditor as C } from '.'; +import * as Selectors from '@store/selectors'; +import createStoreFunc from '@store/store'; +import reducer from '@store/reducers'; import testTcs from '@test/test_tcs.json'; +import testDbs from '@test/test_dbs.json'; +import testAlgs from '@test/test_algs.json'; -// TODO: fix web workers breaking tests -describe.skip('<ToolchainEditor />', () => { +describe('<ToolchainEditor />', () => { let wrapper; afterEach(() => { @@ -19,24 +25,45 @@ describe.skip('<ToolchainEditor />', () => { }); describe('accepts', () => { - const tcs = [ - ].concat(testTcs); + const tcs = testTcs.map(tc => getValidObj(tc)); + const dbs = testDbs.map(db => getValidDatabaseObj(db)); + const algs = testAlgs.map(alg => getValidAlgorithmObj(alg)); + + const state = { + ...reducer({}, { type: '', payload: {}}), + toolchain: tcs, + database: dbs, + algorithm: algs, + }; + + const sets = Selectors.flattenedDatabases(state); + const normalAlgorithms = Selectors.normalBlocks(state); + const analyzerAlgorithms = Selectors.analyzerBlocks(state); + const store = createStoreFunc(state); tcs.forEach(function(tc){ const saveFunc = () => {}; + const updateFunc = () => {}; it(`${ tc.name }`, () => { wrapper = mount( - <C - data={tc} - toolchains={tcs} - saveFunc={saveFunc} - /> + <Provider store={store}> + <C + data={tc} + sets={sets} + toolchains={state.toolchain} + databases={state.database} + normalAlgorithms={normalAlgorithms} + analyzerAlgorithms={analyzerAlgorithms} + saveFunc={saveFunc} + updateFunc={updateFunc} + /> + </Provider> ); - expect(wrapper).to.have.props( - ['data', 'toolchains', 'saveFunc'] + expect(wrapper.find(C)).to.have.props( + ['data', 'toolchains', 'databases', 'normalAlgorithms', 'analyzerAlgorithms', 'saveFunc', 'updateFunc'] ).deep.equal( - [tc, tcs, saveFunc] + [tc, tcs, state.database, normalAlgorithms, analyzerAlgorithms, saveFunc, updateFunc] ); }); }); diff --git a/conda/js/src/store/index.js b/conda/js/src/store/index.js index 9ddcb5fd..78296f71 100644 --- a/conda/js/src/store/index.js +++ b/conda/js/src/store/index.js @@ -1,21 +1,8 @@ // @flow -// builds the store and fetches the objects -import { createStore, applyMiddleware, compose } from 'redux'; -import reducer from './reducers'; -import thunk from 'redux-thunk'; +import createStore from './store'; import { fetchAllObjects } from './actions.js'; -const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; - -const preloadedState = {}; -const store = createStore( - reducer, - composeEnhancers( - applyMiddleware( - thunk, - ), - ), -); +const store = createStore(); export default store; diff --git a/conda/js/src/store/store.js b/conda/js/src/store/store.js new file mode 100644 index 00000000..3c4fc9bd --- /dev/null +++ b/conda/js/src/store/store.js @@ -0,0 +1,32 @@ +// @flow +// builds the store and fetches the objects +import { createStore, applyMiddleware, compose } from 'redux'; +import reducer from './reducers'; +import type { State } from './reducers'; +import thunk from 'redux-thunk'; + +const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; + +const createStoreFunc = (preloadedState?: State) => { + return preloadedState ? + createStore( + reducer, + preloadedState, + composeEnhancers( + applyMiddleware( + thunk, + ), + ), + ) + : + createStore( + reducer, + composeEnhancers( + applyMiddleware( + thunk, + ), + ), + ); +}; + +export default createStoreFunc; -- GitLab