diff --git a/conda/js/src/components/toolchain/ToolchainEditor.spec.jsx b/conda/js/src/components/toolchain/ToolchainEditor.spec.jsx index 15a67644a07b88e7c838dea534c6b929eeec702c..0756590ae7813a381018296fa69ba5f971fe4567 100644 --- a/conda/js/src/components/toolchain/ToolchainEditor.spec.jsx +++ b/conda/js/src/components/toolchain/ToolchainEditor.spec.jsx @@ -638,4 +638,262 @@ describe('<ToolchainEditor />', function() { }); }); }); + + describe.only('Insert Object Modal', () => { + const timeout = (ms) => { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + 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 protocols = Selectors.databaseProtocols(state); + const analyzerAlgorithms = Selectors.analyzerBlocks(state); + + it(`inserts test/iris_advanced/1`, async () => { + const saveFunc = sinon.spy(); + const _updateFunc = (obj) => { + wrapper.setProps && wrapper.setProps({ data: obj }); + }; + const updateFunc = sinon.spy(_updateFunc); + const tcName = 'test/iom/1'; + const tc = getValidObj({name: tcName, contents: {}}); + wrapper = mount( + <C + data={tc} + sets={sets} + protocols={protocols} + toolchains={state.toolchain} + databases={state.database} + normalAlgorithms={normalAlgorithms} + analyzerAlgorithms={analyzerAlgorithms} + saveFunc={saveFunc} + updateFunc={updateFunc} + /> + ); + + expect(wrapper).to.have.props( + ['data', 'sets', 'protocols', 'toolchains', 'databases', 'normalAlgorithms', 'analyzerAlgorithms', 'saveFunc', 'updateFunc'] + ); + + expect(wrapper.props().data).to.have.property('name', tcName); + + const _selectBlocks = (bNames: string[]) => { return; }; + const selectBlocks = sinon.spy(_selectBlocks); + + // context-menu insert obj modal + // insert at x:6 because thats where the original toolchain has its first block on the x-axis + wrapper.instance().handleSvgContextMenu({}, { clicked: 'addObject', x: 6, y: 0, selectBlocks }); + wrapper.update(); + expect(wrapper.find('InsertObjectModal').props().active).to.equal(true); + expect(updateFunc.callCount).to.equal(0); + + // search for "test/iris" in toolchain list + wrapper.find('InsertObjectModal Input[placeholder="Search..."]').prop('onChange')( { target: { value: 'test/iris' }}); + wrapper.update(); + + // wait for fuse process to search & return result list + await timeout(1000); + wrapper.update(); + + // click on the iris_advanced one, which should be first + const res = wrapper.find('ListGroup.searchResults ListGroupItem'); + expect(res).to.have.lengthOf(4); + expect(res.at(0).html()).to.include('test/iris_advanced/1'); + res.at(0).simulate('click'); + wrapper.update(); + + const data = wrapper.props().data; + const ch1 = data.contents.representation.channel_colors['training_data']; + const ch2 = data.contents.representation.channel_colors['testing_data']; + + // make sure the toolchain was inserted + // basically make sure the toolchain is the same as test/iris_advanced/1 but w different name + expect(data.contents).to.deep.equalInAnyOrder({ + 'analyzers': [ + { + 'inputs': [ + 'scores', + 'species' + ], + 'name': 'analyzer', + 'synchronized_channel': 'testing_data' + } + ], + 'blocks': [ + { + 'inputs': [ + 'measurements', + 'species' + ], + 'name': 'training_alg', + 'outputs': [ + 'lda_machine' + ], + 'synchronized_channel': 'training_data' + }, + { + 'inputs': [ + 'lda_machine', + 'measurements' + ], + 'name': 'testing_alg', + 'outputs': [ + 'scores' + ], + 'synchronized_channel': 'testing_data' + }, + { + 'inputs': [ + 'measurements' + ], + 'name': 'pre_training', + 'outputs': [ + 'measurements' + ], + 'synchronized_channel': 'training_data' + }, + { + 'inputs': [ + 'measurements' + ], + 'name': 'pre_testing', + 'outputs': [ + 'measurements' + ], + 'synchronized_channel': 'testing_data' + } + ], + 'connections': [ + { + 'channel': 'testing_data', + 'from': 'testing_alg.scores', + 'to': 'analyzer.scores' + }, + { + 'channel': 'training_data', + 'from': 'training_alg.lda_machine', + 'to': 'testing_alg.lda_machine' + }, + { + 'channel': 'testing_data', + 'from': 'testing_data.species', + 'to': 'analyzer.species' + }, + { + 'channel': 'training_data', + 'from': 'training_data.species', + 'to': 'training_alg.species' + }, + { + 'channel': 'training_data', + 'from': 'training_data.measurements', + 'to': 'pre_training.measurements' + }, + { + 'channel': 'training_data', + 'from': 'pre_training.measurements', + 'to': 'training_alg.measurements' + }, + { + 'channel': 'testing_data', + 'from': 'testing_data.measurements', + 'to': 'pre_testing.measurements' + }, + { + 'channel': 'testing_data', + 'from': 'pre_testing.measurements', + 'to': 'testing_alg.measurements' + } + ], + 'datasets': [ + { + 'name': 'training_data', + 'outputs': [ + 'measurements', + 'species' + ] + }, + { + 'name': 'testing_data', + 'outputs': [ + 'measurements', + 'species' + ] + } + ], + 'description': '', + 'representation': { + 'blocks': { + 'analyzer': { + 'col': 59, + 'height': 3, + 'row': 6, + 'width': 10 + }, + 'pre_testing': { + 'col': 19, + 'height': 3, + 'row': 5, + 'width': 10 + }, + 'pre_training': { + 'col': 19, + 'height': 3, + 'row': 0, + 'width': 10 + }, + 'testing_alg': { + 'col': 46, + 'height': 3, + 'row': 5, + 'width': 10 + }, + 'testing_data': { + 'col': 6, + 'height': 3, + 'row': 6, + 'width': 10 + }, + 'training_alg': { + 'col': 32, + 'height': 3, + 'row': 1, + 'width': 10 + }, + 'training_data': { + 'col': 6, + 'height': 3, + 'row': 1, + 'width': 10 + } + }, + 'channel_colors': { + 'testing_data': ch2, + 'training_data': ch1 + }, + 'connections': { + 'pre_testing.measurements/testing_alg.measurements': [], + 'pre_training.measurements/training_alg.measurements': [], + 'testing_alg.scores/analyzer.scores': [], + 'testing_data.measurements/pre_testing.measurements': [], + 'testing_data.species/analyzer.species': [], + 'training_alg.lda_machine/testing_alg.lda_machine': [], + 'training_data.measurements/pre_training.measurements': [], + 'training_data.species/training_alg.species': [] + } + } + }); + }); + }); });