diff --git a/conda/js/src/components/toolchain/ToolchainEditor.spec.jsx b/conda/js/src/components/toolchain/ToolchainEditor.spec.jsx index 601ee0404ef7e270ee15a16ed6e03a11d1c1c308..cb73d692110036bacf11e2e2c4a01d0f3db6f2e7 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 9ddcb5fdae43b736ef36660ee8eeb82667cfd071..78296f7110aac7a5800ee13c57322fb8293b412e 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 0000000000000000000000000000000000000000..3c4fc9bde082f91b37b2cb7c378c9e2114032dbb --- /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;