From 7e6c3d132f8dfea32297642098e4124c7ac86bcd Mon Sep 17 00:00:00 2001
From: Jaden Diefenbaugh <jaden.diefenbaugh@idiap.ch>
Date: Mon, 20 Aug 2018 15:51:59 -0700
Subject: [PATCH] [js][tc] start expanding tests

---
 .../components/toolchain/GraphicalEditor.jsx  |  2 +-
 .../toolchain/ToolchainEditor.spec.jsx        | 59 ++++++++++++++++++-
 2 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/conda/js/src/components/toolchain/GraphicalEditor.jsx b/conda/js/src/components/toolchain/GraphicalEditor.jsx
index 71063bf1..860aa27c 100644
--- a/conda/js/src/components/toolchain/GraphicalEditor.jsx
+++ b/conda/js/src/components/toolchain/GraphicalEditor.jsx
@@ -583,7 +583,7 @@ export default class GraphicalEditor extends React.PureComponent<Props, State> {
 	}
 
 	// show a little black dot signifying the closest grid point to the current mouse location.
-	// left-clicking the svg background will use this location for its context menu's actions (e.g. adding/pasting blocks).
+	// right-clicking the svg background will use this location for its context menu's actions (e.g. adding/pasting blocks).
 	initD3MouseMovement = () => {
 		// mouse movement
 		setTimeout(() => {
diff --git a/conda/js/src/components/toolchain/ToolchainEditor.spec.jsx b/conda/js/src/components/toolchain/ToolchainEditor.spec.jsx
index cb73d692..451cdd56 100644
--- a/conda/js/src/components/toolchain/ToolchainEditor.spec.jsx
+++ b/conda/js/src/components/toolchain/ToolchainEditor.spec.jsx
@@ -69,7 +69,64 @@ describe('<ToolchainEditor />', () => {
 		});
 	});
 
-	describe('creates', () => {
+	describe.only('creates', () => {
+		const tcs = [];
+		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);
+
+		it(`test/iris/1`, () => {
+			const saveFunc = sinon.spy();
+			const _updateFunc = (obj) => {
+				wrapper.setProps && wrapper.setProps({ data: obj });
+			};
+			const updateFunc = sinon.spy(_updateFunc);
+			const tcName = 'test/iris/1';
+			const tc = getValidObj({name: tcName, contents: {}});
+			wrapper = mount(
+				<Provider store={store}>
+					<C
+						data={tc}
+						sets={sets}
+						toolchains={state.toolchain}
+						databases={state.database}
+						normalAlgorithms={normalAlgorithms}
+						analyzerAlgorithms={analyzerAlgorithms}
+						saveFunc={saveFunc}
+						updateFunc={updateFunc}
+					/>
+				</Provider>
+			);
 
+			const cWrapper = wrapper.find(C);
+
+			expect(cWrapper).to.have.props(
+				['data', 'toolchains', 'databases', 'normalAlgorithms', 'analyzerAlgorithms', 'saveFunc', 'updateFunc']
+			);
+
+			expect(cWrapper.props().data).to.have.property('name', tcName);
+
+			// add lots of blocks
+			const _selectBlocks = (bNames: string[]) => { return; };
+			const selectBlocks = sinon.spy(_selectBlocks);
+
+			// pretend to right click at a spot by calling the event handler
+			cWrapper.instance().handleSvgContextMenu({}, { clicked: 'addDataset', x: 1, y: 1, selectBlocks });
+			wrapper.update();
+			expect(updateFunc.callCount).to.equal(1);
+			console.log(JSON.stringify(cWrapper.props().data.contents, null, 4));
+			expect(cWrapper.props().data.contents.datasets.length).to.equal(1);
+		});
 	});
 });
-- 
GitLab