ExperimentEditor.spec.jsx 19.1 KB
Newer Older
1
2
3
4
5
6
7
8
// @flow
import React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import sinon from 'sinon';
import { spies } from '@test';

import * as Selectors from '@store/selectors.js';
9
import { ExperimentEditor as C } from '.';
10
import {  getValidExperimentObj as getValidObj } from '@helpers/beat';
11
12
13
14
15
16

import testAlgs from '@test/test_algs.json';
import testDbs from '@test/test_dbs.json';
import testExps from '@test/test_exps.json';
import testTcs from '@test/test_tcs.json';

17
18
const envs = {
	'Scientific Python 2.7': {
19
20
21
22
		name: 'Scientific Python 2.7',
		version: '1.0.0',
		queues: {
			Default: {}
23
24
		},
		packages: {}
25
	}
26
};
27

28
describe('<ExperimentEditor />', () => {
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
	let wrapper;
	const normalBlocks = Selectors.normalBlocks({ algorithm: testAlgs });
	const analyzerBlocks = Selectors.analyzerBlocks({ algorithm: testAlgs });
	const datasets = Selectors.flattenedDatabases({ database: testDbs });

	afterEach(() => {
		if(wrapper && wrapper.unmount)
			wrapper.unmount();
	});

	describe('accepts', () => {
		const exps = [
		].concat(testExps);

		exps.forEach(function(exp){
44
45
			if(exp.name !== 'user/user/single/1/single_add')
				return;
46
			const saveFunc = () => {};
47
			const updateFunc = () => {};
48
49
50
51
52
53
54
55
56
57
58
59
			const tc = testTcs.find(tc => exp.name.includes(tc.name));

			it(`${ exp.name }`, () => {
				wrapper = mount(
					<C
						data={exp}
						experiments={exps}
						normalBlocks={normalBlocks}
						analyzerBlocks={analyzerBlocks}
						datasets={datasets}
						toolchain={tc}
						saveFunc={saveFunc}
60
						environments={envs}
61
						updateFunc={updateFunc}
62
63
64
65
					/>
				);

				expect(wrapper).to.have.props(
66
					['data', 'experiments', 'normalBlocks', 'analyzerBlocks', 'datasets', 'toolchain', 'saveFunc', 'environments', 'updateFunc']
67
68
69
70
71
				);
			});
		});
	});

72
	describe('creates', () => {
73
74
75
		it(`user/user/single/1/single_add`, () => {
			const expName = 'user/user/single/1/single_add';
			const saveFunc = sinon.spy();
76
77
78
79
			const _updateFunc = (obj) => {
				wrapper.setProps && wrapper.setProps({ data: obj });
			};
			const updateFunc = sinon.spy(_updateFunc);
80
81
82
			const tc = testTcs.find(tc => expName.includes(tc.name));
			wrapper = mount(
				<C
83
					data={getValidObj({name: expName, contents: {}}, tc, [...normalBlocks, ...analyzerBlocks])}
84
85
86
87
88
89
					experiments={[]}
					normalBlocks={normalBlocks}
					analyzerBlocks={analyzerBlocks}
					datasets={datasets}
					toolchain={tc}
					saveFunc={saveFunc}
90
					environments={envs}
91
					updateFunc={updateFunc}
92
93
94
				/>
			);

95
96
			//console.log('doing name');

97
			expect(wrapper.props().data).to.have.property('name', expName);
98

99
100
			//console.log('finished name change, doing dataset');

101
			wrapper.find('svg #block_set').simulate('click');
102
			wrapper.find('div.dataset0 select').simulate('change', { target: { value: 'protocol/set (simple/1)'}});
103
104
			expect(updateFunc.callCount).to.equal(1);
			expect(wrapper.props().data.contents).to.have.deep.property('datasets', {
105
106
107
108
109
110
111
				'set': {
					'set': 'set',
					'protocol': 'protocol',
					'database': 'simple/1'
				}
			});

112
113
114
			//console.log('finished dataset, doing block');

			wrapper.find('svg #block_echo').simulate('click');
115
			expect(wrapper.find({ name: 'echo', set: 'blocks'}).find('.tcBlockBackground').prop('className')).to.include('highlighted');
116
			wrapper.find('div.block0 div.algorithm select').at(0).simulate('change', { target: { value: 'user/integers_add/1'}});
117
118
			expect(updateFunc.callCount).to.equal(2);
			expect(wrapper.props().data.contents).to.have.deep.property('blocks', {
119
120
121
122
123
124
125
126
127
128
129
130
				'echo': {
					'inputs': {
						'in_data': 'in'
					},
					'algorithm': 'user/integers_add/1',
					'outputs': {
						'out_data': 'out'
					},
					parameters: {}
				}
			});

131
132
133
			//console.log('finished block, doing analyzer');

			wrapper.find('svg #block_analysis').simulate('click');
134
			expect(wrapper.find({ name: 'analysis', set: 'analyzers'}).find('.tcBlockBackground').prop('className')).to.include('highlighted');
135
			wrapper.find('div.block0 div.algorithm select').at(0).simulate('change', { target: { value: 'user/integers_echo_analyzer/1'}});
136
137
			expect(updateFunc.callCount).to.equal(3);
			expect(wrapper.props().data.contents).to.have.deep.property('analyzers', {
138
139
140
141
142
143
144
145
146
				'analysis': {
					'inputs': {
						'in_data': 'in'
					},
					'algorithm': 'user/integers_echo_analyzer/1',
					parameters: {},
				}
			});

147
148
			//console.log('finished analyzer, doing env');

149
			wrapper.find('.globals select.env').simulate('change', { target: { value: 'Scientific Python 2.7 (1.0.0)'}});
150
			expect(updateFunc.callCount).to.equal(4);
151
			wrapper.find('.globals select.queue').simulate('change', { target: { value: 'Default'}});
152
153
			expect(updateFunc.callCount).to.equal(5);
			expect(wrapper.props().data.contents).to.have.deep.property('globals', {
154
				'queue': 'Default',
155
				'environment': {
156
157
					'version': '1.0.0',
					'name': 'Scientific Python 2.7'
158
159
160
161
162
163
				},
				'user/integers_add/1': {
					offset: 1
				},
			});

164
165
			//console.log('finished env, doing cache check');

166
			expect(wrapper.props().data).to.be.deep.equal({
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
				'name': 'user/user/single/1/single_add',
				'contents': {
					description: '',
					'analyzers': {
						'analysis': {
							'inputs': {
								'in_data': 'in'
							},
							'algorithm': 'user/integers_echo_analyzer/1',
							parameters: {},
						}
					},
					'datasets': {
						'set': {
							'set': 'set',
							'protocol': 'protocol',
							'database': 'simple/1'
						}
					},
					'blocks': {
						'echo': {
							'inputs': {
								'in_data': 'in'
							},
							'algorithm': 'user/integers_add/1',
							'outputs': {
								'out_data': 'out'
							},
							parameters: {}
						}
					},
					'globals': {
199
						'queue': 'Default',
200
						'environment': {
201
202
							'version': '1.0.0',
							'name': 'Scientific Python 2.7'
203
204
205
206
207
208
209
210
						},
						'user/integers_add/1': {
							offset: 1
						},
					}
				}
			});
		});
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238

		// tests:
		// - assigning protocol for datasets
		// - copy block algs
		it('test/test/iris_advanced/1/iris', () => {
			const expName ='test/test/iris_advanced/1/iris';
			const saveFunc = sinon.spy();
			const _updateFunc = (obj) => {
				wrapper.setProps && wrapper.setProps({ data: obj });
			};
			const updateFunc = sinon.spy(_updateFunc);
			const tc = testTcs.find(tc => expName.includes(tc.name));
			wrapper = mount(
				<C
					data={getValidObj({name: expName, contents: {}}, tc, [...normalBlocks, ...analyzerBlocks])}
					experiments={[]}
					normalBlocks={normalBlocks}
					analyzerBlocks={analyzerBlocks}
					datasets={datasets}
					toolchain={tc}
					saveFunc={saveFunc}
					environments={envs}
					updateFunc={updateFunc}
				/>
			);

			expect(wrapper.props().data).to.have.property('name', expName);

239
			//console.log('doing dataset');
240

241
			wrapper.find('svg #block_training_data').simulate('click');
242
			wrapper.find('div.datasets select').at(0).simulate('change', { target: { value: '{"testing_data":{"database":"iris/1","protocol":"Main","set":"testing"},"training_data":{"database":"iris/1","protocol":"Main","set":"training"}}'}});
243
244
245
246
247
			expect(updateFunc.callCount).to.equal(1);
			expect(wrapper.props().data.contents).to.have.deep.property('datasets', {
				'testing_data': {
					'database': 'iris/1',
					'protocol': 'Main',
248
					'set': 'testing'
249
250
251
252
				},
				'training_data': {
					'database': 'iris/1',
					'protocol': 'Main',
253
					'set': 'training'
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
				}
			});

			//console.log('finished dataset, doing preprocessor blocks');

			wrapper.find('svg #block_pre_training').simulate('click');
			expect(wrapper.find({ name: 'pre_training', set: 'blocks'}).find('.tcBlockBackground').prop('className')).to.include('highlighted');
			wrapper.find('div.block0 div.algorithm select').at(0).simulate('change', { target: { value: 'test/iris_preprocessor/1'}});
			//console.log('finished preprocessor_training, copying alg to other preprocessors');
			expect(updateFunc.callCount).to.equal(2);
			wrapper.find('div.block0 div.algorithm button').at(0).simulate('click');
			expect(updateFunc.callCount).to.equal(3);

			expect(wrapper.props().data.contents).to.have.deep.property('blocks', {
				'pre_testing': {
					'algorithm': 'test/iris_preprocessor/1',
					'inputs': {
						'measurements': 'measurements'
					},
					'outputs': {
						'measurements': 'measurements'
					},
					'parameters': {}
				},
				'pre_training': {
					'algorithm': 'test/iris_preprocessor/1',
					'inputs': {
						'measurements': 'measurements'
					},
					'outputs': {
						'measurements': 'measurements'
					},
					'parameters': {}
				},
				'testing_alg': {
					'algorithm': '',
					'inputs': {
						'lda_machine': '',
						'measurements': ''
					},
					'outputs': {
						'scores': ''
					},
					'parameters': {}
				},
				'training_alg': {
					'algorithm': '',
					'inputs': {
						'measurements': '',
						'species': ''
					},
					'outputs': {
						'lda_machine': ''
					},
					'parameters': {}
				}
			});

			//console.log('finished preprocessors, doing training');

			wrapper.find('svg #block_training_alg').simulate('click');
			expect(wrapper.find({ name: 'training_alg', set: 'blocks'}).find('.tcBlockBackground').prop('className')).to.include('highlighted');
			wrapper.find('div.block0 div.algorithm select').at(0).simulate('change', { target: { value: 'test/iris_training/1'}});
			expect(updateFunc.callCount).to.equal(4);
			expect(wrapper.props().data.contents).to.have.deep.property('blocks', {
				'pre_testing': {
					'algorithm': 'test/iris_preprocessor/1',
					'inputs': {
						'measurements': 'measurements'
					},
					'outputs': {
						'measurements': 'measurements'
					},
					'parameters': {}
				},
				'pre_training': {
					'algorithm': 'test/iris_preprocessor/1',
					'inputs': {
						'measurements': 'measurements'
					},
					'outputs': {
						'measurements': 'measurements'
					},
					'parameters': {}
				},
				'testing_alg': {
					'algorithm': '',
					'inputs': {
						'lda_machine': '',
						'measurements': ''
					},
					'outputs': {
						'scores': ''
					},
					'parameters': {}
				},
				'training_alg': {
					'algorithm': 'test/iris_training/1',
					'inputs': {
						'measurements': 'measurements',
						'species': 'species'
					},
					'outputs': {
						'lda_machine': 'lda_machine'
					},
					'parameters': {}
				}
			});

			//console.log('finished training, doing testing');

			wrapper.find('svg #block_testing_alg').simulate('click');
			expect(wrapper.find({ name: 'testing_alg', set: 'blocks'}).find('.tcBlockBackground').prop('className')).to.include('highlighted');
			wrapper.find('div.block0 div.algorithm select').at(0).simulate('change', { target: { value: 'test/iris_testing/1'}});
			expect(updateFunc.callCount).to.equal(5);
			expect(wrapper.props().data.contents).to.have.deep.property('blocks', {
				'pre_testing': {
					'algorithm': 'test/iris_preprocessor/1',
					'inputs': {
						'measurements': 'measurements'
					},
					'outputs': {
						'measurements': 'measurements'
					},
					'parameters': {}
				},
				'pre_training': {
					'algorithm': 'test/iris_preprocessor/1',
					'inputs': {
						'measurements': 'measurements'
					},
					'outputs': {
						'measurements': 'measurements'
					},
					'parameters': {}
				},
				'testing_alg': {
					'algorithm': 'test/iris_testing/1',
					'inputs': {
						'lda_machine': 'lda_machine',
						'measurements': 'measurements'
					},
					'outputs': {
						'scores': 'scores'
					},
					'parameters': {}
				},
				'training_alg': {
					'algorithm': 'test/iris_training/1',
					'inputs': {
						'measurements': 'measurements',
						'species': 'species'
					},
					'outputs': {
						'lda_machine': 'lda_machine'
					},
					'parameters': {}
				}
			});

			//console.log('finished blocks, doing analyzer');

			wrapper.find('svg #block_analyzer').simulate('click');
			expect(wrapper.find({ name: 'analyzer', set: 'analyzers'}).find('.tcBlockBackground').prop('className')).to.include('highlighted');
			wrapper.find('div.block0 div.algorithm select').at(0).simulate('change', { target: { value: 'test/iris_analyzer/1'}});
			expect(updateFunc.callCount).to.equal(6);
			expect(wrapper.props().data.contents).to.have.deep.property('analyzers', {
				'analyzer': {
					'algorithm': 'test/iris_analyzer/1',
					'inputs': {
						'scores': 'scores',
						'species': 'species'
					},
					'parameters': {}
				}
			});

			//console.log('finished analyzer, doing cache check');

			expect(wrapper.props().data).to.be.deep.equal({
				'name': 'test/test/iris_advanced/1/iris',
				'contents': {
					'description': '',
					'analyzers': {
						'analyzer': {
							'algorithm': 'test/iris_analyzer/1',
							'inputs': {
								'scores': 'scores',
								'species': 'species'
							},
							'parameters': {}
						}
					},
					'blocks': {
						'pre_testing': {
							'algorithm': 'test/iris_preprocessor/1',
							'inputs': {
								'measurements': 'measurements'
							},
							'outputs': {
								'measurements': 'measurements'
							},
							'parameters': {}
						},
						'pre_training': {
							'algorithm': 'test/iris_preprocessor/1',
							'inputs': {
								'measurements': 'measurements'
							},
							'outputs': {
								'measurements': 'measurements'
							},
							'parameters': {}
						},
						'testing_alg': {
							'algorithm': 'test/iris_testing/1',
							'inputs': {
								'lda_machine': 'lda_machine',
								'measurements': 'measurements'
							},
							'outputs': {
								'scores': 'scores'
							},
							'parameters': {}
						},
						'training_alg': {
							'algorithm': 'test/iris_training/1',
							'inputs': {
								'measurements': 'measurements',
								'species': 'species'
							},
							'outputs': {
								'lda_machine': 'lda_machine'
							},
							'parameters': {}
						}
					},
					'datasets': {
						'testing_data': {
							'database': 'iris/1',
							'protocol': 'Main',
495
							'set': 'testing'
496
497
498
499
						},
						'training_data': {
							'database': 'iris/1',
							'protocol': 'Main',
500
							'set': 'training'
501
502
503
504
505
506
507
508
509
510
511
512
						}
					},
					'globals': {
						'queue': 'Default',
						'environment': {
							'name': 'Scientific Python 2.7',
							'version': '0.0.4'
						}
					}
				}
			});
		});
513
	});
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613

	describe('Regression Tests', () => {
		it(`clears the 'echo' & 'analysis' blocks from user/user/single/1/single_add`, () => {
			const expName = 'user/user/single/1/single_add';
			const saveFunc = sinon.spy();
			const _updateFunc = (obj) => {
				wrapper.setProps && wrapper.setProps({ data: obj });
			};
			const updateFunc = sinon.spy(_updateFunc);
			const exp = testExps.find(exp => expName === exp.name);
			const tc = testTcs.find(tc => expName.includes(tc.name));
			wrapper = mount(
				<C
					data={getValidObj(exp, tc, [...normalBlocks, ...analyzerBlocks])}
					experiments={[]}
					normalBlocks={normalBlocks}
					analyzerBlocks={analyzerBlocks}
					datasets={datasets}
					toolchain={tc}
					saveFunc={saveFunc}
					environments={envs}
					updateFunc={updateFunc}
				/>
			);

			expect(wrapper.props().data).to.have.property('name', expName);
			expect(wrapper.props().data.contents).to.have.deep.property('blocks', {
				'echo': {
					'inputs': {
						'in_data': 'in'
					},
					'algorithm': 'user/integers_add/1',
					'outputs': {
						'out_data': 'out'
					},
					parameters: {}
				}
			});

			wrapper.find('svg #block_echo').simulate('click');
			wrapper.update();
			wrapper.find('.algorithm button.btn-secondary').simulate('click');
			expect(updateFunc.callCount).to.equal(1);
			expect(wrapper.props().data.contents).to.have.deep.property('blocks',
				{ echo: {
					inputs: {},
					algorithm: '',
					outputs: {},
					parameters: {}
				}}
			);

			wrapper.find('svg #block_analysis').simulate('click');
			wrapper.update();
			wrapper.find('.algorithm button.btn-secondary').simulate('click');
			expect(updateFunc.callCount).to.equal(2);
			expect(wrapper.props().data.contents).to.have.deep.property('analyzers',
				{ analysis: {
					inputs: {},
					algorithm: '',
					parameters: {}
				}}
			);

			expect(wrapper.props().data).to.be.deep.equal({
				'name': 'user/user/single/1/single_add',
				'contents': {
					description: '',
					'analyzers': {
						'analysis': {
							inputs: {},
							algorithm: '',
							parameters: {}
						}
					},
					'datasets': {
						'set': {
							'set': 'set',
							'protocol': 'protocol',
							'database': 'simple/1'
						}
					},
					'blocks': {
						'echo': {
							algorithm: '',
							inputs: {},
							outputs: {},
							parameters: {}
						}
					},
					'globals': {
						'queue': 'queue',
						'environment': {
							'version': '1.2.0',
							'name': 'Python 2.7'
						},
					}
				}
			});
		});
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692

		it(`doesnt change the lockMap after an algorithm or dataset is assigned`, () => {
			const expName = 'user/user/single/1/single_add';
			const saveFunc = sinon.spy();
			const _updateFunc = (obj) => {
				wrapper.setProps && wrapper.setProps({ data: obj });
			};
			const updateFunc = sinon.spy(_updateFunc);
			const tc = testTcs.find(tc => expName.includes(tc.name));
			wrapper = mount(
				<C
					data={getValidObj({name: expName, contents: {}}, tc, [...normalBlocks, ...analyzerBlocks])}
					experiments={[]}
					normalBlocks={normalBlocks}
					analyzerBlocks={analyzerBlocks}
					datasets={datasets}
					toolchain={tc}
					saveFunc={saveFunc}
					environments={envs}
					updateFunc={updateFunc}
				/>
			);

			expect(wrapper.props().data).to.have.property('name', expName);

			//console.log('finished name change, doing dataset');

			wrapper.find('svg #block_set').simulate('click');
			wrapper.find('div.dataset0 select').simulate('change', { target: { value: 'protocol/set (simple/1)'}});
			expect(updateFunc.callCount).to.equal(1);
			expect(wrapper.props().data.contents).to.have.deep.property('datasets', {
				'set': {
					'set': 'set',
					'protocol': 'protocol',
					'database': 'simple/1'
				}
			});

			//console.log('finished dataset, doing block');

			wrapper.find('svg #block_echo').simulate('click');
			expect(wrapper.find({ name: 'echo', set: 'blocks'}).find('.tcBlockBackground').prop('className')).to.include('highlighted');
			wrapper.find('div.block0 div.algorithm select').at(0).simulate('change', { target: { value: 'user/integers_add/1'}});
			expect(updateFunc.callCount).to.equal(2);
			expect(wrapper.props().data.contents).to.have.deep.property('blocks', {
				'echo': {
					'inputs': {
						'in_data': 'in'
					},
					'algorithm': 'user/integers_add/1',
					'outputs': {
						'out_data': 'out'
					},
					parameters: {}
				}
			});

			//console.log('finished block, doing analyzer');

			wrapper.find('svg #block_analysis').simulate('click');
			expect(wrapper.find({ name: 'analysis', set: 'analyzers'}).find('.tcBlockBackground').prop('className')).to.include('highlighted');
			wrapper.find('div.block0 div.algorithm select').at(0).simulate('change', { target: { value: 'user/integers_echo_analyzer/1'}});
			expect(updateFunc.callCount).to.equal(3);
			expect(wrapper.props().data.contents).to.have.deep.property('analyzers', {
				'analysis': {
					'inputs': {
						'in_data': 'in'
					},
					'algorithm': 'user/integers_echo_analyzer/1',
					parameters: {},
				}
			});

			expect(wrapper.state().lockMap).to.deep.equal({
				set: false,
				echo: false,
				analysis: false,
			});
		});
693
	});
694
});